2 * Copyright 2004, 2007 Freescale Semiconductor.
3 * Srikanth Srinivasan <srikanth.srinivaan@freescale.com>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 /* U-Boot - Startup Code for 86xx PowerPC based Embedded Boards
27 * The processor starts at 0xfff00100 and the code is executed
28 * from flash. The code is organized to be at an other address
29 * in memory, but as long we don't jump around before relocating.
30 * board_init lies at a quite high address and when the cpu has
31 * jumped there, everything is ok.
37 #include <ppc_asm.tmpl>
40 #include <asm/cache.h>
43 #ifndef CONFIG_IDENT_STRING
44 #define CONFIG_IDENT_STRING ""
48 * Need MSR_DR | MSR_IR enabled to access I/O (printf) in exceptions
52 * Set up GOT: Global Offset Table
54 * Use r14 to access the GOT
57 GOT_ENTRY(_GOT2_TABLE_)
58 GOT_ENTRY(_FIXUP_TABLE_)
61 GOT_ENTRY(_start_of_vectors)
62 GOT_ENTRY(_end_of_vectors)
63 GOT_ENTRY(transfer_to_handler)
67 GOT_ENTRY(__bss_start)
71 * r3 - 1st arg to board_init(): IMMP pointer
72 * r4 - 2nd arg to board_init(): boot flag
75 .long 0x27051956 /* U-Boot Magic Number */
79 .ascii " (", __DATE__, " - ", __TIME__, ")"
80 .ascii CONFIG_IDENT_STRING, "\0"
85 li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
89 . = EXC_OFF_SYS_RESET + 0x10
93 li r21, BOOTFLAG_WARM /* Software reboot */
97 /* the boot code is located below the exception table */
99 .globl _start_of_vectors
103 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
105 /* Data Storage exception. */
106 STD_EXCEPTION(0x300, DataStorage, UnknownException)
108 /* Instruction Storage exception. */
109 STD_EXCEPTION(0x400, InstStorage, UnknownException)
111 /* External Interrupt exception. */
112 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
114 /* Alignment exception. */
117 EXCEPTION_PROLOG(SRR0, SRR1)
122 addi r3,r1,STACK_FRAME_OVERHEAD
124 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
125 lwz r6,GOT(transfer_to_handler)
129 .long AlignmentException - _start + EXC_OFF_SYS_RESET
130 .long int_return - _start + EXC_OFF_SYS_RESET
132 /* Program check exception */
135 EXCEPTION_PROLOG(SRR0, SRR1)
136 addi r3,r1,STACK_FRAME_OVERHEAD
138 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
139 lwz r6,GOT(transfer_to_handler)
143 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
144 .long int_return - _start + EXC_OFF_SYS_RESET
146 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
148 /* I guess we could implement decrementer, and may have
149 * to someday for timekeeping.
151 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
152 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
153 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
154 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
155 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
156 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
157 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
158 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
159 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
160 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
161 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
162 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
163 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
164 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
165 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
166 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
167 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
168 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
169 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
170 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
171 STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
172 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
173 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
175 .globl _end_of_vectors
183 /* if this is a multi-core system we need to check which cpu
184 * this is, if it is not cpu 0 send the cpu to the linux reset
186 #if (CONFIG_NUM_CPUS > 1)
189 rlwinm r0,r0,27,31,31
193 bl secondary_cpu_setup
197 #ifdef CONFIG_SYS_RAMBOOT
198 /* disable everything */
205 /* Invalidate BATs */
208 /* Invalidate all of TLB before MMU turn on */
213 /* init the L2 cache */
215 ori r3, r3, L2_INIT@l
217 /* invalidate the L2 cache */
218 bl l2cache_invalidate
222 #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR)
223 /* setup ccsrbar now while we're in real mode */
228 * Calculate absolute address in FLASH and jump there
229 *------------------------------------------------------*/
230 lis r3, CONFIG_SYS_MONITOR_BASE@h
231 ori r3, r3, CONFIG_SYS_MONITOR_BASE@l
232 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
237 /* let the C-code set up the rest */
239 /* Be careful to keep code relocatable ! */
240 /*------------------------------------------------------*/
241 /* perform low-level init */
243 /* enable extended addressing */
250 * Cache must be enabled here for stack-in-cache trick.
251 * This means we need to enable the BATS.
252 * Cache should be turned on after BATs, since by default
253 * everything is write-through.
256 /* enable address translation */
260 /* enable and invalidate the data cache */
261 /* bl l1dcache_enable */
269 #ifdef CONFIG_SYS_INIT_RAM_LOCK
274 /* set up the stack pointer in our newly created
276 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
277 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
279 li r0, 0 /* Make room for stack frame header and */
280 stwu r0, -4(r1) /* clear final stack frame so that */
281 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
283 GET_GOT /* initialize GOT access */
285 /* setup the rest of the bats */
290 /* run low-level CPU init code (from Flash) */
296 /* Load PX_AUX register address in r4 */
299 /* Load contents of PX_AUX in r3 bits 24 to 31*/
302 /* Mask and obtain the bit in r3 */
303 rlwinm. r3, r3, 0, 24, 24
304 /* If not zero, jump and continue with u-boot */
307 /* Load back contents of PX_AUX in r3 bits 24 to 31 */
309 /* Set the MSB of the register value */
311 /* Write value in r3 back to PX_AUX */
314 /* Get the address to jump to in r3*/
315 lis r3, CONFIG_SYS_DIAG_ADDR@h
316 ori r3, r3, CONFIG_SYS_DIAG_ADDR@l
318 /* Load the LR with the branch address */
321 /* Branch to diagnostic */
327 /* bl l2cache_enable */
331 /* run 1st part of board init code (from Flash) */
337 .globl invalidate_bats
341 /* invalidate BATs */
368 * Set up bats needed early on - this is usually the BAT for the
369 * stack-in-cache, the Flash, and CCSR space
374 lis r4, CONFIG_SYS_IBAT3L@h
375 ori r4, r4, CONFIG_SYS_IBAT3L@l
376 lis r3, CONFIG_SYS_IBAT3U@h
377 ori r3, r3, CONFIG_SYS_IBAT3U@l
383 lis r4, CONFIG_SYS_DBAT3L@h
384 ori r4, r4, CONFIG_SYS_DBAT3L@l
385 lis r3, CONFIG_SYS_DBAT3U@h
386 ori r3, r3, CONFIG_SYS_DBAT3U@l
392 lis r4, CONFIG_SYS_IBAT5L@h
393 ori r4, r4, CONFIG_SYS_IBAT5L@l
394 lis r3, CONFIG_SYS_IBAT5U@h
395 ori r3, r3, CONFIG_SYS_IBAT5U@l
401 lis r4, CONFIG_SYS_DBAT5L@h
402 ori r4, r4, CONFIG_SYS_DBAT5L@l
403 lis r3, CONFIG_SYS_DBAT5U@h
404 ori r3, r3, CONFIG_SYS_DBAT5U@l
410 lis r4, CONFIG_SYS_IBAT6L@h
411 ori r4, r4, CONFIG_SYS_IBAT6L@l
412 lis r3, CONFIG_SYS_IBAT6U@h
413 ori r3, r3, CONFIG_SYS_IBAT6U@l
419 lis r4, CONFIG_SYS_DBAT6L@h
420 ori r4, r4, CONFIG_SYS_DBAT6L@l
421 lis r3, CONFIG_SYS_DBAT6U@h
422 ori r3, r3, CONFIG_SYS_DBAT6U@l
441 .globl enable_addr_trans
443 /* enable address translation */
445 ori r5, r5, (MSR_IR | MSR_DR)
450 .globl disable_addr_trans
452 /* disable address translation */
455 andi. r0, r3, (MSR_IR | MSR_DR)
463 * This code finishes saving the registers to the exception frame
464 * and jumps to the appropriate handler for the exception.
465 * Register r21 is pointer into trap frame, r1 has new stack pointer.
467 .globl transfer_to_handler
478 andi. r24,r23,0x3f00 /* get vector offset */
482 mtspr SPRG2,r22 /* r1 is now kernel sp */
483 lwz r24,0(r23) /* virtual address of handler */
484 lwz r23,4(r23) /* where to go when done */
489 rfi /* jump to handler, enable MMU */
492 mfmsr r28 /* Disable interrupts */
496 SYNC /* Some chip revs need this... */
511 lwz r2,_NIP(r1) /* Restore environment */
538 * Description: Input 8 bits
547 * Description: Output 8 bits
556 * Description: Output 16 bits
565 * Description: Byte reverse and output 16 bits
574 * Description: Output 32 bits
583 * Description: Byte reverse and output 32 bits
592 * Description: Input 16 bits
601 * Description: Input 16 bits and byte reverse
610 * Description: Input 32 bits
619 * Description: Input 32 bits and byte reverse
627 * void relocate_code (addr_sp, gd, addr_moni)
629 * This "function" does not return, instead it continues in RAM
630 * after relocating the monitor code.
634 * r5 = length in bytes
640 mr r1, r3 /* Set new stack pointer */
641 mr r9, r4 /* Save copy of Global Data pointer */
642 mr r10, r5 /* Save copy of Destination Address */
644 mr r3, r5 /* Destination Address */
645 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
646 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
647 lwz r5, GOT(__init_end)
649 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
654 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
660 /* First our own GOT */
662 /* then the one used by the C code */
671 beq cr1,4f /* In place copy is not necessary */
672 beq 7f /* Protect against 0 count */
690 * Now flush the cache: note that we must start from a cache aligned
691 * address. Otherwise we might miss one cache line.
695 beq 7f /* Always flush prefetch queue in any case */
703 sync /* Wait for all dcbst to complete on bus */
709 7: sync /* Wait for all icbi to complete on bus */
713 * We are done. Do not return, instead branch to second part of board
714 * initialization, now running from RAM.
716 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
722 * Relocation Function, r14 point to got2+0x8000
724 * Adjust got2 pointers, no need to check for 0, this code
725 * already puts a few entries in the table.
727 li r0,__got2_entries@sectoff@l
728 la r3,GOT(_GOT2_TABLE_)
729 lwz r11,GOT(_GOT2_TABLE_)
739 * Now adjust the fixups and the pointers to the fixups
740 * in case we need to move ourselves again.
742 2: li r0,__fixup_entries@sectoff@l
743 lwz r3,GOT(_FIXUP_TABLE_)
757 * Now clear BSS segment
759 lwz r3,GOT(__bss_start)
772 mr r3, r9 /* Init Date pointer */
773 mr r4, r10 /* Destination Address */
776 /* not reached - end relocate_code */
777 /*-----------------------------------------------------------------------*/
780 * Copy exception vector code to low memory
783 * r7: source address, r8: end address, r9: target address
788 lwz r8, GOT(_end_of_vectors)
790 li r9, 0x100 /* reset vector always at 0x100 */
793 bgelr /* return if r7>=r8 - just in case */
795 mflr r4 /* save link register */
805 * relocate `hdlr' and `int_return' entries
807 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
808 li r8, Alignment - _start + EXC_OFF_SYS_RESET
811 addi r7, r7, 0x100 /* next exception vector */
815 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
818 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
821 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
822 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
825 addi r7, r7, 0x100 /* next exception vector */
829 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
830 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
833 addi r7, r7, 0x100 /* next exception vector */
837 /* enable execptions from RAM vectors */
841 ori r7,r7,MSR_ME /* Enable Machine Check */
844 mtlr r4 /* restore link register */
848 * Function: relocate entries for one exception vector
851 lwz r0, 0(r7) /* hdlr ... */
852 add r0, r0, r3 /* ... += dest_addr */
855 lwz r0, 4(r7) /* int_return ... */
856 add r0, r0, r3 /* ... += dest_addr */
864 .globl enable_ext_addr
867 lis r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@h
868 ori r0, r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@l
874 #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR)
877 /* Special sequence needed to update CCSRBAR itself */
878 lis r4, CONFIG_SYS_CCSRBAR_DEFAULT@h
879 ori r4, r4, CONFIG_SYS_CCSRBAR_DEFAULT@l
881 lis r5, CONFIG_SYS_CCSRBAR@h
882 ori r5, r5, CONFIG_SYS_CCSRBAR@l
892 lis r3, CONFIG_SYS_CCSRBAR@h
893 lwz r5, CONFIG_SYS_CCSRBAR@l(r3)
899 #ifdef CONFIG_SYS_INIT_RAM_LOCK
901 /* Allocate Initial RAM in data cache.
903 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
904 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
905 li r4, ((CONFIG_SYS_INIT_RAM_END & ~31) + \
906 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
913 /* Lock the data cache */
922 /* Lock the first way of the data cache */
925 #if defined(CONFIG_ALTIVEC)
935 .globl unlock_ram_in_cache
937 /* invalidate the INIT_RAM section */
938 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
939 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
940 li r4, ((CONFIG_SYS_INIT_RAM_END & ~31) + \
941 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
946 sync /* Wait for all icbi to complete on bus */
949 /* Unlock the data cache and invalidate it */
961 /* Unlock the first way of the data cache */
965 #ifdef CONFIG_ALTIVEC
981 /* If this is a multi-cpu system then we need to handle the
982 * 2nd cpu. The assumption is that the 2nd cpu is being
983 * held in boot holdoff mode until the 1st cpu unlocks it
984 * from Linux. We'll do some basic cpu init and then pass
985 * it to the Linux Reset Vector.
986 * Sri: Much of this initialization is not required. Linux
987 * rewrites the bats, and the sprs and also enables the L1 cache.
989 #if (CONFIG_NUM_CPUS > 1)
990 .globl secondary_cpu_setup
992 /* Do only core setup on all cores except cpu0 */
998 /* init the L2 cache */
999 addis r3, r0, L2_INIT@h
1000 ori r3, r3, L2_INIT@l
1003 #ifdef CONFIG_ALTIVEC
1006 /* invalidate the L2 cache */
1007 bl l2cache_invalidate
1011 /* enable and invalidate the data cache */
1015 /* enable and invalidate the instruction cache*/
1026 /* MCP|SYNCBE|ABE in HID1 */
1034 lis r3, CONFIG_LINUX_RESET_VEC@h
1035 ori r3, r3, CONFIG_LINUX_RESET_VEC@l
1039 /* Never Returns, Running in Linux Now */