blob: 8ddb0c9264d1520cce033ae882fabfc4233acb67 [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 *
66 * do important init only if we don't start from memory!
67 * 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/*
82 * Note: _armboot_end_data and _armboot_end are defined
83 * by the (board-dependent) linker script.
84 * _armboot_end_data is the first usable FLASH address after armboot
85 */
86.globl _armboot_end_data
87_armboot_end_data:
88 .word armboot_end_data
89.globl _armboot_end
90_armboot_end:
91 .word armboot_end
92
wdenkfe8c2802002-11-03 00:38:21 +000093#ifdef CONFIG_USE_IRQ
94/* IRQ stack memory (calculated at run-time) */
95.globl IRQ_STACK_START
96IRQ_STACK_START:
97 .word 0x0badc0de
98
99/* IRQ stack memory (calculated at run-time) */
100.globl FIQ_STACK_START
101FIQ_STACK_START:
102 .word 0x0badc0de
103#endif
104
105
106/*
107 * the actual reset code
108 */
109
110reset:
111 /*
112 * set the cpu to SVC32 mode
113 */
114 mrs r0,cpsr
115 bic r0,r0,#0x1f
116 orr r0,r0,#0x13
117 msr cpsr,r0
118
119 /*
120 * we do sys-critical inits only at reboot,
121 * not when booting from ram!
122 */
123#ifdef CONFIG_INIT_CRITICAL
124 bl cpu_init_crit
125#endif
126
wdenka8c7c702003-12-06 19:49:23 +0000127relocate: /* relocate U-Boot to RAM */
128 adr r0, _start /* r0 <- current position of code */
129 ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
130 cmp r0, r1 /* don't reloc during debug */
131 beq stack_setup
132
wdenkfe8c2802002-11-03 00:38:21 +0000133 ldr r2, _armboot_start
134 ldr r3, _armboot_end
wdenka8c7c702003-12-06 19:49:23 +0000135 sub r2, r3, r2 /* r2 <- size of armboot */
136 add r2, r0, r2 /* r2 <- source end address */
wdenkfe8c2802002-11-03 00:38:21 +0000137
wdenkfe8c2802002-11-03 00:38:21 +0000138copy_loop:
wdenka8c7c702003-12-06 19:49:23 +0000139 ldmia r0!, {r3-r10} /* copy from source address [r0] */
140 stmia r1!, {r3-r10} /* copy to target address [r1] */
141 cmp r0, r2 /* until source end addreee [r2] */
wdenkfe8c2802002-11-03 00:38:21 +0000142 ble copy_loop
143
wdenka8c7c702003-12-06 19:49:23 +0000144 /* Set up the stack */
145stack_setup:
146 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
147 sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
148 sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */
149#ifdef CONFIG_USE_IRQ
150 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
151#endif
152 sub sp, r0, #12 /* leave 3 words for abort-stack */
wdenkfe8c2802002-11-03 00:38:21 +0000153
154 ldr pc, _start_armboot
155
156_start_armboot: .word start_armboot
157
158
159/*
160 *************************************************************************
161 *
162 * CPU_init_critical registers
163 *
164 * setup important registers
165 * setup memory timing
166 *
167 *************************************************************************
168 */
169
170
171/* Interupt-Controller base addresses */
172INTMR1: .word 0x80000280 @ 32 bit size
173INTMR2: .word 0x80001280 @ 16 bit size
174INTMR3: .word 0x80002280 @ 8 bit size
175
176/* SYSCONs */
177SYSCON1: .word 0x80000100
178SYSCON2: .word 0x80001100
179SYSCON3: .word 0x80002200
180
181#define CLKCTL 0x6 /* mask */
182#define CLKCTL_18 0x0 /* 18.432 MHz */
183#define CLKCTL_36 0x2 /* 36.864 MHz */
184#define CLKCTL_49 0x4 /* 49.152 MHz */
185#define CLKCTL_73 0x6 /* 73.728 MHz */
186
187cpu_init_crit:
188 /*
189 * mask all IRQs by clearing all bits in the INTMRs
190 */
191 mov r1, #0x00
192 ldr r0, INTMR1
193 str r1, [r0]
194 ldr r0, INTMR2
195 str r1, [r0]
196 ldr r0, INTMR3
197 str r1, [r0]
198
199 /*
200 * flush v4 I/D caches
201 */
202 mov r0, #0
203 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
204 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
205
206 /*
207 * disable MMU stuff and caches
208 */
209 mrc p15,0,r0,c1,c0
210 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
211 bic r0, r0, #0x0000008f @ clear bits 7, 3:0 (B--- WCAM)
212 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
213 mcr p15,0,r0,c1,c0
214
215#ifdef CONFIG_ARM7_REVD
216 /* set clock speed */
217 /* !!! we run @ 36 MHz due to a hardware flaw in Rev. D processors */
218 /* !!! not doing DRAM refresh properly! */
219 ldr r0, SYSCON3
220 ldr r1, [r0]
221 bic r1, r1, #CLKCTL
222 orr r1, r1, #CLKCTL_36
223 str r1, [r0]
224#endif
225
226 /*
227 * before relocating, we have to setup RAM timing
228 * because memory timing is board-dependend, you will
229 * find a memsetup.S in your board directory.
230 */
231 mov ip, lr
232 bl memsetup
233 mov lr, ip
234
235 mov pc, lr
236
237
wdenkfe8c2802002-11-03 00:38:21 +0000238/*
239 *************************************************************************
240 *
241 * Interrupt handling
242 *
243 *************************************************************************
244 */
245
246@
247@ IRQ stack frame.
248@
249#define S_FRAME_SIZE 72
250
251#define S_OLD_R0 68
252#define S_PSR 64
253#define S_PC 60
254#define S_LR 56
255#define S_SP 52
256
257#define S_IP 48
258#define S_FP 44
259#define S_R10 40
260#define S_R9 36
261#define S_R8 32
262#define S_R7 28
263#define S_R6 24
264#define S_R5 20
265#define S_R4 16
266#define S_R3 12
267#define S_R2 8
268#define S_R1 4
269#define S_R0 0
270
271#define MODE_SVC 0x13
272#define I_BIT 0x80
273
274/*
275 * use bad_save_user_regs for abort/prefetch/undef/swi ...
276 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
277 */
278
279 .macro bad_save_user_regs
280 sub sp, sp, #S_FRAME_SIZE
281 stmia sp, {r0 - r12} @ Calling r0-r12
282 add r8, sp, #S_PC
283
284 ldr r2, _armboot_end
285 add r2, r2, #CONFIG_STACKSIZE
286 sub r2, r2, #8
287 ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0
288 add r0, sp, #S_FRAME_SIZE @ restore sp_SVC
289
290 add r5, sp, #S_SP
291 mov r1, lr
292 stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r
293 mov r0, sp
294 .endm
295
296 .macro irq_save_user_regs
297 sub sp, sp, #S_FRAME_SIZE
298 stmia sp, {r0 - r12} @ Calling r0-r12
299 add r8, sp, #S_PC
300 stmdb r8, {sp, lr}^ @ Calling SP, LR
301 str lr, [r8, #0] @ Save calling PC
302 mrs r6, spsr
303 str r6, [r8, #4] @ Save CPSR
304 str r0, [r8, #8] @ Save OLD_R0
305 mov r0, sp
306 .endm
307
308 .macro irq_restore_user_regs
309 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
310 mov r0, r0
311 ldr lr, [sp, #S_PC] @ Get PC
312 add sp, sp, #S_FRAME_SIZE
313 subs pc, lr, #4 @ return & move spsr_svc into cpsr
314 .endm
315
316 .macro get_bad_stack
317 ldr r13, _armboot_end @ setup our mode stack
318 add r13, r13, #CONFIG_STACKSIZE @ resides at top of normal stack
319 sub r13, r13, #8
320
321 str lr, [r13] @ save caller lr / spsr
322 mrs lr, spsr
323 str lr, [r13, #4]
324
325 mov r13, #MODE_SVC @ prepare SVC-Mode
326 msr spsr_c, r13
327 mov lr, pc
328 movs pc, lr
329 .endm
330
331 .macro get_irq_stack @ setup IRQ stack
332 ldr sp, IRQ_STACK_START
333 .endm
334
335 .macro get_fiq_stack @ setup FIQ stack
336 ldr sp, FIQ_STACK_START
337 .endm
338
339/*
340 * exception handlers
341 */
342 .align 5
343undefined_instruction:
344 get_bad_stack
345 bad_save_user_regs
346 bl do_undefined_instruction
347
348 .align 5
349software_interrupt:
350 get_bad_stack
351 bad_save_user_regs
352 bl do_software_interrupt
353
354 .align 5
355prefetch_abort:
356 get_bad_stack
357 bad_save_user_regs
358 bl do_prefetch_abort
359
360 .align 5
361data_abort:
362 get_bad_stack
363 bad_save_user_regs
364 bl do_data_abort
365
366 .align 5
367not_used:
368 get_bad_stack
369 bad_save_user_regs
370 bl do_not_used
371
372#ifdef CONFIG_USE_IRQ
373
374 .align 5
375irq:
376 get_irq_stack
377 irq_save_user_regs
378 bl do_irq
379 irq_restore_user_regs
380
381 .align 5
382fiq:
383 get_fiq_stack
384 /* someone ought to write a more effiction fiq_save_user_regs */
385 irq_save_user_regs
386 bl do_fiq
387 irq_restore_user_regs
388
389#else
390
391 .align 5
392irq:
393 get_bad_stack
394 bad_save_user_regs
395 bl do_irq
396
397 .align 5
398fiq:
399 get_bad_stack
400 bad_save_user_regs
401 bl do_fiq
402
403#endif
404
405 .align 5
406.globl reset_cpu
407reset_cpu:
408 mov ip, #0
409 mcr p15, 0, ip, c7, c7, 0 @ invalidate cache
410 mcr p15, 0, ip, c8, c7, 0 @ flush TLB (v4)
411 mrc p15, 0, ip, c1, c0, 0 @ get ctrl register
412 bic ip, ip, #0x000f @ ............wcam
413 bic ip, ip, #0x2100 @ ..v....s........
414 mcr p15, 0, ip, c1, c0, 0 @ ctrl register
415 mov pc, r0