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 - 2003 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,
26 * U-Boot - Startup Code for MPC5xxx CPUs
32 #define CONFIG_MPC5XXX 1 /* needed for Linux kernel header files */
33 #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
35 #include <ppc_asm.tmpl>
38 #include <asm/cache.h>
41 #ifndef CONFIG_IDENT_STRING
42 #define CONFIG_IDENT_STRING ""
45 /* We don't want the MMU yet.
48 /* Floating Point enable, Machine Check and Recoverable Interr. */
50 #define MSR_KERNEL (MSR_FP|MSR_RI)
52 #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
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)
81 .ascii " (", __DATE__, " - ", __TIME__, ")"
82 .ascii CONFIG_IDENT_STRING, "\0"
91 li r21, BOOTFLAG_COLD /* Normal Power-On */
95 . = EXC_OFF_SYS_RESET + 0x10
99 li r21, BOOTFLAG_WARM /* Software reboot */
104 mfmsr r5 /* save msr contents */
106 #if defined(CFG_DEFAULT_MBAR) && !defined(CFG_RAMBOOT)
108 ori r3, r3, CFG_MBAR@l
109 #if defined(CONFIG_MPC5200)
110 rlwinm r3, r3, 16, 16, 31
112 #if defined(CONFIG_MGT5100)
113 rlwinm r3, r3, 17, 15, 31
115 lis r4, CFG_DEFAULT_MBAR@h
117 #endif /* CFG_DEFAULT_MBAR */
119 /* Initialise the MPC5xxx processor core */
120 /*--------------------------------------------------------------*/
124 /* initialize some things that are hard to access from C */
125 /*--------------------------------------------------------------*/
127 /* set up stack in on-chip SRAM */
128 lis r3, CFG_INIT_RAM_ADDR@h
129 ori r3, r3, CFG_INIT_RAM_ADDR@l
130 ori r1, r3, CFG_INIT_SP_OFFSET
131 li r0, 0 /* Make room for stack frame header and */
132 stwu r0, -4(r1) /* clear final stack frame so that */
133 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
135 /* let the C-code set up the rest */
137 /* Be careful to keep code relocatable ! */
138 /*--------------------------------------------------------------*/
140 GET_GOT /* initialize GOT access */
143 bl cpu_init_f /* run low-level CPU init code (in Flash)*/
147 bl board_init_f /* run 1st part of board init code (in Flash)*/
153 .globl _start_of_vectors
157 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
159 /* Data Storage exception. */
160 STD_EXCEPTION(0x300, DataStorage, UnknownException)
162 /* Instruction Storage exception. */
163 STD_EXCEPTION(0x400, InstStorage, UnknownException)
165 /* External Interrupt exception. */
166 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
168 /* Alignment exception. */
176 addi r3,r1,STACK_FRAME_OVERHEAD
178 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
179 rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */
180 lwz r6,GOT(transfer_to_handler)
184 .long AlignmentException - _start + EXC_OFF_SYS_RESET
185 .long int_return - _start + EXC_OFF_SYS_RESET
187 /* Program check exception */
191 addi r3,r1,STACK_FRAME_OVERHEAD
193 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
194 rlwimi r20,r23,0,25,25 /* copy IP bit from saved MSR */
195 lwz r6,GOT(transfer_to_handler)
199 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
200 .long int_return - _start + EXC_OFF_SYS_RESET
202 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
204 /* I guess we could implement decrementer, and may have
205 * to someday for timekeeping.
207 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
209 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
210 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
211 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
212 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
214 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
215 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
217 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
218 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
219 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
223 * This exception occurs when the program counter matches the
224 * Instruction Address Breakpoint Register (IABR).
226 * I want the cpu to halt if this occurs so I can hunt around
227 * with the debugger and look at things.
229 * When DEBUG is defined, both machine check enable (in the MSR)
230 * and checkstop reset enable (in the reset mode register) are
231 * turned off and so a checkstop condition will result in the cpu
234 * I force the cpu into a checkstop condition by putting an illegal
235 * instruction here (at least this is the theory).
237 * well - that didnt work, so just do an infinite loop!
241 STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
243 STD_EXCEPTION(0x1400, SMI, UnknownException)
245 STD_EXCEPTION(0x1500, Trap_15, UnknownException)
246 STD_EXCEPTION(0x1600, Trap_16, UnknownException)
247 STD_EXCEPTION(0x1700, Trap_17, UnknownException)
248 STD_EXCEPTION(0x1800, Trap_18, UnknownException)
249 STD_EXCEPTION(0x1900, Trap_19, UnknownException)
250 STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
251 STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
252 STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
253 STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
254 STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
255 STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
256 STD_EXCEPTION(0x2000, Trap_20, UnknownException)
257 STD_EXCEPTION(0x2100, Trap_21, UnknownException)
258 STD_EXCEPTION(0x2200, Trap_22, UnknownException)
259 STD_EXCEPTION(0x2300, Trap_23, UnknownException)
260 STD_EXCEPTION(0x2400, Trap_24, UnknownException)
261 STD_EXCEPTION(0x2500, Trap_25, UnknownException)
262 STD_EXCEPTION(0x2600, Trap_26, UnknownException)
263 STD_EXCEPTION(0x2700, Trap_27, UnknownException)
264 STD_EXCEPTION(0x2800, Trap_28, UnknownException)
265 STD_EXCEPTION(0x2900, Trap_29, UnknownException)
266 STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
267 STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
268 STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
269 STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
270 STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
271 STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
274 .globl _end_of_vectors
280 * This code finishes saving the registers to the exception frame
281 * and jumps to the appropriate handler for the exception.
282 * Register r21 is pointer into trap frame, r1 has new stack pointer.
284 .globl transfer_to_handler
295 andi. r24,r23,0x3f00 /* get vector offset */
299 lwz r24,0(r23) /* virtual address of handler */
300 lwz r23,4(r23) /* where to go when done */
305 rfi /* jump to handler, enable MMU */
308 mfmsr r28 /* Disable interrupts */
312 SYNC /* Some chip revs need this... */
327 lwz r2,_NIP(r1) /* Restore environment */
338 * This code initialises the MPC5xxx processor core
339 * (conforms to PowerPC 603e spec)
340 * Note: expects original MSR contents to be in r5.
346 /* Initialize machine status; enable machine check interrupt */
347 /*--------------------------------------------------------------*/
349 li r3, MSR_KERNEL /* Set ME and RI flags */
350 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
352 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
354 SYNC /* Some chip revs need this... */
357 mtspr SRR1, r3 /* Make SRR1 match MSR */
359 /* Initialize the Hardware Implementation-dependent Registers */
360 /* HID0 also contains cache control */
361 /*--------------------------------------------------------------*/
363 lis r3, CFG_HID0_INIT@h
364 ori r3, r3, CFG_HID0_INIT@l
368 lis r3, CFG_HID0_FINAL@h
369 ori r3, r3, CFG_HID0_FINAL@l
373 /* clear all BAT's */
374 /*--------------------------------------------------------------*/
395 /* invalidate all tlb's */
397 /* From the 603e User Manual: "The 603e provides the ability to */
398 /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie) */
399 /* instruction invalidates the TLB entry indexed by the EA, and */
400 /* operates on both the instruction and data TLBs simultaneously*/
401 /* invalidating four TLB entries (both sets in each TLB). The */
402 /* index corresponds to bits 15-19 of the EA. To invalidate all */
403 /* entries within both TLBs, 32 tlbie instructions should be */
404 /* issued, incrementing this field by one each time." */
406 /* "Note that the tlbia instruction is not implemented on the */
409 /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 */
410 /* incrementing by 0x1000 each time. The code below is sort of */
411 /* based on code in "flush_tlbs" from arch/ppc/kernel/head.S */
413 /*--------------------------------------------------------------*/
424 /*--------------------------------------------------------------*/
430 * Note: requires that all cache bits in
431 * HID0 are in the low half word.
438 ori r4, r4, HID0_ILOCK
440 ori r4, r3, HID0_ICFI
442 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
444 mtspr HID0, r3 /* clears invalidate */
447 .globl icache_disable
451 ori r4, r4, HID0_ICE|HID0_ILOCK
453 ori r4, r3, HID0_ICFI
455 mtspr HID0, r4 /* sets invalidate, clears enable and lock */
457 mtspr HID0, r3 /* clears invalidate */
463 rlwinm r3, r3, HID0_ICE_BITPOS + 1, 31, 31
471 ori r4, r4, HID0_DLOCK
475 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
477 mtspr HID0, r3 /* clears invalidate */
480 .globl dcache_disable
484 ori r4, r4, HID0_DCE|HID0_DLOCK
488 mtspr HID0, r4 /* sets invalidate, clears enable and lock */
490 mtspr HID0, r3 /* clears invalidate */
496 rlwinm r3, r3, HID0_DCE_BITPOS + 1, 31, 31
504 /*------------------------------------------------------------------------------*/
507 * void relocate_code (addr_sp, gd, addr_moni)
509 * This "function" does not return, instead it continues in RAM
510 * after relocating the monitor code.
514 * r5 = length in bytes
519 mr r1, r3 /* Set new stack pointer */
520 mr r9, r4 /* Save copy of Global Data pointer */
521 mr r10, r5 /* Save copy of Destination Address */
523 mr r3, r5 /* Destination Address */
524 lis r4, CFG_MONITOR_BASE@h /* Source Address */
525 ori r4, r4, CFG_MONITOR_BASE@l
526 lwz r5, GOT(__init_end)
528 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
533 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
539 /* First our own GOT */
541 /* then the one used by the C code */
551 beq cr1,4f /* In place copy is not necessary */
552 beq 7f /* Protect against 0 count */
571 * Now flush the cache: note that we must start from a cache aligned
572 * address. Otherwise we might miss one cache line.
576 beq 7f /* Always flush prefetch queue in any case */
579 mfspr r7,HID0 /* don't do dcbst if dcache is disabled */
580 rlwinm r7,r7,HID0_DCE_BITPOS+1,31,31
588 sync /* Wait for all dcbst to complete on bus */
589 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
590 rlwinm r7,r7,HID0_ICE_BITPOS+1,31,31
598 7: sync /* Wait for all icbi to complete on bus */
602 * We are done. Do not return, instead branch to second part of board
603 * initialization, now running from RAM.
606 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
613 * Relocation Function, r14 point to got2+0x8000
615 * Adjust got2 pointers, no need to check for 0, this code
616 * already puts a few entries in the table.
618 li r0,__got2_entries@sectoff@l
619 la r3,GOT(_GOT2_TABLE_)
620 lwz r11,GOT(_GOT2_TABLE_)
630 * Now adjust the fixups and the pointers to the fixups
631 * in case we need to move ourselves again.
633 2: li r0,__fixup_entries@sectoff@l
634 lwz r3,GOT(_FIXUP_TABLE_)
648 * Now clear BSS segment
650 lwz r3,GOT(__bss_start)
664 mr r3, r9 /* Global Data pointer */
665 mr r4, r10 /* Destination Address */
669 * Copy exception vector code to low memory
672 * r7: source address, r8: end address, r9: target address
677 lwz r8, GOT(_end_of_vectors)
679 li r9, 0x100 /* reset vector always at 0x100 */
682 bgelr /* return if r7>=r8 - just in case */
684 mflr r4 /* save link register */
694 * relocate `hdlr' and `int_return' entries
696 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
697 li r8, Alignment - _start + EXC_OFF_SYS_RESET
700 addi r7, r7, 0x100 /* next exception vector */
704 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
707 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
710 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
711 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
714 addi r7, r7, 0x100 /* next exception vector */
718 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
719 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
722 addi r7, r7, 0x100 /* next exception vector */
726 mfmsr r3 /* now that the vectors have */
727 lis r7, MSR_IP@h /* relocated into low memory */
728 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
729 andc r3, r3, r7 /* (if it was on) */
730 SYNC /* Some chip revs need this... */
734 mtlr r4 /* restore link register */
738 * Function: relocate entries for one exception vector
741 lwz r0, 0(r7) /* hdlr ... */
742 add r0, r0, r3 /* ... += dest_addr */
745 lwz r0, 4(r7) /* int_return ... */
746 add r0, r0, r3 /* ... += dest_addr */