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>
23 *************************************************************************
25 * Jump vector table as in table 3.1 in [1]
27 *************************************************************************
34 ldr pc, _undefined_instruction
35 ldr pc, _software_interrupt
36 ldr pc, _prefetch_abort
42 _undefined_instruction:
43 .word undefined_instruction
45 .word software_interrupt
57 .balignl 16,0xdeadbeef
62 *************************************************************************
64 * Startup Code (reset vector)
66 * do important init only if we don't start from memory!
67 * setup Memory and board specific bits prior to relocation.
68 * relocate armboot to ram
71 *************************************************************************
76 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
77 .word CONFIG_SPL_TEXT_BASE
79 .word CONFIG_SYS_TEXT_BASE
83 * These are defined in the board-specific linker script.
84 * Subtracting _start from them lets the linker put their
85 * relative position in the executable instead of leaving
90 .word __bss_start - _start
94 .word __bss_end - _start
100 #ifdef CONFIG_USE_IRQ
101 /* IRQ stack memory (calculated at run-time) */
102 .globl IRQ_STACK_START
106 /* IRQ stack memory (calculated at run-time) */
107 .globl FIQ_STACK_START
112 /* IRQ stack memory (calculated at run-time) + 8 bytes */
113 .globl IRQ_STACK_START_IN
118 * the actual reset code
123 * set the cpu to SVC32 mode
131 * we do sys-critical inits only at reboot,
132 * not when booting from ram!
134 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
140 /*------------------------------------------------------------------------------*/
142 .globl c_runtime_cpu_setup
148 *************************************************************************
150 * CPU_init_critical registers
152 * setup important registers
153 * setup memory timing
155 *************************************************************************
159 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
162 * flush v4 I/D caches
165 mcr p15, 0, r0, c7, c5, 0 /* flush v4 I-cache */
166 mcr p15, 0, r0, c7, c6, 0 /* flush v4 D-cache */
169 * disable MMU stuff and caches
171 mrc p15, 0, r0, c1, c0, 0
172 bic r0, r0, #0x00002300 /* clear bits 13, 9:8 (--V- --RS) */
173 bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
174 orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
175 orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
176 mcr p15, 0, r0, c1, c0, 0
179 * Go setup Memory and board specific bits prior to relocation.
181 mov ip, lr /* perserve link reg across call */
182 bl lowlevel_init /* go setup memory */
183 mov lr, ip /* restore link */
184 mov pc, lr /* back to my caller */
187 *************************************************************************
191 *************************************************************************
197 #define S_FRAME_SIZE 72
219 #define MODE_SVC 0x13
223 * use bad_save_user_regs for abort/prefetch/undef/swi ...
224 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
227 .macro bad_save_user_regs
228 @ carve out a frame on current user stack
229 sub sp, sp, #S_FRAME_SIZE
230 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
232 ldr r2, IRQ_STACK_START_IN
233 @ get values for "aborted" pc and cpsr (into parm regs)
235 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
238 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
239 mov r0, sp @ save current stack into r0 (param register)
242 .macro irq_save_user_regs
243 sub sp, sp, #S_FRAME_SIZE
244 stmia sp, {r0 - r12} @ Calling r0-r12
245 @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
247 stmdb r8, {sp, lr}^ @ Calling SP, LR
248 str lr, [r8, #0] @ Save calling PC
250 str r6, [r8, #4] @ Save CPSR
251 str r0, [r8, #8] @ Save OLD_R0
255 .macro irq_restore_user_regs
256 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
258 ldr lr, [sp, #S_PC] @ Get PC
259 add sp, sp, #S_FRAME_SIZE
260 subs pc, lr, #4 @ return & move spsr_svc into cpsr
264 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
266 str lr, [r13] @ save caller lr in position 0 of saved stack
267 mrs lr, spsr @ get the spsr
268 str lr, [r13, #4] @ save spsr in position 1 of saved stack
269 mov r13, #MODE_SVC @ prepare SVC-Mode
271 msr spsr, r13 @ switch modes, make sure moves will execute
272 mov lr, pc @ capture return pc
273 movs pc, lr @ jump to next instruction & switch modes.
276 .macro get_irq_stack @ setup IRQ stack
277 ldr sp, IRQ_STACK_START
280 .macro get_fiq_stack @ setup FIQ stack
281 ldr sp, FIQ_STACK_START
288 undefined_instruction:
291 bl do_undefined_instruction
297 bl do_software_interrupt
317 #ifdef CONFIG_USE_IRQ
324 irq_restore_user_regs
329 /* someone ought to write a more effiction fiq_save_user_regs */
332 irq_restore_user_regs
350 # ifdef CONFIG_INTEGRATOR
352 /* Satisfied by general board level routine */
360 ldr r1, rstctl1 /* get clkm1 reset ctl */
362 strh r3, [r1] /* clear it */
364 strh r3, [r1] /* force dsp+arm reset */
371 #endif /* #ifdef CONFIG_INTEGRATOR */