Merge tag 'xilinx-for-v2018.09-rc2' of git://git.denx.de/u-boot-microblaze
[oweals/u-boot.git] / arch / arm / lib / crt0_64.S
index 9c46c93ca4c5857b9b62d431a7d214ee96754717..d6b632aa87d10952a9b10edfba1013240c5d76e1 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * crt0 - C-runtime startup Code for AArch64 U-Boot
  *
@@ -6,8 +7,6 @@
  *
  * (C) Copyright 2012
  * Albert ARIBAUD <albert.u.boot@aribaud.net>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <config.h>
@@ -73,6 +72,9 @@ ENTRY(_main)
        ldr     x0, =(CONFIG_TPL_STACK)
 #elif defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
        ldr     x0, =(CONFIG_SPL_STACK)
+#elif defined(CONFIG_SYS_INIT_SP_BSS_OFFSET)
+       adr     x0, __bss_start
+       add     x0, x0, #CONFIG_SYS_INIT_SP_BSS_OFFSET
 #else
        ldr     x0, =(CONFIG_SYS_INIT_SP_ADDR)
 #endif
@@ -98,6 +100,14 @@ ENTRY(_main)
        ldr     x18, [x18, #GD_NEW_GD]          /* x18 <- gd->new_gd */
 
        adr     lr, relocation_return
+#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 */
        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 */
@@ -112,6 +122,9 @@ relocation_return:
 #endif /* !CONFIG_SPL_BUILD */
 #if defined(CONFIG_SPL_BUILD)
        bl      spl_relocate_stack_gd           /* may return NULL */
+       /* set up gd here, outside any C code, if new stack is returned */
+       cmp     x0, #0
+       csel    x18, x0, x18, ne
        /*
         * Perform 'sp = (x0 != NULL) ? x0 : sp' while working
         * around the constraint that conditional moves can not