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>
5 * Copyright (C) 2001 Josh Huber <huber@mclx.com>
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 /* U-Boot - Startup Code for PowerPC based Embedded Boards
29 * The processor starts at 0xfff00100 and the code is executed
30 * from flash. The code is organized to be at an other address
31 * in memory, but as long we don't jump around before relocating.
32 * board_init lies at a quite high address and when the cpu has
33 * jumped there, everything is ok.
39 #include <ppc_asm.tmpl>
42 #include <asm/cache.h>
45 #if !defined(CONFIG_DB64360) && \
46 !defined(CONFIG_DB64460) && \
47 !defined(CONFIG_CPCI750) && \
49 #include <galileo/gt64260R.h>
52 #ifndef CONFIG_IDENT_STRING
53 #define CONFIG_IDENT_STRING ""
56 /* We don't want the MMU yet.
59 /* Machine Check and Recoverable Interr. */
60 #define MSR_KERNEL ( MSR_ME | MSR_RI )
63 * Set up GOT: Global Offset Table
65 * Use r14 to access the GOT
68 GOT_ENTRY(_GOT2_TABLE_)
69 GOT_ENTRY(_FIXUP_TABLE_)
72 GOT_ENTRY(_start_of_vectors)
73 GOT_ENTRY(_end_of_vectors)
74 GOT_ENTRY(transfer_to_handler)
78 GOT_ENTRY(__bss_start)
82 * r3 - 1st arg to board_init(): IMMP pointer
83 * r4 - 2nd arg to board_init(): boot flag
86 .long 0x27051956 /* U-Boot Magic Number */
90 .ascii " (", __DATE__, " - ", __TIME__, ")"
91 .ascii CONFIG_IDENT_STRING, "\0"
96 li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
100 . = EXC_OFF_SYS_RESET + 0x10
104 li r21, BOOTFLAG_WARM /* Software reboot */
108 /* the boot code is located below the exception table */
110 .globl _start_of_vectors
114 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
116 /* Data Storage exception. "Never" generated on the 860. */
117 STD_EXCEPTION(0x300, DataStorage, UnknownException)
119 /* Instruction Storage exception. "Never" generated on the 860. */
120 STD_EXCEPTION(0x400, InstStorage, UnknownException)
122 /* External Interrupt exception. */
123 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
125 /* Alignment exception. */
128 EXCEPTION_PROLOG(SRR0, SRR1)
133 addi r3,r1,STACK_FRAME_OVERHEAD
135 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
136 lwz r6,GOT(transfer_to_handler)
140 .long AlignmentException - _start + EXC_OFF_SYS_RESET
141 .long int_return - _start + EXC_OFF_SYS_RESET
143 /* Program check exception */
146 EXCEPTION_PROLOG(SRR0, SRR1)
147 addi r3,r1,STACK_FRAME_OVERHEAD
149 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
150 lwz r6,GOT(transfer_to_handler)
154 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
155 .long int_return - _start + EXC_OFF_SYS_RESET
157 /* No FPU on MPC8xx. This exception is not supposed to happen.
159 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
161 /* I guess we could implement decrementer, and may have
162 * to someday for timekeeping.
164 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
165 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
166 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
167 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
168 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
170 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
171 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
174 * On the MPC8xx, this is a software emulation interrupt. It
175 * occurs for all unimplemented and illegal instructions.
177 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
179 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
180 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
181 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
182 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
184 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
185 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
186 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
187 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
188 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
189 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
190 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
192 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
193 STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
194 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
195 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
197 .globl _end_of_vectors
204 /* disable everything */
213 /* init the L2 cache */
214 addis r3, r0, L2_INIT@h
215 ori r3, r3, L2_INIT@l
219 #if defined(CONFIG_ALTIVEC) && defined(CONFIG_74xx)
222 * dssall instruction, gas doesn't have it yet
223 * ...for altivec, data stream stop all this probably
224 * isn't needed unless we warm (software) reboot U-Boot
229 /* invalidate the L2 cache */
230 bl l2cache_invalidate
233 #ifdef CFG_BOARD_ASM_INIT
239 * Calculate absolute address in FLASH and jump there
240 *------------------------------------------------------*/
241 lis r3, CFG_MONITOR_BASE@h
242 ori r3, r3, CFG_MONITOR_BASE@l
243 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
248 /* let the C-code set up the rest */
250 /* Be careful to keep code relocatable ! */
251 /*------------------------------------------------------*/
253 /* perform low-level init */
254 /* sdram init, galileo init, etc */
255 /* r3: NHR bit from HID0 */
262 * Cache must be enabled here for stack-in-cache trick.
263 * This means we need to enable the BATS.
265 * 1) for the EVB, original gt regs need to be mapped
266 * 2) need to have an IBAT for the 0xf region,
267 * we are running there!
268 * Cache should be turned on after BATs, since by default
269 * everything is write-through.
270 * The init-mem BAT can be reused after reloc. The old
271 * gt-regs BAT can be reused after board_init_f calls
272 * board_early_init_f (EVB only).
274 #if !defined(CONFIG_BAB7xx) && !defined(CONFIG_ELPPC) && !defined(CONFIG_P3Mx)
275 /* enable address translation */
279 /* enable and invalidate the data cache */
283 #ifdef CFG_INIT_RAM_LOCK
288 /* set up the stack pointer in our newly created
290 lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
291 ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
293 li r0, 0 /* Make room for stack frame header and */
294 stwu r0, -4(r1) /* clear final stack frame so that */
295 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
297 GET_GOT /* initialize GOT access */
299 /* run low-level CPU init code (from Flash) */
306 /* run 1st part of board init code (from Flash) */
312 .globl invalidate_bats
314 /* invalidate BATs */
319 #ifdef CONFIG_HIGH_BATS
330 #ifdef CONFIG_HIGH_BATS
340 /* setup_bats - set them up to some initial state */
346 addis r4, r0, CFG_IBAT0L@h
347 ori r4, r4, CFG_IBAT0L@l
348 addis r3, r0, CFG_IBAT0U@h
349 ori r3, r3, CFG_IBAT0U@l
355 addis r4, r0, CFG_DBAT0L@h
356 ori r4, r4, CFG_DBAT0L@l
357 addis r3, r0, CFG_DBAT0U@h
358 ori r3, r3, CFG_DBAT0U@l
364 addis r4, r0, CFG_IBAT1L@h
365 ori r4, r4, CFG_IBAT1L@l
366 addis r3, r0, CFG_IBAT1U@h
367 ori r3, r3, CFG_IBAT1U@l
373 addis r4, r0, CFG_DBAT1L@h
374 ori r4, r4, CFG_DBAT1L@l
375 addis r3, r0, CFG_DBAT1U@h
376 ori r3, r3, CFG_DBAT1U@l
382 addis r4, r0, CFG_IBAT2L@h
383 ori r4, r4, CFG_IBAT2L@l
384 addis r3, r0, CFG_IBAT2U@h
385 ori r3, r3, CFG_IBAT2U@l
391 addis r4, r0, CFG_DBAT2L@h
392 ori r4, r4, CFG_DBAT2L@l
393 addis r3, r0, CFG_DBAT2U@h
394 ori r3, r3, CFG_DBAT2U@l
400 addis r4, r0, CFG_IBAT3L@h
401 ori r4, r4, CFG_IBAT3L@l
402 addis r3, r0, CFG_IBAT3U@h
403 ori r3, r3, CFG_IBAT3U@l
409 addis r4, r0, CFG_DBAT3L@h
410 ori r4, r4, CFG_DBAT3L@l
411 addis r3, r0, CFG_DBAT3U@h
412 ori r3, r3, CFG_DBAT3U@l
417 #ifdef CONFIG_HIGH_BATS
419 addis r4, r0, CFG_IBAT4L@h
420 ori r4, r4, CFG_IBAT4L@l
421 addis r3, r0, CFG_IBAT4U@h
422 ori r3, r3, CFG_IBAT4U@l
428 addis r4, r0, CFG_DBAT4L@h
429 ori r4, r4, CFG_DBAT4L@l
430 addis r3, r0, CFG_DBAT4U@h
431 ori r3, r3, CFG_DBAT4U@l
437 addis r4, r0, CFG_IBAT5L@h
438 ori r4, r4, CFG_IBAT5L@l
439 addis r3, r0, CFG_IBAT5U@h
440 ori r3, r3, CFG_IBAT5U@l
446 addis r4, r0, CFG_DBAT5L@h
447 ori r4, r4, CFG_DBAT5L@l
448 addis r3, r0, CFG_DBAT5U@h
449 ori r3, r3, CFG_DBAT5U@l
455 addis r4, r0, CFG_IBAT6L@h
456 ori r4, r4, CFG_IBAT6L@l
457 addis r3, r0, CFG_IBAT6U@h
458 ori r3, r3, CFG_IBAT6U@l
464 addis r4, r0, CFG_DBAT6L@h
465 ori r4, r4, CFG_DBAT6L@l
466 addis r3, r0, CFG_DBAT6U@h
467 ori r3, r3, CFG_DBAT6U@l
473 addis r4, r0, CFG_IBAT7L@h
474 ori r4, r4, CFG_IBAT7L@l
475 addis r3, r0, CFG_IBAT7U@h
476 ori r3, r3, CFG_IBAT7U@l
482 addis r4, r0, CFG_DBAT7L@h
483 ori r4, r4, CFG_DBAT7L@l
484 addis r3, r0, CFG_DBAT7U@h
485 ori r3, r3, CFG_DBAT7U@l
491 /* bats are done, now invalidate the TLBs */
494 addis r5, 0, 0x4 /* upper bound of 0x00040000 for 7400/750 */
507 .globl enable_addr_trans
509 /* enable address translation */
511 ori r5, r5, (MSR_IR | MSR_DR)
516 .globl disable_addr_trans
518 /* disable address translation */
521 andi. r0, r3, (MSR_IR | MSR_DR)
529 * This code finishes saving the registers to the exception frame
530 * and jumps to the appropriate handler for the exception.
531 * Register r21 is pointer into trap frame, r1 has new stack pointer.
533 .globl transfer_to_handler
544 andi. r24,r23,0x3f00 /* get vector offset */
548 mtspr SPRG2,r22 /* r1 is now kernel sp */
549 lwz r24,0(r23) /* virtual address of handler */
550 lwz r23,4(r23) /* where to go when done */
555 rfi /* jump to handler, enable MMU */
558 mfmsr r28 /* Disable interrupts */
562 SYNC /* Some chip revs need this... */
577 lwz r2,_NIP(r1) /* Restore environment */
596 /*-----------------------------------------------------------------------*/
598 * void relocate_code (addr_sp, gd, addr_moni)
600 * This "function" does not return, instead it continues in RAM
601 * after relocating the monitor code.
605 * r5 = length in bytes
610 mr r1, r3 /* Set new stack pointer */
611 mr r9, r4 /* Save copy of Global Data pointer */
612 mr r10, r5 /* Save copy of Destination Address */
614 mr r3, r5 /* Destination Address */
615 lis r4, CFG_MONITOR_BASE@h /* Source Address */
616 ori r4, r4, CFG_MONITOR_BASE@l
617 lwz r5, GOT(__init_end)
619 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
624 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
630 /* First our own GOT */
632 /* then the one used by the C code */
639 bl board_relocate_rom
641 mr r3, r10 /* Destination Address */
642 lis r4, CFG_MONITOR_BASE@h /* Source Address */
643 ori r4, r4, CFG_MONITOR_BASE@l
644 lwz r5, GOT(__init_end)
646 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
651 beq cr1,4f /* In place copy is not necessary */
652 beq 7f /* Protect against 0 count */
671 * Now flush the cache: note that we must start from a cache aligned
672 * address. Otherwise we might miss one cache line.
676 beq 7f /* Always flush prefetch queue in any case */
684 sync /* Wait for all dcbst to complete on bus */
690 7: sync /* Wait for all icbi to complete on bus */
694 * We are done. Do not return, instead branch to second part of board
695 * initialization, now running from RAM.
697 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
706 * Relocation Function, r14 point to got2+0x8000
708 * Adjust got2 pointers, no need to check for 0, this code
709 * already puts a few entries in the table.
711 li r0,__got2_entries@sectoff@l
712 la r3,GOT(_GOT2_TABLE_)
713 lwz r11,GOT(_GOT2_TABLE_)
723 * Now adjust the fixups and the pointers to the fixups
724 * in case we need to move ourselves again.
726 2: li r0,__fixup_entries@sectoff@l
727 lwz r3,GOT(_FIXUP_TABLE_)
741 * Now clear BSS segment
743 lwz r3,GOT(__bss_start)
756 mr r3, r10 /* Destination Address */
757 #if defined(CONFIG_AMIGAONEG3SE) || \
758 defined(CONFIG_DB64360) || \
759 defined(CONFIG_DB64460) || \
760 defined(CONFIG_CPCI750) || \
761 defined(CONFIG_PPMC7XX) || \
763 mr r4, r9 /* Use RAM copy of the global data */
767 /* not reached - end relocate_code */
768 /*-----------------------------------------------------------------------*/
771 * Copy exception vector code to low memory
774 * r7: source address, r8: end address, r9: target address
779 lwz r8, GOT(_end_of_vectors)
781 li r9, 0x100 /* reset vector always at 0x100 */
784 bgelr /* return if r7>=r8 - just in case */
786 mflr r4 /* save link register */
796 * relocate `hdlr' and `int_return' entries
798 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
799 li r8, Alignment - _start + EXC_OFF_SYS_RESET
802 addi r7, r7, 0x100 /* next exception vector */
806 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
809 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
812 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
813 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
816 addi r7, r7, 0x100 /* next exception vector */
820 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
821 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
824 addi r7, r7, 0x100 /* next exception vector */
828 /* enable execptions from RAM vectors */
834 mtlr r4 /* restore link register */
838 * Function: relocate entries for one exception vector
841 lwz r0, 0(r7) /* hdlr ... */
842 add r0, r0, r3 /* ... += dest_addr */
845 lwz r0, 4(r7) /* int_return ... */
846 add r0, r0, r3 /* ... += dest_addr */
854 #ifdef CFG_INIT_RAM_LOCK
856 /* Allocate Initial RAM in data cache.
858 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
859 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
860 li r2, ((CFG_INIT_RAM_END & ~31) + \
861 (CFG_INIT_RAM_ADDR & 31) + 31) / 32
868 /* Lock the data cache */
876 .globl unlock_ram_in_cache
878 /* invalidate the INIT_RAM section */
879 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
880 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
881 li r2, ((CFG_INIT_RAM_END & ~31) + \
882 (CFG_INIT_RAM_ADDR & 31) + 31) / 32
887 sync /* Wait for all icbi to complete on bus */
890 /* Unlock the data cache and invalidate it */