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 * SPDX-License-Identifier: GPL-2.0+
9 /* U-Boot - Startup Code for PowerPC based Embedded Boards
12 * The processor starts at 0x00000100 and the code is executed
13 * from flash. The code is organized to be at an other address
14 * in memory, but as long we don't jump around before relocating,
15 * board_init lies at a quite high address and when the cpu has
16 * jumped there, everything is ok.
17 * This works because the cpu gives the FLASH (CS0) the whole
18 * address space at startup, and board_init lies as a echo of
19 * the flash somewhere up there in the memory map.
21 * board_init will change CS0 to be positioned at the correct
22 * address and (s)dram will be positioned at address 0
24 #include <asm-offsets.h>
29 #include <ppc_asm.tmpl>
32 #include <asm/cache.h>
34 #include <asm/u-boot.h>
36 /* We don't want the MMU yet.
39 #define MSR_KERNEL ( MSR_ME | MSR_RI ) /* Machine Check and Recoverable Interr. */
42 * Set up GOT: Global Offset Table
44 * Use r12 to access the GOT
47 GOT_ENTRY(_GOT2_TABLE_)
48 GOT_ENTRY(_FIXUP_TABLE_)
51 GOT_ENTRY(_start_of_vectors)
52 GOT_ENTRY(_end_of_vectors)
53 GOT_ENTRY(transfer_to_handler)
57 GOT_ENTRY(__bss_start)
61 * r3 - 1st arg to board_init(): IMMP pointer
62 * r4 - 2nd arg to board_init(): boot flag
65 .long 0x27051956 /* U-Boot Magic Number */
68 .ascii U_BOOT_VERSION_STRING, "\0"
73 lis r3, CONFIG_SYS_IMMR@h /* position IMMR */
76 /* Initialize machine status; enable machine check interrupt */
77 /*----------------------------------------------------------------------*/
78 li r3, MSR_KERNEL /* Set ME, RI flags */
80 mtspr SRR1, r3 /* Make SRR1 match MSR */
82 mfspr r3, ICR /* clear Interrupt Cause Register */
84 /* Initialize debug port registers */
85 /*----------------------------------------------------------------------*/
86 xor r0, r0, r0 /* Clear R0 */
87 mtspr LCTRL1, r0 /* Initialize debug port regs */
92 /* Reset the caches */
93 /*----------------------------------------------------------------------*/
95 mfspr r3, IC_CST /* Clear error bits */
98 lis r3, IDC_UNALL@h /* Unlock all */
102 lis r3, IDC_INVALL@h /* Invalidate all */
106 lis r3, IDC_DISABLE@h /* Disable data cache */
109 #if !defined(CONFIG_SYS_DELAYED_ICACHE)
110 /* On IP860 and PCU E,
111 * we cannot enable IC yet
113 lis r3, IDC_ENABLE@h /* Enable instruction cache */
117 /* invalidate all tlb's */
118 /*----------------------------------------------------------------------*/
124 * Calculate absolute address in FLASH and jump there
125 *----------------------------------------------------------------------*/
127 lis r3, CONFIG_SYS_MONITOR_BASE@h
128 ori r3, r3, CONFIG_SYS_MONITOR_BASE@l
129 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
135 /* initialize some SPRs that are hard to access from C */
136 /*----------------------------------------------------------------------*/
138 lis r3, CONFIG_SYS_IMMR@h /* pass IMMR as arg1 to C routine */
139 ori r1, r3, CONFIG_SYS_INIT_SP_OFFSET /* set up the stack in internal DPRAM */
140 /* Note: R0 is still 0 here */
141 stwu r0, -4(r1) /* clear final stack frame so that */
142 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
145 * Disable serialized ifetch and show cycles
146 * (i.e. set processor to normal mode).
147 * This is also a silicon bug workaround, see errata
153 /* Set up debug mode entry */
155 lis r2, CONFIG_SYS_DER@h
156 ori r2, r2, CONFIG_SYS_DER@l
159 /* let the C-code set up the rest */
161 /* Be careful to keep code relocatable ! */
162 /*----------------------------------------------------------------------*/
164 GET_GOT /* initialize GOT access */
167 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) */
171 /* NOTREACHED - board_init_f() does not return */
174 .globl _start_of_vectors
178 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
180 /* Data Storage exception. "Never" generated on the 860. */
181 STD_EXCEPTION(0x300, DataStorage, UnknownException)
183 /* Instruction Storage exception. "Never" generated on the 860. */
184 STD_EXCEPTION(0x400, InstStorage, UnknownException)
186 /* External Interrupt exception. */
187 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
189 /* Alignment exception. */
192 EXCEPTION_PROLOG(SRR0, SRR1)
197 addi r3,r1,STACK_FRAME_OVERHEAD
198 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
200 /* Program check exception */
203 EXCEPTION_PROLOG(SRR0, SRR1)
204 addi r3,r1,STACK_FRAME_OVERHEAD
205 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
208 /* No FPU on MPC8xx. This exception is not supposed to happen.
210 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
212 /* I guess we could implement decrementer, and may have
213 * to someday for timekeeping.
215 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
216 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
217 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
218 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
219 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
221 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
222 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
224 /* On the MPC8xx, this is a software emulation interrupt. It occurs
225 * for all unimplemented and illegal instructions.
227 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
229 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
230 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
231 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
232 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
234 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
235 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
236 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
237 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
238 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
239 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
240 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
242 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
243 STD_EXCEPTION(0x1d00, InstructionBreakpoint, DebugException)
244 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
245 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
248 .globl _end_of_vectors
255 * This code finishes saving the registers to the exception frame
256 * and jumps to the appropriate handler for the exception.
257 * Register r21 is pointer into trap frame, r1 has new stack pointer.
259 .globl transfer_to_handler
270 andi. r24,r23,0x3f00 /* get vector offset */
274 mtspr SPRG2,r22 /* r1 is now kernel sp */
275 lwz r24,0(r23) /* virtual address of handler */
276 lwz r23,4(r23) /* where to go when done */
281 rfi /* jump to handler, enable MMU */
284 mfmsr r28 /* Disable interrupts */
288 SYNC /* Some chip revs need this... */
303 lwz r2,_NIP(r1) /* Restore environment */
324 .globl icache_disable
327 lis r3, IDC_DISABLE@h
334 srwi r3, r3, 31 /* >>31 => select bit 0 */
343 lis r3, 0x0400 /* Set cache mode with MMU off */
357 .globl dcache_disable
360 lis r3, IDC_DISABLE@h
369 srwi r3, r3, 31 /* >>31 => select bit 0 */
379 * unsigned int get_immr (unsigned int mask)
381 * return (mask ? (IMMR & mask) : IMMR);
385 mr r4,r3 /* save mask */
386 mfspr r3, IMMR /* IMMR */
387 cmpwi 0,r4,0 /* mask != 0 ? */
389 and r3,r3,r4 /* IMMR & mask */
430 /*------------------------------------------------------------------------------*/
433 * void relocate_code (addr_sp, gd, addr_moni)
435 * This "function" does not return, instead it continues in RAM
436 * after relocating the monitor code.
440 * r5 = length in bytes
445 mr r1, r3 /* Set new stack pointer */
446 mr r9, r4 /* Save copy of Global Data pointer */
447 mr r10, r5 /* Save copy of Destination Address */
450 mr r3, r5 /* Destination Address */
451 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
452 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
453 lwz r5, GOT(__init_end)
455 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
460 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
466 /* First our own GOT */
468 /* then the one used by the C code */
478 beq cr1,4f /* In place copy is not necessary */
479 beq 7f /* Protect against 0 count */
498 * Now flush the cache: note that we must start from a cache aligned
499 * address. Otherwise we might miss one cache line.
503 beq 7f /* Always flush prefetch queue in any case */
511 sync /* Wait for all dcbst to complete on bus */
517 7: sync /* Wait for all icbi to complete on bus */
521 * We are done. Do not return, instead branch to second part of board
522 * initialization, now running from RAM.
525 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
532 * Relocation Function, r12 point to got2+0x8000
534 * Adjust got2 pointers, no need to check for 0, this code
535 * already puts a few entries in the table.
537 li r0,__got2_entries@sectoff@l
538 la r3,GOT(_GOT2_TABLE_)
539 lwz r11,GOT(_GOT2_TABLE_)
551 * Now adjust the fixups and the pointers to the fixups
552 * in case we need to move ourselves again.
554 li r0,__fixup_entries@sectoff@l
555 lwz r3,GOT(_FIXUP_TABLE_)
571 * Now clear BSS segment
573 lwz r3,GOT(__bss_start)
574 lwz r4,GOT(__bss_end)
587 mr r3, r9 /* Global Data pointer */
588 mr r4, r10 /* Destination Address */
592 * Copy exception vector code to low memory
595 * r7: source address, r8: end address, r9: target address
599 mflr r4 /* save link register */
602 lwz r8, GOT(_end_of_vectors)
604 li r9, 0x100 /* reset vector always at 0x100 */
607 bgelr /* return if r7>=r8 - just in case */
617 * relocate `hdlr' and `int_return' entries
619 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
620 li r8, Alignment - _start + EXC_OFF_SYS_RESET
623 addi r7, r7, 0x100 /* next exception vector */
627 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
630 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
633 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
634 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
637 addi r7, r7, 0x100 /* next exception vector */
641 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
642 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
645 addi r7, r7, 0x100 /* next exception vector */
649 mtlr r4 /* restore link register */