2 * armboot - Startup Code for XScale
4 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
5 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
6 * Copyright (C) 2000 Wolfgang Denk <wd@denx.de>
7 * Copyright (C) 2001 Alex Zuepke <azu@sysgo.de>
8 * Copyright (C) 2002 Kyle Harris <kharris@nexus-tech.net>
9 * Copyright (C) 2003 Robert Schwebel <r.schwebel@pengutronix.de>
10 * Copyright (C) 2003 Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de>
11 * Copyright (c) 2010 Marek Vasut <marek.vasut@gmail.com>
13 * See file CREDITS for list of people who contributed to this
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #include <asm-offsets.h>
35 #include <asm/arch/pxa-regs.h>
37 /* takes care the CP15 update has taken place */
39 mrc p15,0,\reg,c2,c0,0
46 #ifdef CONFIG_PRELOADER
63 .word 0x12345678 /* now 16*4=64 */
65 ldr pc, _undefined_instruction
66 ldr pc, _software_interrupt
67 ldr pc, _prefetch_abort
73 _undefined_instruction: .word undefined_instruction
74 _software_interrupt: .word software_interrupt
75 _prefetch_abort: .word prefetch_abort
76 _data_abort: .word data_abort
77 _not_used: .word not_used
80 #endif /* CONFIG_PRELOADER */
82 .balignl 16,0xdeadbeef
86 * Startup Code (reset vector)
88 * do important init only if we don't start from RAM!
89 * - relocate armboot to RAM
91 * - jump to second stage
96 .word CONFIG_SYS_TEXT_BASE
99 * These are defined in the board-specific linker script.
101 .globl _bss_start_ofs
103 .word __bss_start - _start
109 #ifdef CONFIG_USE_IRQ
110 /* IRQ stack memory (calculated at run-time) */
111 .globl IRQ_STACK_START
115 /* IRQ stack memory (calculated at run-time) */
116 .globl FIQ_STACK_START
119 #endif /* CONFIG_USE_IRQ */
121 #ifndef CONFIG_PRELOADER
122 /* IRQ stack memory (calculated at run-time) + 8 bytes */
123 .globl IRQ_STACK_START_IN
128 * the actual reset code
133 * set the cpu to SVC32 mode
141 * Enable MMU to use DCache as DRAM
143 /* Domain access -- enable for all CPs */
145 mcr p15, 0, r0, c3, c0, 0
147 /* Point TTBR to MMU table */
151 mcr p15, 0, r0, c2, c0, 0
153 /* !!! Hereby, check if the code is running from SRAM !!! */
154 /* If the code is running from SRAM, alias SRAM to 0x0 to simulate NOR. The code
155 * is linked to 0x0 too, so this makes things easier. */
162 /* Kick in MMU, ICache, DCache, BTB */
163 mrc p15, 0, r0, c1, c0, 0
168 mcr p15, 0, r0, c1, c0, 0
171 /* Unlock Icache, Dcache */
172 mcr p15, 0, r0, c9, c1, 1
173 mcr p15, 0, r0, c9, c2, 1
175 /* Flush Icache, Dcache, BTB */
176 mcr p15, 0, r0, c7, c7, 0
178 /* Unlock I-TLB, D-TLB */
179 mcr p15, 0, r0, c10, c4, 1
180 mcr p15, 0, r0, c10, c8, 1
183 mcr p15, 0, r0, c8, c7, 0
184 /* Allocate 4096 bytes of Dcache as RAM */
186 /* Drain pending loads and stores */
187 mcr p15, 0, r0, c7, c10, 4
192 mcr p15, 0, r0, c9, c2, 0
195 /* 128 lines reserved (128 x 32bytes = 4096 bytes total) */
199 mcr p15, 0, r1, c7, c2, 5
200 /* Drain pending loads and stores */
201 mcr p15, 0, r0, c7, c10, 4
208 /* Drain pending loads and stores */
209 mcr p15, 0, r0, c7, c10, 4
211 mcr p15, 0, r2, c9, c2, 0
214 /* Jump to 0x0 ( + offset) if running from SRAM */
220 /* Set stackpointer in internal RAM to call board_init_f */
222 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
223 bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
227 /*------------------------------------------------------------------------------*/
230 * void relocate_code (addr_sp, gd, addr_moni)
232 * This "function" does not return, instead it continues in RAM
233 * after relocating the monitor code.
238 mov r4, r0 /* save addr_sp */
239 mov r5, r1 /* save addr of gd */
240 mov r6, r2 /* save addr of destination */
242 /* Set up the stack */
248 beq clear_bss /* skip relocation */
249 mov r1, r6 /* r1 <- scratch for copy_loop */
250 ldr r3, _bss_start_ofs
251 add r2, r0, r3 /* r2 <- source end address */
255 ldmia r0!, {r3-r5, r7-r11} /* copy from source address [r0] */
256 stmia r1!, {r3-r5, r7-r11} /* copy to target address [r1] */
257 cmp r0, r2 /* until source end address [r2] */
261 #ifndef CONFIG_PRELOADER
263 * fix .rel.dyn relocations
265 ldr r0, _TEXT_BASE /* r0 <- Text base */
266 sub r9, r6, r0 /* r9 <- relocation offset */
267 ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */
268 add r10, r10, r0 /* r10 <- sym table in FLASH */
269 ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */
270 add r2, r2, r0 /* r2 <- rel dyn start in FLASH */
271 ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */
272 add r3, r3, r0 /* r3 <- rel dyn end in FLASH */
274 ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */
275 add r0, r9 /* r0 <- location to fix up in RAM */
278 cmp r7, #23 /* relative fixup? */
280 cmp r7, #2 /* absolute fixup? */
282 /* ignore unknown type of fixup */
285 /* absolute fix: set location to (offset) symbol value */
286 mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */
287 add r1, r10, r1 /* r1 <- address of symbol in table */
288 ldr r1, [r1, #4] /* r1 <- symbol value */
289 add r1, r1, r9 /* r1 <- relocated sym addr */
292 /* relative fix: increase location by offset */
297 add r2, r2, #8 /* each rel.dyn entry is 8 bytes */
300 #endif /* #ifndef CONFIG_PRELOADER */
303 #ifndef CONFIG_PRELOADER
304 ldr r0, _bss_start_ofs
306 mov r4, r6 /* reloc addr */
309 mov r2, #0x00000000 /* clear */
311 clbss_l:str r2, [r0] /* clear loop... */
315 #endif /* #ifndef CONFIG_PRELOADER */
318 * We are done. Do not return, instead branch to second part of board
319 * initialization, now running from RAM.
321 #ifdef CONFIG_ONENAND_IPL
322 ldr r0, _start_oneboot_ofs
326 : .word start_oneboot
328 ldr r0, _board_init_r_ofs
332 /* setup parameters for board_init_r */
333 mov r0, r5 /* gd_t */
334 mov r1, r6 /* dest_addr */
339 .word board_init_r - _start
340 #endif /* CONFIG_ONENAND_IPL */
343 .word __rel_dyn_start - _start
345 .word __rel_dyn_end - _start
347 .word __dynsym_start - _start
349 #else /* CONFIG_PRELOADER */
351 /****************************************************************************/
353 /* the actual reset code for OneNAND IPL */
355 /****************************************************************************/
357 #ifndef CONFIG_PXA27X
358 #error OneNAND IPL is not supported on PXA25x and 26x due to lack of SRAM
362 /* Set CPU to SVC32 mode */
368 /* Point stack at the end of SRAM and leave 32 words for abort-stack */
371 /* Start OneNAND IPL */
372 ldr pc, =start_oneboot
374 #endif /* CONFIG_PRELOADER */
376 #ifndef CONFIG_PRELOADER
377 /****************************************************************************/
379 /* Interrupt handling */
381 /****************************************************************************/
383 /* IRQ stack frame */
385 #define S_FRAME_SIZE 72
407 #define MODE_SVC 0x13
409 /* use bad_save_user_regs for abort/prefetch/undef/swi ... */
411 .macro bad_save_user_regs
412 sub sp, sp, #S_FRAME_SIZE
413 stmia sp, {r0 - r12} /* Calling r0-r12 */
416 ldr r2, IRQ_STACK_START_IN
417 ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */
418 add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */
422 stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
427 /* use irq_save_user_regs / irq_restore_user_regs for */
428 /* IRQ/FIQ handling */
430 .macro irq_save_user_regs
431 sub sp, sp, #S_FRAME_SIZE
432 stmia sp, {r0 - r12} /* Calling r0-r12 */
434 stmdb r8, {sp, lr}^ /* Calling SP, LR */
435 str lr, [r8, #0] /* Save calling PC */
437 str r6, [r8, #4] /* Save CPSR */
438 str r0, [r8, #8] /* Save OLD_R0 */
442 .macro irq_restore_user_regs
443 ldmia sp, {r0 - lr}^ @ Calling r0 - lr
445 ldr lr, [sp, #S_PC] @ Get PC
446 add sp, sp, #S_FRAME_SIZE
447 subs pc, lr, #4 @ return & move spsr_svc into cpsr
451 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
453 str lr, [r13] @ save caller lr / spsr
457 mov r13, #MODE_SVC @ prepare SVC-Mode
463 .macro get_irq_stack @ setup IRQ stack
464 ldr sp, IRQ_STACK_START
467 .macro get_fiq_stack @ setup FIQ stack
468 ldr sp, FIQ_STACK_START
470 #endif /* CONFIG_PRELOADER
473 /****************************************************************************/
475 /* exception handlers */
477 /****************************************************************************/
479 #ifdef CONFIG_PRELOADER
482 ldr sp, _TEXT_BASE /* use 32 words abort stack */
483 bl hang /* hang and never return */
486 undefined_instruction:
489 bl do_undefined_instruction
495 bl do_software_interrupt
515 #ifdef CONFIG_USE_IRQ
522 irq_restore_user_regs
527 irq_save_user_regs /* someone ought to write a more */
528 bl do_fiq /* effiction fiq_save_user_regs */
529 irq_restore_user_regs
531 #else /* !CONFIG_USE_IRQ */
544 #endif /* CONFIG_PRELOADER */
545 #endif /* CONFIG_USE_IRQ */
547 /****************************************************************************/
549 /* Reset function: the PXA250 doesn't have a reset function, so we have to */
550 /* perform a watchdog timeout for a soft reset. */
552 /****************************************************************************/
553 /* Operating System Timer */
557 /* FIXME: this code is PXA250 specific. How is this handled on */
558 /* other XScale processors? */
562 /* We set OWE:WME (watchdog enable) and wait until timeout happens */
566 orr r1, r1, #0x0001 /* bit0: WME */
569 /* OS timer does only wrap every 1165 seconds, so we have to set */
570 /* the match register as well. */
573 ldr r1, [r0] /* read OS timer */
574 add r1, r1, #0x800 /* let OSMR3 match after */
575 add r1, r1, #0x800 /* 4096*(1/3.6864MHz)=1ms */
583 #ifndef CONFIG_PRELOADER
584 .section .mmudata, "a"
588 /* 0x00000000 - 0xa0000000 : 1:1, uncached mapping */
591 .word (__base << 20) | 0xc12
592 .set __base, __base + 1
595 /* 0xa0000000 - 0xa0100000 : 1:1, cached mapping */
596 .word (0xa00 << 20) | 0x1c1e
600 .word (__base << 20) | 0xc12
601 .set __base, __base + 1
603 #endif /* CONFIG_PRELOADER */