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 #include <galileo/gt64260R.h>
47 #ifndef CONFIG_IDENT_STRING
48 #define CONFIG_IDENT_STRING ""
51 /* We don't want the MMU yet.
54 /* Machine Check and Recoverable Interr. */
55 #define MSR_KERNEL ( MSR_ME | MSR_RI )
58 * Set up GOT: Global Offset Table
60 * Use r14 to access the GOT
63 GOT_ENTRY(_GOT2_TABLE_)
64 GOT_ENTRY(_FIXUP_TABLE_)
67 GOT_ENTRY(_start_of_vectors)
68 GOT_ENTRY(_end_of_vectors)
69 GOT_ENTRY(transfer_to_handler)
76 * r3 - 1st arg to board_init(): IMMP pointer
77 * r4 - 2nd arg to board_init(): boot flag
80 .long 0x27051956 /* U-Boot Magic Number */
84 .ascii " (", __DATE__, " - ", __TIME__, ")"
85 .ascii CONFIG_IDENT_STRING, "\0"
90 li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
94 . = EXC_OFF_SYS_RESET + 0x10
98 li r21, BOOTFLAG_WARM /* Software reboot */
102 /* the boot code is located below the exception table */
104 .globl _start_of_vectors
108 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
110 /* Data Storage exception. "Never" generated on the 860. */
111 STD_EXCEPTION(0x300, DataStorage, UnknownException)
113 /* Instruction Storage exception. "Never" generated on the 860. */
114 STD_EXCEPTION(0x400, InstStorage, UnknownException)
116 /* External Interrupt exception. */
117 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
119 /* Alignment exception. */
127 addi r3,r1,STACK_FRAME_OVERHEAD
129 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
130 lwz r6,GOT(transfer_to_handler)
134 .long AlignmentException - _start + EXC_OFF_SYS_RESET
135 .long int_return - _start + EXC_OFF_SYS_RESET
137 /* Program check exception */
141 addi r3,r1,STACK_FRAME_OVERHEAD
143 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
144 lwz r6,GOT(transfer_to_handler)
148 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
149 .long int_return - _start + EXC_OFF_SYS_RESET
151 /* No FPU on MPC8xx. This exception is not supposed to happen.
153 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
155 /* I guess we could implement decrementer, and may have
156 * to someday for timekeeping.
158 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
159 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
160 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
164 * r0 - SYSCALL number
168 addis r11,r0,0 /* get functions table addr */
169 ori r11,r11,0 /* Note: this code is patched in trap_init */
170 addis r12,r0,0 /* get number of functions */
176 rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
180 li r12,0xd00-4*3 /* save LR & SRRx */
188 li r12,0xc00+_back-SystemCall
197 mfmsr r11 /* Disable interrupts */
201 SYNC /* Some chip revs need this... */
205 li r12,0xd00-4*3 /* restore regs */
216 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
218 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
219 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
222 * On the MPC8xx, this is a software emulation interrupt. It
223 * occurs for all unimplemented and illegal instructions.
225 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
227 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
228 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
229 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
230 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
232 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
233 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
234 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
235 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
236 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
237 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
238 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
240 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
241 STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
242 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
243 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
245 .globl _end_of_vectors
252 /* disable everything */
261 /* init the L2 cache */
262 addis r3, r0, L2_INIT@h
263 ori r3, r3, L2_INIT@l
267 #if defined(CONFIG_ALTIVEC) && defined(CONFIG_74xx)
270 * dssall instruction, gas doesn't have it yet
271 * ...for altivec, data stream stop all this probably
272 * isn't needed unless we warm (software) reboot U-Boot
277 /* invalidate the L2 cache */
278 bl l2cache_invalidate
281 #ifdef CFG_BOARD_ASM_INIT
287 * Calculate absolute address in FLASH and jump there
288 *------------------------------------------------------*/
289 lis r3, CFG_MONITOR_BASE@h
290 ori r3, r3, CFG_MONITOR_BASE@l
291 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
296 /* let the C-code set up the rest */
298 /* Be careful to keep code relocatable ! */
299 /*------------------------------------------------------*/
301 /* perform low-level init */
302 /* sdram init, galileo init, etc */
303 /* r3: NHR bit from HID0 */
310 * Cache must be enabled here for stack-in-cache trick.
311 * This means we need to enable the BATS.
313 * 1) for the EVB, original gt regs need to be mapped
314 * 2) need to have an IBAT for the 0xf region,
315 * we are running there!
316 * Cache should be turned on after BATs, since by default
317 * everything is write-through.
318 * The init-mem BAT can be reused after reloc. The old
319 * gt-regs BAT can be reused after board_init_f calls
320 * board_pre_init (EVB only).
322 #if !defined(CONFIG_BAB7xx) && !defined(CONFIG_ELPPC)
323 /* enable address translation */
327 /* enable and invalidate the data cache */
331 #ifdef CFG_INIT_RAM_LOCK
336 /* set up the stack pointer in our newly created
338 lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
339 ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
341 li r0, 0 /* Make room for stack frame header and */
342 stwu r0, -4(r1) /* clear final stack frame so that */
343 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
345 GET_GOT /* initialize GOT access */
347 /* run low-level CPU init code (from Flash) */
354 /* run 1st part of board init code (from Flash) */
360 .globl invalidate_bats
362 /* invalidate BATs */
376 /* setup_bats - set them up to some initial state */
382 addis r4, r0, CFG_IBAT0L@h
383 ori r4, r4, CFG_IBAT0L@l
384 addis r3, r0, CFG_IBAT0U@h
385 ori r3, r3, CFG_IBAT0U@l
391 addis r4, r0, CFG_DBAT0L@h
392 ori r4, r4, CFG_DBAT0L@l
393 addis r3, r0, CFG_DBAT0U@h
394 ori r3, r3, CFG_DBAT0U@l
400 addis r4, r0, CFG_IBAT1L@h
401 ori r4, r4, CFG_IBAT1L@l
402 addis r3, r0, CFG_IBAT1U@h
403 ori r3, r3, CFG_IBAT1U@l
409 addis r4, r0, CFG_DBAT1L@h
410 ori r4, r4, CFG_DBAT1L@l
411 addis r3, r0, CFG_DBAT1U@h
412 ori r3, r3, CFG_DBAT1U@l
418 addis r4, r0, CFG_IBAT2L@h
419 ori r4, r4, CFG_IBAT2L@l
420 addis r3, r0, CFG_IBAT2U@h
421 ori r3, r3, CFG_IBAT2U@l
427 addis r4, r0, CFG_DBAT2L@h
428 ori r4, r4, CFG_DBAT2L@l
429 addis r3, r0, CFG_DBAT2U@h
430 ori r3, r3, CFG_DBAT2U@l
436 addis r4, r0, CFG_IBAT3L@h
437 ori r4, r4, CFG_IBAT3L@l
438 addis r3, r0, CFG_IBAT3U@h
439 ori r3, r3, CFG_IBAT3U@l
445 addis r4, r0, CFG_DBAT3L@h
446 ori r4, r4, CFG_DBAT3L@l
447 addis r3, r0, CFG_DBAT3U@h
448 ori r3, r3, CFG_DBAT3U@l
453 /* bats are done, now invalidate the TLBs */
456 addis r5, 0, 0x4 /* upper bound of 0x00040000 for 7400/750 */
469 .globl enable_addr_trans
471 /* enable address translation */
473 ori r5, r5, (MSR_IR | MSR_DR)
478 .globl disable_addr_trans
480 /* disable address translation */
483 andi. r0, r3, (MSR_IR | MSR_DR)
491 * This code finishes saving the registers to the exception frame
492 * and jumps to the appropriate handler for the exception.
493 * Register r21 is pointer into trap frame, r1 has new stack pointer.
495 .globl transfer_to_handler
506 andi. r24,r23,0x3f00 /* get vector offset */
510 mtspr SPRG2,r22 /* r1 is now kernel sp */
511 lwz r24,0(r23) /* virtual address of handler */
512 lwz r23,4(r23) /* where to go when done */
517 rfi /* jump to handler, enable MMU */
520 mfmsr r28 /* Disable interrupts */
524 SYNC /* Some chip revs need this... */
539 lwz r2,_NIP(r1) /* Restore environment */
558 /*-----------------------------------------------------------------------*/
560 * void relocate_code (addr_sp, gd, addr_moni)
562 * This "function" does not return, instead it continues in RAM
563 * after relocating the monitor code.
567 * r5 = length in bytes
572 mr r1, r3 /* Set new stack pointer */
573 mr r9, r4 /* Save copy of Global Data pointer */
574 mr r10, r5 /* Save copy of Destination Address */
576 mr r3, r5 /* Destination Address */
577 lis r4, CFG_MONITOR_BASE@h /* Source Address */
578 ori r4, r4, CFG_MONITOR_BASE@l
579 lis r5, CFG_MONITOR_LEN@h /* Length in Bytes */
580 ori r5, r5, CFG_MONITOR_LEN@l
581 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
586 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
592 /* First our own GOT */
594 /* then the one used by the C code */
601 bl board_relocate_rom
603 mr r3, r10 /* Destination Address */
604 lis r4, CFG_MONITOR_BASE@h /* Source Address */
605 ori r4, r4, CFG_MONITOR_BASE@l
606 lis r5, CFG_MONITOR_LEN@h /* Length in Bytes */
607 ori r5, r5, CFG_MONITOR_LEN@l
608 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
613 beq cr1,4f /* In place copy is not necessary */
614 beq 7f /* Protect against 0 count */
633 * Now flush the cache: note that we must start from a cache aligned
634 * address. Otherwise we might miss one cache line.
638 beq 7f /* Always flush prefetch queue in any case */
646 sync /* Wait for all dcbst to complete on bus */
652 7: sync /* Wait for all icbi to complete on bus */
656 * We are done. Do not return, instead branch to second part of board
657 * initialization, now running from RAM.
659 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
668 * Relocation Function, r14 point to got2+0x8000
670 * Adjust got2 pointers, no need to check for 0, this code
671 * already puts a few entries in the table.
673 li r0,__got2_entries@sectoff@l
674 la r3,GOT(_GOT2_TABLE_)
675 lwz r11,GOT(_GOT2_TABLE_)
685 * Now adjust the fixups and the pointers to the fixups
686 * in case we need to move ourselves again.
688 2: li r0,__fixup_entries@sectoff@l
689 lwz r3,GOT(_FIXUP_TABLE_)
703 * Now clear BSS segment
718 mr r3, r10 /* Destination Address */
721 /* not reached - end relocate_code */
722 /*-----------------------------------------------------------------------*/
724 /* Problems accessing "end" in C, so do it here */
731 * Copy exception vector code to low memory
734 * r7: source address, r8: end address, r9: target address
739 lwz r8, GOT(_end_of_vectors)
741 rlwinm r9, r7, 0, 18, 31 /* _start & 0x3FFF */
744 bgelr /* return if r7>=r8 - just in case */
746 mflr r4 /* save link register */
756 * relocate `hdlr' and `int_return' entries
758 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
759 li r8, Alignment - _start + EXC_OFF_SYS_RESET
762 addi r7, r7, 0x100 /* next exception vector */
766 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
769 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
772 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
773 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
776 addi r7, r7, 0x100 /* next exception vector */
780 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
781 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
784 addi r7, r7, 0x100 /* next exception vector */
788 /* enable execptions from RAM vectors */
794 mtlr r4 /* restore link register */
798 * Function: relocate entries for one exception vector
801 lwz r0, 0(r7) /* hdlr ... */
802 add r0, r0, r3 /* ... += dest_addr */
805 lwz r0, 4(r7) /* int_return ... */
806 add r0, r0, r3 /* ... += dest_addr */
814 #ifdef CFG_INIT_RAM_LOCK
816 /* Allocate Initial RAM in data cache.
818 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
819 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
820 li r2, ((CFG_INIT_RAM_END & ~31) + \
821 (CFG_INIT_RAM_ADDR & 31) + 31) / 32
828 /* Lock the data cache */
836 .globl unlock_ram_in_cache
838 /* invalidate the INIT_RAM section */
839 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
840 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
841 li r2, ((CFG_INIT_RAM_END & ~31) + \
842 (CFG_INIT_RAM_ADDR & 31) + 31) / 32
847 sync /* Wait for all icbi to complete on bus */
850 /* Unlock the data cache and invalidate it */