blob: 7fe36c6ded05a3849b5d086b7a85fd3a267dad3b [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
2 * armboot - Startup Code for ARM720 CPU-core
3 *
4 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
5 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26
wdenkfe8c2802002-11-03 00:38:21 +000027#include <config.h>
28#include <version.h>
29
30
31/*
32 *************************************************************************
33 *
34 * Jump vector table as in table 3.1 in [1]
35 *
36 *************************************************************************
37 */
38
39
40.globl _start
41_start: b reset
42 ldr pc, _undefined_instruction
43 ldr pc, _software_interrupt
44 ldr pc, _prefetch_abort
45 ldr pc, _data_abort
46 ldr pc, _not_used
47 ldr pc, _irq
48 ldr pc, _fiq
49
50_undefined_instruction: .word undefined_instruction
51_software_interrupt: .word software_interrupt
52_prefetch_abort: .word prefetch_abort
53_data_abort: .word data_abort
54_not_used: .word not_used
55_irq: .word irq
56_fiq: .word fiq
57
58 .balignl 16,0xdeadbeef
59
60
61/*
62 *************************************************************************
63 *
64 * Startup Code (reset vector)
65 *
wdenk927034e2004-02-08 19:38:38 +000066 * do important init only if we don't start from RAM!
wdenkfe8c2802002-11-03 00:38:21 +000067 * relocate armboot to ram
68 * setup stack
69 * jump to second stage
70 *
71 *************************************************************************
72 */
73
wdenkfe8c2802002-11-03 00:38:21 +000074_TEXT_BASE:
75 .word TEXT_BASE
76
77.globl _armboot_start
78_armboot_start:
79 .word _start
80
81/*
wdenk927034e2004-02-08 19:38:38 +000082 * These are defined in the board-specific linker script.
wdenkfe8c2802002-11-03 00:38:21 +000083 */
wdenk927034e2004-02-08 19:38:38 +000084.globl _bss_start
85_bss_start:
86 .word __bss_start
87
88.globl _bss_end
89_bss_end:
90 .word _end
wdenkfe8c2802002-11-03 00:38:21 +000091
wdenkfe8c2802002-11-03 00:38:21 +000092#ifdef CONFIG_USE_IRQ
93/* IRQ stack memory (calculated at run-time) */
94.globl IRQ_STACK_START
95IRQ_STACK_START:
96 .word 0x0badc0de
97
98/* IRQ stack memory (calculated at run-time) */
99.globl FIQ_STACK_START
100FIQ_STACK_START:
101 .word 0x0badc0de
102#endif
103
104
105/*
106 * the actual reset code
107 */
108
109reset:
110 /*
111 * set the cpu to SVC32 mode
112 */
113 mrs r0,cpsr
114 bic r0,r0,#0x1f
115 orr r0,r0,#0x13
116 msr cpsr,r0
117
118 /*
119 * we do sys-critical inits only at reboot,
120 * not when booting from ram!
121 */
122#ifdef CONFIG_INIT_CRITICAL
123 bl cpu_init_crit
124#endif
125
wdenkc0aa5c52003-12-06 19:49:23 +0000126relocate: /* relocate U-Boot to RAM */
127 adr r0, _start /* r0 <- current position of code */
128 ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
129 cmp r0, r1 /* don't reloc during debug */
130 beq stack_setup
131
wdenkfe8c2802002-11-03 00:38:21 +0000132 ldr r2, _armboot_start
wdenk927034e2004-02-08 19:38:38 +0000133 ldr r3, _bss_start
wdenkc0aa5c52003-12-06 19:49:23 +0000134 sub r2, r3, r2 /* r2 <- size of armboot */
135 add r2, r0, r2 /* r2 <- source end address */
wdenkfe8c2802002-11-03 00:38:21 +0000136
wdenkfe8c2802002-11-03 00:38:21 +0000137copy_loop:
wdenkc0aa5c52003-12-06 19:49:23 +0000138 ldmia r0!, {r3-r10} /* copy from source address [r0] */
139 stmia r1!, {r3-r10} /* copy to target address [r1] */
140 cmp r0, r2 /* until source end addreee [r2] */
wdenkfe8c2802002-11-03 00:38:21 +0000141 ble copy_loop
142
wdenkc0aa5c52003-12-06 19:49:23 +0000143 /* Set up the stack */
144stack_setup:
145 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
146 sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
147 sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */
148#ifdef CONFIG_USE_IRQ
149 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
150#endif
151 sub sp, r0, #12 /* leave 3 words for abort-stack */
wdenkfe8c2802002-11-03 00:38:21 +0000152
wdenk927034e2004-02-08 19:38:38 +0000153clear_bss:
154 ldr r0, _bss_start /* find start of bss segment */
155 add r0, r0, #4 /* start at first byte of bss */
156 ldr r1, _bss_end /* stop here */
157 mov r2, #0x00000000 /* clear */
158
159clbss_l:str r2, [r0] /* clear loop... */
160 add r0, r0, #4
161 cmp r0, r1
162 bne clbss_l
163
wdenkfe8c2802002-11-03 00:38:21 +0000164 ldr pc, _start_armboot
165
166_start_armboot: .word start_armboot
167
168
169/*
170 *************************************************************************
171 *
172 * CPU_init_critical registers
173 *
174 * setup important registers
175 * setup memory timing
176 *
177 *************************************************************************
178 */
179
180
181/* Interupt-Controller base addresses */
182INTMR1: .word 0x80000280 @ 32 bit size
183INTMR2: .word 0x80001280 @ 16 bit size
184INTMR3: .word 0x80002280 @ 8 bit size
185
186/* SYSCONs */
187SYSCON1: .word 0x80000100
188SYSCON2: .word 0x80001100
189SYSCON3: .word 0x80002200
190
191#define CLKCTL 0x6 /* mask */
192#define CLKCTL_18 0x0 /* 18.432 MHz */
193#define CLKCTL_36 0x2 /* 36.864 MHz */
194#define CLKCTL_49 0x4 /* 49.152 MHz */
195#define CLKCTL_73 0x6 /* 73.728 MHz */
196
197cpu_init_crit:
198 /*
199 * mask all IRQs by clearing all bits in the INTMRs
200 */
201 mov r1, #0x00
202 ldr r0, INTMR1
203 str r1, [r0]
204 ldr r0, INTMR2
205 str r1, [r0]
206 ldr r0, INTMR3
207 str r1, [r0]
208
209 /*
210 * flush v4 I/D caches
211 */
212 mov r0, #0
213 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
214 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
215
216 /*
217 * disable MMU stuff and caches
218 */
219 mrc p15,0,r0,c1,c0
220 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
221 bic r0, r0, #0x0000008f @ clear bits 7, 3:0 (B--- WCAM)
222 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
223 mcr p15,0,r0,c1,c0
224
225#ifdef CONFIG_ARM7_REVD
226 /* set clock speed */
227 /* !!! we run @ 36 MHz due to a hardware flaw in Rev. D processors */
228 /* !!! not doing DRAM refresh properly! */
229 ldr r0, SYSCON3
230 ldr r1, [r0]
231 bic r1, r1, #CLKCTL
232 orr r1, r1, #CLKCTL_36
233 str r1, [r0]
234#endif
235
236 /*
237 * before relocating, we have to setup RAM timing
wdenk927034e2004-02-08 19:38:38 +0000238 * because memory timing is board-dependent, you will
wdenkfe8c2802002-11-03 00:38:21 +0000239 * find a memsetup.S in your board directory.
240 */
241 mov ip, lr
242 bl memsetup
243 mov lr, ip
244
245 mov pc, lr
246
247
wdenkfe8c2802002-11-03 00:38:21 +0000248/*
249 *************************************************************************
250 *
251 * Interrupt handling
252 *
253 *************************************************************************
254 */
255
256@
257@ IRQ stack frame.
258@
259#define S_FRAME_SIZE 72
260
261#define S_OLD_R0 68
262#define S_PSR 64
263#define S_PC 60
264#define S_LR 56
265#define S_SP 52
266
267#define S_IP 48
268#define S_FP 44
269#define S_R10 40
270#define S_R9 36
271#define S_R8 32
272#define S_R7 28
273#define S_R6 24
274#define S_R5 20
275#define S_R4 16
276#define S_R3 12
277#define S_R2 8
278#define S_R1 4
279#define S_R0 0
280
281#define MODE_SVC 0x13
282#define I_BIT 0x80
283
284/*
285 * use bad_save_user_regs for abort/prefetch/undef/swi ...
286 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
287 */
288
289 .macro bad_save_user_regs
290 sub sp, sp, #S_FRAME_SIZE
291 stmia sp, {r0 - r12} @ Calling r0-r12
292 add r8, sp, #S_PC
293
wdenk927034e2004-02-08 19:38:38 +0000294 ldr r2, _armboot_start
295 sub r2, r2, #(CONFIG_STACKSIZE+CFG_MALLOC_LEN)
296 sub r2, r2, #(CFG_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
wdenkfe8c2802002-11-03 00:38:21 +0000297 ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0
298 add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
299
300 add r5, sp, #S_SP
301 mov r1, lr
302 stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r
303 mov r0, sp
304 .endm
305
306 .macro irq_save_user_regs
307 sub sp, sp, #S_FRAME_SIZE
308 stmia sp, {r0 - r12} @ Calling r0-r12
309 add r8, sp, #S_PC
310 stmdb r8, {sp, lr}^ @ Calling SP, LR
311 str lr, [r8, #0] @ Save calling PC
312 mrs r6, spsr
313 str r6, [r8, #4] @ Save CPSR
314 str r0, [r8, #8] @ Save OLD_R0
315 mov r0, sp
316 .endm
317
318 .macro irq_restore_user_regs
319 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
320 mov r0, r0
321 ldr lr, [sp, #S_PC] @ Get PC
322 add sp, sp, #S_FRAME_SIZE
323 subs pc, lr, #4 @ return & move spsr_svc into cpsr
324 .endm
325
326 .macro get_bad_stack
wdenk927034e2004-02-08 19:38:38 +0000327 ldr r13, _armboot_start @ setup our mode stack
328 sub r13, r13, #(CONFIG_STACKSIZE+CFG_MALLOC_LEN)
329 sub r13, r13, #(CFG_GBL_DATA_SIZE+8) @ reserved a couple spots in abort stack
wdenkfe8c2802002-11-03 00:38:21 +0000330
331 str lr, [r13] @ save caller lr / spsr
332 mrs lr, spsr
333 str lr, [r13, #4]
334
335 mov r13, #MODE_SVC @ prepare SVC-Mode
336 msr spsr_c, r13
337 mov lr, pc
338 movs pc, lr
339 .endm
340
341 .macro get_irq_stack @ setup IRQ stack
342 ldr sp, IRQ_STACK_START
343 .endm
344
345 .macro get_fiq_stack @ setup FIQ stack
346 ldr sp, FIQ_STACK_START
347 .endm
348
349/*
350 * exception handlers
351 */
352 .align 5
353undefined_instruction:
354 get_bad_stack
355 bad_save_user_regs
356 bl do_undefined_instruction
357
358 .align 5
359software_interrupt:
360 get_bad_stack
361 bad_save_user_regs
362 bl do_software_interrupt
363
364 .align 5
365prefetch_abort:
366 get_bad_stack
367 bad_save_user_regs
368 bl do_prefetch_abort
369
370 .align 5
371data_abort:
372 get_bad_stack
373 bad_save_user_regs
374 bl do_data_abort
375
376 .align 5
377not_used:
378 get_bad_stack
379 bad_save_user_regs
380 bl do_not_used
381
382#ifdef CONFIG_USE_IRQ
383
384 .align 5
385irq:
386 get_irq_stack
387 irq_save_user_regs
388 bl do_irq
389 irq_restore_user_regs
390
391 .align 5
392fiq:
393 get_fiq_stack
394 /* someone ought to write a more effiction fiq_save_user_regs */
395 irq_save_user_regs
396 bl do_fiq
397 irq_restore_user_regs
398
399#else
400
401 .align 5
402irq:
403 get_bad_stack
404 bad_save_user_regs
405 bl do_irq
406
407 .align 5
408fiq:
409 get_bad_stack
410 bad_save_user_regs
411 bl do_fiq
412
413#endif
414
415 .align 5
416.globl reset_cpu
417reset_cpu:
418 mov ip, #0
419 mcr p15, 0, ip, c7, c7, 0 @ invalidate cache
420 mcr p15, 0, ip, c8, c7, 0 @ flush TLB (v4)
421 mrc p15, 0, ip, c1, c0, 0 @ get ctrl register
422 bic ip, ip, #0x000f @ ............wcam
423 bic ip, ip, #0x2100 @ ..v....s........
424 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
425 mov pc, r0