From 4260eff80426b2f38ba02f80b5fadc9b8bd6148f Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Sat, 1 Apr 2017 21:51:34 +0000 Subject: [PATCH] Preserve the registers containing argc, argv, and return address values passed in from u-boot across the call to self_reloc and any other early-init code, and restore them before calling main(). The self_reloc() routine uses r0 and r1 (and calling it uses lr), and depending on what values get left in them, main() would intermittantly lock up trying to interpret them as argc and argv values. This problem affected the self-relocatable ubldr.bin but not ubldr (the elf version). --- sys/boot/arm/uboot/start.S | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/boot/arm/uboot/start.S b/sys/boot/arm/uboot/start.S index 1ef21f3671f0..3f7764f2b7b0 100644 --- a/sys/boot/arm/uboot/start.S +++ b/sys/boot/arm/uboot/start.S @@ -45,6 +45,13 @@ _start: orr ip, ip, #(CPU_CONTROL_AFLT_ENABLE) mcr p15, 0, ip, c1, c0, 0 #endif + + /* + * Save r0 and r1 (argc and argv passed from u-boot), and lr (trashed + * by the call to self_reloc below) until we're ready to call main(). + */ + push {r0, r1, lr} + /* * Do self-relocation when the weak external symbol _DYNAMIC is non-NULL. * When linked as a dynamic relocatable file, the linker automatically @@ -71,9 +78,11 @@ _start: str r9, [ip, #4] /* + * First restore argc, argv, and the u-boot return address, then * Start loader. This is basically a tail-recursion call; if main() * returns, it returns to u-boot (which reports the value returned r0). */ + pop {r0, r1, lr} b main /*