blob: 8cacc1663627e4abd9e019d5917717cb7f67c456 [file] [log] [blame]
wdenkf8062712005-01-09 23:16:25 +00001/*
2 * armboot - Startup Code for OMP2420/ARM1136 CPU-core
3 *
wdenk2e405bf2005-01-10 00:01:04 +00004 * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
wdenkf8062712005-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
wdenk2e405bf2005-01-10 00:01:04 +000022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenkf8062712005-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
wdenk2e405bf2005-01-10 00:01:04 +000036_start: b reset
wdenkf8062712005-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
wdenk2e405bf2005-01-10 00:01:04 +000045_undefined_instruction: .word undefined_instruction
wdenkf8062712005-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
wdenk2e405bf2005-01-10 00:01:04 +000052_pad: .word 0x12345678 /* now 16*4=64 */
wdenkf8062712005-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
wdenk2e405bf2005-01-10 00:01:04 +0000114 /* Copy vectors to mask ROM indirect addr */
115 adr r0, _start /* r0 <- current position of code */
116 mov r2, #64 /* r2 <- size to copy */
117 add r2, r0, r2 /* r2 <- source end address */
118 mov r1, #SRAM_OFFSET0 /* build vect addr */
119 mov r3, #SRAM_OFFSET1
120 add r1, r1, r3
121 mov r3, #SRAM_OFFSET2
122 add r1, r1, r3
wdenkf8062712005-01-09 23:16:25 +0000123next:
wdenk2e405bf2005-01-10 00:01:04 +0000124 ldmia r0!, {r3-r10} /* copy from source address [r0] */
125 stmia r1!, {r3-r10} /* copy to target address [r1] */
126 cmp r0, r2 /* until source end address [r2] */
127 bne next /* loop until equal */
wdenkf8062712005-01-09 23:16:25 +0000128#ifdef CONFIG_PARTIAL_SRAM
wdenk2e405bf2005-01-10 00:01:04 +0000129 bl cpy_clk_code /* put dpll adjust code behind vectors */
wdenkf8062712005-01-09 23:16:25 +0000130#endif
131#endif
132 /* the mask ROM code should have PLL and others stable */
133 bl cpu_init_crit
134
135relocate: /* relocate U-Boot to RAM */
136 adr r0, _start /* r0 <- current position of code */
137 ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
wdenk2e405bf2005-01-10 00:01:04 +0000138 cmp r0, r1 /* don't reloc during debug */
139 beq stack_setup
wdenkf8062712005-01-09 23:16:25 +0000140
141 ldr r2, _armboot_start
142 ldr r3, _bss_start
wdenk2e405bf2005-01-10 00:01:04 +0000143 sub r2, r3, r2 /* r2 <- size of armboot */
144 add r2, r0, r2 /* r2 <- source end address */
wdenkf8062712005-01-09 23:16:25 +0000145
146copy_loop:
147 ldmia r0!, {r3-r10} /* copy from source address [r0] */
148 stmia r1!, {r3-r10} /* copy to target address [r1] */
149 cmp r0, r2 /* until source end addreee [r2] */
150 ble copy_loop
151
152 /* Set up the stack */
153stack_setup:
154 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
wdenk2e405bf2005-01-10 00:01:04 +0000155 sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
156 sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */
wdenkf8062712005-01-09 23:16:25 +0000157#ifdef CONFIG_USE_IRQ
158 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
159#endif
160 sub sp, r0, #12 /* leave 3 words for abort-stack */
161
162clear_bss:
wdenk2e405bf2005-01-10 00:01:04 +0000163 ldr r0, _bss_start /* find start of bss segment */
164 ldr r1, _bss_end /* stop here */
165 mov r2, #0x00000000 /* clear */
wdenkf8062712005-01-09 23:16:25 +0000166
wdenk2e405bf2005-01-10 00:01:04 +0000167clbss_l:str r2, [r0] /* clear loop... */
wdenkf8062712005-01-09 23:16:25 +0000168 add r0, r0, #4
169 cmp r0, r1
170 bne clbss_l
171
172 ldr pc, _start_armboot
173
wdenk2e405bf2005-01-10 00:01:04 +0000174_start_armboot: .word start_armboot
wdenkf8062712005-01-09 23:16:25 +0000175
176
177/*
178 *************************************************************************
179 *
180 * CPU_init_critical registers
181 *
182 * setup important registers
183 * setup memory timing
184 *
185 *************************************************************************
186 */
187cpu_init_crit:
188 /*
189 * flush v4 I/D caches
190 */
191 mov r0, #0
192 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
193 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
194
195 /*
196 * disable MMU stuff and caches
197 */
198 mrc p15, 0, r0, c1, c0, 0
199 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
200 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
201 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
202#ifndef CONFIG_ICACHE_OFF
203 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
204#endif
205 mcr p15, 0, r0, c1, c0, 0
206
207 /*
wdenk2e405bf2005-01-10 00:01:04 +0000208 * Jump to board specific initialization... The Mask ROM will have already initialized
209 * basic memory. Go here to bump up clock rate and handle wake up conditions.
wdenkf8062712005-01-09 23:16:25 +0000210 */
211 adr r0, _start /* r0 <- current position of code */
212 ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
wdenk2e405bf2005-01-10 00:01:04 +0000213 cmp r0, r1 /* pass on info about skipping some init portions */
214 moveq r0,#0x1 /* flag to skip prcm and sdrc setup */
215 movne r0,#0x0
216 mov ip, lr /* persevere link reg across call */
217 bl platformsetup /* go setup pll,mux,memory */
218 mov lr, ip /* restore link */
219 mov pc, lr /* back to my caller */
wdenkf8062712005-01-09 23:16:25 +0000220/*
221 *************************************************************************
222 *
223 * Interrupt handling
224 *
225 *************************************************************************
226 */
227@
228@ IRQ stack frame.
229@
230#define S_FRAME_SIZE 72
231
232#define S_OLD_R0 68
233#define S_PSR 64
234#define S_PC 60
235#define S_LR 56
236#define S_SP 52
237
238#define S_IP 48
239#define S_FP 44
240#define S_R10 40
241#define S_R9 36
242#define S_R8 32
243#define S_R7 28
244#define S_R6 24
245#define S_R5 20
246#define S_R4 16
247#define S_R3 12
248#define S_R2 8
249#define S_R1 4
250#define S_R0 0
251
252#define MODE_SVC 0x13
253#define I_BIT 0x80
254
255/*
256 * use bad_save_user_regs for abort/prefetch/undef/swi ...
257 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
258 */
259
260 .macro bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000261 sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack
wdenkf8062712005-01-09 23:16:25 +0000262 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
263
264 ldr r2, _armboot_start
265 sub r2, r2, #(CFG_MALLOC_LEN)
wdenk2e405bf2005-01-10 00:01:04 +0000266 sub r2, r2, #(CFG_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
267 ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs)
wdenkf8062712005-01-09 23:16:25 +0000268 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
269
270 add r5, sp, #S_SP
271 mov r1, lr
wdenk2e405bf2005-01-10 00:01:04 +0000272 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
273 mov r0, sp @ save current stack into r0 (param register)
wdenkf8062712005-01-09 23:16:25 +0000274 .endm
275
276 .macro irq_save_user_regs
277 sub sp, sp, #S_FRAME_SIZE
278 stmia sp, {r0 - r12} @ Calling r0-r12
wdenk2e405bf2005-01-10 00:01:04 +0000279 add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
280 stmdb r8, {sp, lr}^ @ Calling SP, LR
281 str lr, [r8, #0] @ Save calling PC
282 mrs r6, spsr
283 str r6, [r8, #4] @ Save CPSR
284 str r0, [r8, #8] @ Save OLD_R0
wdenkf8062712005-01-09 23:16:25 +0000285 mov r0, sp
286 .endm
287
288 .macro irq_restore_user_regs
289 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
290 mov r0, r0
291 ldr lr, [sp, #S_PC] @ Get PC
292 add sp, sp, #S_FRAME_SIZE
293 subs pc, lr, #4 @ return & move spsr_svc into cpsr
294 .endm
295
296 .macro get_bad_stack
297 ldr r13, _armboot_start @ setup our mode stack (enter in banked mode)
wdenk2e405bf2005-01-10 00:01:04 +0000298 sub r13, r13, #(CFG_MALLOC_LEN) @ move past malloc pool
wdenkf8062712005-01-09 23:16:25 +0000299 sub r13, r13, #(CFG_GBL_DATA_SIZE+8) @ move to reserved a couple spots for abort stack
300
301 str lr, [r13] @ save caller lr in position 0 of saved stack
wdenk2e405bf2005-01-10 00:01:04 +0000302 mrs lr, spsr @ get the spsr
303 str lr, [r13, #4] @ save spsr in position 1 of saved stack
wdenkf8062712005-01-09 23:16:25 +0000304
305 mov r13, #MODE_SVC @ prepare SVC-Mode
306 @ msr spsr_c, r13
wdenk2e405bf2005-01-10 00:01:04 +0000307 msr spsr, r13 @ switch modes, make sure moves will execute
308 mov lr, pc @ capture return pc
309 movs pc, lr @ jump to next instruction & switch modes.
wdenkf8062712005-01-09 23:16:25 +0000310 .endm
311
312 .macro get_bad_stack_swi
wdenk2e405bf2005-01-10 00:01:04 +0000313 sub r13, r13, #4 @ space on current stack for scratch reg.
314 str r0, [r13] @ save R0's value.
wdenkf8062712005-01-09 23:16:25 +0000315 ldr r0, _armboot_start @ get data regions start
wdenk2e405bf2005-01-10 00:01:04 +0000316 sub r0, r0, #(CFG_MALLOC_LEN) @ move past malloc pool
317 sub r0, r0, #(CFG_GBL_DATA_SIZE+8) @ move past gbl and a couple spots for abort stack
wdenkf8062712005-01-09 23:16:25 +0000318 str lr, [r0] @ save caller lr in position 0 of saved stack
wdenk2e405bf2005-01-10 00:01:04 +0000319 mrs r0, spsr @ get the spsr
320 str lr, [r0, #4] @ save spsr in position 1 of saved stack
321 ldr r0, [r13] @ restore r0
322 add r13, r13, #4 @ pop stack entry
wdenkf8062712005-01-09 23:16:25 +0000323 .endm
324
325 .macro get_irq_stack @ setup IRQ stack
326 ldr sp, IRQ_STACK_START
327 .endm
328
329 .macro get_fiq_stack @ setup FIQ stack
330 ldr sp, FIQ_STACK_START
331 .endm
332
333/*
334 * exception handlers
335 */
wdenk2e405bf2005-01-10 00:01:04 +0000336 .align 5
wdenkf8062712005-01-09 23:16:25 +0000337undefined_instruction:
338 get_bad_stack
339 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000340 bl do_undefined_instruction
wdenkf8062712005-01-09 23:16:25 +0000341
342 .align 5
343software_interrupt:
344 get_bad_stack_swi
345 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000346 bl do_software_interrupt
wdenkf8062712005-01-09 23:16:25 +0000347
348 .align 5
349prefetch_abort:
350 get_bad_stack
351 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000352 bl do_prefetch_abort
wdenkf8062712005-01-09 23:16:25 +0000353
354 .align 5
355data_abort:
356 get_bad_stack
357 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000358 bl do_data_abort
wdenkf8062712005-01-09 23:16:25 +0000359
360 .align 5
361not_used:
362 get_bad_stack
363 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000364 bl do_not_used
wdenkf8062712005-01-09 23:16:25 +0000365
366#ifdef CONFIG_USE_IRQ
367
368 .align 5
369irq:
370 get_irq_stack
371 irq_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000372 bl do_irq
wdenkf8062712005-01-09 23:16:25 +0000373 irq_restore_user_regs
374
375 .align 5
376fiq:
377 get_fiq_stack
378 /* someone ought to write a more effiction fiq_save_user_regs */
379 irq_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000380 bl do_fiq
wdenkf8062712005-01-09 23:16:25 +0000381 irq_restore_user_regs
382
383#else
384
385 .align 5
386irq:
387 get_bad_stack
388 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000389 bl do_irq
wdenkf8062712005-01-09 23:16:25 +0000390
391 .align 5
392fiq:
393 get_bad_stack
394 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000395 bl do_fiq
wdenkf8062712005-01-09 23:16:25 +0000396
397#endif
398 .align 5
399.global arm1136_cache_flush
400arm1136_cache_flush:
401 mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
402 mov pc, lr @ back to caller
403
404 .align 5
405.globl reset_cpu
406reset_cpu:
wdenk2e405bf2005-01-10 00:01:04 +0000407 ldr r1, rstctl /* get addr for global reset reg */
408 mov r3, #0x3 /* full reset pll+mpu */
409 str r3, [r1] /* force reset */
wdenkf8062712005-01-09 23:16:25 +0000410 mov r0, r0
411_loop_forever:
412 b _loop_forever
413rstctl:
414 .word PM_RSTCTRL_WKUP