arm64: add an option to switch visibility of CONFIG_SYS_INIT_SP_BSS_OFFSET
[oweals/u-boot.git] / arch / arm / lib / crt0_64.S
index da7c62cbe0aa2ae04eca2ad961e1f02aa5dbe3e2..e76b25a03e8c7621717cc9595c7b2fd5be9807e9 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_INIT_SP_RELATIVE)
+       adr     x0, __bss_start
+       add     x0, x0, #CONFIG_SYS_INIT_SP_BSS_OFFSET
 #else
        ldr     x0, =(CONFIG_SYS_INIT_SP_ADDR)
 #endif
@@ -120,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