[U-Boot] [PATCHv1 15/22] arm: socfpga: spl: add relocate_stack_to_sdram to lowlevel_init.S

dinguyen at opensource.altera.com
2015-01-14T16:40:55Z

From: Dinh Nguyen <dinguyen@opensource.altera.com>

Add a function to relocate the stack from OCRAM to SDRAM.

Signed-off-by: Dinh Nguyen <dinguyen@opensource.altera.com>
---
arch/arm/cpu/armv7/socfpga/lowlevel_init.S | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

diff --git a/arch/arm/cpu/armv7/socfpga/lowlevel_init.S b/arch/arm/cpu/armv7/socfpga/lowlevel_init.S
index ee3c9fa..9ae8e3c 100644
--- a/arch/arm/cpu/armv7/socfpga/lowlevel_init.S
+++ b/arch/arm/cpu/armv7/socfpga/lowlevel_init.S
@@ -52,3 +52,27 @@ clrsp: cmp r0, r1 /* while not at end of BSS */
blo clrsp
#endif /* #ifdef CONFIG_SPL_BUILD */
bx lr
+
+#ifdef CONFIG_SPL_BUILD
+ENTRY(relocate_stack_to_sdram)
+ PUSH {r4-r11, lr} /* save registers per AAPCS */
+
+ mov r0, sp /* [r0] source address */
+ ldr r2, =__stack_start /* [r2] source end address */
+ sub r3, r2, r0
+ ldr r4, =__sdram_stack_start
+ sub r1, r4, r3 /* [r1] target address */
+ mov r5, r1 /* [r5] new sp within SDRAM */
+
+relocate_loop1:
+ ldmia r0!, {r3}
+ stmia r1!, {r3}
+ cmp r0, r2
+ blo relocate_loop1
+
+ /* assign SP to new address within SDRAM now */
+ mov sp, r5
+
+ POP {r4-r11, pc}
+ENDPROC(relocate_stack_to_sdram)
+#endif /* CONFIG_SPL_BUILD */
--
2.2.1