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
30 #include <timestamp.h>
33 #define CONFIG_MPC5xxx 1 /* needed for Linux kernel header files */
34 #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
36 #include <ppc_asm.tmpl>
39 #include <asm/cache.h>
42 #ifndef CONFIG_IDENT_STRING
43 #define CONFIG_IDENT_STRING ""
46 /* We don't want the MMU yet.
49 /* Floating Point enable, Machine Check and Recoverable Interr. */
51 #define MSR_KERNEL (MSR_FP|MSR_RI)
53 #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
57 * Set up GOT: Global Offset Table
59 * Use r14 to access the GOT
62 GOT_ENTRY(_GOT2_TABLE_)
63 GOT_ENTRY(_FIXUP_TABLE_)
66 GOT_ENTRY(_start_of_vectors)
67 GOT_ENTRY(_end_of_vectors)
68 GOT_ENTRY(transfer_to_handler)
72 GOT_ENTRY(__bss_start)
82 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
83 .ascii CONFIG_IDENT_STRING, "\0"
92 li r21, BOOTFLAG_COLD /* Normal Power-On */
96 . = EXC_OFF_SYS_RESET + 0x10
100 li r21, BOOTFLAG_WARM /* Software reboot */
105 mfmsr r5 /* save msr contents */
107 /* Move CSBoot and adjust instruction pointer */
108 /*--------------------------------------------------------------*/
110 #if defined(CONFIG_SYS_LOWBOOT)
111 # if defined(CONFIG_SYS_RAMBOOT)
112 # error CONFIG_SYS_LOWBOOT is incompatible with CONFIG_SYS_RAMBOOT
113 # endif /* CONFIG_SYS_RAMBOOT */
114 # if defined(CONFIG_MGT5100)
115 # error CONFIG_SYS_LOWBOOT is incompatible with MGT5100
116 # endif /* CONFIG_MGT5100 */
117 lis r4, CONFIG_SYS_DEFAULT_MBAR@h
118 lis r3, START_REG(CONFIG_SYS_BOOTCS_START)@h
119 ori r3, r3, START_REG(CONFIG_SYS_BOOTCS_START)@l
120 stw r3, 0x4(r4) /* CS0 start */
121 lis r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@h
122 ori r3, r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@l
123 stw r3, 0x8(r4) /* CS0 stop */
125 ori r3, r3, 0x02010000@l
126 stw r3, 0x54(r4) /* CS0 and Boot enable */
128 lis r3, lowboot_reentry@h /* jump from bootlow address space (0x0000xxxx) */
129 ori r3, r3, lowboot_reentry@l /* to the address space the linker used */
134 lis r3, START_REG(CONFIG_SYS_BOOTCS_START)@h
135 ori r3, r3, START_REG(CONFIG_SYS_BOOTCS_START)@l
136 stw r3, 0x4c(r4) /* Boot start */
137 lis r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@h
138 ori r3, r3, STOP_REG(CONFIG_SYS_BOOTCS_START, CONFIG_SYS_BOOTCS_SIZE)@l
139 stw r3, 0x50(r4) /* Boot stop */
141 ori r3, r3, 0x02000001@l
142 stw r3, 0x54(r4) /* Boot enable, CS0 disable */
143 #endif /* CONFIG_SYS_LOWBOOT */
145 #if defined(CONFIG_SYS_DEFAULT_MBAR) && !defined(CONFIG_SYS_RAMBOOT)
146 lis r3, CONFIG_SYS_MBAR@h
147 ori r3, r3, CONFIG_SYS_MBAR@l
148 #if defined(CONFIG_MPC5200)
149 /* MBAR is mirrored into the MBAR SPR */
151 rlwinm r3, r3, 16, 16, 31
153 #if defined(CONFIG_MGT5100)
154 rlwinm r3, r3, 17, 15, 31
156 lis r4, CONFIG_SYS_DEFAULT_MBAR@h
158 #endif /* CONFIG_SYS_DEFAULT_MBAR */
160 /* Initialise the MPC5xxx processor core */
161 /*--------------------------------------------------------------*/
165 /* initialize some things that are hard to access from C */
166 /*--------------------------------------------------------------*/
168 /* set up stack in on-chip SRAM */
169 lis r3, CONFIG_SYS_INIT_RAM_ADDR@h
170 ori r3, r3, CONFIG_SYS_INIT_RAM_ADDR@l
171 ori r1, r3, CONFIG_SYS_INIT_SP_OFFSET
172 li r0, 0 /* Make room for stack frame header and */
173 stwu r0, -4(r1) /* clear final stack frame so that */
174 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
176 /* let the C-code set up the rest */
178 /* Be careful to keep code relocatable ! */
179 /*--------------------------------------------------------------*/
181 GET_GOT /* initialize GOT access */
184 bl cpu_init_f /* run low-level CPU init code (in Flash)*/
188 bl board_init_f /* run 1st part of board init code (in Flash)*/
194 .globl _start_of_vectors
198 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
200 /* Data Storage exception. */
201 STD_EXCEPTION(0x300, DataStorage, UnknownException)
203 /* Instruction Storage exception. */
204 STD_EXCEPTION(0x400, InstStorage, UnknownException)
206 /* External Interrupt exception. */
207 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
209 /* Alignment exception. */
212 EXCEPTION_PROLOG(SRR0, SRR1)
217 addi r3,r1,STACK_FRAME_OVERHEAD
218 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
220 /* Program check exception */
223 EXCEPTION_PROLOG(SRR0, SRR1)
224 addi r3,r1,STACK_FRAME_OVERHEAD
225 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
228 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
230 /* I guess we could implement decrementer, and may have
231 * to someday for timekeeping.
233 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
235 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
236 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
237 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
238 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
240 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
241 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
243 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
244 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
245 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
249 * This exception occurs when the program counter matches the
250 * Instruction Address Breakpoint Register (IABR).
252 * I want the cpu to halt if this occurs so I can hunt around
253 * with the debugger and look at things.
255 * When DEBUG is defined, both machine check enable (in the MSR)
256 * and checkstop reset enable (in the reset mode register) are
257 * turned off and so a checkstop condition will result in the cpu
260 * I force the cpu into a checkstop condition by putting an illegal
261 * instruction here (at least this is the theory).
263 * well - that didnt work, so just do an infinite loop!
267 STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
269 STD_EXCEPTION(0x1400, SMI, UnknownException)
271 STD_EXCEPTION(0x1500, Trap_15, UnknownException)
272 STD_EXCEPTION(0x1600, Trap_16, UnknownException)
273 STD_EXCEPTION(0x1700, Trap_17, UnknownException)
274 STD_EXCEPTION(0x1800, Trap_18, UnknownException)
275 STD_EXCEPTION(0x1900, Trap_19, UnknownException)
276 STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
277 STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
278 STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
279 STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
280 STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
281 STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
282 STD_EXCEPTION(0x2000, Trap_20, UnknownException)
283 STD_EXCEPTION(0x2100, Trap_21, UnknownException)
284 STD_EXCEPTION(0x2200, Trap_22, UnknownException)
285 STD_EXCEPTION(0x2300, Trap_23, UnknownException)
286 STD_EXCEPTION(0x2400, Trap_24, UnknownException)
287 STD_EXCEPTION(0x2500, Trap_25, UnknownException)
288 STD_EXCEPTION(0x2600, Trap_26, UnknownException)
289 STD_EXCEPTION(0x2700, Trap_27, UnknownException)
290 STD_EXCEPTION(0x2800, Trap_28, UnknownException)
291 STD_EXCEPTION(0x2900, Trap_29, UnknownException)
292 STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
293 STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
294 STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
295 STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
296 STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
297 STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
300 .globl _end_of_vectors
306 * This code finishes saving the registers to the exception frame
307 * and jumps to the appropriate handler for the exception.
308 * Register r21 is pointer into trap frame, r1 has new stack pointer.
310 .globl transfer_to_handler
321 andi. r24,r23,0x3f00 /* get vector offset */
325 lwz r24,0(r23) /* virtual address of handler */
326 lwz r23,4(r23) /* where to go when done */
331 rfi /* jump to handler, enable MMU */
334 mfmsr r28 /* Disable interrupts */
338 SYNC /* Some chip revs need this... */
353 lwz r2,_NIP(r1) /* Restore environment */
364 * This code initialises the MPC5xxx processor core
365 * (conforms to PowerPC 603e spec)
366 * Note: expects original MSR contents to be in r5.
372 /* Initialize machine status; enable machine check interrupt */
373 /*--------------------------------------------------------------*/
375 li r3, MSR_KERNEL /* Set ME and RI flags */
376 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
378 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
380 SYNC /* Some chip revs need this... */
383 mtspr SRR1, r3 /* Make SRR1 match MSR */
385 /* Initialize the Hardware Implementation-dependent Registers */
386 /* HID0 also contains cache control */
387 /*--------------------------------------------------------------*/
389 lis r3, CONFIG_SYS_HID0_INIT@h
390 ori r3, r3, CONFIG_SYS_HID0_INIT@l
394 lis r3, CONFIG_SYS_HID0_FINAL@h
395 ori r3, r3, CONFIG_SYS_HID0_FINAL@l
399 /* clear all BAT's */
400 /*--------------------------------------------------------------*/
437 /* invalidate all tlb's */
439 /* From the 603e User Manual: "The 603e provides the ability to */
440 /* invalidate a TLB entry. The TLB Invalidate Entry (tlbie) */
441 /* instruction invalidates the TLB entry indexed by the EA, and */
442 /* operates on both the instruction and data TLBs simultaneously*/
443 /* invalidating four TLB entries (both sets in each TLB). The */
444 /* index corresponds to bits 15-19 of the EA. To invalidate all */
445 /* entries within both TLBs, 32 tlbie instructions should be */
446 /* issued, incrementing this field by one each time." */
448 /* "Note that the tlbia instruction is not implemented on the */
451 /* bits 15-19 correspond to addresses 0x00000000 to 0x0001F000 */
452 /* incrementing by 0x1000 each time. The code below is sort of */
453 /* based on code in "flush_tlbs" from arch/ppc/kernel/head.S */
455 /*--------------------------------------------------------------*/
466 /*--------------------------------------------------------------*/
472 * Note: requires that all cache bits in
473 * HID0 are in the low half word.
480 ori r4, r4, HID0_ILOCK
482 ori r4, r3, HID0_ICFI
484 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
486 mtspr HID0, r3 /* clears invalidate */
489 .globl icache_disable
493 ori r4, r4, HID0_ICE|HID0_ILOCK
495 ori r4, r3, HID0_ICFI
497 mtspr HID0, r4 /* sets invalidate, clears enable and lock */
499 mtspr HID0, r3 /* clears invalidate */
505 rlwinm r3, r3, HID0_ICE_BITPOS + 1, 31, 31
513 ori r4, r4, HID0_DLOCK
517 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
519 mtspr HID0, r3 /* clears invalidate */
522 .globl dcache_disable
526 ori r4, r4, HID0_DCE|HID0_DLOCK
530 mtspr HID0, r4 /* sets invalidate, clears enable and lock */
532 mtspr HID0, r3 /* clears invalidate */
538 rlwinm r3, r3, HID0_DCE_BITPOS + 1, 31, 31
551 /*------------------------------------------------------------------------------*/
554 * void relocate_code (addr_sp, gd, addr_moni)
556 * This "function" does not return, instead it continues in RAM
557 * after relocating the monitor code.
561 * r5 = length in bytes
566 mr r1, r3 /* Set new stack pointer */
567 mr r9, r4 /* Save copy of Global Data pointer */
568 mr r10, r5 /* Save copy of Destination Address */
570 mr r3, r5 /* Destination Address */
571 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
572 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
573 lwz r5, GOT(__init_end)
575 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
580 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
586 /* First our own GOT */
588 /* then the one used by the C code */
598 beq cr1,4f /* In place copy is not necessary */
599 beq 7f /* Protect against 0 count */
618 * Now flush the cache: note that we must start from a cache aligned
619 * address. Otherwise we might miss one cache line.
623 beq 7f /* Always flush prefetch queue in any case */
626 mfspr r7,HID0 /* don't do dcbst if dcache is disabled */
627 rlwinm r7,r7,HID0_DCE_BITPOS+1,31,31
635 sync /* Wait for all dcbst to complete on bus */
636 9: mfspr r7,HID0 /* don't do icbi if icache is disabled */
637 rlwinm r7,r7,HID0_ICE_BITPOS+1,31,31
645 7: sync /* Wait for all icbi to complete on bus */
649 * We are done. Do not return, instead branch to second part of board
650 * initialization, now running from RAM.
653 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
660 * Relocation Function, r14 point to got2+0x8000
662 * Adjust got2 pointers, no need to check for 0, this code
663 * already puts a few entries in the table.
665 li r0,__got2_entries@sectoff@l
666 la r3,GOT(_GOT2_TABLE_)
667 lwz r11,GOT(_GOT2_TABLE_)
679 * Now adjust the fixups and the pointers to the fixups
680 * in case we need to move ourselves again.
682 li r0,__fixup_entries@sectoff@l
683 lwz r3,GOT(_FIXUP_TABLE_)
697 * Now clear BSS segment
699 lwz r3,GOT(__bss_start)
713 mr r3, r9 /* Global Data pointer */
714 mr r4, r10 /* Destination Address */
718 * Copy exception vector code to low memory
721 * r7: source address, r8: end address, r9: target address
726 lwz r8, GOT(_end_of_vectors)
728 li r9, 0x100 /* reset vector always at 0x100 */
731 bgelr /* return if r7>=r8 - just in case */
733 mflr r4 /* save link register */
743 * relocate `hdlr' and `int_return' entries
745 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
746 li r8, Alignment - _start + EXC_OFF_SYS_RESET
749 addi r7, r7, 0x100 /* next exception vector */
753 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
756 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
759 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
760 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
763 addi r7, r7, 0x100 /* next exception vector */
767 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
768 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
771 addi r7, r7, 0x100 /* next exception vector */
775 mfmsr r3 /* now that the vectors have */
776 lis r7, MSR_IP@h /* relocated into low memory */
777 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
778 andc r3, r3, r7 /* (if it was on) */
779 SYNC /* Some chip revs need this... */
783 mtlr r4 /* restore link register */