2 * armboot - Startup Code for SA1100 CPU
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 Züpke <azu@sysgo.de>
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
35 *************************************************************************
37 * Jump vector table as in table 3.1 in [1]
39 *************************************************************************
45 ldr pc, _undefined_instruction
46 ldr pc, _software_interrupt
47 ldr pc, _prefetch_abort
53 _undefined_instruction: .word undefined_instruction
54 _software_interrupt: .word software_interrupt
55 _prefetch_abort: .word prefetch_abort
56 _data_abort: .word data_abort
57 _not_used: .word not_used
61 .balignl 16,0xdeadbeef
65 *************************************************************************
67 * Startup Code (reset vector)
69 * do important init only if we don't start from memory!
70 * relocate armboot to ram
72 * jump to second stage
74 *************************************************************************
78 * CFG_MEM_END is in the board dependent config-file (configs/config_BOARD.h)
88 * Note: _armboot_end_data and _armboot_end are defined
89 * by the (board-dependent) linker script.
90 * _armboot_end_data is the first usable FLASH address after armboot
92 .globl _armboot_end_data
94 .word armboot_end_data
100 * _armboot_real_end is the first usable RAM address behind armboot
101 * and the various stacks
103 .globl _armboot_real_end
107 #ifdef CONFIG_USE_IRQ
108 /* IRQ stack memory (calculated at run-time) */
109 .globl IRQ_STACK_START
113 /* IRQ stack memory (calculated at run-time) */
114 .globl FIQ_STACK_START
121 * the actual reset code
126 * set the cpu to SVC32 mode
134 * we do sys-critical inits only at reboot,
135 * not when booting from ram!
137 #ifdef CONFIG_INIT_CRITICAL
143 * relocate armboot to RAM
145 adr r0, _start /* r0 <- current position of code */
146 ldr r2, _armboot_start
148 sub r2, r3, r2 /* r2 <- size of armboot */
149 ldr r1, _TEXT_BASE /* r1 <- destination address */
150 add r2, r0, r2 /* r2 <- source end address */
153 * r0 = source address
154 * r1 = target address
155 * r2 = source end address
163 /* set up the stack */
165 add r0, r0, #CONFIG_STACKSIZE
166 sub sp, r0, #12 /* leave 3 words for abort-stack */
168 ldr pc, _start_armboot
170 _start_armboot: .word start_armboot
174 *************************************************************************
176 * CPU_init_critical registers
178 * setup important registers
179 * setup memory timing
181 *************************************************************************
185 /* Interupt-Controller base address */
186 IC_BASE: .word 0x90050000
190 /* Reset-Controller */
191 RST_BASE: .word 0x90030000
197 PWR_BASE: .word 0x90020000
200 cpuspeed: .word CFG_CPUSPEED
211 /* set clock speed */
217 * before relocating, we have to setup RAM timing
218 * because memory timing is board-dependend, you will
219 * find a memsetup.S in your board directory.
226 * disable MMU stuff and enable I-cache
229 bic r0, r0, #0x00002000 @ clear bit 13 (X)
230 bic r0, r0, #0x0000000f @ clear bits 3-0 (WCAM)
231 orr r0, r0, #0x00001000 @ set bit 12 (I) Icache
232 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
236 * flush v4 I/D caches
239 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
240 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
248 *************************************************************************
252 *************************************************************************
258 #define S_FRAME_SIZE 72
280 #define MODE_SVC 0x13
284 * use bad_save_user_regs for abort/prefetch/undef/swi ...
285 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
288 .macro bad_save_user_regs
289 sub sp, sp, #S_FRAME_SIZE
290 stmia sp, {r0 - r12} @ Calling r0-r12
294 add r2, r2, #CONFIG_STACKSIZE
296 ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0
297 add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
301 stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r
305 .macro irq_save_user_regs
306 sub sp, sp, #S_FRAME_SIZE
307 stmia sp, {r0 - r12} @ Calling r0-r12
309 stmdb r8, {sp, lr}^ @ Calling SP, LR
310 str lr, [r8, #0] @ Save calling PC
312 str r6, [r8, #4] @ Save CPSR
313 str r0, [r8, #8] @ Save OLD_R0
317 .macro irq_restore_user_regs
318 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
320 ldr lr, [sp, #S_PC] @ Get PC
321 add sp, sp, #S_FRAME_SIZE
322 subs pc, lr, #4 @ return & move spsr_svc into cpsr
326 ldr r13, _armboot_end @ setup our mode stack
327 add r13, r13, #CONFIG_STACKSIZE @ resides at top of normal stack
330 str lr, [r13] @ save caller lr / spsr
334 mov r13, #MODE_SVC @ prepare SVC-Mode
340 .macro get_irq_stack @ setup IRQ stack
341 ldr sp, IRQ_STACK_START
344 .macro get_fiq_stack @ setup FIQ stack
345 ldr sp, FIQ_STACK_START
352 undefined_instruction:
355 bl do_undefined_instruction
361 bl do_software_interrupt
381 #ifdef CONFIG_USE_IRQ
388 irq_restore_user_regs
393 /* someone ought to write a more effiction fiq_save_user_regs */
396 irq_restore_user_regs
418 mov r1, #0x0 @ set bit 3-0 ...
419 str r1, [r0, #RCSR] @ ... to clear in RCSR
421 str r1, [r0, #RSRR] @ and perform reset
422 b reset_cpu @ silly, but repeat endlessly