1 /* vi: set ts=8 sw=8 noet: */
3 * u-boot - Startup Code for XScale IXP
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
98 .word CONFIG_SYS_TEXT_BASE
100 #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
101 .globl _armboot_start
107 * These are defined in the board-specific linker script.
117 #ifdef CONFIG_USE_IRQ
118 /* IRQ stack memory (calculated at run-time) */
119 .globl IRQ_STACK_START
123 /* IRQ stack memory (calculated at run-time) */
124 .globl FIQ_STACK_START
129 #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
130 /* IRQ stack memory (calculated at run-time) + 8 bytes */
131 .globl IRQ_STACK_START_IN
135 .globl _datarel_start
137 .word __datarel_start
139 .globl _datarelrolocal_start
140 _datarelrolocal_start:
141 .word __datarelrolocal_start
143 .globl _datarellocal_start
145 .word __datarellocal_start
147 .globl _datarelro_start
149 .word __datarelro_start
160 * the actual reset code
164 /* disable mmu, set big-endian */
166 mcr p15, 0, r0, c1, c0, 0
169 /* invalidate I & D caches & BTB */
170 mcr p15, 0, r0, c7, c7, 0
173 /* invalidate I & Data TLB */
174 mcr p15, 0, r0, c8, c7, 0
177 /* drain write and fill buffers */
178 mcr p15, 0, r0, c7, c10, 4
181 /* disable write buffer coalescing */
182 mrc p15, 0, r0, c1, c0, 1
184 mcr p15, 0, r0, c1, c0, 1
187 /* set EXP CS0 to the optimum timing */
188 ldr r1, =CONFIG_SYS_EXP_CS0
189 ldr r2, =IXP425_EXP_CS0
192 /* make sure flash is visible at 0 */
194 ldr r2, =IXP425_EXP_CFG0
196 orr r1, r1, #0x80000000
199 mov r1, #CONFIG_SYS_SDR_CONFIG
200 ldr r2, =IXP425_SDR_CONFIG
203 /* disable refresh cycles */
205 ldr r3, =IXP425_SDR_REFRESH
208 /* send nop command */
210 ldr r4, =IXP425_SDR_IR
214 /* set SDRAM internal refresh val */
215 ldr r1, =CONFIG_SYS_SDRAM_REFRESH_CNT
219 /* send precharge-all command to close all open banks */
224 /* provide 8 auto-refresh cycles */
232 /* set mode register in sdram */
233 mov r1, #CONFIG_SYS_SDR_MODE_CONFIG
237 /* send normal operation command */
245 add r2, r0, #CONFIG_SYS_MONITOR_LEN
255 /* invalidate I & D caches & BTB */
256 mcr p15, 0, r0, c7, c7, 0
259 /* invalidate I & Data TLB */
260 mcr p15, 0, r0, c8, c7, 0
263 /* drain write and fill buffers */
264 mcr p15, 0, r0, c7, c10, 4
267 /* move flash to 0x50000000 */
268 ldr r2, =IXP425_EXP_CFG0
270 bic r1, r1, #0x80000000
280 /* invalidate I & Data TLB */
281 mcr p15, 0, r0, c8, c7, 0
285 mrc p15, 0, r0, c1, c0, 0
286 orr r0, r0, #MMU_Control_I
287 mcr p15, 0, r0, c1, c0, 0
290 mrs r0,cpsr /* set the cpu to SVC32 mode */
291 bic r0,r0,#0x1f /* (superviser mode, M=10011) */
295 /* Set stackpointer in internal RAM to call board_init_f */
297 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
301 /*------------------------------------------------------------------------------*/
304 * void relocate_code (addr_sp, gd, addr_moni)
306 * This "function" does not return, instead it continues in RAM
307 * after relocating the monitor code.
312 mov r4, r0 /* save addr_sp */
313 mov r5, r1 /* save addr of gd */
314 mov r6, r2 /* save addr of destination */
315 mov r7, r2 /* save addr of destination */
317 /* Set up the stack */
324 sub r2, r3, r2 /* r2 <- size of armboot */
325 add r2, r0, r2 /* r2 <- source end address */
329 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
331 ldmia r0!, {r9-r10} /* copy from source address [r0] */
332 stmia r6!, {r9-r10} /* copy to target address [r1] */
333 cmp r0, r2 /* until source end address [r2] */
336 #ifndef CONFIG_PRELOADER
337 /* fix got entries */
338 ldr r1, _TEXT_BASE /* Text base */
339 mov r0, r7 /* reloc addr */
340 ldr r2, _got_start /* addr in Flash */
341 ldr r3, _got_end /* addr in Flash */
356 #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
359 #ifndef CONFIG_PRELOADER
362 ldr r3, _TEXT_BASE /* Text base */
363 mov r4, r7 /* reloc addr */
368 mov r2, #0x00000000 /* clear */
370 clbss_l:str r2, [r0] /* clear loop... */
380 * We are done. Do not return, instead branch to second part of board
381 * initialization, now running from RAM.
384 ldr r2, _board_init_r
386 add r2, r2, r7 /* position from board_init_r in RAM */
387 /* setup parameters for board_init_r */
388 mov r0, r5 /* gd_t */
389 mov r1, r7 /* dest_addr */
394 _board_init_r: .word board_init_r
396 #else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
397 /****************************************************************************/
399 /* the actual reset code */
401 /****************************************************************************/
404 /* disable mmu, set big-endian */
406 mcr p15, 0, r0, c1, c0, 0
409 /* invalidate I & D caches & BTB */
410 mcr p15, 0, r0, c7, c7, 0
413 /* invalidate I & Data TLB */
414 mcr p15, 0, r0, c8, c7, 0
417 /* drain write and fill buffers */
418 mcr p15, 0, r0, c7, c10, 4
421 /* disable write buffer coalescing */
422 mrc p15, 0, r0, c1, c0, 1
424 mcr p15, 0, r0, c1, c0, 1
427 /* set EXP CS0 to the optimum timing */
428 ldr r1, =CONFIG_SYS_EXP_CS0
429 ldr r2, =IXP425_EXP_CS0
432 /* make sure flash is visible at 0 */
434 ldr r2, =IXP425_EXP_CFG0
436 orr r1, r1, #0x80000000
439 mov r1, #CONFIG_SYS_SDR_CONFIG
440 ldr r2, =IXP425_SDR_CONFIG
443 /* disable refresh cycles */
445 ldr r3, =IXP425_SDR_REFRESH
448 /* send nop command */
450 ldr r4, =IXP425_SDR_IR
454 /* set SDRAM internal refresh val */
455 ldr r1, =CONFIG_SYS_SDRAM_REFRESH_CNT
459 /* send precharge-all command to close all open banks */
464 /* provide 8 auto-refresh cycles */
472 /* set mode register in sdram */
473 mov r1, #CONFIG_SYS_SDR_MODE_CONFIG
477 /* send normal operation command */
485 add r2, r0, #CONFIG_SYS_MONITOR_LEN
495 /* invalidate I & D caches & BTB */
496 mcr p15, 0, r0, c7, c7, 0
499 /* invalidate I & Data TLB */
500 mcr p15, 0, r0, c8, c7, 0
503 /* drain write and fill buffers */
504 mcr p15, 0, r0, c7, c10, 4
507 /* move flash to 0x50000000 */
508 ldr r2, =IXP425_EXP_CFG0
510 bic r1, r1, #0x80000000
520 /* invalidate I & Data TLB */
521 mcr p15, 0, r0, c8, c7, 0
525 mrc p15, 0, r0, c1, c0, 0
526 orr r0, r0, #MMU_Control_I
527 mcr p15, 0, r0, c1, c0, 0
530 mrs r0,cpsr /* set the cpu to SVC32 mode */
531 bic r0,r0,#0x1f /* (superviser mode, M=10011) */
535 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
536 relocate: /* relocate U-Boot to RAM */
537 adr r0, _start /* r0 <- current position of code */
538 ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
539 cmp r0, r1 /* don't reloc during debug */
542 ldr r2, _armboot_start
544 sub r2, r3, r2 /* r2 <- size of armboot */
545 add r2, r0, r2 /* r2 <- source end address */
548 ldmia r0!, {r3-r10} /* copy from source address [r0] */
549 stmia r1!, {r3-r10} /* copy to target address [r1] */
550 cmp r0, r2 /* until source end address [r2] */
552 #endif /* CONFIG_SKIP_RELOCATE_UBOOT */
554 /* Set up the stack */
556 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
557 sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
558 sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */
559 #ifdef CONFIG_USE_IRQ
560 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
562 sub sp, r0, #12 /* leave 3 words for abort-stack */
563 bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
566 ldr r0, _bss_start /* find start of bss segment */
567 ldr r1, _bss_end /* stop here */
568 mov r2, #0x00000000 /* clear */
570 clbss_l:str r2, [r0] /* clear loop... */
575 ldr pc, _start_armboot
577 _start_armboot: .word start_armboot
578 #endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
581 /****************************************************************************/
583 /* Interrupt handling */
585 /****************************************************************************/
587 /* IRQ stack frame */
589 #define S_FRAME_SIZE 72
611 #define MODE_SVC 0x13
613 /* use bad_save_user_regs for abort/prefetch/undef/swi ... */
615 .macro bad_save_user_regs
616 sub sp, sp, #S_FRAME_SIZE
617 stmia sp, {r0 - r12} /* Calling r0-r12 */
620 #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
621 ldr r2, _armboot_start
622 sub r2, r2, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN)
623 sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ set base 2 words into abort stack
625 ldr r2, IRQ_STACK_START_IN
627 ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */
628 add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */
632 stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
637 /* use irq_save_user_regs / irq_restore_user_regs for */
638 /* IRQ/FIQ handling */
640 .macro irq_save_user_regs
641 sub sp, sp, #S_FRAME_SIZE
642 stmia sp, {r0 - r12} /* Calling r0-r12 */
644 stmdb r8, {sp, lr}^ /* Calling SP, LR */
645 str lr, [r8, #0] /* Save calling PC */
647 str r6, [r8, #4] /* Save CPSR */
648 str r0, [r8, #8] /* Save OLD_R0 */
652 .macro irq_restore_user_regs
653 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
655 ldr lr, [sp, #S_PC] @ Get PC
656 add sp, sp, #S_FRAME_SIZE
657 subs pc, lr, #4 @ return & move spsr_svc into cpsr
661 #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
662 ldr r13, _armboot_start @ setup our mode stack
663 sub r13, r13, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN)
664 sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ reserved a couple spots in abort stack
666 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
669 str lr, [r13] @ save caller lr / spsr
673 mov r13, #MODE_SVC @ prepare SVC-Mode
679 .macro get_irq_stack @ setup IRQ stack
680 ldr sp, IRQ_STACK_START
683 .macro get_fiq_stack @ setup FIQ stack
684 ldr sp, FIQ_STACK_START
688 /****************************************************************************/
690 /* exception handlers */
692 /****************************************************************************/
695 undefined_instruction:
698 bl do_undefined_instruction
704 bl do_software_interrupt
724 #ifdef CONFIG_USE_IRQ
731 irq_restore_user_regs
736 irq_save_user_regs /* someone ought to write a more */
737 bl do_fiq /* effiction fiq_save_user_regs */
738 irq_restore_user_regs
756 /****************************************************************************/
758 /* Reset function: Use Watchdog to reset */
760 /****************************************************************************/
782 #ifdef CONFIG_USE_IRQ
784 .LC0: .word loops_per_jiffy
795 ldr r2, [r2] @ max = 0x0fffffff
796 mov r0, r0, lsr #11 @ max = 0x00003fff
797 mov r2, r2, lsr #11 @ max = 0x0003ffff
798 mul r0, r2, r0 @ max = 2^32-1
806 #endif /* CONFIG_USE_IRQ */