blob: 27fcc89cc90ea0384f13bc3e375ebe037dd49120 [file] [log] [blame]
wdenk8ed96042005-01-09 23:16:25 +00001/*
2 * armboot - Startup Code for OMP2420/ARM1136 CPU-core
3 *
wdenk082acfd2005-01-10 00:01:04 +00004 * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
wdenk8ed96042005-01-09 23:16:25 +00005 *
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 <gj@denx.de>
9 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
10 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
11 *
12 * See file CREDITS for list of people who contributed to this
13 * project.
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenk082acfd2005-01-10 00:01:04 +000022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk8ed96042005-01-09 23:16:25 +000023 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
29 */
30
31#include <config.h>
32#include <version.h>
33#include <asm/arch/omap2420.h>
34
35.globl _start
wdenk082acfd2005-01-10 00:01:04 +000036_start: b reset
wdenk8ed96042005-01-09 23:16:25 +000037 ldr pc, _undefined_instruction
38 ldr pc, _software_interrupt
39 ldr pc, _prefetch_abort
40 ldr pc, _data_abort
41 ldr pc, _not_used
42 ldr pc, _irq
43 ldr pc, _fiq
44
wdenk082acfd2005-01-10 00:01:04 +000045_undefined_instruction: .word undefined_instruction
wdenk8ed96042005-01-09 23:16:25 +000046_software_interrupt: .word software_interrupt
47_prefetch_abort: .word prefetch_abort
48_data_abort: .word data_abort
49_not_used: .word not_used
50_irq: .word irq
51_fiq: .word fiq
wdenk082acfd2005-01-10 00:01:04 +000052_pad: .word 0x12345678 /* now 16*4=64 */
wdenk8ed96042005-01-09 23:16:25 +000053.global _end_vect
54_end_vect:
55
56 .balignl 16,0xdeadbeef
57/*
58 *************************************************************************
59 *
60 * Startup Code (reset vector)
61 *
62 * do important init only if we don't start from memory!
63 * setup Memory and board specific bits prior to relocation.
64 * relocate armboot to ram
65 * setup stack
66 *
67 *************************************************************************
68 */
69
70_TEXT_BASE:
71 .word TEXT_BASE
72
73.globl _armboot_start
74_armboot_start:
75 .word _start
76
77/*
78 * These are defined in the board-specific linker script.
79 */
80.globl _bss_start
81_bss_start:
82 .word __bss_start
83
84.globl _bss_end
85_bss_end:
86 .word _end
87
88#ifdef CONFIG_USE_IRQ
89/* IRQ stack memory (calculated at run-time) */
90.globl IRQ_STACK_START
91IRQ_STACK_START:
92 .word 0x0badc0de
93
94/* IRQ stack memory (calculated at run-time) */
95.globl FIQ_STACK_START
96FIQ_STACK_START:
97 .word 0x0badc0de
98#endif
99
100/*
101 * the actual reset code
102 */
103
104reset:
105 /*
106 * set the cpu to SVC32 mode
107 */
108 mrs r0,cpsr
109 bic r0,r0,#0x1f
110 orr r0,r0,#0xd3
111 msr cpsr,r0
112
113#ifdef CONFIG_OMAP2420H4
wdenk082acfd2005-01-10 00:01:04 +0000114 /* Copy vectors to mask ROM indirect addr */
115 adr r0, _start /* r0 <- current position of code */
wdenk289f9322005-01-12 00:15:14 +0000116 add r0, r0, #4 /* skip reset vector */
wdenk082acfd2005-01-10 00:01:04 +0000117 mov r2, #64 /* r2 <- size to copy */
118 add r2, r0, r2 /* r2 <- source end address */
119 mov r1, #SRAM_OFFSET0 /* build vect addr */
120 mov r3, #SRAM_OFFSET1
121 add r1, r1, r3
122 mov r3, #SRAM_OFFSET2
123 add r1, r1, r3
wdenk8ed96042005-01-09 23:16:25 +0000124next:
wdenk082acfd2005-01-10 00:01:04 +0000125 ldmia r0!, {r3-r10} /* copy from source address [r0] */
126 stmia r1!, {r3-r10} /* copy to target address [r1] */
127 cmp r0, r2 /* until source end address [r2] */
128 bne next /* loop until equal */
wdenk082acfd2005-01-10 00:01:04 +0000129 bl cpy_clk_code /* put dpll adjust code behind vectors */
wdenk8ed96042005-01-09 23:16:25 +0000130#endif
wdenk8ed96042005-01-09 23:16:25 +0000131 /* the mask ROM code should have PLL and others stable */
132 bl cpu_init_crit
133
134relocate: /* relocate U-Boot to RAM */
135 adr r0, _start /* r0 <- current position of code */
136 ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
wdenk082acfd2005-01-10 00:01:04 +0000137 cmp r0, r1 /* don't reloc during debug */
138 beq stack_setup
wdenk8ed96042005-01-09 23:16:25 +0000139
140 ldr r2, _armboot_start
141 ldr r3, _bss_start
wdenk082acfd2005-01-10 00:01:04 +0000142 sub r2, r3, r2 /* r2 <- size of armboot */
143 add r2, r0, r2 /* r2 <- source end address */
wdenk8ed96042005-01-09 23:16:25 +0000144
145copy_loop:
146 ldmia r0!, {r3-r10} /* copy from source address [r0] */
147 stmia r1!, {r3-r10} /* copy to target address [r1] */
148 cmp r0, r2 /* until source end addreee [r2] */
149 ble copy_loop
150
151 /* Set up the stack */
152stack_setup:
153 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
wdenk082acfd2005-01-10 00:01:04 +0000154 sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
155 sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */
wdenk8ed96042005-01-09 23:16:25 +0000156#ifdef CONFIG_USE_IRQ
157 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
158#endif
159 sub sp, r0, #12 /* leave 3 words for abort-stack */
160
161clear_bss:
wdenk082acfd2005-01-10 00:01:04 +0000162 ldr r0, _bss_start /* find start of bss segment */
163 ldr r1, _bss_end /* stop here */
164 mov r2, #0x00000000 /* clear */
wdenk8ed96042005-01-09 23:16:25 +0000165
wdenk082acfd2005-01-10 00:01:04 +0000166clbss_l:str r2, [r0] /* clear loop... */
wdenk8ed96042005-01-09 23:16:25 +0000167 add r0, r0, #4
168 cmp r0, r1
169 bne clbss_l
170
171 ldr pc, _start_armboot
172
wdenk082acfd2005-01-10 00:01:04 +0000173_start_armboot: .word start_armboot
wdenk8ed96042005-01-09 23:16:25 +0000174
175
176/*
177 *************************************************************************
178 *
179 * CPU_init_critical registers
180 *
181 * setup important registers
182 * setup memory timing
183 *
184 *************************************************************************
185 */
186cpu_init_crit:
187 /*
188 * flush v4 I/D caches
189 */
190 mov r0, #0
191 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
192 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
193
194 /*
195 * disable MMU stuff and caches
196 */
197 mrc p15, 0, r0, c1, c0, 0
198 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
199 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
200 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
wdenk8ed96042005-01-09 23:16:25 +0000201 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
wdenk8ed96042005-01-09 23:16:25 +0000202 mcr p15, 0, r0, c1, c0, 0
203
204 /*
wdenk082acfd2005-01-10 00:01:04 +0000205 * Jump to board specific initialization... The Mask ROM will have already initialized
206 * basic memory. Go here to bump up clock rate and handle wake up conditions.
wdenk8ed96042005-01-09 23:16:25 +0000207 */
wdenk082acfd2005-01-10 00:01:04 +0000208 mov ip, lr /* persevere link reg across call */
209 bl platformsetup /* go setup pll,mux,memory */
210 mov lr, ip /* restore link */
211 mov pc, lr /* back to my caller */
wdenk8ed96042005-01-09 23:16:25 +0000212/*
213 *************************************************************************
214 *
215 * Interrupt handling
216 *
217 *************************************************************************
218 */
219@
220@ IRQ stack frame.
221@
222#define S_FRAME_SIZE 72
223
224#define S_OLD_R0 68
225#define S_PSR 64
226#define S_PC 60
227#define S_LR 56
228#define S_SP 52
229
230#define S_IP 48
231#define S_FP 44
232#define S_R10 40
233#define S_R9 36
234#define S_R8 32
235#define S_R7 28
236#define S_R6 24
237#define S_R5 20
238#define S_R4 16
239#define S_R3 12
240#define S_R2 8
241#define S_R1 4
242#define S_R0 0
243
244#define MODE_SVC 0x13
245#define I_BIT 0x80
246
247/*
248 * use bad_save_user_regs for abort/prefetch/undef/swi ...
249 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
250 */
251
252 .macro bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000253 sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack
wdenk8ed96042005-01-09 23:16:25 +0000254 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
255
256 ldr r2, _armboot_start
257 sub r2, r2, #(CFG_MALLOC_LEN)
wdenk082acfd2005-01-10 00:01:04 +0000258 sub r2, r2, #(CFG_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
259 ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs)
wdenk8ed96042005-01-09 23:16:25 +0000260 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
261
262 add r5, sp, #S_SP
263 mov r1, lr
wdenk082acfd2005-01-10 00:01:04 +0000264 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
265 mov r0, sp @ save current stack into r0 (param register)
wdenk8ed96042005-01-09 23:16:25 +0000266 .endm
267
268 .macro irq_save_user_regs
269 sub sp, sp, #S_FRAME_SIZE
270 stmia sp, {r0 - r12} @ Calling r0-r12
wdenk082acfd2005-01-10 00:01:04 +0000271 add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
272 stmdb r8, {sp, lr}^ @ Calling SP, LR
273 str lr, [r8, #0] @ Save calling PC
274 mrs r6, spsr
275 str r6, [r8, #4] @ Save CPSR
276 str r0, [r8, #8] @ Save OLD_R0
wdenk8ed96042005-01-09 23:16:25 +0000277 mov r0, sp
278 .endm
279
280 .macro irq_restore_user_regs
281 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
282 mov r0, r0
283 ldr lr, [sp, #S_PC] @ Get PC
284 add sp, sp, #S_FRAME_SIZE
285 subs pc, lr, #4 @ return & move spsr_svc into cpsr
286 .endm
287
288 .macro get_bad_stack
289 ldr r13, _armboot_start @ setup our mode stack (enter in banked mode)
wdenk082acfd2005-01-10 00:01:04 +0000290 sub r13, r13, #(CFG_MALLOC_LEN) @ move past malloc pool
wdenk8ed96042005-01-09 23:16:25 +0000291 sub r13, r13, #(CFG_GBL_DATA_SIZE+8) @ move to reserved a couple spots for abort stack
292
293 str lr, [r13] @ save caller lr in position 0 of saved stack
wdenk082acfd2005-01-10 00:01:04 +0000294 mrs lr, spsr @ get the spsr
295 str lr, [r13, #4] @ save spsr in position 1 of saved stack
wdenk8ed96042005-01-09 23:16:25 +0000296
297 mov r13, #MODE_SVC @ prepare SVC-Mode
298 @ msr spsr_c, r13
wdenk082acfd2005-01-10 00:01:04 +0000299 msr spsr, r13 @ switch modes, make sure moves will execute
300 mov lr, pc @ capture return pc
301 movs pc, lr @ jump to next instruction & switch modes.
wdenk8ed96042005-01-09 23:16:25 +0000302 .endm
303
304 .macro get_bad_stack_swi
wdenk082acfd2005-01-10 00:01:04 +0000305 sub r13, r13, #4 @ space on current stack for scratch reg.
306 str r0, [r13] @ save R0's value.
wdenk8ed96042005-01-09 23:16:25 +0000307 ldr r0, _armboot_start @ get data regions start
wdenk082acfd2005-01-10 00:01:04 +0000308 sub r0, r0, #(CFG_MALLOC_LEN) @ move past malloc pool
309 sub r0, r0, #(CFG_GBL_DATA_SIZE+8) @ move past gbl and a couple spots for abort stack
wdenk8ed96042005-01-09 23:16:25 +0000310 str lr, [r0] @ save caller lr in position 0 of saved stack
wdenk082acfd2005-01-10 00:01:04 +0000311 mrs r0, spsr @ get the spsr
312 str lr, [r0, #4] @ save spsr in position 1 of saved stack
313 ldr r0, [r13] @ restore r0
314 add r13, r13, #4 @ pop stack entry
wdenk8ed96042005-01-09 23:16:25 +0000315 .endm
316
317 .macro get_irq_stack @ setup IRQ stack
318 ldr sp, IRQ_STACK_START
319 .endm
320
321 .macro get_fiq_stack @ setup FIQ stack
322 ldr sp, FIQ_STACK_START
323 .endm
324
325/*
326 * exception handlers
327 */
wdenk082acfd2005-01-10 00:01:04 +0000328 .align 5
wdenk8ed96042005-01-09 23:16:25 +0000329undefined_instruction:
330 get_bad_stack
331 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000332 bl do_undefined_instruction
wdenk8ed96042005-01-09 23:16:25 +0000333
334 .align 5
335software_interrupt:
336 get_bad_stack_swi
337 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000338 bl do_software_interrupt
wdenk8ed96042005-01-09 23:16:25 +0000339
340 .align 5
341prefetch_abort:
342 get_bad_stack
343 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000344 bl do_prefetch_abort
wdenk8ed96042005-01-09 23:16:25 +0000345
346 .align 5
347data_abort:
348 get_bad_stack
349 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000350 bl do_data_abort
wdenk8ed96042005-01-09 23:16:25 +0000351
352 .align 5
353not_used:
354 get_bad_stack
355 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000356 bl do_not_used
wdenk8ed96042005-01-09 23:16:25 +0000357
358#ifdef CONFIG_USE_IRQ
359
360 .align 5
361irq:
362 get_irq_stack
363 irq_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000364 bl do_irq
wdenk8ed96042005-01-09 23:16:25 +0000365 irq_restore_user_regs
366
367 .align 5
368fiq:
369 get_fiq_stack
370 /* someone ought to write a more effiction fiq_save_user_regs */
371 irq_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000372 bl do_fiq
wdenk8ed96042005-01-09 23:16:25 +0000373 irq_restore_user_regs
374
375#else
376
377 .align 5
378irq:
379 get_bad_stack
380 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000381 bl do_irq
wdenk8ed96042005-01-09 23:16:25 +0000382
383 .align 5
384fiq:
385 get_bad_stack
386 bad_save_user_regs
wdenk082acfd2005-01-10 00:01:04 +0000387 bl do_fiq
wdenk8ed96042005-01-09 23:16:25 +0000388
389#endif
390 .align 5
391.global arm1136_cache_flush
392arm1136_cache_flush:
393 mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
394 mov pc, lr @ back to caller
395
396 .align 5
397.globl reset_cpu
398reset_cpu:
wdenk082acfd2005-01-10 00:01:04 +0000399 ldr r1, rstctl /* get addr for global reset reg */
wdenk289f9322005-01-12 00:15:14 +0000400 mov r3, #0x2 /* full reset pll+mpu */
wdenk082acfd2005-01-10 00:01:04 +0000401 str r3, [r1] /* force reset */
wdenk8ed96042005-01-09 23:16:25 +0000402 mov r0, r0
403_loop_forever:
404 b _loop_forever
405rstctl:
406 .word PM_RSTCTRL_WKUP