1 /* vi: set ts=8 sw=8 noet: */
3 * u-boot - Startup Code for XScale IXP
5 * Copyright (C) 2003 Kyle Harris <kharris@nexus-tech.net>
7 * Based on startup code example contained in the
8 * Intel IXP4xx Programmer's Guide and past u-boot Start.S
11 * See file CREDITS for list of people who contributed to this
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <asm-offsets.h>
33 #include <asm/arch/ixp425.h>
35 #define MMU_Control_M 0x001 /* Enable MMU */
36 #define MMU_Control_A 0x002 /* Enable address alignment faults */
37 #define MMU_Control_C 0x004 /* Enable cache */
38 #define MMU_Control_W 0x008 /* Enable write-buffer */
39 #define MMU_Control_P 0x010 /* Compatability: 32 bit code */
40 #define MMU_Control_D 0x020 /* Compatability: 32 bit data */
41 #define MMU_Control_L 0x040 /* Compatability: */
42 #define MMU_Control_B 0x080 /* Enable Big-Endian */
43 #define MMU_Control_S 0x100 /* Enable system protection */
44 #define MMU_Control_R 0x200 /* Enable ROM protection */
45 #define MMU_Control_I 0x1000 /* Enable Instruction cache */
46 #define MMU_Control_X 0x2000 /* Set interrupt vectors at 0xFFFF0000 */
47 #define MMU_Control_Init (MMU_Control_P|MMU_Control_D|MMU_Control_L)
54 .macro DELAY_FOR cycles, reg0
60 /* wait for coprocessor write complete */
62 mrc p15,0,\reg,c2,c0,0
70 ldr pc, _undefined_instruction
71 ldr pc, _software_interrupt
72 ldr pc, _prefetch_abort
79 _undefined_instruction: .word undefined_instruction
80 _software_interrupt: .word software_interrupt
81 _prefetch_abort: .word prefetch_abort
82 _data_abort: .word data_abort
83 _not_used: .word not_used
87 .balignl 16,0xdeadbeef
91 * Startup Code (reset vector)
93 * do important init only if we don't start from memory!
94 * - relocate armboot to ram
96 * - jump to second stage
101 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
102 .word CONFIG_SPL_TEXT_BASE
104 .word CONFIG_SYS_TEXT_BASE
108 * These are defined in the board-specific linker script.
109 * Subtracting _start from them lets the linker put their
110 * relative position in the executable instead of leaving
113 .globl _bss_start_ofs
115 .word __bss_start - _start
119 .word __bss_end - _start
125 #ifdef CONFIG_USE_IRQ
126 /* IRQ stack memory (calculated at run-time) */
127 .globl IRQ_STACK_START
131 /* IRQ stack memory (calculated at run-time) */
132 .globl FIQ_STACK_START
137 /* IRQ stack memory (calculated at run-time) + 8 bytes */
138 .globl IRQ_STACK_START_IN
143 * the actual reset code
147 /* disable mmu, set big-endian */
149 mcr p15, 0, r0, c1, c0, 0
152 /* invalidate I & D caches & BTB */
153 mcr p15, 0, r0, c7, c7, 0
156 /* invalidate I & Data TLB */
157 mcr p15, 0, r0, c8, c7, 0
160 /* drain write and fill buffers */
161 mcr p15, 0, r0, c7, c10, 4
164 /* disable write buffer coalescing */
165 mrc p15, 0, r0, c1, c0, 1
167 mcr p15, 0, r0, c1, c0, 1
170 /* set EXP CS0 to the optimum timing */
171 ldr r1, =CONFIG_SYS_EXP_CS0
172 ldr r2, =IXP425_EXP_CS0
175 /* make sure flash is visible at 0 */
176 mov r1, #CONFIG_SYS_SDR_CONFIG
177 ldr r2, =IXP425_SDR_CONFIG
180 /* disable refresh cycles */
182 ldr r3, =IXP425_SDR_REFRESH
185 /* send nop command */
187 ldr r4, =IXP425_SDR_IR
191 /* set SDRAM internal refresh val */
192 ldr r1, =CONFIG_SYS_SDRAM_REFRESH_CNT
196 /* send precharge-all command to close all open banks */
201 /* provide 8 auto-refresh cycles */
209 /* set mode register in sdram */
210 mov r1, #CONFIG_SYS_SDR_MODE_CONFIG
214 /* send normal operation command */
219 /* invalidate I & D caches & BTB */
220 mcr p15, 0, r0, c7, c7, 0
223 /* invalidate I & Data TLB */
224 mcr p15, 0, r0, c8, c7, 0
227 /* drain write and fill buffers */
228 mcr p15, 0, r0, c7, c10, 4
231 /* remove flash mirror at 0x00000000 */
232 ldr r2, =IXP425_EXP_CFG0
234 bic r1, r1, #0x80000000
237 /* invalidate I & Data TLB */
238 mcr p15, 0, r0, c8, c7, 0
242 mrc p15, 0, r0, c1, c0, 0
243 orr r0, r0, #MMU_Control_I
244 mcr p15, 0, r0, c1, c0, 0
247 mrs r0,cpsr /* set the cpu to SVC32 mode */
248 bic r0,r0,#0x1f /* (superviser mode, M=10011) */
254 /*------------------------------------------------------------------------------*/
257 * void relocate_code (addr_sp, gd, addr_moni)
259 * This function relocates the monitor code.
263 mov r4, r0 /* save addr_sp */
264 mov r5, r1 /* save addr of gd */
265 mov r6, r2 /* save addr of destination */
268 subs r9, r6, r0 /* r9 <- relocation offset */
269 beq relocate_done /* skip relocation */
270 mov r1, r6 /* r1 <- scratch for copy_loop */
271 ldr r3, _bss_start_ofs
272 add r2, r0, r3 /* r2 <- source end address */
275 ldmia r0!, {r10-r11} /* copy from source address [r0] */
276 stmia r1!, {r10-r11} /* copy to target address [r1] */
277 cmp r0, r2 /* until source end address [r2] */
280 #ifndef CONFIG_SPL_BUILD
282 * fix .rel.dyn relocations
284 ldr r0, _TEXT_BASE /* r0 <- Text base */
285 ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
286 add r10, r10, r0 /* r10 <- sym table in FLASH */
287 ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
288 add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
289 ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
290 add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
292 ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
293 add r0, r0, r9 /* r0 <- location to fix up in RAM */
296 cmp r7, #23 /* relative fixup? */
298 cmp r7, #2 /* absolute fixup? */
300 /* ignore unknown type of fixup */
303 /* absolute fix: set location to (offset) symbol value */
304 mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
305 add r1, r10, r1 /* r1 <- address of symbol in table */
306 ldr r1, [r1, #4] /* r1 <- symbol value */
307 add r1, r1, r9 /* r1 <- relocated sym addr */
310 /* relative fix: increase location by offset */
315 add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
325 .word __rel_dyn_start - _start
327 .word __rel_dyn_end - _start
329 .word __dynsym_start - _start
331 .globl c_runtime_cpu_setup
336 /****************************************************************************/
338 /* Interrupt handling */
340 /****************************************************************************/
342 /* IRQ stack frame */
344 #define S_FRAME_SIZE 72
366 #define MODE_SVC 0x13
368 /* use bad_save_user_regs for abort/prefetch/undef/swi ... */
370 .macro bad_save_user_regs
371 sub sp, sp, #S_FRAME_SIZE
372 stmia sp, {r0 - r12} /* Calling r0-r12 */
375 ldr r2, IRQ_STACK_START_IN
376 ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */
377 add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */
381 stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
386 /* use irq_save_user_regs / irq_restore_user_regs for */
387 /* IRQ/FIQ handling */
389 .macro irq_save_user_regs
390 sub sp, sp, #S_FRAME_SIZE
391 stmia sp, {r0 - r12} /* Calling r0-r12 */
393 stmdb r8, {sp, lr}^ /* Calling SP, LR */
394 str lr, [r8, #0] /* Save calling PC */
396 str r6, [r8, #4] /* Save CPSR */
397 str r0, [r8, #8] /* Save OLD_R0 */
401 .macro irq_restore_user_regs
402 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
404 ldr lr, [sp, #S_PC] @ Get PC
405 add sp, sp, #S_FRAME_SIZE
406 subs pc, lr, #4 @ return & move spsr_svc into cpsr
410 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
412 str lr, [r13] @ save caller lr / spsr
416 mov r13, #MODE_SVC @ prepare SVC-Mode
422 .macro get_irq_stack @ setup IRQ stack
423 ldr sp, IRQ_STACK_START
426 .macro get_fiq_stack @ setup FIQ stack
427 ldr sp, FIQ_STACK_START
431 /****************************************************************************/
433 /* exception handlers */
435 /****************************************************************************/
438 undefined_instruction:
441 bl do_undefined_instruction
447 bl do_software_interrupt
467 #ifdef CONFIG_USE_IRQ
474 irq_restore_user_regs
479 irq_save_user_regs /* someone ought to write a more */
480 bl do_fiq /* effiction fiq_save_user_regs */
481 irq_restore_user_regs
499 /****************************************************************************/
501 /* Reset function: Use Watchdog to reset */
503 /****************************************************************************/