2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2013-12-14 03:47:35 +00:00
|
|
|
/*
|
|
|
|
* crt0 - C-runtime startup Code for AArch64 U-Boot
|
|
|
|
*
|
|
|
|
* (C) Copyright 2013
|
|
|
|
* David Feng <fenghua@phytium.com.cn>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2012
|
|
|
|
* Albert ARIBAUD <albert.u.boot@aribaud.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <asm-offsets.h>
|
|
|
|
#include <asm/macro.h>
|
|
|
|
#include <linux/linkage.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file handles the target-independent stages of the U-Boot
|
|
|
|
* start-up where a C runtime environment is needed. Its entry point
|
|
|
|
* is _main and is branched into from the target's start.S file.
|
|
|
|
*
|
|
|
|
* _main execution sequence is:
|
|
|
|
*
|
|
|
|
* 1. Set up initial environment for calling board_init_f().
|
|
|
|
* This environment only provides a stack and a place to store
|
|
|
|
* the GD ('global data') structure, both located in some readily
|
|
|
|
* available RAM (SRAM, locked cache...). In this context, VARIABLE
|
|
|
|
* global data, initialized or not (BSS), are UNAVAILABLE; only
|
2015-08-01 14:55:46 +00:00
|
|
|
* CONSTANT initialized data are available. GD should be zeroed
|
|
|
|
* before board_init_f() is called.
|
2013-12-14 03:47:35 +00:00
|
|
|
*
|
|
|
|
* 2. Call board_init_f(). This function prepares the hardware for
|
|
|
|
* execution from system RAM (DRAM, DDR...) As system RAM may not
|
|
|
|
* be available yet, , board_init_f() must use the current GD to
|
|
|
|
* store any data which must be passed on to later stages. These
|
|
|
|
* data include the relocation destination, the future stack, and
|
|
|
|
* the future GD location.
|
|
|
|
*
|
|
|
|
* 3. Set up intermediate environment where the stack and GD are the
|
|
|
|
* ones allocated by board_init_f() in system RAM, but BSS and
|
|
|
|
* initialized non-const data are still not available.
|
|
|
|
*
|
2015-08-01 14:55:46 +00:00
|
|
|
* 4a.For U-Boot proper (not SPL), call relocate_code(). This function
|
|
|
|
* relocates U-Boot from its current location into the relocation
|
|
|
|
* destination computed by board_init_f().
|
|
|
|
*
|
|
|
|
* 4b.For SPL, board_init_f() just returns (to crt0). There is no
|
|
|
|
* code relocation in SPL.
|
2013-12-14 03:47:35 +00:00
|
|
|
*
|
|
|
|
* 5. Set up final environment for calling board_init_r(). This
|
|
|
|
* environment has BSS (initialized to 0), initialized non-const
|
|
|
|
* data (initialized to their intended value), and stack in system
|
2015-08-01 14:55:46 +00:00
|
|
|
* RAM (for SPL moving the stack and GD into RAM is optional - see
|
|
|
|
* CONFIG_SPL_STACK_R). GD has retained values set by board_init_f().
|
|
|
|
*
|
|
|
|
* TODO: For SPL, implement stack relocation on AArch64.
|
2013-12-14 03:47:35 +00:00
|
|
|
*
|
2015-08-01 14:55:46 +00:00
|
|
|
* 6. For U-Boot proper (not SPL), some CPUs have some work left to do
|
|
|
|
* at this point regarding memory, so call c_runtime_cpu_setup.
|
|
|
|
*
|
|
|
|
* 7. Branch to board_init_r().
|
|
|
|
*
|
|
|
|
* For more information see 'Board Initialisation Flow in README.
|
2013-12-14 03:47:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
ENTRY(_main)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up initial C runtime environment and call board_init_f(0).
|
|
|
|
*/
|
2017-07-28 18:04:09 +00:00
|
|
|
#if defined(CONFIG_TPL_BUILD) && defined(CONFIG_TPL_NEEDS_SEPARATE_STACK)
|
2017-07-04 09:02:14 +00:00
|
|
|
ldr x0, =(CONFIG_TPL_STACK)
|
|
|
|
#elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
|
2015-03-24 20:25:02 +00:00
|
|
|
ldr x0, =(CONFIG_SPL_STACK)
|
2019-06-26 04:51:46 +00:00
|
|
|
#elif defined(CONFIG_INIT_SP_RELATIVE)
|
2017-12-20 01:30:36 +00:00
|
|
|
adr x0, __bss_start
|
|
|
|
add x0, x0, #CONFIG_SYS_INIT_SP_BSS_OFFSET
|
2015-03-24 20:25:02 +00:00
|
|
|
#else
|
2013-12-14 03:47:35 +00:00
|
|
|
ldr x0, =(CONFIG_SYS_INIT_SP_ADDR)
|
2015-01-31 03:55:28 +00:00
|
|
|
#endif
|
2013-12-14 03:47:35 +00:00
|
|
|
bic sp, x0, #0xf /* 16-byte alignment for ABI compliance */
|
2015-11-25 16:56:32 +00:00
|
|
|
mov x0, sp
|
|
|
|
bl board_init_f_alloc_reserve
|
2015-10-19 12:49:59 +00:00
|
|
|
mov sp, x0
|
2016-01-14 21:03:11 +00:00
|
|
|
/* set up gd here, outside any C code */
|
|
|
|
mov x18, x0
|
2015-11-25 16:56:32 +00:00
|
|
|
bl board_init_f_init_reserve
|
2015-10-19 12:49:59 +00:00
|
|
|
|
2013-12-14 03:47:35 +00:00
|
|
|
mov x0, #0
|
|
|
|
bl board_init_f
|
|
|
|
|
2015-03-24 20:25:02 +00:00
|
|
|
#if !defined(CONFIG_SPL_BUILD)
|
2013-12-14 03:47:35 +00:00
|
|
|
/*
|
|
|
|
* Set up intermediate environment (new sp and gd) and call
|
|
|
|
* relocate_code(addr_moni). Trick here is that we'll return
|
|
|
|
* 'here' but relocated.
|
|
|
|
*/
|
|
|
|
ldr x0, [x18, #GD_START_ADDR_SP] /* x0 <- gd->start_addr_sp */
|
|
|
|
bic sp, x0, #0xf /* 16-byte alignment for ABI compliance */
|
2017-09-22 06:39:13 +00:00
|
|
|
ldr x18, [x18, #GD_NEW_GD] /* x18 <- gd->new_gd */
|
2013-12-14 03:47:35 +00:00
|
|
|
|
|
|
|
adr lr, relocation_return
|
2017-11-03 00:11:27 +00:00
|
|
|
#if CONFIG_POSITION_INDEPENDENT
|
|
|
|
/* Add in link-vs-runtime offset */
|
|
|
|
adr x0, _start /* x0 <- Runtime value of _start */
|
|
|
|
ldr x9, _TEXT_BASE /* x9 <- Linked value of _start */
|
|
|
|
sub x9, x9, x0 /* x9 <- Run-vs-link offset */
|
|
|
|
add lr, lr, x9
|
|
|
|
#endif
|
|
|
|
/* Add in link-vs-relocation offset */
|
2013-12-14 03:47:35 +00:00
|
|
|
ldr x9, [x18, #GD_RELOC_OFF] /* x9 <- gd->reloc_off */
|
|
|
|
add lr, lr, x9 /* new return address after relocation */
|
|
|
|
ldr x0, [x18, #GD_RELOCADDR] /* x0 <- gd->relocaddr */
|
|
|
|
b relocate_code
|
|
|
|
|
|
|
|
relocation_return:
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up final (full) environment
|
|
|
|
*/
|
|
|
|
bl c_runtime_cpu_setup /* still call old routine */
|
2016-07-18 16:01:02 +00:00
|
|
|
#endif /* !CONFIG_SPL_BUILD */
|
2017-03-01 20:04:15 +00:00
|
|
|
#if defined(CONFIG_SPL_BUILD)
|
|
|
|
bl spl_relocate_stack_gd /* may return NULL */
|
2017-12-07 21:16:07 +00:00
|
|
|
/* set up gd here, outside any C code, if new stack is returned */
|
|
|
|
cmp x0, #0
|
|
|
|
csel x18, x0, x18, ne
|
2017-03-01 20:04:15 +00:00
|
|
|
/*
|
|
|
|
* Perform 'sp = (x0 != NULL) ? x0 : sp' while working
|
|
|
|
* around the constraint that conditional moves can not
|
|
|
|
* have 'sp' as an operand
|
|
|
|
*/
|
|
|
|
mov x1, sp
|
|
|
|
cmp x0, #0
|
|
|
|
csel x0, x0, x1, ne
|
|
|
|
mov sp, x0
|
|
|
|
#endif
|
2015-08-01 14:55:46 +00:00
|
|
|
|
2013-12-14 03:47:35 +00:00
|
|
|
/*
|
|
|
|
* Clear BSS section
|
|
|
|
*/
|
|
|
|
ldr x0, =__bss_start /* this is auto-relocated! */
|
|
|
|
ldr x1, =__bss_end /* this is auto-relocated! */
|
|
|
|
clear_loop:
|
2017-01-27 07:15:30 +00:00
|
|
|
str xzr, [x0], #8
|
2013-12-14 03:47:35 +00:00
|
|
|
cmp x0, x1
|
|
|
|
b.lo clear_loop
|
|
|
|
|
|
|
|
/* call board_init_r(gd_t *id, ulong dest_addr) */
|
|
|
|
mov x0, x18 /* gd_t */
|
|
|
|
ldr x1, [x18, #GD_RELOCADDR] /* dest_addr */
|
|
|
|
b board_init_r /* PC relative jump */
|
|
|
|
|
|
|
|
/* NOTREACHED - board_init_r() does not return */
|
|
|
|
|
|
|
|
ENDPROC(_main)
|