diff mbox

[U-Boot,v6,2/2] arm: move gd handling outside of C code

Message ID 1448109112-7380-2-git-send-email-albert.u.boot@aribaud.net
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Albert ARIBAUD Nov. 21, 2015, 12:31 p.m. UTC
As of gcc 5.2.1 for Thumb-1, it is not possible any
more to assign gd from C code, as gd is mapped to r9,
and r9 may now be saved in the prolog sequence, and
restored in the epilog sequence, of any C functions.

Therefore arch_setup_gd(), which is supposed to set
r9, may actually have no effect, causing U-Boot to
use a bad address to access GD.

Fix this by never calling arch_setup_gd() for ARM,
and instead setting r9 in arch/arm/lib/crt0.S, to
the value returned by board_init_f_alloc_reserve().

Signed-off-by: Albert ARIBAUD <albert.u.boot@aribaud.net>
---

Changes in v6:
- moved ARM r9 fix into its own patch

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/lib/crt0.S      | 2 ++
 common/init/board_init.c | 8 ++++----
 2 files changed, 6 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/arch/arm/lib/crt0.S b/arch/arm/lib/crt0.S
index 4f2a712..9c34f2c 100644
--- a/arch/arm/lib/crt0.S
+++ b/arch/arm/lib/crt0.S
@@ -85,6 +85,8 @@  ENTRY(_main)
 	mov	r0, sp
 	bl	board_init_f_alloc_reserve
 	mov	sp, r0
+	/* set up gd here, outside any C code */
+	mov	r9, r0
 	bl	board_init_f_init_reserve
 
 	mov	r0, #0
diff --git a/common/init/board_init.c b/common/init/board_init.c
index e649e07..d98648e 100644
--- a/common/init/board_init.c
+++ b/common/init/board_init.c
@@ -21,13 +21,13 @@  DECLARE_GLOBAL_DATA_PTR;
 #define _USE_MEMCPY
 #endif
 
-/* Unfortunately x86 can't compile this code as gd cannot be assigned */
-#ifndef CONFIG_X86
+/* Unfortunately x86 or ARM can't compile this code as gd cannot be assigned */
+#if !defined(CONFIG_X86) && !defined(CONFIG_ARM)
 __weak void arch_setup_gd(struct global_data *gd_ptr)
 {
 	gd = gd_ptr;
 }
-#endif /* !CONFIG_X86 */
+#endif /* !CONFIG_X86 && !CONFIG_ARM */
 
 /*
  * Allocate reserved space for use as 'globals' from 'top' address and
@@ -128,7 +128,7 @@  void board_init_f_init_reserve(ulong base)
 		*ptr++ = 0;
 #endif
 	/* set GD unless architecture did it already */
-#ifndef CONFIG_X86
+#if !defined(CONFIG_X86) && !defined(CONFIG_ARM)
 	arch_setup_gd(gd_ptr);
 #endif
 	/* next alloc will be higher by one GD plus 16-byte alignment */