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>
5 * Copyright (C) 2003 Martin Winistoerfer, martinwinistoerfer@gmx.ch.
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * Discription: startup code
37 #define CONFIG_5xx 1 /* needed for Linux kernel header files */
38 #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
40 #include <ppc_asm.tmpl>
43 #include <linux/config.h>
44 #include <asm/processor.h>
46 #ifndef CONFIG_IDENT_STRING
47 #define CONFIG_IDENT_STRING ""
50 /* We don't have a MMU.
53 #define MSR_KERNEL ( MSR_ME | MSR_RI ) /* Machine Check and Recoverable Interr. */
56 * Set up GOT: Global Offset Table
58 * Use r14 to access the GOT
61 GOT_ENTRY(_GOT2_TABLE_)
62 GOT_ENTRY(_FIXUP_TABLE_)
65 GOT_ENTRY(_start_of_vectors)
66 GOT_ENTRY(_end_of_vectors)
67 GOT_ENTRY(transfer_to_handler)
71 GOT_ENTRY(__bss_start)
75 * r3 - 1st arg to board_init(): IMMP pointer
76 * r4 - 2nd arg to board_init(): boot flag
79 .long 0x27051956 /* U-Boot Magic Number */
83 .ascii " (", __DATE__, " - ", __TIME__, ")"
84 .ascii CONFIG_IDENT_STRING, "\0"
90 li r4, CFG_ISB /* Set ISB bit */
93 li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
96 . = EXC_OFF_SYS_RESET + 0x20
100 li r21, BOOTFLAG_WARM /* Software reboot */
106 /* Initialize machine status; enable machine check interrupt */
107 /*----------------------------------------------------------------------*/
108 li r3, MSR_KERNEL /* Set ME, RI flags */
110 mtspr SRR1, r3 /* Make SRR1 match MSR */
112 /* Initialize debug port registers */
113 /*----------------------------------------------------------------------*/
114 xor r0, r0, r0 /* Clear R0 */
115 mtspr LCTRL1, r0 /* Initialize debug port regs */
120 #if defined(CONFIG_PATI)
121 /* the external flash access on PATI fails if programming the PLL to 40MHz.
122 * Copy the PLL programming code to the internal RAM and execute it
123 *----------------------------------------------------------------------*/
124 lis r3, CFG_MONITOR_BASE@h
125 ori r3, r3, CFG_MONITOR_BASE@l
126 addi r3, r3, pll_prog_code_start - _start + EXC_OFF_SYS_RESET
128 lis r4, CFG_INIT_RAM_ADDR@h
129 ori r4, r4, CFG_INIT_RAM_ADDR@l
132 ori r5,r5,((pll_prog_code_end - pll_prog_code_start) >>2)
139 bdnz 0b /* copy loop */
144 * Calculate absolute address in FLASH and jump there
145 *----------------------------------------------------------------------*/
147 lis r3, CFG_MONITOR_BASE@h
148 ori r3, r3, CFG_MONITOR_BASE@l
149 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
155 /* Initialize some SPRs that are hard to access from C */
156 /*----------------------------------------------------------------------*/
158 lis r3, CFG_IMMR@h /* Pass IMMR as arg1 to C routine */
159 lis r2, CFG_INIT_SP_ADDR@h
160 ori r1, r2, CFG_INIT_SP_ADDR@l /* Set up the stack in internal SRAM */
161 /* Note: R0 is still 0 here */
162 stwu r0, -4(r1) /* Clear final stack frame so that */
163 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
166 * Disable serialized ifetch and show cycles
167 * (i.e. set processor to normal mode) for maximum
174 /* Set up debug mode entry */
177 ori r2, r2, CFG_DER@l
180 /* Let the C-code set up the rest */
182 /* Be careful to keep code relocatable ! */
183 /*----------------------------------------------------------------------*/
185 GET_GOT /* initialize GOT access */
188 bl cpu_init_f /* run low-level CPU init code (from Flash) */
192 bl board_init_f /* run 1st part of board init code (from Flash) */
195 .globl _start_of_vectors
199 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
201 /* Data Storage exception. "Never" generated on the 860. */
202 STD_EXCEPTION(0x300, DataStorage, UnknownException)
204 /* Instruction Storage exception. "Never" generated on the 860. */
205 STD_EXCEPTION(0x400, InstStorage, UnknownException)
207 /* External Interrupt exception. */
208 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
210 /* Alignment exception. */
213 EXCEPTION_PROLOG(SRR0, SRR1)
218 addi r3,r1,STACK_FRAME_OVERHEAD
220 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
221 lwz r6,GOT(transfer_to_handler)
225 .long AlignmentException - _start + EXC_OFF_SYS_RESET
226 .long int_return - _start + EXC_OFF_SYS_RESET
228 /* Program check exception */
231 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 ProgramCheckException - _start + EXC_OFF_SYS_RESET
240 .long int_return - _start + EXC_OFF_SYS_RESET
242 /* FPU on MPC5xx available. We will use it later.
244 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
246 /* I guess we could implement decrementer, and may have
247 * to someday for timekeeping.
249 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
250 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
251 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
252 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
253 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
255 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
256 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
258 /* On the MPC8xx, this is a software emulation interrupt. It occurs
259 * for all unimplemented and illegal instructions.
261 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
262 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
263 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
264 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
265 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
267 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
268 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
269 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
270 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
271 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
272 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
273 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
275 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
276 STD_EXCEPTION(0x1d00, InstructionBreakpoint, DebugException)
277 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
278 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
281 .globl _end_of_vectors
288 * This code finishes saving the registers to the exception frame
289 * and jumps to the appropriate handler for the exception.
290 * Register r21 is pointer into trap frame, r1 has new stack pointer.
292 .globl transfer_to_handler
303 andi. r24,r23,0x3f00 /* get vector offset */
307 mtspr SPRG2,r22 /* r1 is now kernel sp */
308 lwz r24,0(r23) /* virtual address of handler */
309 lwz r23,4(r23) /* where to go when done */
314 rfi /* jump to handler, enable MMU */
317 mfmsr r28 /* Disable interrupts */
321 SYNC /* Some chip revs need this... */
336 lwz r2,_NIP(r1) /* Restore environment */
348 * unsigned int get_immr (unsigned int mask)
350 * return (mask ? (IMMR & mask) : IMMR);
354 mr r4,r3 /* save mask */
355 mfspr r3, IMMR /* IMMR */
356 cmpwi 0,r4,0 /* mask != 0 ? */
358 and r3,r3,r4 /* IMMR & mask */
368 /*------------------------------------------------------------------------------*/
371 * void relocate_code (addr_sp, gd, addr_moni)
373 * This "function" does not return, instead it continues in RAM
374 * after relocating the monitor code.
378 * r5 = length in bytes
383 mr r1, r3 /* Set new stack pointer in SRAM */
384 mr r9, r4 /* Save copy of global data pointer in SRAM */
385 mr r10, r5 /* Save copy of monitor destination Address in SRAM */
387 mr r3, r5 /* Destination Address */
388 lis r4, CFG_MONITOR_BASE@h /* Source Address */
389 ori r4, r4, CFG_MONITOR_BASE@l
390 lwz r5, GOT(__init_end)
396 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
402 /* First our own GOT */
404 /* the the one used by the C code */
414 beq cr1,4f /* In place copy is not necessary */
415 beq 4f /* Protect against 0 count */
437 * We are done. Do not return, instead branch to second part of board
438 * initialization, now running from RAM.
441 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
448 * Relocation Function, r14 point to got2+0x8000
450 * Adjust got2 pointers, no need to check for 0, this code
451 * already puts a few entries in the table.
453 li r0,__got2_entries@sectoff@l
454 la r3,GOT(_GOT2_TABLE_)
455 lwz r11,GOT(_GOT2_TABLE_)
465 * Now adjust the fixups and the pointers to the fixups
466 * in case we need to move ourselves again.
468 2: li r0,__fixup_entries@sectoff@l
469 lwz r3,GOT(_FIXUP_TABLE_)
483 * Now clear BSS segment
485 lwz r3,GOT(__bss_start)
498 mr r3, r9 /* Global Data pointer */
499 mr r4, r10 /* Destination Address */
503 * Copy exception vector code to low memory
506 * r7: source address, r8: end address, r9: target address
511 lwz r8, GOT(_end_of_vectors)
513 li r9, 0x100 /* reset vector always at 0x100 */
516 bgelr /* return if r7>=r8 - just in case */
518 mflr r4 /* save link register */
528 * relocate `hdlr' and `int_return' entries
530 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
531 li r8, Alignment - _start + EXC_OFF_SYS_RESET
534 addi r7, r7, 0x100 /* next exception vector */
538 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
541 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
544 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
545 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
548 addi r7, r7, 0x100 /* next exception vector */
552 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
553 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
556 addi r7, r7, 0x100 /* next exception vector */
560 mtlr r4 /* restore link register */
564 * Function: relocate entries for one exception vector
567 lwz r0, 0(r7) /* hdlr ... */
568 add r0, r0, r3 /* ... += dest_addr */
571 lwz r0, 4(r7) /* int_return ... */
572 add r0, r0, r3 /* ... += dest_addr */
581 #if defined(CONFIG_PATI)
582 /* Program the PLL */
584 lis r4, (CFG_IMMR + 0x002fc384)@h
585 ori r4, r4, (CFG_IMMR + 0x002fc384)@l
586 lis r3, (0x55ccaa33)@h
587 ori r3, r3, (0x55ccaa33)@l
589 lis r4, (CFG_IMMR + 0x002fc284)@h
590 ori r4, r4, (CFG_IMMR + 0x002fc284)@l
592 ori r3, r3, CFG_PLPRCR@l
598 bdnz ..spinlp /* spin loop */