2 * armboot - Startup Code for ARM926EJS CPU-core
4 * Copyright (c) 2003 Texas Instruments
6 * ----- Adapted for OMAP1610 OMAP730 from ARM925t code ------
8 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
9 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
10 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
11 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
12 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
13 * Copyright (c) 2010 Albert Aribaud <albert.u.boot@aribaud.net>
15 * SPDX-License-Identifier: GPL-2.0+
18 #include <asm-offsets.h>
24 *************************************************************************
26 * Jump vector table as in table 3.1 in [1]
28 *************************************************************************
32 #ifdef CONFIG_SYS_DV_NOR_BOOT_CFG
37 .word CONFIG_SYS_DV_NOR_BOOT_CFG
44 #ifdef CONFIG_SPL_BUILD
45 /* No exception handlers in preloader */
56 /* pad to 64 byte boundary */
65 ldr pc, _undefined_instruction
66 ldr pc, _software_interrupt
67 ldr pc, _prefetch_abort
73 _undefined_instruction:
74 .word undefined_instruction
76 .word software_interrupt
88 #endif /* CONFIG_SPL_BUILD */
89 .balignl 16,0xdeadbeef
93 *************************************************************************
95 * Startup Code (reset vector)
97 * do important init only if we don't start from memory!
98 * setup Memory and board specific bits prior to relocation.
99 * relocate armboot to ram
102 *************************************************************************
107 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
108 .word CONFIG_SPL_TEXT_BASE
110 .word CONFIG_SYS_TEXT_BASE
114 * These are defined in the board-specific linker script.
115 * Subtracting _start from them lets the linker put their
116 * relative position in the executable instead of leaving
119 .globl _bss_start_ofs
121 .word __bss_start - _start
125 .word __bss_end - _start
131 #ifdef CONFIG_USE_IRQ
132 /* IRQ stack memory (calculated at run-time) */
133 .globl IRQ_STACK_START
137 /* IRQ stack memory (calculated at run-time) */
138 .globl FIQ_STACK_START
143 /* IRQ stack memory (calculated at run-time) + 8 bytes */
144 .globl IRQ_STACK_START_IN
149 * the actual reset code
154 * set the cpu to SVC32 mode
162 * we do sys-critical inits only at reboot,
163 * not when booting from ram!
165 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
171 /*------------------------------------------------------------------------------*/
173 .globl c_runtime_cpu_setup
179 *************************************************************************
181 * CPU_init_critical registers
183 * setup important registers
184 * setup memory timing
186 *************************************************************************
188 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
191 * flush D cache before disabling it
195 mrc p15, 0, r15, c7, c10, 3
198 mcr p15, 0, r0, c8, c7, 0 /* invalidate TLB */
199 mcr p15, 0, r0, c7, c5, 0 /* invalidate I Cache */
202 * disable MMU and D cache
203 * enable I cache if CONFIG_SYS_ICACHE_OFF is not defined
205 mrc p15, 0, r0, c1, c0, 0
206 bic r0, r0, #0x00000300 /* clear bits 9:8 (---- --RS) */
207 bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
208 #ifdef CONFIG_SYS_EXCEPTION_VECTORS_HIGH
209 orr r0, r0, #0x00002000 /* set bit 13 (--V- ----) */
211 bic r0, r0, #0x00002000 /* clear bit 13 (--V- ----) */
213 orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
214 #ifndef CONFIG_SYS_ICACHE_OFF
215 orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
217 mcr p15, 0, r0, c1, c0, 0
220 * Go setup Memory and board specific bits prior to relocation.
222 mov ip, lr /* perserve link reg across call */
223 bl lowlevel_init /* go setup pll,mux,memory */
224 mov lr, ip /* restore link */
225 mov pc, lr /* back to my caller */
226 #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
228 #ifndef CONFIG_SPL_BUILD
230 *************************************************************************
234 *************************************************************************
240 #define S_FRAME_SIZE 72
262 #define MODE_SVC 0x13
266 * use bad_save_user_regs for abort/prefetch/undef/swi ...
267 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
270 .macro bad_save_user_regs
271 @ carve out a frame on current user stack
272 sub sp, sp, #S_FRAME_SIZE
273 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
274 ldr r2, IRQ_STACK_START_IN
275 @ get values for "aborted" pc and cpsr (into parm regs)
277 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
280 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
281 mov r0, sp @ save current stack into r0 (param register)
284 .macro irq_save_user_regs
285 sub sp, sp, #S_FRAME_SIZE
286 stmia sp, {r0 - r12} @ Calling r0-r12
287 @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
289 stmdb r8, {sp, lr}^ @ Calling SP, LR
290 str lr, [r8, #0] @ Save calling PC
292 str r6, [r8, #4] @ Save CPSR
293 str r0, [r8, #8] @ Save OLD_R0
297 .macro irq_restore_user_regs
298 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
300 ldr lr, [sp, #S_PC] @ Get PC
301 add sp, sp, #S_FRAME_SIZE
302 subs pc, lr, #4 @ return & move spsr_svc into cpsr
306 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
308 str lr, [r13] @ save caller lr in position 0 of saved stack
309 mrs lr, spsr @ get the spsr
310 str lr, [r13, #4] @ save spsr in position 1 of saved stack
311 mov r13, #MODE_SVC @ prepare SVC-Mode
313 msr spsr, r13 @ switch modes, make sure moves will execute
314 mov lr, pc @ capture return pc
315 movs pc, lr @ jump to next instruction & switch modes.
318 .macro get_irq_stack @ setup IRQ stack
319 ldr sp, IRQ_STACK_START
322 .macro get_fiq_stack @ setup FIQ stack
323 ldr sp, FIQ_STACK_START
325 #endif /* CONFIG_SPL_BUILD */
330 #ifdef CONFIG_SPL_BUILD
333 ldr sp, _TEXT_BASE /* switch to abort stack */
335 bl 1b /* hang and never return */
336 #else /* !CONFIG_SPL_BUILD */
338 undefined_instruction:
341 bl do_undefined_instruction
347 bl do_software_interrupt
367 #ifdef CONFIG_USE_IRQ
374 irq_restore_user_regs
379 /* someone ought to write a more effiction fiq_save_user_regs */
382 irq_restore_user_regs
399 #endif /* CONFIG_SPL_BUILD */