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,
32 #include <asm/arch/ixp425.h>
34 #define MMU_Control_M 0x001 /* Enable MMU */
35 #define MMU_Control_A 0x002 /* Enable address alignment faults */
36 #define MMU_Control_C 0x004 /* Enable cache */
37 #define MMU_Control_W 0x008 /* Enable write-buffer */
38 #define MMU_Control_P 0x010 /* Compatability: 32 bit code */
39 #define MMU_Control_D 0x020 /* Compatability: 32 bit data */
40 #define MMU_Control_L 0x040 /* Compatability: */
41 #define MMU_Control_B 0x080 /* Enable Big-Endian */
42 #define MMU_Control_S 0x100 /* Enable system protection */
43 #define MMU_Control_R 0x200 /* Enable ROM protection */
44 #define MMU_Control_I 0x1000 /* Enable Instruction cache */
45 #define MMU_Control_X 0x2000 /* Set interrupt vectors at 0xFFFF0000 */
46 #define MMU_Control_Init (MMU_Control_P|MMU_Control_D|MMU_Control_L)
53 .macro DELAY_FOR cycles, reg0
59 /* wait for coprocessor write complete */
61 mrc p15,0,\reg,c2,c0,0
68 ldr pc, _undefined_instruction
69 ldr pc, _software_interrupt
70 ldr pc, _prefetch_abort
76 _undefined_instruction: .word undefined_instruction
77 _software_interrupt: .word software_interrupt
78 _prefetch_abort: .word prefetch_abort
79 _data_abort: .word data_abort
80 _not_used: .word not_used
84 .balignl 16,0xdeadbeef
88 * Startup Code (reset vector)
90 * do important init only if we don't start from memory!
91 * - relocate armboot to ram
93 * - jump to second stage
104 * These are defined in the board-specific linker script.
114 #ifdef CONFIG_USE_IRQ
115 /* IRQ stack memory (calculated at run-time) */
116 .globl IRQ_STACK_START
120 /* IRQ stack memory (calculated at run-time) */
121 .globl FIQ_STACK_START
126 /****************************************************************************/
128 /* the actual reset code */
130 /****************************************************************************/
133 /* disable mmu, set big-endian */
135 mcr p15, 0, r0, c1, c0, 0
138 /* invalidate I & D caches & BTB */
139 mcr p15, 0, r0, c7, c7, 0
142 /* invalidate I & Data TLB */
143 mcr p15, 0, r0, c8, c7, 0
146 /* drain write and fill buffers */
147 mcr p15, 0, r0, c7, c10, 4
150 /* disable write buffer coalescing */
151 mrc p15, 0, r0, c1, c0, 1
153 mcr p15, 0, r0, c1, c0, 1
156 /* set EXP CS0 to the optimum timing */
158 ldr r2, =IXP425_EXP_CS0
161 /* make sure flash is visible at 0 */
163 ldr r2, =IXP425_EXP_CFG0
165 orr r1, r1, #0x80000000
168 mov r1, #CFG_SDR_CONFIG
169 ldr r2, =IXP425_SDR_CONFIG
172 /* disable refresh cycles */
174 ldr r3, =IXP425_SDR_REFRESH
177 /* send nop command */
179 ldr r4, =IXP425_SDR_IR
183 /* set SDRAM internal refresh val */
184 ldr r1, =CFG_SDRAM_REFRESH_CNT
188 /* send precharge-all command to close all open banks */
193 /* provide 8 auto-refresh cycles */
201 /* set mode register in sdram */
202 mov r1, #CFG_SDR_MODE_CONFIG
206 /* send normal operation command */
224 /* invalidate I & D caches & BTB */
225 mcr p15, 0, r0, c7, c7, 0
228 /* invalidate I & Data TLB */
229 mcr p15, 0, r0, c8, c7, 0
232 /* drain write and fill buffers */
233 mcr p15, 0, r0, c7, c10, 4
236 /* move flash to 0x50000000 */
237 ldr r2, =IXP425_EXP_CFG0
239 bic r1, r1, #0x80000000
249 /* invalidate I & Data TLB */
250 mcr p15, 0, r0, c8, c7, 0
254 mrc p15, 0, r0, c1, c0, 0
255 orr r0, r0, #MMU_Control_I
256 mcr p15, 0, r0, c1, c0, 0
259 mrs r0,cpsr /* set the cpu to SVC32 mode */
260 bic r0,r0,#0x1f /* (superviser mode, M=10011) */
264 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
265 relocate: /* relocate U-Boot to RAM */
266 adr r0, _start /* r0 <- current position of code */
267 ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
268 cmp r0, r1 /* don't reloc during debug */
271 ldr r2, _armboot_start
273 sub r2, r3, r2 /* r2 <- size of armboot */
274 add r2, r0, r2 /* r2 <- source end address */
277 ldmia r0!, {r3-r10} /* copy from source address [r0] */
278 stmia r1!, {r3-r10} /* copy to target address [r1] */
279 cmp r0, r2 /* until source end addreee [r2] */
281 #endif /* CONFIG_SKIP_RELOCATE_UBOOT */
283 /* Set up the stack */
285 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
286 sub r0, r0, #CFG_MALLOC_LEN /* malloc area */
287 sub r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo */
288 #ifdef CONFIG_USE_IRQ
289 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
291 sub sp, r0, #12 /* leave 3 words for abort-stack */
294 ldr r0, _bss_start /* find start of bss segment */
295 ldr r1, _bss_end /* stop here */
296 mov r2, #0x00000000 /* clear */
298 clbss_l:str r2, [r0] /* clear loop... */
303 ldr pc, _start_armboot
305 _start_armboot: .word start_armboot
308 /****************************************************************************/
310 /* Interrupt handling */
312 /****************************************************************************/
314 /* IRQ stack frame */
316 #define S_FRAME_SIZE 72
338 #define MODE_SVC 0x13
340 /* use bad_save_user_regs for abort/prefetch/undef/swi ... */
342 .macro bad_save_user_regs
343 sub sp, sp, #S_FRAME_SIZE
344 stmia sp, {r0 - r12} /* Calling r0-r12 */
347 ldr r2, _armboot_start
348 sub r2, r2, #(CONFIG_STACKSIZE+CFG_MALLOC_LEN)
349 sub r2, r2, #(CFG_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
350 ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */
351 add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */
355 stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
360 /* use irq_save_user_regs / irq_restore_user_regs for */
361 /* IRQ/FIQ handling */
363 .macro irq_save_user_regs
364 sub sp, sp, #S_FRAME_SIZE
365 stmia sp, {r0 - r12} /* Calling r0-r12 */
367 stmdb r8, {sp, lr}^ /* Calling SP, LR */
368 str lr, [r8, #0] /* Save calling PC */
370 str r6, [r8, #4] /* Save CPSR */
371 str r0, [r8, #8] /* Save OLD_R0 */
375 .macro irq_restore_user_regs
376 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
378 ldr lr, [sp, #S_PC] @ Get PC
379 add sp, sp, #S_FRAME_SIZE
380 subs pc, lr, #4 @ return & move spsr_svc into cpsr
384 ldr r13, _armboot_start @ setup our mode stack
385 sub r13, r13, #(CONFIG_STACKSIZE+CFG_MALLOC_LEN)
386 sub r13, r13, #(CFG_GBL_DATA_SIZE+8) @ reserved a couple spots in abort stack
388 str lr, [r13] @ save caller lr / spsr
392 mov r13, #MODE_SVC @ prepare SVC-Mode
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
407 /****************************************************************************/
409 /* exception handlers */
411 /****************************************************************************/
414 undefined_instruction:
417 bl do_undefined_instruction
423 bl do_software_interrupt
443 #ifdef CONFIG_USE_IRQ
450 irq_restore_user_regs
455 irq_save_user_regs /* someone ought to write a more */
456 bl do_fiq /* effiction fiq_save_user_regs */
457 irq_restore_user_regs
475 /****************************************************************************/
477 /* Reset function: Use Watchdog to reset */
479 /****************************************************************************/