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 *************************************************************************
40 * Jump vector table as in table 3.1 in [1]
42 *************************************************************************
49 ldr pc, _undefined_instruction
50 ldr pc, _software_interrupt
51 ldr pc, _prefetch_abort
57 _undefined_instruction:
58 .word undefined_instruction
60 .word software_interrupt
72 .balignl 16,0xdeadbeef
76 *************************************************************************
78 * Startup Code (reset vector)
80 * do important init only if we don't start from memory!
81 * setup Memory and board specific bits prior to relocation.
82 * relocate armboot to ram
85 *************************************************************************
90 .word CONFIG_SYS_TEXT_BASE
93 * These are defined in the board-specific linker script.
103 #ifdef CONFIG_USE_IRQ
104 /* IRQ stack memory (calculated at run-time) */
105 .globl IRQ_STACK_START
109 /* IRQ stack memory (calculated at run-time) */
110 .globl FIQ_STACK_START
115 /* IRQ stack memory (calculated at run-time) + 8 bytes */
116 .globl IRQ_STACK_START_IN
120 .globl _datarel_start
122 .word __datarel_start
124 .globl _datarelrolocal_start
125 _datarelrolocal_start:
126 .word __datarelrolocal_start
128 .globl _datarellocal_start
130 .word __datarellocal_start
132 .globl _datarelro_start
134 .word __datarelro_start
145 * the actual reset code
150 * set the cpu to SVC32 mode
158 * we do sys-critical inits only at reboot,
159 * not when booting from ram!
161 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
165 /* Set stackpointer in internal RAM to call board_init_f */
167 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
171 /*------------------------------------------------------------------------------*/
174 * void relocate_code (addr_sp, gd, addr_moni)
176 * This "function" does not return, instead it continues in RAM
177 * after relocating the monitor code.
182 mov r4, r0 /* save addr_sp */
183 mov r5, r1 /* save addr of gd */
184 mov r6, r2 /* save addr of destination */
185 mov r7, r2 /* save addr of destination */
187 /* Set up the stack */
194 sub r2, r3, r2 /* r2 <- size of armboot */
195 add r2, r0, r2 /* r2 <- source end address */
199 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
201 ldmia r0!, {r9-r10} /* copy from source address [r0] */
202 stmia r6!, {r9-r10} /* copy to target address [r1] */
203 cmp r0, r2 /* until source end address [r2] */
206 #ifndef CONFIG_PRELOADER
207 /* fix got entries */
208 ldr r1, _TEXT_BASE /* Text base */
209 mov r0, r7 /* reloc addr */
210 ldr r2, _got_start /* addr in Flash */
211 ldr r3, _got_end /* addr in Flash */
226 #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
229 #ifndef CONFIG_PRELOADER
232 ldr r3, _TEXT_BASE /* Text base */
233 mov r4, r7 /* reloc addr */
238 mov r2, #0x00000000 /* clear */
240 clbss_l:str r2, [r0] /* clear loop... */
247 * We are done. Do not return, instead branch to second part of board
248 * initialization, now running from RAM.
250 #ifdef CONFIG_NAND_SPL
253 _nand_boot: .word nand_boot
256 ldr r2, _board_init_r
258 add r2, r2, r7 /* position from board_init_r in RAM */
259 /* setup parameters for board_init_r */
260 mov r0, r5 /* gd_t */
261 mov r1, r7 /* dest_addr */
266 _board_init_r: .word board_init_r
270 *************************************************************************
272 * CPU_init_critical registers
274 * setup important registers
275 * setup memory timing
277 *************************************************************************
281 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
284 * flush v4 I/D caches
287 mcr p15, 0, r0, c7, c5, 0 /* flush v4 I-cache */
288 mcr p15, 0, r0, c7, c6, 0 /* flush v4 D-cache */
291 * disable MMU stuff and caches
293 mrc p15, 0, r0, c1, c0, 0
294 bic r0, r0, #0x00002300 /* clear bits 13, 9:8 (--V- --RS) */
295 bic r0, r0, #0x00000087 /* clear bits 7, 2:0 (B--- -CAM) */
296 orr r0, r0, #0x00000002 /* set bit 2 (A) Align */
297 orr r0, r0, #0x00001000 /* set bit 12 (I) I-Cache */
298 mcr p15, 0, r0, c1, c0, 0
301 * Go setup Memory and board specific bits prior to relocation.
303 mov ip, lr /* perserve link reg across call */
304 bl lowlevel_init /* go setup memory */
305 mov lr, ip /* restore link */
306 mov pc, lr /* back to my caller */
309 *************************************************************************
313 *************************************************************************
319 #define S_FRAME_SIZE 72
341 #define MODE_SVC 0x13
345 * use bad_save_user_regs for abort/prefetch/undef/swi ...
346 * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
349 .macro bad_save_user_regs
350 @ carve out a frame on current user stack
351 sub sp, sp, #S_FRAME_SIZE
352 stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12
354 ldr r2, IRQ_STACK_START_IN
355 @ get values for "aborted" pc and cpsr (into parm regs)
357 add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack
360 stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr
361 mov r0, sp @ save current stack into r0 (param register)
364 .macro irq_save_user_regs
365 sub sp, sp, #S_FRAME_SIZE
366 stmia sp, {r0 - r12} @ Calling r0-r12
367 @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
369 stmdb r8, {sp, lr}^ @ Calling SP, LR
370 str lr, [r8, #0] @ Save calling PC
372 str r6, [r8, #4] @ Save CPSR
373 str r0, [r8, #8] @ Save OLD_R0
377 .macro irq_restore_user_regs
378 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
380 ldr lr, [sp, #S_PC] @ Get PC
381 add sp, sp, #S_FRAME_SIZE
382 subs pc, lr, #4 @ return & move spsr_svc into cpsr
386 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
388 str lr, [r13] @ save caller lr in position 0 of saved stack
389 mrs lr, spsr @ get the spsr
390 str lr, [r13, #4] @ save spsr in position 1 of saved stack
391 mov r13, #MODE_SVC @ prepare SVC-Mode
393 msr spsr, r13 @ switch modes, make sure moves will execute
394 mov lr, pc @ capture return pc
395 movs pc, lr @ jump to next instruction & switch modes.
398 .macro get_irq_stack @ setup IRQ stack
399 ldr sp, IRQ_STACK_START
402 .macro get_fiq_stack @ setup FIQ stack
403 ldr sp, FIQ_STACK_START
410 undefined_instruction:
413 bl do_undefined_instruction
419 bl do_software_interrupt
439 #ifdef CONFIG_USE_IRQ
446 irq_restore_user_regs
451 /* someone ought to write a more effiction fiq_save_user_regs */
454 irq_restore_user_regs
472 # ifdef CONFIG_INTEGRATOR
474 /* Satisfied by general board level routine */
482 ldr r1, rstctl1 /* get clkm1 reset ctl */
484 strh r3, [r1] /* clear it */
486 strh r3, [r1] /* force dsp+arm reset */
493 #endif /* #ifdef CONFIG_INTEGRATOR */