2 * armboot - Startup Code for OMP2420/ARM1136 CPU-core
4 * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
6 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
7 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
8 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
9 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
10 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
12 * SPDX-License-Identifier: GPL-2.0+
15 #include <asm-offsets.h>
20 #ifdef CONFIG_SPL_BUILD
37 .word 0x12345678 /* now 16*4=64 */
39 ldr pc, _undefined_instruction
40 ldr pc, _software_interrupt
41 ldr pc, _prefetch_abort
47 _undefined_instruction: .word undefined_instruction
48 _software_interrupt: .word software_interrupt
49 _prefetch_abort: .word prefetch_abort
50 _data_abort: .word data_abort
51 _not_used: .word not_used
54 _pad: .word 0x12345678 /* now 16*4=64 */
55 #endif /* CONFIG_SPL_BUILD */
59 .balignl 16,0xdeadbeef
61 *************************************************************************
63 * Startup Code (reset vector)
65 * do important init only if we don't start from memory!
66 * setup Memory and board specific bits prior to relocation.
67 * relocate armboot to ram
70 *************************************************************************
75 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
76 .word CONFIG_SPL_TEXT_BASE
78 .word CONFIG_SYS_TEXT_BASE
82 * These are defined in the board-specific linker script.
83 * Subtracting _start from them lets the linker put their
84 * relative position in the executable instead of leaving
89 .word __bss_start - _start
93 .word __bss_end - _start
100 /* IRQ stack memory (calculated at run-time) */
101 .globl IRQ_STACK_START
105 /* IRQ stack memory (calculated at run-time) */
106 .globl FIQ_STACK_START
111 /* IRQ stack memory (calculated at run-time) + 8 bytes */
112 .globl IRQ_STACK_START_IN
117 * the actual reset code
122 * set the cpu to SVC32 mode
129 /* the mask ROM code should have PLL and others stable */
130 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
136 /*------------------------------------------------------------------------------*/
138 .globl c_runtime_cpu_setup
144 *************************************************************************
146 * CPU_init_critical registers
148 * setup important registers
149 * setup memory timing
151 *************************************************************************
153 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
156 * flush v4 I/D caches
159 mcr p15, 0, r0, c7, c7, 0 /* Invalidate I+D+BTB caches */
160 mcr p15, 0, r0, c8, c7, 0 /* Invalidate Unified TLB */
163 * disable MMU stuff and caches
165 mrc p15, 0, r0, c1, c0, 0
166 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
167 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
168 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
169 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
170 mcr p15, 0, r0, c1, c0, 0
173 * Jump to board specific initialization... The Mask ROM will have already initialized
174 * basic memory. Go here to bump up clock rate and handle wake up conditions.
176 mov ip, lr /* persevere link reg across call */
177 bl lowlevel_init /* go setup pll,mux,memory */
178 mov lr, ip /* restore link */
179 mov pc, lr /* back to my caller */
180 #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
182 #ifndef CONFIG_SPL_BUILD
184 *************************************************************************
188 *************************************************************************
193 #define S_FRAME_SIZE 72
215 #define MODE_SVC 0x13
219 * use bad_save_user_regs for abort/prefetch/undef/swi ...
220 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
223 .macro bad_save_user_regs
224 sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack
225 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
227 ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort stack
228 ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs)
229 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
233 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
234 mov r0, sp @ save current stack into r0 (param register)
237 .macro irq_save_user_regs
238 sub sp, sp, #S_FRAME_SIZE
239 stmia sp, {r0 - r12} @ Calling r0-r12
240 add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
241 stmdb r8, {sp, lr}^ @ Calling SP, LR
242 str lr, [r8, #0] @ Save calling PC
244 str r6, [r8, #4] @ Save CPSR
245 str r0, [r8, #8] @ Save OLD_R0
249 .macro irq_restore_user_regs
250 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
252 ldr lr, [sp, #S_PC] @ Get PC
253 add sp, sp, #S_FRAME_SIZE
254 subs pc, lr, #4 @ return & move spsr_svc into cpsr
258 ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter in banked mode)
260 str lr, [r13] @ save caller lr in position 0 of saved stack
261 mrs lr, spsr @ get the spsr
262 str lr, [r13, #4] @ save spsr in position 1 of saved stack
264 mov r13, #MODE_SVC @ prepare SVC-Mode
266 msr spsr, r13 @ switch modes, make sure moves will execute
267 mov lr, pc @ capture return pc
268 movs pc, lr @ jump to next instruction & switch modes.
271 .macro get_bad_stack_swi
272 sub r13, r13, #4 @ space on current stack for scratch reg.
273 str r0, [r13] @ save R0's value.
274 ldr r0, IRQ_STACK_START_IN @ get data regions start
275 str lr, [r0] @ save caller lr in position 0 of saved stack
276 mrs lr, spsr @ get the spsr
277 str lr, [r0, #4] @ save spsr in position 1 of saved stack
278 ldr lr, [r0] @ restore lr
279 ldr r0, [r13] @ restore r0
280 add r13, r13, #4 @ pop stack entry
283 .macro get_irq_stack @ setup IRQ stack
284 ldr sp, IRQ_STACK_START
287 .macro get_fiq_stack @ setup FIQ stack
288 ldr sp, FIQ_STACK_START
290 #endif /* CONFIG_SPL_BUILD */
295 #ifdef CONFIG_SPL_BUILD
298 ldr sp, _TEXT_BASE /* use 32 words about stack */
299 bl hang /* hang and never return */
300 #else /* !CONFIG_SPL_BUILD */
302 undefined_instruction:
305 bl do_undefined_instruction
311 bl do_software_interrupt
331 #ifdef CONFIG_USE_IRQ
338 irq_restore_user_regs
343 /* someone ought to write a more effiction fiq_save_user_regs */
346 irq_restore_user_regs
364 .global arm1136_cache_flush
366 #if !defined(CONFIG_SYS_ICACHE_OFF)
367 mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
369 #if !defined(CONFIG_SYS_DCACHE_OFF)
370 mcr p15, 0, r1, c7, c14, 0 @ invalidate D cache
372 mov pc, lr @ back to caller
373 #endif /* CONFIG_SPL_BUILD */