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 * 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,
25 /* U-Boot - Startup Code for PowerPC based Embedded Boards
28 * The processor starts at 0x00000100 and the code is executed
29 * from flash. The code is organized to be at an other address
30 * in memory, but as long we don't jump around before relocating,
31 * board_init lies at a quite high address and when the cpu has
32 * jumped there, everything is ok.
33 * This works because the cpu gives the FLASH (CS0) the whole
34 * address space at startup, and board_init lies as a echo of
35 * the flash somewhere up there in the memory map.
37 * board_init will change CS0 to be positioned at the correct
38 * address and (s)dram will be positioned at address 0
42 #include <timestamp.h>
45 #define CONFIG_8xx 1 /* needed for Linux kernel header files */
46 #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
48 #include <ppc_asm.tmpl>
51 #include <asm/cache.h>
53 #include <asm/u-boot.h>
55 #ifndef CONFIG_IDENT_STRING
56 #define CONFIG_IDENT_STRING ""
59 /* We don't want the MMU yet.
62 #define MSR_KERNEL ( MSR_ME | MSR_RI ) /* Machine Check and Recoverable Interr. */
65 * Set up GOT: Global Offset Table
67 * Use r12 to access the GOT
70 GOT_ENTRY(_GOT2_TABLE_)
71 GOT_ENTRY(_FIXUP_TABLE_)
74 GOT_ENTRY(_start_of_vectors)
75 GOT_ENTRY(_end_of_vectors)
76 GOT_ENTRY(transfer_to_handler)
80 GOT_ENTRY(__bss_start)
84 * r3 - 1st arg to board_init(): IMMP pointer
85 * r4 - 2nd arg to board_init(): boot flag
88 .long 0x27051956 /* U-Boot Magic Number */
92 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
93 .ascii CONFIG_IDENT_STRING, "\0"
98 lis r3, CONFIG_SYS_IMMR@h /* position IMMR */
101 /* Initialize machine status; enable machine check interrupt */
102 /*----------------------------------------------------------------------*/
103 li r3, MSR_KERNEL /* Set ME, RI flags */
105 mtspr SRR1, r3 /* Make SRR1 match MSR */
107 mfspr r3, ICR /* clear Interrupt Cause Register */
109 /* Initialize debug port registers */
110 /*----------------------------------------------------------------------*/
111 xor r0, r0, r0 /* Clear R0 */
112 mtspr LCTRL1, r0 /* Initialize debug port regs */
117 /* Reset the caches */
118 /*----------------------------------------------------------------------*/
120 mfspr r3, IC_CST /* Clear error bits */
123 lis r3, IDC_UNALL@h /* Unlock all */
127 lis r3, IDC_INVALL@h /* Invalidate all */
131 lis r3, IDC_DISABLE@h /* Disable data cache */
134 #if !defined(CONFIG_SYS_DELAYED_ICACHE)
135 /* On IP860 and PCU E,
136 * we cannot enable IC yet
138 lis r3, IDC_ENABLE@h /* Enable instruction cache */
142 /* invalidate all tlb's */
143 /*----------------------------------------------------------------------*/
149 * Calculate absolute address in FLASH and jump there
150 *----------------------------------------------------------------------*/
152 lis r3, CONFIG_SYS_MONITOR_BASE@h
153 ori r3, r3, CONFIG_SYS_MONITOR_BASE@l
154 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
160 /* initialize some SPRs that are hard to access from C */
161 /*----------------------------------------------------------------------*/
163 lis r3, CONFIG_SYS_IMMR@h /* pass IMMR as arg1 to C routine */
164 ori r1, r3, CONFIG_SYS_INIT_SP_OFFSET /* set up the stack in internal DPRAM */
165 /* Note: R0 is still 0 here */
166 stwu r0, -4(r1) /* clear final stack frame so that */
167 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
170 * Disable serialized ifetch and show cycles
171 * (i.e. set processor to normal mode).
172 * This is also a silicon bug workaround, see errata
178 /* Set up debug mode entry */
180 lis r2, CONFIG_SYS_DER@h
181 ori r2, r2, CONFIG_SYS_DER@l
184 /* let the C-code set up the rest */
186 /* Be careful to keep code relocatable ! */
187 /*----------------------------------------------------------------------*/
189 GET_GOT /* initialize GOT access */
192 bl cpu_init_f /* run low-level CPU init code (from Flash) */
194 bl board_init_f /* run 1st part of board init code (from Flash) */
196 /* NOTREACHED - board_init_f() does not return */
199 .globl _start_of_vectors
203 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
205 /* Data Storage exception. "Never" generated on the 860. */
206 STD_EXCEPTION(0x300, DataStorage, UnknownException)
208 /* Instruction Storage exception. "Never" generated on the 860. */
209 STD_EXCEPTION(0x400, InstStorage, UnknownException)
211 /* External Interrupt exception. */
212 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
214 /* Alignment exception. */
217 EXCEPTION_PROLOG(SRR0, SRR1)
222 addi r3,r1,STACK_FRAME_OVERHEAD
223 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
225 /* Program check exception */
228 EXCEPTION_PROLOG(SRR0, SRR1)
229 addi r3,r1,STACK_FRAME_OVERHEAD
230 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
233 /* No FPU on MPC8xx. This exception is not supposed to happen.
235 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
237 /* I guess we could implement decrementer, and may have
238 * to someday for timekeeping.
240 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
241 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
242 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
243 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
244 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
246 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
247 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
249 /* On the MPC8xx, this is a software emulation interrupt. It occurs
250 * for all unimplemented and illegal instructions.
252 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
254 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
255 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
256 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
257 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
259 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
260 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
261 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
262 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
263 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
264 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
265 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
267 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
268 STD_EXCEPTION(0x1d00, InstructionBreakpoint, DebugException)
269 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
270 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
273 .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 mtspr SPRG2,r22 /* r1 is now kernel sp */
300 lwz r24,0(r23) /* virtual address of handler */
301 lwz r23,4(r23) /* where to go when done */
306 rfi /* jump to handler, enable MMU */
309 mfmsr r28 /* Disable interrupts */
313 SYNC /* Some chip revs need this... */
328 lwz r2,_NIP(r1) /* Restore environment */
349 .globl icache_disable
352 lis r3, IDC_DISABLE@h
359 srwi r3, r3, 31 /* >>31 => select bit 0 */
368 lis r3, 0x0400 /* Set cache mode with MMU off */
382 .globl dcache_disable
385 lis r3, IDC_DISABLE@h
394 srwi r3, r3, 31 /* >>31 => select bit 0 */
404 * unsigned int get_immr (unsigned int mask)
406 * return (mask ? (IMMR & mask) : IMMR);
410 mr r4,r3 /* save mask */
411 mfspr r3, IMMR /* IMMR */
412 cmpwi 0,r4,0 /* mask != 0 ? */
414 and r3,r3,r4 /* IMMR & mask */
455 /*------------------------------------------------------------------------------*/
458 * void relocate_code (addr_sp, gd, addr_moni)
460 * This "function" does not return, instead it continues in RAM
461 * after relocating the monitor code.
465 * r5 = length in bytes
470 mr r1, r3 /* Set new stack pointer */
471 mr r9, r4 /* Save copy of Global Data pointer */
472 mr r10, r5 /* Save copy of Destination Address */
475 mr r3, r5 /* Destination Address */
476 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
477 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
478 lwz r5, GOT(__init_end)
480 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
485 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
491 /* First our own GOT */
493 /* then the one used by the C code */
503 beq cr1,4f /* In place copy is not necessary */
504 beq 7f /* Protect against 0 count */
523 * Now flush the cache: note that we must start from a cache aligned
524 * address. Otherwise we might miss one cache line.
528 beq 7f /* Always flush prefetch queue in any case */
536 sync /* Wait for all dcbst to complete on bus */
542 7: sync /* Wait for all icbi to complete on bus */
546 * We are done. Do not return, instead branch to second part of board
547 * initialization, now running from RAM.
550 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
557 * Relocation Function, r12 point to got2+0x8000
559 * Adjust got2 pointers, no need to check for 0, this code
560 * already puts a few entries in the table.
562 li r0,__got2_entries@sectoff@l
563 la r3,GOT(_GOT2_TABLE_)
564 lwz r11,GOT(_GOT2_TABLE_)
576 * Now adjust the fixups and the pointers to the fixups
577 * in case we need to move ourselves again.
579 li r0,__fixup_entries@sectoff@l
580 lwz r3,GOT(_FIXUP_TABLE_)
594 * Now clear BSS segment
596 lwz r3,GOT(__bss_start)
610 mr r3, r9 /* Global Data pointer */
611 mr r4, r10 /* Destination Address */
615 * Copy exception vector code to low memory
618 * r7: source address, r8: end address, r9: target address
622 mflr r4 /* save link register */
625 lwz r8, GOT(_end_of_vectors)
627 li r9, 0x100 /* reset vector always at 0x100 */
630 bgelr /* return if r7>=r8 - just in case */
640 * relocate `hdlr' and `int_return' entries
642 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
643 li r8, Alignment - _start + EXC_OFF_SYS_RESET
646 addi r7, r7, 0x100 /* next exception vector */
650 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
653 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
656 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
657 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
660 addi r7, r7, 0x100 /* next exception vector */
664 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
665 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
668 addi r7, r7, 0x100 /* next exception vector */
672 mtlr r4 /* restore link register */