1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 1998 Dan Malek <dmalek@jlc.net>
4 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
5 * Copyright (C) 2000,2001,2002 Wolfgang Denk <wd@denx.de>
8 /* U-Boot - Startup Code for PowerPC based Embedded Boards
11 * The processor starts at 0x00000100 and the code is executed
12 * from flash. The code is organized to be at an other address
13 * in memory, but as long we don't jump around before relocating,
14 * board_init lies at a quite high address and when the cpu has
15 * jumped there, everything is ok.
16 * This works because the cpu gives the FLASH (CS0) the whole
17 * address space at startup, and board_init lies as a echo of
18 * the flash somewhere up there in the memory map.
20 * board_init will change CS0 to be positioned at the correct
21 * address and (s)dram will be positioned at address 0
23 #include <asm-offsets.h>
28 #include <ppc_asm.tmpl>
31 #include <asm/cache.h>
33 #include <asm/u-boot.h>
35 /* We don't want the MMU yet.
38 #define MSR_KERNEL ( MSR_ME | MSR_RI ) /* Machine Check and Recoverable Interr. */
41 * Set up GOT: Global Offset Table
43 * Use r12 to access the GOT
46 GOT_ENTRY(_GOT2_TABLE_)
47 GOT_ENTRY(_FIXUP_TABLE_)
50 GOT_ENTRY(_start_of_vectors)
51 GOT_ENTRY(_end_of_vectors)
52 GOT_ENTRY(transfer_to_handler)
56 GOT_ENTRY(__bss_start)
60 * r3 - 1st arg to board_init(): IMMP pointer
61 * r4 - 2nd arg to board_init(): boot flag
64 .long 0x27051956 /* U-Boot Magic Number */
67 .ascii U_BOOT_VERSION_STRING, "\0"
72 lis r3, CONFIG_SYS_IMMR@h /* position IMMR */
75 /* Initialize machine status; enable machine check interrupt */
76 /*----------------------------------------------------------------------*/
77 li r3, MSR_KERNEL /* Set ME, RI flags */
79 mtspr SRR1, r3 /* Make SRR1 match MSR */
81 mfspr r3, ICR /* clear Interrupt Cause Register */
83 /* Initialize debug port registers */
84 /*----------------------------------------------------------------------*/
85 xor r0, r0, r0 /* Clear R0 */
86 mtspr LCTRL1, r0 /* Initialize debug port regs */
91 /* Reset the caches */
92 /*----------------------------------------------------------------------*/
94 mfspr r3, IC_CST /* Clear error bits */
97 lis r3, IDC_UNALL@h /* Unlock all */
101 lis r3, IDC_INVALL@h /* Invalidate all */
105 lis r3, IDC_DISABLE@h /* Disable data cache */
108 lis r3, IDC_ENABLE@h /* Enable instruction cache */
111 /* invalidate all tlb's */
112 /*----------------------------------------------------------------------*/
118 * Calculate absolute address in FLASH and jump there
119 *----------------------------------------------------------------------*/
121 lis r3, CONFIG_SYS_MONITOR_BASE@h
122 ori r3, r3, CONFIG_SYS_MONITOR_BASE@l
123 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
129 /* initialize some SPRs that are hard to access from C */
130 /*----------------------------------------------------------------------*/
133 * Disable serialized ifetch and show cycles
134 * (i.e. set processor to normal mode).
135 * This is also a silicon bug workaround, see errata
141 /* Set up debug mode entry */
143 lis r2, CONFIG_SYS_DER@h
144 ori r2, r2, CONFIG_SYS_DER@l
147 /* set up the stack on top of internal DPRAM */
148 lis r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@h
149 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE)@l
154 bl board_init_f_alloc_reserve
157 /* Zeroise the CPM dpram */
158 lis r4, CONFIG_SYS_IMMR@h
159 ori r4, r4, (0x2000 - 4)
166 bl board_init_f_init_reserve
168 /* let the C-code set up the rest */
170 /* Be careful to keep code relocatable ! */
171 /*----------------------------------------------------------------------*/
173 GET_GOT /* initialize GOT access */
175 lis r3, CONFIG_SYS_IMMR@h
176 bl cpu_init_f /* run low-level CPU init code (from Flash) */
178 bl board_init_f /* run 1st part of board init code (from Flash) */
180 /* NOTREACHED - board_init_f() does not return */
183 .globl _start_of_vectors
187 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
189 /* Data Storage exception. "Never" generated on the 860. */
190 STD_EXCEPTION(0x300, DataStorage, UnknownException)
192 /* Instruction Storage exception. "Never" generated on the 860. */
193 STD_EXCEPTION(0x400, InstStorage, UnknownException)
195 /* External Interrupt exception. */
196 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
198 /* Alignment exception. */
201 EXCEPTION_PROLOG(SRR0, SRR1)
206 addi r3,r1,STACK_FRAME_OVERHEAD
207 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
209 /* Program check exception */
212 EXCEPTION_PROLOG(SRR0, SRR1)
213 addi r3,r1,STACK_FRAME_OVERHEAD
214 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
217 /* No FPU on MPC8xx. This exception is not supposed to happen.
219 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
221 /* I guess we could implement decrementer, and may have
222 * to someday for timekeeping.
224 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
225 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
226 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
227 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
228 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
230 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
231 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
233 /* On the MPC8xx, this is a software emulation interrupt. It occurs
234 * for all unimplemented and illegal instructions.
236 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
238 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
239 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
240 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
241 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
243 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
244 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
245 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
246 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
247 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
248 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
249 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
251 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
252 STD_EXCEPTION(0x1d00, InstructionBreakpoint, DebugException)
253 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
254 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
257 .globl _end_of_vectors
264 * This code finishes saving the registers to the exception frame
265 * and jumps to the appropriate handler for the exception.
266 * Register r21 is pointer into trap frame, r1 has new stack pointer.
268 .globl transfer_to_handler
279 andi. r24,r23,0x3f00 /* get vector offset */
283 mtspr SPRG2,r22 /* r1 is now kernel sp */
284 lwz r24,0(r23) /* virtual address of handler */
285 lwz r23,4(r23) /* where to go when done */
290 rfi /* jump to handler, enable MMU */
293 mfmsr r28 /* Disable interrupts */
297 SYNC /* Some chip revs need this... */
312 lwz r2,_NIP(r1) /* Restore environment */
322 /*------------------------------------------------------------------------------*/
325 * void relocate_code(addr_sp, gd, addr_moni)
327 * This "function" does not return, instead it continues in RAM
328 * after relocating the monitor code.
332 * r5 = length in bytes
337 mr r1, r3 /* Set new stack pointer */
338 mr r9, r4 /* Save copy of Global Data pointer */
339 mr r10, r5 /* Save copy of Destination Address */
342 mr r3, r5 /* Destination Address */
343 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
344 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
345 lwz r5, GOT(__init_end)
347 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
352 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
358 /* First our own GOT */
360 /* then the one used by the C code */
370 beq cr1,4f /* In place copy is not necessary */
371 beq 7f /* Protect against 0 count */
390 * Now flush the cache: note that we must start from a cache aligned
391 * address. Otherwise we might miss one cache line.
395 beq 7f /* Always flush prefetch queue in any case */
403 sync /* Wait for all dcbst to complete on bus */
409 7: sync /* Wait for all icbi to complete on bus */
413 * We are done. Do not return, instead branch to second part of board
414 * initialization, now running from RAM.
417 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
424 * Relocation Function, r12 point to got2+0x8000
426 * Adjust got2 pointers, no need to check for 0, this code
427 * already puts a few entries in the table.
429 li r0,__got2_entries@sectoff@l
430 la r3,GOT(_GOT2_TABLE_)
431 lwz r11,GOT(_GOT2_TABLE_)
443 * Now adjust the fixups and the pointers to the fixups
444 * in case we need to move ourselves again.
446 li r0,__fixup_entries@sectoff@l
447 lwz r3,GOT(_FIXUP_TABLE_)
463 * Now clear BSS segment
465 lwz r3,GOT(__bss_start)
466 lwz r4,GOT(__bss_end)
479 mr r3, r9 /* Global Data pointer */
480 mr r4, r10 /* Destination Address */
484 * Copy exception vector code to low memory
487 * r7: source address, r8: end address, r9: target address
491 mflr r4 /* save link register */
494 lwz r8, GOT(_end_of_vectors)
496 li r9, 0x100 /* reset vector always at 0x100 */
499 bgelr /* return if r7>=r8 - just in case */
509 * relocate `hdlr' and `int_return' entries
511 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
512 li r8, Alignment - _start + EXC_OFF_SYS_RESET
515 addi r7, r7, 0x100 /* next exception vector */
519 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
522 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
525 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
526 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
529 addi r7, r7, 0x100 /* next exception vector */
533 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
534 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
537 addi r7, r7, 0x100 /* next exception vector */
541 mtlr r4 /* restore link register */