2 * armboot - Startup Code for XScale CPU-core
4 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
5 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
6 * Copyright (C) 2000 Wolfgang Denk <wd@denx.de>
7 * Copyright (C) 2001 Alex Zuepke <azu@sysgo.de>
8 * Copyright (C) 2001 Marius Groger <mag@sysgo.de>
9 * Copyright (C) 2002 Alex Zupke <azu@sysgo.de>
10 * Copyright (C) 2002 Gary Jennejohn <garyj@denx.de>
11 * Copyright (C) 2002 Kyle Harris <kharris@nexus-tech.net>
12 * Copyright (C) 2003 Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de>
13 * Copyright (C) 2003 Kshitij <kshitij@ti.com>
14 * Copyright (C) 2003 Richard Woodruff <r-woodruff2@ti.com>
15 * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>
16 * Copyright (C) 2004 Texas Instruments <r-woodruff2@ti.com>
17 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
19 * SPDX-License-Identifier: GPL-2.0+
22 #include <asm-offsets.h>
26 #ifdef CONFIG_CPU_PXA25X
27 #if ((CONFIG_SYS_INIT_SP_ADDR) != 0xfffff800)
28 #error "Init SP address must be set to 0xfffff800 for PXA250"
34 #ifdef CONFIG_SPL_BUILD
51 .word 0x12345678 /* now 16*4=64 */
53 ldr pc, _undefined_instruction
54 ldr pc, _software_interrupt
55 ldr pc, _prefetch_abort
61 _undefined_instruction: .word undefined_instruction
62 _software_interrupt: .word software_interrupt
63 _prefetch_abort: .word prefetch_abort
64 _data_abort: .word data_abort
65 _not_used: .word not_used
68 _pad: .word 0x12345678 /* now 16*4=64 */
69 #endif /* CONFIG_SPL_BUILD */
73 .balignl 16,0xdeadbeef
75 *************************************************************************
77 * Startup Code (reset vector)
79 * do important init only if we don't start from memory!
80 * setup Memory and board specific bits prior to relocation.
81 * relocate armboot to ram
84 *************************************************************************
88 /* IRQ stack memory (calculated at run-time) */
89 .globl IRQ_STACK_START
93 /* IRQ stack memory (calculated at run-time) */
94 .globl FIQ_STACK_START
99 /* IRQ stack memory (calculated at run-time) + 8 bytes */
100 .globl IRQ_STACK_START_IN
105 * the actual reset code
110 * set the cpu to SVC32 mode
117 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
121 #ifdef CONFIG_CPU_PXA25X
122 bl lock_cache_for_stack
127 /*------------------------------------------------------------------------------*/
129 .globl c_runtime_cpu_setup
132 #ifdef CONFIG_CPU_PXA25X
134 * Unlock (actually, disable) the cache now that board_init_f
135 * is done. We could do this earlier but we would need to add
136 * a new C runtime hook, whereas c_runtime_cpu_setup already
138 * As this routine is just a call to cpu_init_crit, let us
139 * tail-optimize and do a simple branch here.
147 *************************************************************************
149 * CPU_init_critical registers
151 * setup important registers
152 * setup memory timing
154 *************************************************************************
156 #if !defined(CONFIG_SKIP_LOWLEVEL_INIT) || defined(CONFIG_CPU_PXA25X)
159 * flush v4 I/D caches
162 mcr p15, 0, r0, c7, c7, 0 /* Invalidate I+D+BTB caches */
163 mcr p15, 0, r0, c8, c7, 0 /* Invalidate Unified TLB */
166 * disable MMU stuff and caches
168 mrc p15, 0, r0, c1, c0, 0
169 bic r0, r0, #0x00003300 @ clear bits 13:12, 9:8 (--VI --RS)
170 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
171 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
172 mcr p15, 0, r0, c1, c0, 0
174 mov pc, lr /* back to my caller */
175 #endif /* !CONFIG_SKIP_LOWLEVEL_INIT || CONFIG_CPU_PXA25X */
177 #ifndef CONFIG_SPL_BUILD
179 *************************************************************************
183 *************************************************************************
188 #define S_FRAME_SIZE 72
210 #define MODE_SVC 0x13
214 * use bad_save_user_regs for abort/prefetch/undef/swi ...
215 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
218 .macro bad_save_user_regs
219 sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack
220 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
222 ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort stack
223 ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs)
224 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
228 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
229 mov r0, sp @ save current stack into r0 (param register)
232 .macro irq_save_user_regs
233 sub sp, sp, #S_FRAME_SIZE
234 stmia sp, {r0 - r12} @ Calling r0-r12
235 add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
236 stmdb r8, {sp, lr}^ @ Calling SP, LR
237 str lr, [r8, #0] @ Save calling PC
239 str r6, [r8, #4] @ Save CPSR
240 str r0, [r8, #8] @ Save OLD_R0
244 .macro irq_restore_user_regs
245 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
247 ldr lr, [sp, #S_PC] @ Get PC
248 add sp, sp, #S_FRAME_SIZE
249 subs pc, lr, #4 @ return & move spsr_svc into cpsr
253 ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter in banked mode)
255 str lr, [r13] @ save caller lr in position 0 of saved stack
256 mrs lr, spsr @ get the spsr
257 str lr, [r13, #4] @ save spsr in position 1 of saved stack
259 mov r13, #MODE_SVC @ prepare SVC-Mode
261 msr spsr, r13 @ switch modes, make sure moves will execute
262 mov lr, pc @ capture return pc
263 movs pc, lr @ jump to next instruction & switch modes.
266 .macro get_bad_stack_swi
267 sub r13, r13, #4 @ space on current stack for scratch reg.
268 str r0, [r13] @ save R0's value.
269 ldr r0, IRQ_STACK_START_IN @ get data regions start
270 str lr, [r0] @ save caller lr in position 0 of saved stack
271 mrs lr, spsr @ get the spsr
272 str lr, [r0, #4] @ save spsr in position 1 of saved stack
273 ldr lr, [r0] @ restore lr
274 ldr r0, [r13] @ restore r0
275 add r13, r13, #4 @ pop stack entry
278 .macro get_irq_stack @ setup IRQ stack
279 ldr sp, IRQ_STACK_START
282 .macro get_fiq_stack @ setup FIQ stack
283 ldr sp, FIQ_STACK_START
285 #endif /* CONFIG_SPL_BUILD */
290 #ifdef CONFIG_SPL_BUILD
293 bl hang /* hang and never return */
294 #else /* !CONFIG_SPL_BUILD */
296 undefined_instruction:
299 bl do_undefined_instruction
305 bl do_software_interrupt
325 #ifdef CONFIG_USE_IRQ
332 irq_restore_user_regs
337 /* someone ought to write a more effiction fiq_save_user_regs */
340 irq_restore_user_regs
358 #endif /* CONFIG_SPL_BUILD */
362 * Enable MMU to use DCache as DRAM.
364 * This is useful on PXA25x and PXA26x in early bootstages, where there is no
365 * other possible memory available to hold stack.
367 #ifdef CONFIG_CPU_PXA25X
369 mrc p15, 0, \reg, c2, c0, 0
373 lock_cache_for_stack:
374 /* Domain access -- enable for all CPs */
376 mcr p15, 0, r0, c3, c0, 0
378 /* Point TTBR to MMU table */
380 mcr p15, 0, r0, c2, c0, 0
382 /* Kick in MMU, ICache, DCache, BTB */
383 mrc p15, 0, r0, c1, c0, 0
388 mcr p15, 0, r0, c1, c0, 0
391 /* Unlock Icache, Dcache */
392 mcr p15, 0, r0, c9, c1, 1
393 mcr p15, 0, r0, c9, c2, 1
395 /* Flush Icache, Dcache, BTB */
396 mcr p15, 0, r0, c7, c7, 0
398 /* Unlock I-TLB, D-TLB */
399 mcr p15, 0, r0, c10, c4, 1
400 mcr p15, 0, r0, c10, c8, 1
403 mcr p15, 0, r0, c8, c7, 0
405 /* Allocate 4096 bytes of Dcache as RAM */
407 /* Drain pending loads and stores */
408 mcr p15, 0, r0, c7, c10, 4
413 mcr p15, 0, r0, c9, c2, 0
416 /* 128 lines reserved (128 x 32bytes = 4096 bytes total) */
421 mcr p15, 0, r1, c7, c2, 5
422 /* Drain pending loads and stores */
423 mcr p15, 0, r0, c7, c10, 4
430 /* Drain pending loads and stores */
431 mcr p15, 0, r0, c7, c10, 4
433 mcr p15, 0, r2, c9, c2, 0
438 .section .mmutable, "a"
441 /* 0x00000000 - 0xffe00000 : 1:1, uncached mapping */
444 .word (__base << 20) | 0xc12
445 .set __base, __base + 1
448 /* 0xfff00000 : 1:1, cached mapping */
449 .word (0xfff << 20) | 0x1c1e
450 #endif /* CONFIG_CPU_PXA25X */