blob: 51229c61544383f58a1e84295f2f6971e5fc202f [file] [log] [blame]
wdenkf6f96f72003-07-15 20:04:06 +00001/*
2 * armboot - Startup Code for ARM925 CPU-core
3 *
4 * Copyright (c) 2003 Texas Instruments
5 *
6 * ----- Adapted for OMAP1510 from ARM920 code ------
7 *
8 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
9 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
Detlev Zundelf1b3f2b2009-05-13 10:54:10 +020010 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
wdenkf6f96f72003-07-15 20:04:06 +000011 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
Wolfgang Denka1be4762008-05-20 16:00:29 +020012 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
wdenkf6f96f72003-07-15 20:04:06 +000013 *
14 * See file CREDITS for list of people who contributed to this
15 * project.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * MA 02111-1307 USA
31 */
32
Wolfgang Denk0191e472010-10-26 14:34:52 +020033#include <asm-offsets.h>
wdenkf6f96f72003-07-15 20:04:06 +000034#include <config.h>
35#include <version.h>
36
37#if defined(CONFIG_OMAP1510)
38#include <./configs/omap1510.h>
39#endif
40
41/*
42 *************************************************************************
43 *
44 * Jump vector table as in table 3.1 in [1]
45 *
46 *************************************************************************
47 */
48
49
50.globl _start
51_start: b reset
52 ldr pc, _undefined_instruction
53 ldr pc, _software_interrupt
54 ldr pc, _prefetch_abort
55 ldr pc, _data_abort
56 ldr pc, _not_used
57 ldr pc, _irq
58 ldr pc, _fiq
59
60_undefined_instruction: .word undefined_instruction
61_software_interrupt: .word software_interrupt
62_prefetch_abort: .word prefetch_abort
63_data_abort: .word data_abort
64_not_used: .word not_used
65_irq: .word irq
66_fiq: .word fiq
67
68 .balignl 16,0xdeadbeef
69
70
71/*
72 *************************************************************************
73 *
74 * Startup Code (reset vector)
75 *
76 * do important init only if we don't start from memory!
77 * setup Memory and board specific bits prior to relocation.
78 * relocate armboot to ram
79 * setup stack
80 *
81 *************************************************************************
82 */
83
Heiko Schocherdf329fb2010-09-17 13:10:44 +020084.globl _TEXT_BASE
wdenkf6f96f72003-07-15 20:04:06 +000085_TEXT_BASE:
Wolfgang Denk0708bc62010-10-07 21:51:12 +020086 .word CONFIG_SYS_TEXT_BASE
wdenkf6f96f72003-07-15 20:04:06 +000087
wdenkf6f96f72003-07-15 20:04:06 +000088/*
wdenk927034e2004-02-08 19:38:38 +000089 * These are defined in the board-specific linker script.
wdenkf6f96f72003-07-15 20:04:06 +000090 */
wdenk927034e2004-02-08 19:38:38 +000091.globl _bss_start
92_bss_start:
93 .word __bss_start
94
95.globl _bss_end
96_bss_end:
97 .word _end
wdenkf6f96f72003-07-15 20:04:06 +000098
wdenkf6f96f72003-07-15 20:04:06 +000099#ifdef CONFIG_USE_IRQ
100/* IRQ stack memory (calculated at run-time) */
101.globl IRQ_STACK_START
102IRQ_STACK_START:
103 .word 0x0badc0de
104
105/* IRQ stack memory (calculated at run-time) */
106.globl FIQ_STACK_START
107FIQ_STACK_START:
108 .word 0x0badc0de
109#endif
Heiko Schocherdf329fb2010-09-17 13:10:44 +0200110
Heiko Schocherdf329fb2010-09-17 13:10:44 +0200111/* IRQ stack memory (calculated at run-time) + 8 bytes */
112.globl IRQ_STACK_START_IN
113IRQ_STACK_START_IN:
114 .word 0x0badc0de
115
116.globl _datarel_start
117_datarel_start:
118 .word __datarel_start
119
120.globl _datarelrolocal_start
121_datarelrolocal_start:
122 .word __datarelrolocal_start
123
124.globl _datarellocal_start
125_datarellocal_start:
126 .word __datarellocal_start
127
128.globl _datarelro_start
129_datarelro_start:
130 .word __datarelro_start
131
132.globl _got_start
133_got_start:
134 .word __got_start
135
136.globl _got_end
137_got_end:
138 .word __got_end
139
140/*
141 * the actual reset code
142 */
143
144reset:
145 /*
146 * set the cpu to SVC32 mode
147 */
148 mrs r0,cpsr
149 bic r0,r0,#0x1f
150 orr r0,r0,#0xd3
151 msr cpsr,r0
152
153 /*
154 * Set up 925T mode
155 */
156 mov r1, #0x81 /* Set ARM925T configuration. */
157 mcr p15, 0, r1, c15, c1, 0 /* Write ARM925T configuration register. */
158
159 /*
160 * turn off the watchdog, unlock/diable sequence
161 */
162 mov r1, #0xF5
163 ldr r0, =WDTIM_MODE
164 strh r1, [r0]
165 mov r1, #0xA0
166 strh r1, [r0]
167
168 /*
169 * mask all IRQs by setting all bits in the INTMR - default
170 */
171 mov r1, #0xffffffff
172 ldr r0, =REG_IHL1_MIR
173 str r1, [r0]
174 ldr r0, =REG_IHL2_MIR
175 str r1, [r0]
176
177 /*
178 * wait for dpll to lock
179 */
180 ldr r0, =CK_DPLL1
181 mov r1, #0x10
182 strh r1, [r0]
183poll1:
184 ldrh r1, [r0]
185 ands r1, r1, #0x01
186 beq poll1
187
188 /*
189 * we do sys-critical inits only at reboot,
190 * not when booting from ram!
191 */
192#ifndef CONFIG_SKIP_LOWLEVEL_INIT
193 bl cpu_init_crit
194#endif
195
196/* Set stackpointer in internal RAM to call board_init_f */
197call_board_init_f:
198 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
199 ldr r0,=0x00000000
200 bl board_init_f
201
202/*------------------------------------------------------------------------------*/
203
204/*
205 * void relocate_code (addr_sp, gd, addr_moni)
206 *
207 * This "function" does not return, instead it continues in RAM
208 * after relocating the monitor code.
209 *
210 */
211 .globl relocate_code
212relocate_code:
213 mov r4, r0 /* save addr_sp */
214 mov r5, r1 /* save addr of gd */
215 mov r6, r2 /* save addr of destination */
216 mov r7, r2 /* save addr of destination */
217
218 /* Set up the stack */
219stack_setup:
220 mov sp, r4
221
222 adr r0, _start
223 ldr r2, _TEXT_BASE
224 ldr r3, _bss_start
225 sub r2, r3, r2 /* r2 <- size of armboot */
226 add r2, r0, r2 /* r2 <- source end address */
227 cmp r0, r6
228 beq clear_bss
229
Heiko Schocherdf329fb2010-09-17 13:10:44 +0200230copy_loop:
231 ldmia r0!, {r9-r10} /* copy from source address [r0] */
232 stmia r6!, {r9-r10} /* copy to target address [r1] */
Albert Aribaud0668d162010-10-05 16:06:39 +0200233 cmp r0, r2 /* until source end address [r2] */
234 blo copy_loop
Heiko Schocherdf329fb2010-09-17 13:10:44 +0200235
236#ifndef CONFIG_PRELOADER
237 /* fix got entries */
238 ldr r1, _TEXT_BASE /* Text base */
239 mov r0, r7 /* reloc addr */
240 ldr r2, _got_start /* addr in Flash */
241 ldr r3, _got_end /* addr in Flash */
242 sub r3, r3, r1
243 add r3, r3, r0
244 sub r2, r2, r1
245 add r2, r2, r0
246
247fixloop:
248 ldr r4, [r2]
249 sub r4, r4, r1
250 add r4, r4, r0
251 str r4, [r2]
252 add r2, r2, #4
253 cmp r2, r3
Wolfgang Denk98dd07c2010-10-23 23:22:38 +0200254 blo fixloop
Heiko Schocherdf329fb2010-09-17 13:10:44 +0200255#endif
wdenkf6f96f72003-07-15 20:04:06 +0000256
Heiko Schocherdf329fb2010-09-17 13:10:44 +0200257clear_bss:
258#ifndef CONFIG_PRELOADER
259 ldr r0, _bss_start
260 ldr r1, _bss_end
261 ldr r3, _TEXT_BASE /* Text base */
262 mov r4, r7 /* reloc addr */
263 sub r0, r0, r3
264 add r0, r0, r4
265 sub r1, r1, r3
266 add r1, r1, r4
267 mov r2, #0x00000000 /* clear */
wdenkf6f96f72003-07-15 20:04:06 +0000268
Heiko Schocherdf329fb2010-09-17 13:10:44 +0200269clbss_l:str r2, [r0] /* clear loop... */
270 add r0, r0, #4
271 cmp r0, r1
272 bne clbss_l
273
274#endif
275
276/*
277 * We are done. Do not return, instead branch to second part of board
278 * initialization, now running from RAM.
279 */
280#ifdef CONFIG_NAND_SPL
281 ldr pc, _nand_boot
282
283_nand_boot: .word nand_boot
284#else
285 ldr r0, _TEXT_BASE
286 ldr r2, _board_init_r
287 sub r2, r2, r0
288 add r2, r2, r7 /* position from board_init_r in RAM */
289 /* setup parameters for board_init_r */
290 mov r0, r5 /* gd_t */
291 mov r1, r7 /* dest_addr */
292 /* jump to it ... */
293 mov lr, r2
294 mov pc, lr
295
296_board_init_r: .word board_init_r
297#endif
298
wdenkf6f96f72003-07-15 20:04:06 +0000299/*
300 *************************************************************************
301 *
302 * CPU_init_critical registers
303 *
304 * setup important registers
305 * setup memory timing
306 *
307 *************************************************************************
308 */
309
310
311cpu_init_crit:
312 /*
313 * flush v4 I/D caches
314 */
315 mov r0, #0
316 mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */
317 mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */
318
319 /*
320 * disable MMU stuff and caches
321 */
322 mrc p15, 0, r0, c1, c0, 0
323 bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS)
324 bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM)
325 orr r0, r0, #0x00000002 @ set bit 2 (A) Align
326 orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache
327 mcr p15, 0, r0, c1, c0, 0
328
329 /*
330 * Go setup Memory and board specific bits prior to relocation.
331 */
332 mov ip, lr /* perserve link reg across call */
Wolfgang Denk7f88a5e2005-10-06 17:08:18 +0200333 bl lowlevel_init /* go setup pll,mux,memory */
wdenkf6f96f72003-07-15 20:04:06 +0000334 mov lr, ip /* restore link */
335 mov pc, lr /* back to my caller */
336/*
337 *************************************************************************
338 *
339 * Interrupt handling
340 *
341 *************************************************************************
342 */
343
344@
345@ IRQ stack frame.
346@
347#define S_FRAME_SIZE 72
348
349#define S_OLD_R0 68
350#define S_PSR 64
351#define S_PC 60
352#define S_LR 56
353#define S_SP 52
354
355#define S_IP 48
356#define S_FP 44
357#define S_R10 40
358#define S_R9 36
359#define S_R8 32
360#define S_R7 28
361#define S_R6 24
362#define S_R5 20
363#define S_R4 16
364#define S_R3 12
365#define S_R2 8
366#define S_R1 4
367#define S_R0 0
368
369#define MODE_SVC 0x13
370#define I_BIT 0x80
371
372/*
373 * use bad_save_user_regs for abort/prefetch/undef/swi ...
374 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
375 */
376
377 .macro bad_save_user_regs
378 sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack
379 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
380
Heiko Schocherdf329fb2010-09-17 13:10:44 +0200381 ldr r2, IRQ_STACK_START_IN
wdenkf6f96f72003-07-15 20:04:06 +0000382 ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs)
383 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
384
385 add r5, sp, #S_SP
386 mov r1, lr
387 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
388 mov r0, sp @ save current stack into r0 (param register)
389 .endm
390
391 .macro irq_save_user_regs
392 sub sp, sp, #S_FRAME_SIZE
393 stmia sp, {r0 - r12} @ Calling r0-r12
394 add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
395 stmdb r8, {sp, lr}^ @ Calling SP, LR
396 str lr, [r8, #0] @ Save calling PC
397 mrs r6, spsr
398 str r6, [r8, #4] @ Save CPSR
399 str r0, [r8, #8] @ Save OLD_R0
400 mov r0, sp
401 .endm
402
403 .macro irq_restore_user_regs
404 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
405 mov r0, r0
406 ldr lr, [sp, #S_PC] @ Get PC
407 add sp, sp, #S_FRAME_SIZE
408 subs pc, lr, #4 @ return & move spsr_svc into cpsr
409 .endm
410
411 .macro get_bad_stack
Heiko Schocherdf329fb2010-09-17 13:10:44 +0200412 ldr r13, IRQ_STACK_START_IN
wdenkf6f96f72003-07-15 20:04:06 +0000413
414 str lr, [r13] @ save caller lr in position 0 of saved stack
415 mrs lr, spsr @ get the spsr
416 str lr, [r13, #4] @ save spsr in position 1 of saved stack
417
418 mov r13, #MODE_SVC @ prepare SVC-Mode
419 @ msr spsr_c, r13
420 msr spsr, r13 @ switch modes, make sure moves will execute
421 mov lr, pc @ capture return pc
422 movs pc, lr @ jump to next instruction & switch modes.
423 .endm
424
425 .macro get_irq_stack @ setup IRQ stack
426 ldr sp, IRQ_STACK_START
427 .endm
428
429 .macro get_fiq_stack @ setup FIQ stack
430 ldr sp, FIQ_STACK_START
431 .endm
432
433/*
434 * exception handlers
435 */
436 .align 5
437undefined_instruction:
438 get_bad_stack
439 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200440 bl do_undefined_instruction
wdenkf6f96f72003-07-15 20:04:06 +0000441
442 .align 5
443software_interrupt:
444 get_bad_stack
445 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200446 bl do_software_interrupt
wdenkf6f96f72003-07-15 20:04:06 +0000447
448 .align 5
449prefetch_abort:
450 get_bad_stack
451 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200452 bl do_prefetch_abort
wdenkf6f96f72003-07-15 20:04:06 +0000453
454 .align 5
455data_abort:
456 get_bad_stack
457 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200458 bl do_data_abort
wdenkf6f96f72003-07-15 20:04:06 +0000459
460 .align 5
461not_used:
462 get_bad_stack
463 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200464 bl do_not_used
wdenkf6f96f72003-07-15 20:04:06 +0000465
466#ifdef CONFIG_USE_IRQ
467
468 .align 5
469irq:
470 get_irq_stack
471 irq_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200472 bl do_irq
wdenkf6f96f72003-07-15 20:04:06 +0000473 irq_restore_user_regs
474
475 .align 5
476fiq:
477 get_fiq_stack
478 /* someone ought to write a more effiction fiq_save_user_regs */
479 irq_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200480 bl do_fiq
wdenkf6f96f72003-07-15 20:04:06 +0000481 irq_restore_user_regs
482
483#else
484
485 .align 5
486irq:
487 get_bad_stack
488 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200489 bl do_irq
wdenkf6f96f72003-07-15 20:04:06 +0000490
491 .align 5
492fiq:
493 get_bad_stack
494 bad_save_user_regs
Wolfgang Denka1be4762008-05-20 16:00:29 +0200495 bl do_fiq
wdenkf6f96f72003-07-15 20:04:06 +0000496
497#endif
498
499 .align 5
500.globl reset_cpu
501reset_cpu:
502 ldr r1, rstctl1 /* get clkm1 reset ctl */
wdenke58b0dc2003-07-27 00:21:01 +0000503 mov r3, #0x3 /* dsp_en + arm_rst = global reset */
504 strh r3, [r1] /* force reset */
505 mov r0, r0
wdenkf6f96f72003-07-15 20:04:06 +0000506_loop_forever:
507 b _loop_forever
508rstctl1:
509 .word 0xfffece10