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.
33 #include <asm-offsets.h>
36 #include <timestamp.h>
39 #include <ppc_asm.tmpl>
42 #include <asm/cache.h>
44 #include <asm/u-boot.h>
46 #ifndef CONFIG_IDENT_STRING
47 #define CONFIG_IDENT_STRING ""
51 * Need MSR_DR | MSR_IR enabled to access I/O (printf) in exceptions
55 * Set up GOT: Global Offset Table
57 * Use r12 to access the GOT
60 GOT_ENTRY(_GOT2_TABLE_)
61 GOT_ENTRY(_FIXUP_TABLE_)
64 GOT_ENTRY(_start_of_vectors)
65 GOT_ENTRY(_end_of_vectors)
66 GOT_ENTRY(transfer_to_handler)
69 GOT_ENTRY(__bss_end__)
70 GOT_ENTRY(__bss_start)
74 * r3 - 1st arg to board_init(): IMMP pointer
75 * r4 - 2nd arg to board_init(): boot flag
78 .long 0x27051956 /* U-Boot Magic Number */
82 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
83 .ascii CONFIG_IDENT_STRING, "\0"
90 /* the boot code is located below the exception table */
92 .globl _start_of_vectors
96 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
98 /* Data Storage exception. */
99 STD_EXCEPTION(0x300, DataStorage, UnknownException)
101 /* Instruction Storage exception. */
102 STD_EXCEPTION(0x400, InstStorage, UnknownException)
104 /* External Interrupt exception. */
105 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
107 /* Alignment exception. */
110 EXCEPTION_PROLOG(SRR0, SRR1)
115 addi r3,r1,STACK_FRAME_OVERHEAD
116 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
118 /* Program check exception */
121 EXCEPTION_PROLOG(SRR0, SRR1)
122 addi r3,r1,STACK_FRAME_OVERHEAD
123 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
126 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
128 /* I guess we could implement decrementer, and may have
129 * to someday for timekeeping.
131 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
132 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
133 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
134 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
135 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
136 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
137 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
138 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
139 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
140 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
141 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
142 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
143 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
144 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
145 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
146 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
147 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
148 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
149 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
150 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
151 STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
152 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
153 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
155 .globl _end_of_vectors
162 * NOTE: Only Cpu 0 will ever come here. Other cores go to an
163 * address specified by the BPTR
166 #ifdef CONFIG_SYS_RAMBOOT
167 /* disable everything */
174 /* Invalidate BATs */
177 /* Invalidate all of TLB before MMU turn on */
182 /* init the L2 cache */
184 ori r3, r3, L2_INIT@l
186 /* invalidate the L2 cache */
187 bl l2cache_invalidate
192 * Calculate absolute address in FLASH and jump there
193 *------------------------------------------------------*/
194 lis r3, CONFIG_SYS_MONITOR_BASE_EARLY@h
195 ori r3, r3, CONFIG_SYS_MONITOR_BASE_EARLY@l
196 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
201 /* let the C-code set up the rest */
203 /* Be careful to keep code relocatable ! */
204 /*------------------------------------------------------*/
205 /* perform low-level init */
207 /* enable extended addressing */
214 * Cache must be enabled here for stack-in-cache trick.
215 * This means we need to enable the BATS.
216 * Cache should be turned on after BATs, since by default
217 * everything is write-through.
220 /* enable address translation */
222 ori r5, r5, (MSR_IR | MSR_DR)
223 lis r3,addr_trans_enabled@h
224 ori r3, r3, addr_trans_enabled@l
230 /* enable and invalidate the data cache */
231 /* bl l1dcache_enable */
239 #ifdef CONFIG_SYS_INIT_RAM_LOCK
244 #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR)
248 /* set up the stack pointer in our newly created
250 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
251 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
253 li r0, 0 /* Make room for stack frame header and */
254 stwu r0, -4(r1) /* clear final stack frame so that */
255 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
257 GET_GOT /* initialize GOT access */
258 #if defined(__pic__) && __pic__ == 1
259 /* Needed for upcoming -msingle-pic-base */
260 bl _GLOBAL_OFFSET_TABLE_@local-4
263 /* run low-level CPU init code (from Flash) */
269 /* Load PX_AUX register address in r4 */
272 /* Load contents of PX_AUX in r3 bits 24 to 31*/
275 /* Mask and obtain the bit in r3 */
276 rlwinm. r3, r3, 0, 24, 24
277 /* If not zero, jump and continue with u-boot */
280 /* Load back contents of PX_AUX in r3 bits 24 to 31 */
282 /* Set the MSB of the register value */
284 /* Write value in r3 back to PX_AUX */
287 /* Get the address to jump to in r3*/
288 lis r3, CONFIG_SYS_DIAG_ADDR@h
289 ori r3, r3, CONFIG_SYS_DIAG_ADDR@l
291 /* Load the LR with the branch address */
294 /* Branch to diagnostic */
300 /* bl l2cache_enable */
302 /* run 1st part of board init code (from Flash) */
306 /* NOTREACHED - board_init_f() does not return */
308 .globl invalidate_bats
312 /* invalidate BATs */
339 * Set up bats needed early on - this is usually the BAT for the
340 * stack-in-cache, the Flash, and CCSR space
345 lis r4, CONFIG_SYS_IBAT3L@h
346 ori r4, r4, CONFIG_SYS_IBAT3L@l
347 lis r3, CONFIG_SYS_IBAT3U@h
348 ori r3, r3, CONFIG_SYS_IBAT3U@l
354 lis r4, CONFIG_SYS_DBAT3L@h
355 ori r4, r4, CONFIG_SYS_DBAT3L@l
356 lis r3, CONFIG_SYS_DBAT3U@h
357 ori r3, r3, CONFIG_SYS_DBAT3U@l
363 lis r4, CONFIG_SYS_IBAT5L@h
364 ori r4, r4, CONFIG_SYS_IBAT5L@l
365 lis r3, CONFIG_SYS_IBAT5U@h
366 ori r3, r3, CONFIG_SYS_IBAT5U@l
372 lis r4, CONFIG_SYS_DBAT5L@h
373 ori r4, r4, CONFIG_SYS_DBAT5L@l
374 lis r3, CONFIG_SYS_DBAT5U@h
375 ori r3, r3, CONFIG_SYS_DBAT5U@l
381 lis r4, CONFIG_SYS_IBAT6L_EARLY@h
382 ori r4, r4, CONFIG_SYS_IBAT6L_EARLY@l
383 lis r3, CONFIG_SYS_IBAT6U_EARLY@h
384 ori r3, r3, CONFIG_SYS_IBAT6U_EARLY@l
390 lis r4, CONFIG_SYS_DBAT6L_EARLY@h
391 ori r4, r4, CONFIG_SYS_DBAT6L_EARLY@l
392 lis r3, CONFIG_SYS_DBAT6U_EARLY@h
393 ori r3, r3, CONFIG_SYS_DBAT6U_EARLY@l
398 #if(CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR)
400 lis r4, CONFIG_SYS_CCSR_DEFAULT_IBATL@h
401 ori r4, r4, CONFIG_SYS_CCSR_DEFAULT_IBATL@l
402 lis r3, CONFIG_SYS_CCSR_DEFAULT_IBATU@h
403 ori r3, r3, CONFIG_SYS_CCSR_DEFAULT_IBATU@l
409 lis r4, CONFIG_SYS_CCSR_DEFAULT_DBATL@h
410 ori r4, r4, CONFIG_SYS_CCSR_DEFAULT_DBATL@l
411 lis r3, CONFIG_SYS_CCSR_DEFAULT_DBATU@h
412 ori r3, r3, CONFIG_SYS_CCSR_DEFAULT_DBATU@l
432 .globl disable_addr_trans
434 /* disable address translation */
437 andi. r0, r3, (MSR_IR | MSR_DR)
445 * This code finishes saving the registers to the exception frame
446 * and jumps to the appropriate handler for the exception.
447 * Register r21 is pointer into trap frame, r1 has new stack pointer.
449 .globl transfer_to_handler
460 andi. r24,r23,0x3f00 /* get vector offset */
464 mtspr SPRG2,r22 /* r1 is now kernel sp */
465 lwz r24,0(r23) /* virtual address of handler */
466 lwz r23,4(r23) /* where to go when done */
471 rfi /* jump to handler, enable MMU */
474 mfmsr r28 /* Disable interrupts */
478 SYNC /* Some chip revs need this... */
493 lwz r2,_NIP(r1) /* Restore environment */
520 * Description: Input 8 bits
529 * Description: Output 8 bits
538 * Description: Output 16 bits
547 * Description: Byte reverse and output 16 bits
556 * Description: Output 32 bits
565 * Description: Byte reverse and output 32 bits
574 * Description: Input 16 bits
583 * Description: Input 16 bits and byte reverse
592 * Description: Input 32 bits
601 * Description: Input 32 bits and byte reverse
609 * void relocate_code (addr_sp, gd, addr_moni)
611 * This "function" does not return, instead it continues in RAM
612 * after relocating the monitor code.
616 * r5 = length in bytes
622 mr r1, r3 /* Set new stack pointer */
623 mr r9, r4 /* Save copy of Global Data pointer */
624 mr r10, r5 /* Save copy of Destination Address */
627 #if defined(__pic__) && __pic__ == 1
628 /* Needed for upcoming -msingle-pic-base */
629 bl _GLOBAL_OFFSET_TABLE_@local-4
632 mr r3, r5 /* Destination Address */
633 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
634 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
635 lwz r5, GOT(__init_end)
637 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
642 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
648 /* First our own GOT */
650 /* then the one used by the C code */
659 beq cr1,4f /* In place copy is not necessary */
660 beq 7f /* Protect against 0 count */
678 * Now flush the cache: note that we must start from a cache aligned
679 * address. Otherwise we might miss one cache line.
683 beq 7f /* Always flush prefetch queue in any case */
691 sync /* Wait for all dcbst to complete on bus */
697 7: sync /* Wait for all icbi to complete on bus */
701 * We are done. Do not return, instead branch to second part of board
702 * initialization, now running from RAM.
704 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
710 * Relocation Function, r12 point to got2+0x8000
712 * Adjust got2 pointers, no need to check for 0, this code
713 * already puts a few entries in the table.
715 li r0,__got2_entries@sectoff@l
716 la r3,GOT(_GOT2_TABLE_)
717 lwz r11,GOT(_GOT2_TABLE_)
729 * Now adjust the fixups and the pointers to the fixups
730 * in case we need to move ourselves again.
732 li r0,__fixup_entries@sectoff@l
733 lwz r3,GOT(_FIXUP_TABLE_)
749 * Now clear BSS segment
751 lwz r3,GOT(__bss_start)
752 lwz r4,GOT(__bss_end__)
764 mr r3, r9 /* Init Date pointer */
765 mr r4, r10 /* Destination Address */
768 /* not reached - end relocate_code */
769 /*-----------------------------------------------------------------------*/
772 * Copy exception vector code to low memory
775 * r7: source address, r8: end address, r9: target address
779 mflr r4 /* save link register */
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 */
797 * relocate `hdlr' and `int_return' entries
799 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
800 li r8, Alignment - _start + EXC_OFF_SYS_RESET
803 addi r7, r7, 0x100 /* next exception vector */
807 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
810 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
813 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
814 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
817 addi r7, r7, 0x100 /* next exception vector */
821 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
822 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
825 addi r7, r7, 0x100 /* next exception vector */
829 /* enable execptions from RAM vectors */
833 ori r7,r7,MSR_ME /* Enable Machine Check */
836 mtlr r4 /* restore link register */
839 .globl enable_ext_addr
842 lis r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@h
843 ori r0, r0, (HID0_HIGH_BAT_EN | HID0_XBSEN | HID0_XAEN)@l
849 #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR)
852 /* Special sequence needed to update CCSRBAR itself */
853 lis r4, CONFIG_SYS_CCSRBAR_DEFAULT@h
854 ori r4, r4, CONFIG_SYS_CCSRBAR_DEFAULT@l
856 lis r5, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
857 ori r5, r5, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
859 li r6, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
861 stw r5, 0(r4) /* Store physical value of CCSR */
864 lis r5, CONFIG_SYS_TEXT_BASE@h
865 ori r5,r5,CONFIG_SYS_TEXT_BASE@l
869 /* Use VA of CCSR to do read */
870 lis r3, CONFIG_SYS_CCSRBAR@h
871 lwz r5, CONFIG_SYS_CCSRBAR@l(r3)
877 #ifdef CONFIG_SYS_INIT_RAM_LOCK
879 /* Allocate Initial RAM in data cache.
881 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
882 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
883 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
884 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
891 /* Lock the data cache */
900 /* Lock the first way of the data cache */
903 #if defined(CONFIG_ALTIVEC)
913 .globl unlock_ram_in_cache
915 /* invalidate the INIT_RAM section */
916 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
917 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
918 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
919 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
924 sync /* Wait for all icbi to complete on bus */
927 /* Unlock the data cache and invalidate it */
939 /* Unlock the first way of the data cache */
943 #ifdef CONFIG_ALTIVEC