2 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
4 * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 /* U-Boot - Startup Code for PowerPC based Embedded Boards
28 * The processor starts at 0x00000100 and the code is executed
29 * from flash. The code is organized to be at an other address
30 * in memory, but as long we don't jump around before relocating,
31 * board_init lies at a quite high address and when the cpu has
32 * jumped there, everything is ok.
33 * This works because the cpu gives the FLASH (CS0) the whole
34 * address space at startup, and board_init lies as a echo of
35 * the flash somewhere up there in the memory map.
37 * board_init will change CS0 to be positioned at the correct
38 * address and (s)dram will be positioned at address 0
44 #define CONFIG_8xx 1 /* needed for Linux kernel header files */
45 #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
47 #include <ppc_asm.tmpl>
50 #include <asm/cache.h>
53 #ifndef CONFIG_IDENT_STRING
54 #define CONFIG_IDENT_STRING ""
57 /* We don't want the MMU yet.
60 #define MSR_KERNEL ( MSR_ME | MSR_RI ) /* Machine Check and Recoverable Interr. */
63 * Set up GOT: Global Offset Table
65 * Use r14 to access the GOT
68 GOT_ENTRY(_GOT2_TABLE_)
69 GOT_ENTRY(_FIXUP_TABLE_)
72 GOT_ENTRY(_start_of_vectors)
73 GOT_ENTRY(_end_of_vectors)
74 GOT_ENTRY(transfer_to_handler)
78 GOT_ENTRY(__bss_start)
82 * r3 - 1st arg to board_init(): IMMP pointer
83 * r4 - 2nd arg to board_init(): boot flag
86 .long 0x27051956 /* U-Boot Magic Number */
90 .ascii " (", __DATE__, " - ", __TIME__, ")"
91 .ascii CONFIG_IDENT_STRING, "\0"
96 lis r3, CFG_IMMR@h /* position IMMR */
98 li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
101 . = EXC_OFF_SYS_RESET + 0x10
105 li r21, BOOTFLAG_WARM /* Software reboot */
111 /* Initialize machine status; enable machine check interrupt */
112 /*----------------------------------------------------------------------*/
113 li r3, MSR_KERNEL /* Set ME, RI flags */
115 mtspr SRR1, r3 /* Make SRR1 match MSR */
117 mfspr r3, ICR /* clear Interrupt Cause Register */
119 /* Initialize debug port registers */
120 /*----------------------------------------------------------------------*/
121 xor r0, r0, r0 /* Clear R0 */
122 mtspr LCTRL1, r0 /* Initialize debug port regs */
127 /* Reset the caches */
128 /*----------------------------------------------------------------------*/
130 mfspr r3, IC_CST /* Clear error bits */
133 lis r3, IDC_UNALL@h /* Unlock all */
137 lis r3, IDC_INVALL@h /* Invalidate all */
141 lis r3, IDC_DISABLE@h /* Disable data cache */
144 #if !(defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM))
145 /* On IP860 and PCU E,
146 * we cannot enable IC yet
148 lis r3, IDC_ENABLE@h /* Enable instruction cache */
152 /* invalidate all tlb's */
153 /*----------------------------------------------------------------------*/
159 * Calculate absolute address in FLASH and jump there
160 *----------------------------------------------------------------------*/
162 lis r3, CFG_MONITOR_BASE@h
163 ori r3, r3, CFG_MONITOR_BASE@l
164 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
170 /* initialize some SPRs that are hard to access from C */
171 /*----------------------------------------------------------------------*/
173 lis r3, CFG_IMMR@h /* pass IMMR as arg1 to C routine */
174 ori r1, r3, CFG_INIT_SP_OFFSET /* set up the stack in internal DPRAM */
175 /* Note: R0 is still 0 here */
176 stwu r0, -4(r1) /* clear final stack frame so that */
177 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
180 * Disable serialized ifetch and show cycles
181 * (i.e. set processor to normal mode).
182 * This is also a silicon bug workaround, see errata
188 /* Set up debug mode entry */
191 ori r2, r2, CFG_DER@l
194 /* let the C-code set up the rest */
196 /* Be careful to keep code relocatable ! */
197 /*----------------------------------------------------------------------*/
199 GET_GOT /* initialize GOT access */
202 bl cpu_init_f /* run low-level CPU init code (from Flash) */
206 bl board_init_f /* run 1st part of board init code (from Flash) */
209 .globl _start_of_vectors
213 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
215 /* Data Storage exception. "Never" generated on the 860. */
216 STD_EXCEPTION(0x300, DataStorage, UnknownException)
218 /* Instruction Storage exception. "Never" generated on the 860. */
219 STD_EXCEPTION(0x400, InstStorage, UnknownException)
221 /* External Interrupt exception. */
222 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
224 /* Alignment exception. */
227 EXCEPTION_PROLOG(SRR0, SRR1)
232 addi r3,r1,STACK_FRAME_OVERHEAD
234 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
235 lwz r6,GOT(transfer_to_handler)
239 .long AlignmentException - _start + EXC_OFF_SYS_RESET
240 .long int_return - _start + EXC_OFF_SYS_RESET
242 /* Program check exception */
245 EXCEPTION_PROLOG(SRR0, SRR1)
246 addi r3,r1,STACK_FRAME_OVERHEAD
248 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
249 lwz r6,GOT(transfer_to_handler)
253 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
254 .long int_return - _start + EXC_OFF_SYS_RESET
256 /* No FPU on MPC8xx. This exception is not supposed to happen.
258 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
260 /* I guess we could implement decrementer, and may have
261 * to someday for timekeeping.
263 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
264 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
265 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
266 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
267 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
269 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
270 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
272 /* On the MPC8xx, this is a software emulation interrupt. It occurs
273 * for all unimplemented and illegal instructions.
275 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
277 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
278 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
279 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
280 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
282 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
283 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
284 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
285 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
286 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
287 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
288 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
290 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
291 STD_EXCEPTION(0x1d00, InstructionBreakpoint, DebugException)
292 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
293 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
296 .globl _end_of_vectors
303 * This code finishes saving the registers to the exception frame
304 * and jumps to the appropriate handler for the exception.
305 * Register r21 is pointer into trap frame, r1 has new stack pointer.
307 .globl transfer_to_handler
318 andi. r24,r23,0x3f00 /* get vector offset */
322 mtspr SPRG2,r22 /* r1 is now kernel sp */
323 lwz r24,0(r23) /* virtual address of handler */
324 lwz r23,4(r23) /* where to go when done */
329 rfi /* jump to handler, enable MMU */
332 mfmsr r28 /* Disable interrupts */
336 SYNC /* Some chip revs need this... */
351 lwz r2,_NIP(r1) /* Restore environment */
372 .globl icache_disable
375 lis r3, IDC_DISABLE@h
382 srwi r3, r3, 31 /* >>31 => select bit 0 */
391 lis r3, 0x0400 /* Set cache mode with MMU off */
405 .globl dcache_disable
408 lis r3, IDC_DISABLE@h
417 srwi r3, r3, 31 /* >>31 => select bit 0 */
427 * unsigned int get_immr (unsigned int mask)
429 * return (mask ? (IMMR & mask) : IMMR);
433 mr r4,r3 /* save mask */
434 mfspr r3, IMMR /* IMMR */
435 cmpwi 0,r4,0 /* mask != 0 ? */
437 and r3,r3,r4 /* IMMR & mask */
478 /*------------------------------------------------------------------------------*/
481 * void relocate_code (addr_sp, gd, addr_moni)
483 * This "function" does not return, instead it continues in RAM
484 * after relocating the monitor code.
488 * r5 = length in bytes
493 mr r1, r3 /* Set new stack pointer */
494 mr r9, r4 /* Save copy of Global Data pointer */
495 mr r10, r5 /* Save copy of Destination Address */
497 mr r3, r5 /* Destination Address */
498 lis r4, CFG_MONITOR_BASE@h /* Source Address */
499 ori r4, r4, CFG_MONITOR_BASE@l
500 lwz r5, GOT(__init_end)
502 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
507 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
513 /* First our own GOT */
515 /* then the one used by the C code */
525 beq cr1,4f /* In place copy is not necessary */
526 beq 7f /* Protect against 0 count */
545 * Now flush the cache: note that we must start from a cache aligned
546 * address. Otherwise we might miss one cache line.
550 beq 7f /* Always flush prefetch queue in any case */
558 sync /* Wait for all dcbst to complete on bus */
564 7: sync /* Wait for all icbi to complete on bus */
568 * We are done. Do not return, instead branch to second part of board
569 * initialization, now running from RAM.
572 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
579 * Relocation Function, r14 point to got2+0x8000
581 * Adjust got2 pointers, no need to check for 0, this code
582 * already puts a few entries in the table.
584 li r0,__got2_entries@sectoff@l
585 la r3,GOT(_GOT2_TABLE_)
586 lwz r11,GOT(_GOT2_TABLE_)
596 * Now adjust the fixups and the pointers to the fixups
597 * in case we need to move ourselves again.
599 2: li r0,__fixup_entries@sectoff@l
600 lwz r3,GOT(_FIXUP_TABLE_)
614 * Now clear BSS segment
616 lwz r3,GOT(__bss_start)
630 mr r3, r9 /* Global Data pointer */
631 mr r4, r10 /* Destination Address */
635 * Copy exception vector code to low memory
638 * r7: source address, r8: end address, r9: target address
643 lwz r8, GOT(_end_of_vectors)
645 li r9, 0x100 /* reset vector always at 0x100 */
648 bgelr /* return if r7>=r8 - just in case */
650 mflr r4 /* save link register */
660 * relocate `hdlr' and `int_return' entries
662 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
663 li r8, Alignment - _start + EXC_OFF_SYS_RESET
666 addi r7, r7, 0x100 /* next exception vector */
670 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
673 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
676 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
677 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
680 addi r7, r7, 0x100 /* next exception vector */
684 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
685 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
688 addi r7, r7, 0x100 /* next exception vector */
692 mtlr r4 /* restore link register */
696 * Function: relocate entries for one exception vector
699 lwz r0, 0(r7) /* hdlr ... */
700 add r0, r0, r3 /* ... += dest_addr */
703 lwz r0, 4(r7) /* int_return ... */
704 add r0, r0, r3 /* ... += dest_addr */