2 * armboot - Startup Code for ARM926EJS CPU-core
4 * Copyright (c) 2003 Texas Instruments
6 * ----- Adapted for OMAP1610 OMAP730 from ARM925t code ------
8 * Copyright (c) 2001 Marius Gröger <mag@sysgo.de>
9 * Copyright (c) 2002 Alex Züpke <azu@sysgo.de>
10 * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de>
11 * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com>
12 * Copyright (c) 2003 Kshitij <kshitij@ti.com>
14 * See file CREDITS for list of people who contributed to this
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.
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.
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,
33 #include <asm-offsets.h>
38 *************************************************************************
42 *************************************************************************
48 ldr pc, _undefined_instruction
49 ldr pc, _software_interrupt
50 ldr pc, _prefetch_abort
56 _undefined_instruction:
57 .word undefined_instruction
59 .word software_interrupt
71 .balignl 16,0xdeadbeef
74 *************************************************************************
76 * Startup Code (reset vector)
78 * do important init only if we don't start from memory!
79 * setup memory and board specific bits prior to relocation.
80 * relocate armboot to ram
83 *************************************************************************
88 .word CONFIG_SYS_TEXT_BASE /* address of _start in the linked image */
91 * These are defined in the board-specific linker script.
101 #ifdef CONFIG_USE_IRQ
102 /* IRQ stack memory (calculated at run-time) */
103 .globl IRQ_STACK_START
107 /* IRQ stack memory (calculated at run-time) */
108 .globl FIQ_STACK_START
113 /* IRQ stack memory (calculated at run-time) + 8 bytes */
114 .globl IRQ_STACK_START_IN
118 .globl _datarel_start
120 .word __datarel_start
122 .globl _datarelrolocal_start
123 _datarelrolocal_start:
124 .word __datarelrolocal_start
126 .globl _datarellocal_start
128 .word __datarellocal_start
130 .globl _datarelro_start
132 .word __datarelro_start
143 * the actual reset code
148 * set the cpu to SVC32 mode
156 * we do sys-critical inits only at reboot,
157 * not when booting from ram!
159 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
163 /* Set stackpointer in internal RAM to call board_init_f */
165 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
169 /*------------------------------------------------------------------------------*/
172 * void relocate_code (addr_sp, gd, addr_moni)
174 * This "function" does not return, instead it continues in RAM
175 * after relocating the monitor code.
180 mov r4, r0 /* save addr_sp */
181 mov r5, r1 /* save addr of gd */
182 mov r6, r2 /* save addr of destination */
183 mov r7, r2 /* save addr of destination */
185 /* Set up the stack */
192 sub r2, r3, r2 /* r2 <- size of armboot */
193 add r2, r0, r2 /* r2 <- source end address */
198 ldmia r0!, {r9-r10} /* copy from source address [r0] */
199 stmia r6!, {r9-r10} /* copy to target address [r1] */
200 cmp r0, r2 /* until source end address [r2] */
203 #ifndef CONFIG_PRELOADER
204 /* fix got entries */
205 ldr r1, _TEXT_BASE /* Text base */
206 mov r0, r7 /* reloc addr */
207 ldr r2, _got_start /* addr in Flash */
208 ldr r3, _got_end /* addr in Flash */
225 #ifndef CONFIG_PRELOADER
228 ldr r3, _TEXT_BASE /* Text base */
229 mov r4, r7 /* reloc addr */
234 mov r2, #0x00000000 /* clear */
236 clbss_l:str r2, [r0] /* clear loop... */
246 * We are done. Do not return, instead branch to second part of board
247 * initialization, now running from RAM.
250 ldr r2, _board_init_r
252 add r2, r2, r7 /* position from board_init_r in RAM */
253 /* setup parameters for board_init_r */
254 mov r0, r5 /* gd_t */
255 mov r1, r7 /* dest_addr */
260 _board_init_r: .word board_init_r
263 *************************************************************************
265 * CPU_init_critical registers
267 * setup important registers
268 * setup memory timing
270 *************************************************************************
273 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
275 /* arm_int_generic assumes the ARM boot monitor, or user software,
276 * has initialized the platform
278 mov pc, lr /* back to my caller */
281 *************************************************************************
285 *************************************************************************
291 #define S_FRAME_SIZE 72
313 #define MODE_SVC 0x13
317 * use bad_save_user_regs for abort/prefetch/undef/swi ...
318 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
321 .macro bad_save_user_regs
322 @ carve out a frame on current user stack
323 sub sp, sp, #S_FRAME_SIZE
324 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
326 ldr r2, IRQ_STACK_START_IN
327 @ get values for "aborted" pc and cpsr (into parm regs)
329 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
332 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
333 mov r0, sp @ save current stack into r0 (param register)
336 .macro irq_save_user_regs
337 sub sp, sp, #S_FRAME_SIZE
338 stmia sp, {r0 - r12} @ Calling r0-r12
339 @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
341 stmdb r8, {sp, lr}^ @ Calling SP, LR
342 str lr, [r8, #0] @ Save calling PC
344 str r6, [r8, #4] @ Save CPSR
345 str r0, [r8, #8] @ Save OLD_R0
349 .macro irq_restore_user_regs
350 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
352 ldr lr, [sp, #S_PC] @ Get PC
353 add sp, sp, #S_FRAME_SIZE
354 subs pc, lr, #4 @ return & move spsr_svc into cpsr
358 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
360 str lr, [r13] @ save caller lr in position 0 of saved stack
361 mrs lr, spsr @ get the spsr
362 str lr, [r13, #4] @ save spsr in position 1 of saved stack
363 mov r13, #MODE_SVC @ prepare SVC-Mode
365 msr spsr, r13 @ switch modes, make sure moves will execute
366 mov lr, pc @ capture return pc
367 movs pc, lr @ jump to next instruction & switch modes.
370 .macro get_irq_stack @ setup IRQ stack
371 ldr sp, IRQ_STACK_START
374 .macro get_fiq_stack @ setup FIQ stack
375 ldr sp, FIQ_STACK_START
382 .globl undefined_instruction
383 undefined_instruction:
386 bl do_undefined_instruction
389 .globl software_interrupt
393 bl do_software_interrupt
396 .globl prefetch_abort
416 #ifdef CONFIG_USE_IRQ
423 irq_restore_user_regs
429 /* someone ought to write a more effiction fiq_save_user_regs */
432 irq_restore_user_regs