blob: bdf2fad3802f83659eaf11e3da955f2bab303333 [file] [log] [blame]
Dirk Behme7d75a102008-12-14 09:47:13 +01001/*
2 * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core
3 *
4 * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com>
5 *
6 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
7 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
Detlev Zundelf1b3f2b2009-05-13 10:54:10 +02008 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
Dirk Behme7d75a102008-12-14 09:47:13 +01009 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
10 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
11 * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com>
12 *
13 * See file CREDITS for list of people who contributed to this
14 * project.
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 */
31
Wolfgang Denk0191e472010-10-26 14:34:52 +020032#include <asm-offsets.h>
Dirk Behme7d75a102008-12-14 09:47:13 +010033#include <config.h>
34#include <version.h>
35
36.globl _start
37_start: b reset
38 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
46_undefined_instruction: .word undefined_instruction
47_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
53_pad: .word 0x12345678 /* now 16*4=64 */
54.global _end_vect
55_end_vect:
56
57 .balignl 16,0xdeadbeef
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
Heiko Schocher56d0a4d2010-09-17 13:10:41 +020069.globl _TEXT_BASE
Dirk Behme7d75a102008-12-14 09:47:13 +010070_TEXT_BASE:
Wolfgang Denk0708bc62010-10-07 21:51:12 +020071 .word CONFIG_SYS_TEXT_BASE
Dirk Behme7d75a102008-12-14 09:47:13 +010072
Heiko Schocher56d0a4d2010-09-17 13:10:41 +020073#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
Dirk Behme7d75a102008-12-14 09:47:13 +010074.globl _armboot_start
75_armboot_start:
76 .word _start
Heiko Schocher56d0a4d2010-09-17 13:10:41 +020077#endif
Dirk Behme7d75a102008-12-14 09:47:13 +010078
79/*
80 * These are defined in the board-specific linker script.
81 */
Heiko Schocher661a29e2010-10-11 14:08:15 +020082.globl _bss_start_ofs
83_bss_start_ofs:
84 .word __bss_start - _start
Dirk Behme7d75a102008-12-14 09:47:13 +010085
Heiko Schocher661a29e2010-10-11 14:08:15 +020086.globl _bss_end_ofs
87_bss_end_ofs:
88 .word _end - _start
Dirk Behme7d75a102008-12-14 09:47:13 +010089
90#ifdef CONFIG_USE_IRQ
91/* IRQ stack memory (calculated at run-time) */
92.globl IRQ_STACK_START
93IRQ_STACK_START:
94 .word 0x0badc0de
95
96/* IRQ stack memory (calculated at run-time) */
97.globl FIQ_STACK_START
98FIQ_STACK_START:
99 .word 0x0badc0de
100#endif
101
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200102#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
103/* IRQ stack memory (calculated at run-time) + 8 bytes */
104.globl IRQ_STACK_START_IN
105IRQ_STACK_START_IN:
106 .word 0x0badc0de
107
Heiko Schocher661a29e2010-10-11 14:08:15 +0200108.globl _datarel_start_ofs
109_datarel_start_ofs:
110 .word __datarel_start - _start
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200111
Heiko Schocher661a29e2010-10-11 14:08:15 +0200112.globl _datarelrolocal_start_ofs
113_datarelrolocal_start_ofs:
114 .word __datarelrolocal_start - _start
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200115
Heiko Schocher661a29e2010-10-11 14:08:15 +0200116.globl _datarellocal_start_ofs
117_datarellocal_start_ofs:
118 .word __datarellocal_start - _start
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200119
Heiko Schocher661a29e2010-10-11 14:08:15 +0200120.globl _datarelro_start_ofs
121_datarelro_start_ofs:
122 .word __datarelro_start - _start
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200123
Heiko Schocher661a29e2010-10-11 14:08:15 +0200124.globl _got_start_ofs
125_got_start_ofs:
126 .word __got_start - _start
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200127
Heiko Schocher661a29e2010-10-11 14:08:15 +0200128.globl _got_end_Ofs
129_got_end_ofs:
130 .word __got_end - _start
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200131
Dirk Behme7d75a102008-12-14 09:47:13 +0100132/*
133 * the actual reset code
134 */
135
136reset:
137 /*
138 * set the cpu to SVC32 mode
139 */
140 mrs r0, cpsr
141 bic r0, r0, #0x1f
142 orr r0, r0, #0xd3
143 msr cpsr,r0
144
145#if (CONFIG_OMAP34XX)
146 /* Copy vectors to mask ROM indirect addr */
147 adr r0, _start @ r0 <- current position of code
148 add r0, r0, #4 @ skip reset vector
149 mov r2, #64 @ r2 <- size to copy
150 add r2, r0, r2 @ r2 <- source end address
151 mov r1, #SRAM_OFFSET0 @ build vect addr
152 mov r3, #SRAM_OFFSET1
153 add r1, r1, r3
154 mov r3, #SRAM_OFFSET2
155 add r1, r1, r3
156next:
157 ldmia r0!, {r3 - r10} @ copy from source address [r0]
158 stmia r1!, {r3 - r10} @ copy to target address [r1]
159 cmp r0, r2 @ until source end address [r2]
160 bne next @ loop until equal */
161#if !defined(CONFIG_SYS_NAND_BOOT) && !defined(CONFIG_SYS_ONENAND_BOOT)
162 /* No need to copy/exec the clock code - DPLL adjust already done
163 * in NAND/oneNAND Boot.
164 */
165 bl cpy_clk_code @ put dpll adjust code behind vectors
166#endif /* NAND Boot */
167#endif
168 /* the mask ROM code should have PLL and others stable */
169#ifndef CONFIG_SKIP_LOWLEVEL_INIT
170 bl cpu_init_crit
171#endif
172
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200173/* Set stackpointer in internal RAM to call board_init_f */
174call_board_init_f:
175 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
176 ldr r0,=0x00000000
177 bl board_init_f
178
179/*------------------------------------------------------------------------------*/
180
181/*
182 * void relocate_code (addr_sp, gd, addr_moni)
183 *
184 * This "function" does not return, instead it continues in RAM
185 * after relocating the monitor code.
186 *
187 */
188 .globl relocate_code
189relocate_code:
190 mov r4, r0 /* save addr_sp */
191 mov r5, r1 /* save addr of gd */
192 mov r6, r2 /* save addr of destination */
193 mov r7, r2 /* save addr of destination */
194
195 /* Set up the stack */
196stack_setup:
197 mov sp, r4
198
199#ifndef CONFIG_SKIP_RELOCATE_UBOOT
200 adr r0, _start
201 ldr r2, _TEXT_BASE
Heiko Schocher661a29e2010-10-11 14:08:15 +0200202 ldr r3, _bss_start_ofs
203 add r2, r0, r3 /* r2 <- source end address */
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200204 cmp r0, r6
205#ifndef CONFIG_PRELOADER
206 beq jump_2_ram
207#endif
208
209copy_loop:
210 ldmia r0!, {r9-r10} /* copy from source address [r0] */
211 stmia r6!, {r9-r10} /* copy to target address [r1] */
Albert Aribaud0668d162010-10-05 16:06:39 +0200212 cmp r0, r2 /* until source end address [r2] */
213 blo copy_loop
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200214
215#ifndef CONFIG_PRELOADER
Heiko Schocher661a29e2010-10-11 14:08:15 +0200216 /*
217 * fix .rel.dyn relocations
218 */
219 ldr r0, _TEXT_BASE /* r0 <- Text base */
220 sub r9, r7, r0 /* r9 <- relocation offset */
221 ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
222 add r10, r10, r0 /* r10 <- sym table in FLASH */
223 ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
224 add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
225 ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
226 add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200227fixloop:
Gray Remlinea4b2c82010-10-24 16:18:31 +0100228 ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
229 add r0, r0, r9 /* r0 <- location to fix up in RAM */
Heiko Schocher661a29e2010-10-11 14:08:15 +0200230 ldr r1, [r2, #4]
231 and r8, r1, #0xff
Gray Remlinea4b2c82010-10-24 16:18:31 +0100232 cmp r8, #23 /* relative fixup? */
Heiko Schocher661a29e2010-10-11 14:08:15 +0200233 beq fixrel
Gray Remlinea4b2c82010-10-24 16:18:31 +0100234 cmp r8, #2 /* absolute fixup? */
Heiko Schocher661a29e2010-10-11 14:08:15 +0200235 beq fixabs
236 /* ignore unknown type of fixup */
237 b fixnext
238fixabs:
239 /* absolute fix: set location to (offset) symbol value */
240 mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
241 add r1, r10, r1 /* r1 <- address of symbol in table */
242 ldr r1, [r1, #4] /* r1 <- symbol value */
243 add r1, r9 /* r1 <- relocated sym addr */
244 b fixnext
245fixrel:
246 /* relative fix: increase location by offset */
247 ldr r1, [r0]
248 add r1, r1, r9
249fixnext:
250 str r1, [r0]
Gray Remlinea4b2c82010-10-24 16:18:31 +0100251 add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200252 cmp r2, r3
Heiko Schocher661a29e2010-10-11 14:08:15 +0200253 blo fixloop
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200254
255clear_bss:
Heiko Schocher661a29e2010-10-11 14:08:15 +0200256 ldr r0, _bss_start_ofs
257 ldr r1, _bss_end_ofs
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200258 ldr r3, _TEXT_BASE /* Text base */
259 mov r4, r7 /* reloc addr */
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200260 add r0, r0, r4
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200261 add r1, r1, r4
262 mov r2, #0x00000000 /* clear */
263
264clbss_l:str r2, [r0] /* clear loop... */
265 add r0, r0, #4
266 cmp r0, r1
267 bne clbss_l
268#endif /* #ifndef CONFIG_PRELOADER */
269#endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
270
271/*
272 * We are done. Do not return, instead branch to second part of board
273 * initialization, now running from RAM.
274 */
275jump_2_ram:
Heiko Schocher661a29e2010-10-11 14:08:15 +0200276 ldr r0, _board_init_r_ofs
277 adr r1, _start
Darius Augulis50a0a9c2010-10-25 13:45:35 +0300278 add lr, r0, r1
279#ifndef CONFIG_SKIP_RELOCATE_UBOOT
280 add lr, lr, r9
281#endif
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200282 /* setup parameters for board_init_r */
283 mov r0, r5 /* gd_t */
284 mov r1, r7 /* dest_addr */
285 /* jump to it ... */
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200286 mov pc, lr
287
Heiko Schocher661a29e2010-10-11 14:08:15 +0200288_board_init_r_ofs:
289 .word board_init_r - _start
290
291_rel_dyn_start_ofs:
292 .word __rel_dyn_start - _start
293_rel_dyn_end_ofs:
294 .word __rel_dyn_end - _start
295_dynsym_start_ofs:
296 .word __dynsym_start - _start
297
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200298#else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
299/*
300 * the actual reset code
301 */
302
303reset:
304 /*
305 * set the cpu to SVC32 mode
306 */
307 mrs r0, cpsr
308 bic r0, r0, #0x1f
309 orr r0, r0, #0xd3
310 msr cpsr,r0
311
312#if (CONFIG_OMAP34XX)
313 /* Copy vectors to mask ROM indirect addr */
314 adr r0, _start @ r0 <- current position of code
315 add r0, r0, #4 @ skip reset vector
316 mov r2, #64 @ r2 <- size to copy
317 add r2, r0, r2 @ r2 <- source end address
318 mov r1, #SRAM_OFFSET0 @ build vect addr
319 mov r3, #SRAM_OFFSET1
320 add r1, r1, r3
321 mov r3, #SRAM_OFFSET2
322 add r1, r1, r3
323next:
324 ldmia r0!, {r3 - r10} @ copy from source address [r0]
325 stmia r1!, {r3 - r10} @ copy to target address [r1]
326 cmp r0, r2 @ until source end address [r2]
327 bne next @ loop until equal */
328#if !defined(CONFIG_SYS_NAND_BOOT) && !defined(CONFIG_SYS_ONENAND_BOOT)
329 /* No need to copy/exec the clock code - DPLL adjust already done
330 * in NAND/oneNAND Boot.
331 */
332 bl cpy_clk_code @ put dpll adjust code behind vectors
333#endif /* NAND Boot */
334#endif
335 /* the mask ROM code should have PLL and others stable */
336#ifndef CONFIG_SKIP_LOWLEVEL_INIT
337 bl cpu_init_crit
338#endif
339
Dirk Behme7d75a102008-12-14 09:47:13 +0100340#ifndef CONFIG_SKIP_RELOCATE_UBOOT
341relocate: @ relocate U-Boot to RAM
342 adr r0, _start @ r0 <- current position of code
343 ldr r1, _TEXT_BASE @ test if we run from flash or RAM
344 cmp r0, r1 @ don't reloc during debug
345 beq stack_setup
346
347 ldr r2, _armboot_start
348 ldr r3, _bss_start
349 sub r2, r3, r2 @ r2 <- size of armboot
350 add r2, r0, r2 @ r2 <- source end address
351
352copy_loop: @ copy 32 bytes at a time
353 ldmia r0!, {r3 - r10} @ copy from source address [r0]
354 stmia r1!, {r3 - r10} @ copy to target address [r1]
Albert Aribaud0668d162010-10-05 16:06:39 +0200355 cmp r0, r2 @ until source end address [r2]
356 blo copy_loop
Dirk Behme7d75a102008-12-14 09:47:13 +0100357#endif /* CONFIG_SKIP_RELOCATE_UBOOT */
358
359 /* Set up the stack */
360stack_setup:
361 ldr r0, _TEXT_BASE @ upper 128 KiB: relocated uboot
362 sub r0, r0, #CONFIG_SYS_MALLOC_LEN @ malloc area
Wolfgang Denk0191e472010-10-26 14:34:52 +0200363 sub r0, r0, #GENERATED_GBL_DATA_SIZE @ bdinfo
Dirk Behme7d75a102008-12-14 09:47:13 +0100364#ifdef CONFIG_USE_IRQ
365 sub r0, r0, #(CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ)
366#endif
367 sub sp, r0, #12 @ leave 3 words for abort-stack
Vitaly Kuzmichev9c2cec42010-06-15 22:18:11 +0400368 bic sp, sp, #7 @ 8-byte alignment for ABI compliance
Dirk Behme7d75a102008-12-14 09:47:13 +0100369
370 /* Clear BSS (if any). Is below tx (watch load addr - need space) */
371clear_bss:
372 ldr r0, _bss_start @ find start of bss segment
373 ldr r1, _bss_end @ stop here
374 mov r2, #0x00000000 @ clear value
375clbss_l:
376 str r2, [r0] @ clear BSS location
377 cmp r0, r1 @ are we at the end yet
378 add r0, r0, #4 @ increment clear index pointer
379 bne clbss_l @ keep clearing till at end
380
381 ldr pc, _start_armboot @ jump to C code
382
383_start_armboot: .word start_armboot
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200384#endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
Dirk Behme7d75a102008-12-14 09:47:13 +0100385
386/*************************************************************************
387 *
388 * CPU_init_critical registers
389 *
390 * setup important registers
391 * setup memory timing
392 *
393 *************************************************************************/
394cpu_init_crit:
395 /*
396 * Invalidate L1 I/D
397 */
398 mov r0, #0 @ set up for MCR
399 mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs
400 mcr p15, 0, r0, c7, c5, 0 @ invalidate icache
401
402 /*
403 * disable MMU stuff and caches
404 */
405 mrc p15, 0, r0, c1, c0, 0
406 bic r0, r0, #0x00002000 @ clear bits 13 (--V-)
407 bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM)
408 orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align
409 orr r0, r0, #0x00000800 @ set bit 12 (Z---) BTB
410 mcr p15, 0, r0, c1, c0, 0
411
412 /*
413 * Jump to board specific initialization...
414 * The Mask ROM will have already initialized
415 * basic memory. Go here to bump up clock rate and handle
416 * wake up conditions.
417 */
418 mov ip, lr @ persevere link reg across call
419 bl lowlevel_init @ go setup pll,mux,memory
420 mov lr, ip @ restore link
421 mov pc, lr @ back to my caller
422/*
423 *************************************************************************
424 *
425 * Interrupt handling
426 *
427 *************************************************************************
428 */
429@
430@ IRQ stack frame.
431@
432#define S_FRAME_SIZE 72
433
434#define S_OLD_R0 68
435#define S_PSR 64
436#define S_PC 60
437#define S_LR 56
438#define S_SP 52
439
440#define S_IP 48
441#define S_FP 44
442#define S_R10 40
443#define S_R9 36
444#define S_R8 32
445#define S_R7 28
446#define S_R6 24
447#define S_R5 20
448#define S_R4 16
449#define S_R3 12
450#define S_R2 8
451#define S_R1 4
452#define S_R0 0
453
454#define MODE_SVC 0x13
455#define I_BIT 0x80
456
457/*
458 * use bad_save_user_regs for abort/prefetch/undef/swi ...
459 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
460 */
461
462 .macro bad_save_user_regs
463 sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current
464 @ user stack
465 stmia sp, {r0 - r12} @ Save user registers (now in
466 @ svc mode) r0-r12
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200467#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
Dirk Behme7d75a102008-12-14 09:47:13 +0100468 ldr r2, _armboot_start
469 sub r2, r2, #(CONFIG_SYS_MALLOC_LEN)
Wolfgang Denk0191e472010-10-26 14:34:52 +0200470 sub r2, r2, #(GENERATED_GBL_DATA_SIZE + 8) @ set base 2 words into abort
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200471#else
472 ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort
Dirk Behme7d75a102008-12-14 09:47:13 +0100473 @ stack
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200474#endif
Dirk Behme7d75a102008-12-14 09:47:13 +0100475 ldmia r2, {r2 - r3} @ get values for "aborted" pc
476 @ and cpsr (into parm regs)
477 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
478
479 add r5, sp, #S_SP
480 mov r1, lr
481 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
482 mov r0, sp @ save current stack into r0
483 @ (param register)
484 .endm
485
486 .macro irq_save_user_regs
487 sub sp, sp, #S_FRAME_SIZE
488 stmia sp, {r0 - r12} @ Calling r0-r12
489 add r8, sp, #S_PC @ !! R8 NEEDS to be saved !!
490 @ a reserved stack spot would
491 @ be good.
492 stmdb r8, {sp, lr}^ @ Calling SP, LR
493 str lr, [r8, #0] @ Save calling PC
494 mrs r6, spsr
495 str r6, [r8, #4] @ Save CPSR
496 str r0, [r8, #8] @ Save OLD_R0
497 mov r0, sp
498 .endm
499
500 .macro irq_restore_user_regs
501 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
502 mov r0, r0
503 ldr lr, [sp, #S_PC] @ Get PC
504 add sp, sp, #S_FRAME_SIZE
505 subs pc, lr, #4 @ return & move spsr_svc into
506 @ cpsr
507 .endm
508
509 .macro get_bad_stack
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200510#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
Dirk Behme7d75a102008-12-14 09:47:13 +0100511 ldr r13, _armboot_start @ setup our mode stack (enter
Dirk Behme7d75a102008-12-14 09:47:13 +0100512 sub r13, r13, #(CONFIG_SYS_MALLOC_LEN) @ move past malloc pool
Wolfgang Denk0191e472010-10-26 14:34:52 +0200513 sub r13, r13, #(GENERATED_GBL_DATA_SIZE + 8) @ move to reserved a couple
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200514#else
515 ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter
516 @ in banked mode)
517#endif
Dirk Behme7d75a102008-12-14 09:47:13 +0100518
519 str lr, [r13] @ save caller lr in position 0
520 @ of saved stack
521 mrs lr, spsr @ get the spsr
522 str lr, [r13, #4] @ save spsr in position 1 of
523 @ saved stack
524
525 mov r13, #MODE_SVC @ prepare SVC-Mode
526 @ msr spsr_c, r13
527 msr spsr, r13 @ switch modes, make sure
528 @ moves will execute
529 mov lr, pc @ capture return pc
530 movs pc, lr @ jump to next instruction &
531 @ switch modes.
532 .endm
533
534 .macro get_bad_stack_swi
535 sub r13, r13, #4 @ space on current stack for
536 @ scratch reg.
537 str r0, [r13] @ save R0's value.
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200538#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
Dirk Behme7d75a102008-12-14 09:47:13 +0100539 ldr r0, _armboot_start @ get data regions start
540 sub r0, r0, #(CONFIG_SYS_MALLOC_LEN) @ move past malloc pool
Wolfgang Denk0191e472010-10-26 14:34:52 +0200541 sub r0, r0, #(GENERATED_GBL_DATA_SIZE + 8) @ move past gbl and a couple
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200542#else
543 ldr r0, IRQ_STACK_START_IN @ get data regions start
Dirk Behme7d75a102008-12-14 09:47:13 +0100544 @ spots for abort stack
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200545#endif
Dirk Behme7d75a102008-12-14 09:47:13 +0100546 str lr, [r0] @ save caller lr in position 0
547 @ of saved stack
548 mrs r0, spsr @ get the spsr
549 str lr, [r0, #4] @ save spsr in position 1 of
550 @ saved stack
551 ldr r0, [r13] @ restore r0
552 add r13, r13, #4 @ pop stack entry
553 .endm
554
555 .macro get_irq_stack @ setup IRQ stack
556 ldr sp, IRQ_STACK_START
557 .endm
558
559 .macro get_fiq_stack @ setup FIQ stack
560 ldr sp, FIQ_STACK_START
561 .endm
562
563/*
564 * exception handlers
565 */
566 .align 5
567undefined_instruction:
568 get_bad_stack
569 bad_save_user_regs
570 bl do_undefined_instruction
571
572 .align 5
573software_interrupt:
574 get_bad_stack_swi
575 bad_save_user_regs
576 bl do_software_interrupt
577
578 .align 5
579prefetch_abort:
580 get_bad_stack
581 bad_save_user_regs
582 bl do_prefetch_abort
583
584 .align 5
585data_abort:
586 get_bad_stack
587 bad_save_user_regs
588 bl do_data_abort
589
590 .align 5
591not_used:
592 get_bad_stack
593 bad_save_user_regs
594 bl do_not_used
595
596#ifdef CONFIG_USE_IRQ
597
598 .align 5
599irq:
600 get_irq_stack
601 irq_save_user_regs
602 bl do_irq
603 irq_restore_user_regs
604
605 .align 5
606fiq:
607 get_fiq_stack
608 /* someone ought to write a more effective fiq_save_user_regs */
609 irq_save_user_regs
610 bl do_fiq
611 irq_restore_user_regs
612
613#else
614
615 .align 5
616irq:
617 get_bad_stack
618 bad_save_user_regs
619 bl do_irq
620
621 .align 5
622fiq:
623 get_bad_stack
624 bad_save_user_regs
625 bl do_fiq
626
627#endif