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.
37 #include <timestamp.h>
40 #include <ppc_asm.tmpl>
43 #include <asm/cache.h>
46 #if !defined(CONFIG_DB64360) && \
47 !defined(CONFIG_DB64460) && \
48 !defined(CONFIG_CPCI750) && \
50 #include <galileo/gt64260R.h>
53 #ifndef CONFIG_IDENT_STRING
54 #define CONFIG_IDENT_STRING ""
57 /* We don't want the MMU yet.
60 /* Machine Check and Recoverable Interr. */
61 #define MSR_KERNEL ( MSR_ME | MSR_RI )
64 * Set up GOT: Global Offset Table
66 * Use r14 to access the GOT
69 GOT_ENTRY(_GOT2_TABLE_)
70 GOT_ENTRY(_FIXUP_TABLE_)
73 GOT_ENTRY(_start_of_vectors)
74 GOT_ENTRY(_end_of_vectors)
75 GOT_ENTRY(transfer_to_handler)
79 GOT_ENTRY(__bss_start)
83 * r3 - 1st arg to board_init(): IMMP pointer
84 * r4 - 2nd arg to board_init(): boot flag
87 .long 0x27051956 /* U-Boot Magic Number */
91 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
92 .ascii CONFIG_IDENT_STRING, "\0"
97 li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
101 . = EXC_OFF_SYS_RESET + 0x10
105 li r21, BOOTFLAG_WARM /* Software reboot */
109 /* the boot code is located below the exception table */
111 .globl _start_of_vectors
115 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
117 /* Data Storage exception. "Never" generated on the 860. */
118 STD_EXCEPTION(0x300, DataStorage, UnknownException)
120 /* Instruction Storage exception. "Never" generated on the 860. */
121 STD_EXCEPTION(0x400, InstStorage, UnknownException)
123 /* External Interrupt exception. */
124 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
126 /* Alignment exception. */
129 EXCEPTION_PROLOG(SRR0, SRR1)
134 addi r3,r1,STACK_FRAME_OVERHEAD
136 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
137 lwz r6,GOT(transfer_to_handler)
141 .long AlignmentException - _start + EXC_OFF_SYS_RESET
142 .long int_return - _start + EXC_OFF_SYS_RESET
144 /* Program check exception */
147 EXCEPTION_PROLOG(SRR0, SRR1)
148 addi r3,r1,STACK_FRAME_OVERHEAD
150 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
151 lwz r6,GOT(transfer_to_handler)
155 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
156 .long int_return - _start + EXC_OFF_SYS_RESET
158 /* No FPU on MPC8xx. This exception is not supposed to happen.
160 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
162 /* I guess we could implement decrementer, and may have
163 * to someday for timekeeping.
165 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
166 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
167 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
168 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
169 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
171 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
172 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
175 * On the MPC8xx, this is a software emulation interrupt. It
176 * occurs for all unimplemented and illegal instructions.
178 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
180 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
181 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
182 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
183 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
185 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
186 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
187 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
188 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
189 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
190 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
191 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
193 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
194 STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
195 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
196 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
198 .globl _end_of_vectors
205 /* disable everything */
214 /* init the L2 cache */
215 addis r3, r0, L2_INIT@h
216 ori r3, r3, L2_INIT@l
220 #if defined(CONFIG_ALTIVEC) && defined(CONFIG_74xx)
223 * dssall instruction, gas doesn't have it yet
224 * ...for altivec, data stream stop all this probably
225 * isn't needed unless we warm (software) reboot U-Boot
230 /* invalidate the L2 cache */
231 bl l2cache_invalidate
234 #ifdef CONFIG_SYS_BOARD_ASM_INIT
240 * Calculate absolute address in FLASH and jump there
241 *------------------------------------------------------*/
242 lis r3, CONFIG_SYS_MONITOR_BASE@h
243 ori r3, r3, CONFIG_SYS_MONITOR_BASE@l
244 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
249 /* let the C-code set up the rest */
251 /* Be careful to keep code relocatable ! */
252 /*------------------------------------------------------*/
254 /* perform low-level init */
255 /* sdram init, galileo init, etc */
256 /* r3: NHR bit from HID0 */
263 * Cache must be enabled here for stack-in-cache trick.
264 * This means we need to enable the BATS.
266 * 1) for the EVB, original gt regs need to be mapped
267 * 2) need to have an IBAT for the 0xf region,
268 * we are running there!
269 * Cache should be turned on after BATs, since by default
270 * everything is write-through.
271 * The init-mem BAT can be reused after reloc. The old
272 * gt-regs BAT can be reused after board_init_f calls
273 * board_early_init_f (EVB only).
275 #if !defined(CONFIG_BAB7xx) && !defined(CONFIG_ELPPC) && !defined(CONFIG_P3Mx)
276 /* enable address translation */
280 /* enable and invalidate the data cache */
284 #ifdef CONFIG_SYS_INIT_RAM_LOCK
289 /* set up the stack pointer in our newly created
291 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
292 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
294 li r0, 0 /* Make room for stack frame header and */
295 stwu r0, -4(r1) /* clear final stack frame so that */
296 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
298 GET_GOT /* initialize GOT access */
300 /* run low-level CPU init code (from Flash) */
307 /* run 1st part of board init code (from Flash) */
313 .globl invalidate_bats
315 /* invalidate BATs */
320 #ifdef CONFIG_HIGH_BATS
331 #ifdef CONFIG_HIGH_BATS
341 /* setup_bats - set them up to some initial state */
347 addis r4, r0, CONFIG_SYS_IBAT0L@h
348 ori r4, r4, CONFIG_SYS_IBAT0L@l
349 addis r3, r0, CONFIG_SYS_IBAT0U@h
350 ori r3, r3, CONFIG_SYS_IBAT0U@l
356 addis r4, r0, CONFIG_SYS_DBAT0L@h
357 ori r4, r4, CONFIG_SYS_DBAT0L@l
358 addis r3, r0, CONFIG_SYS_DBAT0U@h
359 ori r3, r3, CONFIG_SYS_DBAT0U@l
365 addis r4, r0, CONFIG_SYS_IBAT1L@h
366 ori r4, r4, CONFIG_SYS_IBAT1L@l
367 addis r3, r0, CONFIG_SYS_IBAT1U@h
368 ori r3, r3, CONFIG_SYS_IBAT1U@l
374 addis r4, r0, CONFIG_SYS_DBAT1L@h
375 ori r4, r4, CONFIG_SYS_DBAT1L@l
376 addis r3, r0, CONFIG_SYS_DBAT1U@h
377 ori r3, r3, CONFIG_SYS_DBAT1U@l
383 addis r4, r0, CONFIG_SYS_IBAT2L@h
384 ori r4, r4, CONFIG_SYS_IBAT2L@l
385 addis r3, r0, CONFIG_SYS_IBAT2U@h
386 ori r3, r3, CONFIG_SYS_IBAT2U@l
392 addis r4, r0, CONFIG_SYS_DBAT2L@h
393 ori r4, r4, CONFIG_SYS_DBAT2L@l
394 addis r3, r0, CONFIG_SYS_DBAT2U@h
395 ori r3, r3, CONFIG_SYS_DBAT2U@l
401 addis r4, r0, CONFIG_SYS_IBAT3L@h
402 ori r4, r4, CONFIG_SYS_IBAT3L@l
403 addis r3, r0, CONFIG_SYS_IBAT3U@h
404 ori r3, r3, CONFIG_SYS_IBAT3U@l
410 addis r4, r0, CONFIG_SYS_DBAT3L@h
411 ori r4, r4, CONFIG_SYS_DBAT3L@l
412 addis r3, r0, CONFIG_SYS_DBAT3U@h
413 ori r3, r3, CONFIG_SYS_DBAT3U@l
418 #ifdef CONFIG_HIGH_BATS
420 addis r4, r0, CONFIG_SYS_IBAT4L@h
421 ori r4, r4, CONFIG_SYS_IBAT4L@l
422 addis r3, r0, CONFIG_SYS_IBAT4U@h
423 ori r3, r3, CONFIG_SYS_IBAT4U@l
429 addis r4, r0, CONFIG_SYS_DBAT4L@h
430 ori r4, r4, CONFIG_SYS_DBAT4L@l
431 addis r3, r0, CONFIG_SYS_DBAT4U@h
432 ori r3, r3, CONFIG_SYS_DBAT4U@l
438 addis r4, r0, CONFIG_SYS_IBAT5L@h
439 ori r4, r4, CONFIG_SYS_IBAT5L@l
440 addis r3, r0, CONFIG_SYS_IBAT5U@h
441 ori r3, r3, CONFIG_SYS_IBAT5U@l
447 addis r4, r0, CONFIG_SYS_DBAT5L@h
448 ori r4, r4, CONFIG_SYS_DBAT5L@l
449 addis r3, r0, CONFIG_SYS_DBAT5U@h
450 ori r3, r3, CONFIG_SYS_DBAT5U@l
456 addis r4, r0, CONFIG_SYS_IBAT6L@h
457 ori r4, r4, CONFIG_SYS_IBAT6L@l
458 addis r3, r0, CONFIG_SYS_IBAT6U@h
459 ori r3, r3, CONFIG_SYS_IBAT6U@l
465 addis r4, r0, CONFIG_SYS_DBAT6L@h
466 ori r4, r4, CONFIG_SYS_DBAT6L@l
467 addis r3, r0, CONFIG_SYS_DBAT6U@h
468 ori r3, r3, CONFIG_SYS_DBAT6U@l
474 addis r4, r0, CONFIG_SYS_IBAT7L@h
475 ori r4, r4, CONFIG_SYS_IBAT7L@l
476 addis r3, r0, CONFIG_SYS_IBAT7U@h
477 ori r3, r3, CONFIG_SYS_IBAT7U@l
483 addis r4, r0, CONFIG_SYS_DBAT7L@h
484 ori r4, r4, CONFIG_SYS_DBAT7L@l
485 addis r3, r0, CONFIG_SYS_DBAT7U@h
486 ori r3, r3, CONFIG_SYS_DBAT7U@l
492 /* bats are done, now invalidate the TLBs */
495 addis r5, 0, 0x4 /* upper bound of 0x00040000 for 7400/750 */
508 .globl enable_addr_trans
510 /* enable address translation */
512 ori r5, r5, (MSR_IR | MSR_DR)
517 .globl disable_addr_trans
519 /* disable address translation */
522 andi. r0, r3, (MSR_IR | MSR_DR)
530 * This code finishes saving the registers to the exception frame
531 * and jumps to the appropriate handler for the exception.
532 * Register r21 is pointer into trap frame, r1 has new stack pointer.
534 .globl transfer_to_handler
545 andi. r24,r23,0x3f00 /* get vector offset */
549 mtspr SPRG2,r22 /* r1 is now kernel sp */
550 lwz r24,0(r23) /* virtual address of handler */
551 lwz r23,4(r23) /* where to go when done */
556 rfi /* jump to handler, enable MMU */
559 mfmsr r28 /* Disable interrupts */
563 SYNC /* Some chip revs need this... */
578 lwz r2,_NIP(r1) /* Restore environment */
597 /*-----------------------------------------------------------------------*/
599 * void relocate_code (addr_sp, gd, addr_moni)
601 * This "function" does not return, instead it continues in RAM
602 * after relocating the monitor code.
606 * r5 = length in bytes
611 mr r1, r3 /* Set new stack pointer */
612 mr r9, r4 /* Save copy of Global Data pointer */
613 mr r10, r5 /* Save copy of Destination Address */
615 mr r3, r5 /* Destination Address */
616 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
617 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
618 lwz r5, GOT(__init_end)
620 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
625 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
631 /* First our own GOT */
633 /* then the one used by the C code */
640 bl board_relocate_rom
642 mr r3, r10 /* Destination Address */
643 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
644 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
645 lwz r5, GOT(__init_end)
647 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
652 beq cr1,4f /* In place copy is not necessary */
653 beq 7f /* Protect against 0 count */
672 * Now flush the cache: note that we must start from a cache aligned
673 * address. Otherwise we might miss one cache line.
677 beq 7f /* Always flush prefetch queue in any case */
685 sync /* Wait for all dcbst to complete on bus */
691 7: sync /* Wait for all icbi to complete on bus */
695 * We are done. Do not return, instead branch to second part of board
696 * initialization, now running from RAM.
698 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
707 * Relocation Function, r14 point to got2+0x8000
709 * Adjust got2 pointers, no need to check for 0, this code
710 * already puts a few entries in the table.
712 li r0,__got2_entries@sectoff@l
713 la r3,GOT(_GOT2_TABLE_)
714 lwz r11,GOT(_GOT2_TABLE_)
726 * Now adjust the fixups and the pointers to the fixups
727 * in case we need to move ourselves again.
729 li r0,__fixup_entries@sectoff@l
730 lwz r3,GOT(_FIXUP_TABLE_)
744 * Now clear BSS segment
746 lwz r3,GOT(__bss_start)
759 mr r3, r10 /* Destination Address */
760 #if defined(CONFIG_AMIGAONEG3SE) || \
761 defined(CONFIG_DB64360) || \
762 defined(CONFIG_DB64460) || \
763 defined(CONFIG_CPCI750) || \
764 defined(CONFIG_PPMC7XX) || \
766 mr r4, r9 /* Use RAM copy of the global data */
770 /* not reached - end relocate_code */
771 /*-----------------------------------------------------------------------*/
774 * Copy exception vector code to low memory
777 * r7: source address, r8: end address, r9: target address
782 lwz r8, GOT(_end_of_vectors)
784 li r9, 0x100 /* reset vector always at 0x100 */
787 bgelr /* return if r7>=r8 - just in case */
789 mflr r4 /* save link register */
799 * relocate `hdlr' and `int_return' entries
801 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
802 li r8, Alignment - _start + EXC_OFF_SYS_RESET
805 addi r7, r7, 0x100 /* next exception vector */
809 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
812 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
815 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
816 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
819 addi r7, r7, 0x100 /* next exception vector */
823 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
824 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
827 addi r7, r7, 0x100 /* next exception vector */
831 /* enable execptions from RAM vectors */
837 mtlr r4 /* restore link register */
841 * Function: relocate entries for one exception vector
844 lwz r0, 0(r7) /* hdlr ... */
845 add r0, r0, r3 /* ... += dest_addr */
848 lwz r0, 4(r7) /* int_return ... */
849 add r0, r0, r3 /* ... += dest_addr */
857 #ifdef CONFIG_SYS_INIT_RAM_LOCK
859 /* Allocate Initial RAM in data cache.
861 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
862 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
863 li r4, ((CONFIG_SYS_INIT_RAM_END & ~31) + \
864 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
871 /* Lock the data cache */
879 .globl unlock_ram_in_cache
881 /* invalidate the INIT_RAM section */
882 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
883 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
884 li r4, ((CONFIG_SYS_INIT_RAM_END & ~31) + \
885 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
890 sync /* Wait for all icbi to complete on bus */
893 /* Unlock the data cache and invalidate it */