3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
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 */
121 * Calculate absolute address in FLASH and jump there
122 *----------------------------------------------------------------------*/
124 lis r3, CFG_MONITOR_BASE@h
125 ori r3, r3, CFG_MONITOR_BASE@l
126 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
132 /* Initialize some SPRs that are hard to access from C */
133 /*----------------------------------------------------------------------*/
135 lis r3, CFG_IMMR@h /* Pass IMMR as arg1 to C routine */
136 lis r2, CFG_INIT_SP_ADDR@h
137 ori r1, r2, CFG_INIT_SP_ADDR@l /* Set up the stack in internal SRAM */
138 /* Note: R0 is still 0 here */
139 stwu r0, -4(r1) /* Clear final stack frame so that */
140 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
143 * Disable serialized ifetch and show cycles
144 * (i.e. set processor to normal mode) for maximum
151 /* Set up debug mode entry */
154 ori r2, r2, CFG_DER@l
157 /* Let the C-code set up the rest */
159 /* Be careful to keep code relocatable ! */
160 /*----------------------------------------------------------------------*/
162 GET_GOT /* initialize GOT access */
165 bl cpu_init_f /* run low-level CPU init code (from Flash) */
169 bl board_init_f /* run 1st part of board init code (from Flash) */
172 .globl _start_of_vectors
176 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
178 /* Data Storage exception. "Never" generated on the 860. */
179 STD_EXCEPTION(0x300, DataStorage, UnknownException)
181 /* Instruction Storage exception. "Never" generated on the 860. */
182 STD_EXCEPTION(0x400, InstStorage, UnknownException)
184 /* External Interrupt exception. */
185 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
187 /* Alignment exception. */
195 addi r3,r1,STACK_FRAME_OVERHEAD
197 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
198 lwz r6,GOT(transfer_to_handler)
202 .long AlignmentException - _start + EXC_OFF_SYS_RESET
203 .long int_return - _start + EXC_OFF_SYS_RESET
205 /* Program check exception */
209 addi r3,r1,STACK_FRAME_OVERHEAD
211 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
212 lwz r6,GOT(transfer_to_handler)
216 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
217 .long int_return - _start + EXC_OFF_SYS_RESET
219 /* FPU on MPC5xx available. We will use it later.
221 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
223 /* I guess we could implement decrementer, and may have
224 * to someday for timekeeping.
226 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
227 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
228 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
229 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
230 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
232 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
233 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
235 /* On the MPC8xx, this is a software emulation interrupt. It occurs
236 * for all unimplemented and illegal instructions.
238 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
239 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
240 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
241 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
242 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
244 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
245 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
246 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
247 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
248 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
249 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
250 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
252 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
253 STD_EXCEPTION(0x1d00, InstructionBreakpoint, DebugException)
254 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
255 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
258 .globl _end_of_vectors
265 * This code finishes saving the registers to the exception frame
266 * and jumps to the appropriate handler for the exception.
267 * Register r21 is pointer into trap frame, r1 has new stack pointer.
269 .globl transfer_to_handler
280 andi. r24,r23,0x3f00 /* get vector offset */
284 mtspr SPRG2,r22 /* r1 is now kernel sp */
285 lwz r24,0(r23) /* virtual address of handler */
286 lwz r23,4(r23) /* where to go when done */
291 rfi /* jump to handler, enable MMU */
294 mfmsr r28 /* Disable interrupts */
298 SYNC /* Some chip revs need this... */
313 lwz r2,_NIP(r1) /* Restore environment */
325 * unsigned int get_immr (unsigned int mask)
327 * return (mask ? (IMMR & mask) : IMMR);
331 mr r4,r3 /* save mask */
332 mfspr r3, IMMR /* IMMR */
333 cmpwi 0,r4,0 /* mask != 0 ? */
335 and r3,r3,r4 /* IMMR & mask */
345 /*------------------------------------------------------------------------------*/
348 * void relocate_code (addr_sp, gd, addr_moni)
350 * This "function" does not return, instead it continues in RAM
351 * after relocating the monitor code.
355 * r5 = length in bytes
360 mr r1, r3 /* Set new stack pointer in SRAM */
361 mr r9, r4 /* Save copy of global data pointer in SRAM */
362 mr r10, r5 /* Save copy of monitor destination Address in SRAM */
364 mr r3, r5 /* Destination Address */
365 lis r4, CFG_MONITOR_BASE@h /* Source Address */
366 ori r4, r4, CFG_MONITOR_BASE@l
367 lwz r5, GOT(__init_end)
373 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
379 /* First our own GOT */
381 /* the the one used by the C code */
391 beq cr1,4f /* In place copy is not necessary */
392 beq 4f /* Protect against 0 count */
414 * We are done. Do not return, instead branch to second part of board
415 * initialization, now running from RAM.
418 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
425 * Relocation Function, r14 point to got2+0x8000
427 * Adjust got2 pointers, no need to check for 0, this code
428 * already puts a few entries in the table.
430 li r0,__got2_entries@sectoff@l
431 la r3,GOT(_GOT2_TABLE_)
432 lwz r11,GOT(_GOT2_TABLE_)
442 * Now adjust the fixups and the pointers to the fixups
443 * in case we need to move ourselves again.
445 2: li r0,__fixup_entries@sectoff@l
446 lwz r3,GOT(_FIXUP_TABLE_)
460 * Now clear BSS segment
462 lwz r3,GOT(__bss_start)
475 mr r3, r9 /* Global Data pointer */
476 mr r4, r10 /* Destination Address */
480 * Copy exception vector code to low memory
483 * r7: source address, r8: end address, r9: target address
488 lwz r8, GOT(_end_of_vectors)
490 li r9, 0x100 /* reset vector always at 0x100 */
493 bgelr /* return if r7>=r8 - just in case */
495 mflr r4 /* save link register */
505 * relocate `hdlr' and `int_return' entries
507 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
508 li r8, Alignment - _start + EXC_OFF_SYS_RESET
511 addi r7, r7, 0x100 /* next exception vector */
515 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
518 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
521 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
522 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
525 addi r7, r7, 0x100 /* next exception vector */
529 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
530 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
533 addi r7, r7, 0x100 /* next exception vector */
537 mtlr r4 /* restore link register */
541 * Function: relocate entries for one exception vector
544 lwz r0, 0(r7) /* hdlr ... */
545 add r0, r0, r3 /* ... += dest_addr */
548 lwz r0, 4(r7) /* int_return ... */
549 add r0, r0, r3 /* ... += dest_addr */