blob: 17c7a834919b54a4b02fc929df958dcb0abac0bb [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>
Wolfgang Denk88bd7432005-10-09 00:22:48 +020033#if !defined(CONFIG_INTEGRATOR) && ! defined(CONFIG_ARCH_CINTEGRATOR)
wdenkf8062712005-01-09 23:16:25 +000034#include <asm/arch/omap2420.h>
Wolfgang Denk88bd7432005-10-09 00:22:48 +020035#endif
wdenkf8062712005-01-09 23:16:25 +000036.globl _start
wdenk2e405bf2005-01-10 00:01:04 +000037_start: b reset
wdenkf8062712005-01-09 23:16:25 +000038 ldr pc, _undefined_instruction
39 ldr pc, _software_interrupt
40 ldr pc, _prefetch_abort
41 ldr pc, _data_abort
42 ldr pc, _not_used
43 ldr pc, _irq
44 ldr pc, _fiq
45
wdenk2e405bf2005-01-10 00:01:04 +000046_undefined_instruction: .word undefined_instruction
wdenkf8062712005-01-09 23:16:25 +000047_software_interrupt: .word software_interrupt
48_prefetch_abort: .word prefetch_abort
49_data_abort: .word data_abort
50_not_used: .word not_used
51_irq: .word irq
52_fiq: .word fiq
wdenk2e405bf2005-01-10 00:01:04 +000053_pad: .word 0x12345678 /* now 16*4=64 */
wdenkf8062712005-01-09 23:16:25 +000054.global _end_vect
55_end_vect:
56
57 .balignl 16,0xdeadbeef
58/*
59 *************************************************************************
60 *
61 * Startup Code (reset vector)
62 *
63 * do important init only if we don't start from memory!
64 * setup Memory and board specific bits prior to relocation.
65 * relocate armboot to ram
66 * setup stack
67 *
68 *************************************************************************
69 */
70
71_TEXT_BASE:
72 .word TEXT_BASE
73
74.globl _armboot_start
75_armboot_start:
76 .word _start
77
78/*
79 * These are defined in the board-specific linker script.
80 */
81.globl _bss_start
82_bss_start:
83 .word __bss_start
84
85.globl _bss_end
86_bss_end:
87 .word _end
88
89#ifdef CONFIG_USE_IRQ
90/* IRQ stack memory (calculated at run-time) */
91.globl IRQ_STACK_START
92IRQ_STACK_START:
93 .word 0x0badc0de
94
95/* IRQ stack memory (calculated at run-time) */
96.globl FIQ_STACK_START
97FIQ_STACK_START:
98 .word 0x0badc0de
99#endif
100
101/*
102 * the actual reset code
103 */
104
105reset:
106 /*
107 * set the cpu to SVC32 mode
108 */
109 mrs r0,cpsr
110 bic r0,r0,#0x1f
111 orr r0,r0,#0xd3
112 msr cpsr,r0
113
114#ifdef CONFIG_OMAP2420H4
wdenk2e405bf2005-01-10 00:01:04 +0000115 /* Copy vectors to mask ROM indirect addr */
116 adr r0, _start /* r0 <- current position of code */
wdenkcb99da52005-01-12 00:15:14 +0000117 add r0, r0, #4 /* skip reset vector */
wdenk2e405bf2005-01-10 00:01:04 +0000118 mov r2, #64 /* r2 <- size to copy */
119 add r2, r0, r2 /* r2 <- source end address */
120 mov r1, #SRAM_OFFSET0 /* build vect addr */
121 mov r3, #SRAM_OFFSET1
122 add r1, r1, r3
123 mov r3, #SRAM_OFFSET2
124 add r1, r1, r3
wdenkf8062712005-01-09 23:16:25 +0000125next:
wdenk2e405bf2005-01-10 00:01:04 +0000126 ldmia r0!, {r3-r10} /* copy from source address [r0] */
127 stmia r1!, {r3-r10} /* copy to target address [r1] */
128 cmp r0, r2 /* until source end address [r2] */
129 bne next /* loop until equal */
wdenk2e405bf2005-01-10 00:01:04 +0000130 bl cpy_clk_code /* put dpll adjust code behind vectors */
wdenkf8062712005-01-09 23:16:25 +0000131#endif
wdenkf8062712005-01-09 23:16:25 +0000132 /* the mask ROM code should have PLL and others stable */
wdenk3d3d99f2005-04-04 12:44:11 +0000133#ifndef CONFIG_SKIP_LOWLEVEL_INIT
wdenkf8062712005-01-09 23:16:25 +0000134 bl cpu_init_crit
wdenk3d3d99f2005-04-04 12:44:11 +0000135#endif
wdenkf8062712005-01-09 23:16:25 +0000136
wdenk3d3d99f2005-04-04 12:44:11 +0000137#ifndef CONFIG_SKIP_RELOCATE_UBOOT
wdenkf8062712005-01-09 23:16:25 +0000138relocate: /* relocate U-Boot to RAM */
139 adr r0, _start /* r0 <- current position of code */
140 ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
wdenk2e405bf2005-01-10 00:01:04 +0000141 cmp r0, r1 /* don't reloc during debug */
142 beq stack_setup
wdenkf8062712005-01-09 23:16:25 +0000143
144 ldr r2, _armboot_start
145 ldr r3, _bss_start
wdenk2e405bf2005-01-10 00:01:04 +0000146 sub r2, r3, r2 /* r2 <- size of armboot */
147 add r2, r0, r2 /* r2 <- source end address */
wdenkf8062712005-01-09 23:16:25 +0000148
149copy_loop:
150 ldmia r0!, {r3-r10} /* copy from source address [r0] */
151 stmia r1!, {r3-r10} /* copy to target address [r1] */
152 cmp r0, r2 /* until source end addreee [r2] */
153 ble copy_loop
wdenk3d3d99f2005-04-04 12:44:11 +0000154#endif /* CONFIG_SKIP_RELOCATE_UBOOT */
wdenkf8062712005-01-09 23:16:25 +0000155
156 /* Set up the stack */
157stack_setup:
158 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
wdenk2e405bf2005-01-10 00:01:04 +0000159 sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
160 sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */
wdenkf8062712005-01-09 23:16:25 +0000161#ifdef CONFIG_USE_IRQ
162 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
163#endif
164 sub sp, r0, #12 /* leave 3 words for abort-stack */
165
166clear_bss:
wdenk2e405bf2005-01-10 00:01:04 +0000167 ldr r0, _bss_start /* find start of bss segment */
168 ldr r1, _bss_end /* stop here */
169 mov r2, #0x00000000 /* clear */
wdenkf8062712005-01-09 23:16:25 +0000170
wdenk2e405bf2005-01-10 00:01:04 +0000171clbss_l:str r2, [r0] /* clear loop... */
wdenkf8062712005-01-09 23:16:25 +0000172 add r0, r0, #4
173 cmp r0, r1
174 bne clbss_l
175
176 ldr pc, _start_armboot
177
wdenk2e405bf2005-01-10 00:01:04 +0000178_start_armboot: .word start_armboot
wdenkf8062712005-01-09 23:16:25 +0000179
180
181/*
182 *************************************************************************
183 *
184 * CPU_init_critical registers
185 *
186 * setup important registers
187 * setup memory timing
188 *
189 *************************************************************************
190 */
191cpu_init_crit:
192 /*
193 * flush v4 I/D caches
194 */
195 mov r0, #0
196 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
197 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
198
199 /*
200 * disable MMU stuff and caches
201 */
202 mrc p15, 0, r0, c1, c0, 0
203 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
204 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
205 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
wdenkf8062712005-01-09 23:16:25 +0000206 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
wdenkf8062712005-01-09 23:16:25 +0000207 mcr p15, 0, r0, c1, c0, 0
208
209 /*
wdenk2e405bf2005-01-10 00:01:04 +0000210 * Jump to board specific initialization... The Mask ROM will have already initialized
211 * basic memory. Go here to bump up clock rate and handle wake up conditions.
wdenkf8062712005-01-09 23:16:25 +0000212 */
wdenk2e405bf2005-01-10 00:01:04 +0000213 mov ip, lr /* persevere link reg across call */
Wolfgang Denk7f88a5e2005-10-06 17:08:18 +0200214 bl lowlevel_init /* go setup pll,mux,memory */
wdenk2e405bf2005-01-10 00:01:04 +0000215 mov lr, ip /* restore link */
216 mov pc, lr /* back to my caller */
wdenkf8062712005-01-09 23:16:25 +0000217/*
218 *************************************************************************
219 *
220 * Interrupt handling
221 *
222 *************************************************************************
223 */
224@
225@ IRQ stack frame.
226@
227#define S_FRAME_SIZE 72
228
229#define S_OLD_R0 68
230#define S_PSR 64
231#define S_PC 60
232#define S_LR 56
233#define S_SP 52
234
235#define S_IP 48
236#define S_FP 44
237#define S_R10 40
238#define S_R9 36
239#define S_R8 32
240#define S_R7 28
241#define S_R6 24
242#define S_R5 20
243#define S_R4 16
244#define S_R3 12
245#define S_R2 8
246#define S_R1 4
247#define S_R0 0
248
249#define MODE_SVC 0x13
250#define I_BIT 0x80
251
252/*
253 * use bad_save_user_regs for abort/prefetch/undef/swi ...
254 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
255 */
256
257 .macro bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000258 sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack
wdenkf8062712005-01-09 23:16:25 +0000259 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
260
261 ldr r2, _armboot_start
262 sub r2, r2, #(CFG_MALLOC_LEN)
wdenk2e405bf2005-01-10 00:01:04 +0000263 sub r2, r2, #(CFG_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
264 ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs)
wdenkf8062712005-01-09 23:16:25 +0000265 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
266
267 add r5, sp, #S_SP
268 mov r1, lr
wdenk2e405bf2005-01-10 00:01:04 +0000269 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
270 mov r0, sp @ save current stack into r0 (param register)
wdenkf8062712005-01-09 23:16:25 +0000271 .endm
272
273 .macro irq_save_user_regs
274 sub sp, sp, #S_FRAME_SIZE
275 stmia sp, {r0 - r12} @ Calling r0-r12
wdenk2e405bf2005-01-10 00:01:04 +0000276 add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
277 stmdb r8, {sp, lr}^ @ Calling SP, LR
278 str lr, [r8, #0] @ Save calling PC
279 mrs r6, spsr
280 str r6, [r8, #4] @ Save CPSR
281 str r0, [r8, #8] @ Save OLD_R0
wdenkf8062712005-01-09 23:16:25 +0000282 mov r0, sp
283 .endm
284
285 .macro irq_restore_user_regs
286 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
287 mov r0, r0
288 ldr lr, [sp, #S_PC] @ Get PC
289 add sp, sp, #S_FRAME_SIZE
290 subs pc, lr, #4 @ return & move spsr_svc into cpsr
291 .endm
292
293 .macro get_bad_stack
294 ldr r13, _armboot_start @ setup our mode stack (enter in banked mode)
wdenk2e405bf2005-01-10 00:01:04 +0000295 sub r13, r13, #(CFG_MALLOC_LEN) @ move past malloc pool
wdenkf8062712005-01-09 23:16:25 +0000296 sub r13, r13, #(CFG_GBL_DATA_SIZE+8) @ move to reserved a couple spots for abort stack
297
298 str lr, [r13] @ save caller lr in position 0 of saved stack
wdenk2e405bf2005-01-10 00:01:04 +0000299 mrs lr, spsr @ get the spsr
300 str lr, [r13, #4] @ save spsr in position 1 of saved stack
wdenkf8062712005-01-09 23:16:25 +0000301
302 mov r13, #MODE_SVC @ prepare SVC-Mode
303 @ msr spsr_c, r13
wdenk2e405bf2005-01-10 00:01:04 +0000304 msr spsr, r13 @ switch modes, make sure moves will execute
305 mov lr, pc @ capture return pc
306 movs pc, lr @ jump to next instruction & switch modes.
wdenkf8062712005-01-09 23:16:25 +0000307 .endm
308
309 .macro get_bad_stack_swi
wdenk2e405bf2005-01-10 00:01:04 +0000310 sub r13, r13, #4 @ space on current stack for scratch reg.
311 str r0, [r13] @ save R0's value.
wdenkf8062712005-01-09 23:16:25 +0000312 ldr r0, _armboot_start @ get data regions start
wdenk2e405bf2005-01-10 00:01:04 +0000313 sub r0, r0, #(CFG_MALLOC_LEN) @ move past malloc pool
314 sub r0, r0, #(CFG_GBL_DATA_SIZE+8) @ move past gbl and a couple spots for abort stack
wdenkf8062712005-01-09 23:16:25 +0000315 str lr, [r0] @ save caller lr in position 0 of saved stack
wdenk2e405bf2005-01-10 00:01:04 +0000316 mrs r0, spsr @ get the spsr
317 str lr, [r0, #4] @ save spsr in position 1 of saved stack
318 ldr r0, [r13] @ restore r0
319 add r13, r13, #4 @ pop stack entry
wdenkf8062712005-01-09 23:16:25 +0000320 .endm
321
322 .macro get_irq_stack @ setup IRQ stack
323 ldr sp, IRQ_STACK_START
324 .endm
325
326 .macro get_fiq_stack @ setup FIQ stack
327 ldr sp, FIQ_STACK_START
328 .endm
329
330/*
331 * exception handlers
332 */
wdenk2e405bf2005-01-10 00:01:04 +0000333 .align 5
wdenkf8062712005-01-09 23:16:25 +0000334undefined_instruction:
335 get_bad_stack
336 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000337 bl do_undefined_instruction
wdenkf8062712005-01-09 23:16:25 +0000338
339 .align 5
340software_interrupt:
341 get_bad_stack_swi
342 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000343 bl do_software_interrupt
wdenkf8062712005-01-09 23:16:25 +0000344
345 .align 5
346prefetch_abort:
347 get_bad_stack
348 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000349 bl do_prefetch_abort
wdenkf8062712005-01-09 23:16:25 +0000350
351 .align 5
352data_abort:
353 get_bad_stack
354 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000355 bl do_data_abort
wdenkf8062712005-01-09 23:16:25 +0000356
357 .align 5
358not_used:
359 get_bad_stack
360 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000361 bl do_not_used
wdenkf8062712005-01-09 23:16:25 +0000362
363#ifdef CONFIG_USE_IRQ
364
365 .align 5
366irq:
367 get_irq_stack
368 irq_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000369 bl do_irq
wdenkf8062712005-01-09 23:16:25 +0000370 irq_restore_user_regs
371
372 .align 5
373fiq:
374 get_fiq_stack
375 /* someone ought to write a more effiction fiq_save_user_regs */
376 irq_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000377 bl do_fiq
wdenkf8062712005-01-09 23:16:25 +0000378 irq_restore_user_regs
379
380#else
381
382 .align 5
383irq:
384 get_bad_stack
385 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000386 bl do_irq
wdenkf8062712005-01-09 23:16:25 +0000387
388 .align 5
389fiq:
390 get_bad_stack
391 bad_save_user_regs
wdenk2e405bf2005-01-10 00:01:04 +0000392 bl do_fiq
wdenkf8062712005-01-09 23:16:25 +0000393
394#endif
395 .align 5
396.global arm1136_cache_flush
397arm1136_cache_flush:
398 mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache
399 mov pc, lr @ back to caller
400
Wolfgang Denk7f88a5e2005-10-06 17:08:18 +0200401#if defined(CONFIG_INTEGRATOR) && defined(CONFIG_ARCH_CINTEGRATOR)
402/* Use the IntegratorCP function from board/integratorcp/platform.S */
403#else
404
wdenkf8062712005-01-09 23:16:25 +0000405 .align 5
406.globl reset_cpu
407reset_cpu:
wdenk2e405bf2005-01-10 00:01:04 +0000408 ldr r1, rstctl /* get addr for global reset reg */
wdenkcb99da52005-01-12 00:15:14 +0000409 mov r3, #0x2 /* full reset pll+mpu */
wdenk2e405bf2005-01-10 00:01:04 +0000410 str r3, [r1] /* force reset */
wdenkf8062712005-01-09 23:16:25 +0000411 mov r0, r0
412_loop_forever:
413 b _loop_forever
414rstctl:
415 .word PM_RSTCTRL_WKUP
Wolfgang Denk7f88a5e2005-10-06 17:08:18 +0200416
417#endif