2 * Copyright 2004 Freescale Semiconductor.
3 * Copyright (C) 2003 Motorola,Inc.
4 * Xianghua Xiao<X.Xiao@motorola.com>
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 /* U-Boot Startup Code for Motorola 85xx PowerPC based Embedded Boards
27 * The processor starts at 0xfffffffc and the code is first executed in the
28 * last 4K page(0xfffff000-0xffffffff) in flash/rom.
36 #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
38 #include <ppc_asm.tmpl>
41 #include <asm/cache.h>
44 #ifndef CONFIG_IDENT_STRING
45 #define CONFIG_IDENT_STRING ""
49 #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
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 * e500 Startup -- after reset only the last 4KB of the effective
72 * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
73 * section is located at THIS LAST page and basically does three
74 * things: clear some registers, set up exception tables and
75 * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
76 * continue the boot procedure.
78 * Once the boot rom is mapped by TLB entries we can proceed
79 * with normal startup.
88 lis r1, PVR_85xx_REV1@h
89 ori r1, r1, PVR_85xx_REV1@l
93 /* Semi-bogus errata fixup for Rev 1 */
98 * Before invalidating MMU L1/L2, read TLB1 Entry 0 and then
99 * write it back immediately to fixup a Rev 1 bug (Errata CPU4)
100 * for this initial TLB1 entry 0, otherwise the TLB1 entry 0
101 * will be invalidated (incorrectly).
111 * Clear and set up some registers.
112 * Note: Some registers need strict synchronization by
113 * sync/mbar/msync/isync when being "mtspr".
114 * BookE: isync before PID,tlbivax,tlbwe
115 * BookE: isync after MSR,PID; msync_isync after tlbivax & tlbwe
116 * E500: msync,isync before L1CSR0
117 * E500: isync after BBEAR,BBTAR,BUCSR,DBCR0,DBCR1,HID0,HID1,
118 * L1CSR0, L1CSR1, MAS[0,1,2,3,4,6],MMUCSR0, PID[0,1,2],
122 /* invalidate d-cache */
130 /* disable d-cache */
134 /* invalidate i-cache */
140 /* disable i-cache */
145 /* clear registers */
158 /* not needed and conflicts with some debuggers */
162 /* not needed and conflicts with some debuggers */
169 mtspr DBSR,r1 /* Clear all valid bits */
176 mtspr BUCSR,r0 /* disable branch prediction */
179 #if defined(CONFIG_ENABLE_36BIT_PHYS)
184 /* Setup interrupt vectors */
189 mtspr IVOR0,r1 /* 0: Critical input */
191 mtspr IVOR1,r1 /* 1: Machine check */
193 mtspr IVOR2,r1 /* 2: Data storage */
195 mtspr IVOR3,r1 /* 3: Instruction storage */
197 mtspr IVOR4,r1 /* 4: External interrupt */
199 mtspr IVOR5,r1 /* 5: Alignment */
201 mtspr IVOR6,r1 /* 6: Program check */
203 mtspr IVOR7,r1 /* 7: floating point unavailable */
205 mtspr IVOR8,r1 /* 8: System call */
206 /* 9: Auxiliary processor unavailable(unsupported) */
208 mtspr IVOR10,r1 /* 10: Decrementer */
210 mtspr IVOR11,r1 /* 11: Interval timer */
212 mtspr IVOR12,r1 /* 12: Watchdog timer */
214 mtspr IVOR13,r1 /* 13: Data TLB error */
216 mtspr IVOR14,r1 /* 14: Instruction TLB error */
218 mtspr IVOR15,r1 /* 15: Debug */
221 * Invalidate MMU L1/L2
223 * Note: There is a fixup earlier for Errata CPU4 on
224 * Rev 1 parts that must precede this MMU invalidation.
231 * Invalidate all TLB0 entries.
237 * To avoid REV1 Errata CPU6 issues, make sure
238 * the instruction following tlbivax is not a store.
242 * After reset, CCSRBAR is located at CFG_CCSRBAR_DEFAULT, i.e.
243 * 0xff700000-0xff800000. We need add a TLB1 entry for this 1MB
244 * region before we can access any CCSR registers such as L2
245 * registers, Local Access Registers,etc. We will also re-allocate
246 * CFG_CCSRBAR_DEFAULT to CFG_CCSRBAR immediately after TLB1 setup.
248 * Please refer to board-specif directory for TLB1 entry configuration.
249 * (e.g. board/<yourboard>/init.S)
254 li r1,0x0020 /* max 16 TLB1 plus some TLB0 entries */
256 lwzu r4,0(r5) /* how many TLB1 entries we actually use */
276 #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
277 /* Special sequence needed to update CCSRBAR itself */
278 lis r4, CFG_CCSRBAR_DEFAULT@h
279 ori r4, r4, CFG_CCSRBAR_DEFAULT@l
281 lis r5, CFG_CCSRBAR@h
282 ori r5, r5, CFG_CCSRBAR@l
292 lis r3, CFG_CCSRBAR@h
293 lwz r5, CFG_CCSRBAR@l(r3)
298 /* set up local access windows, defined at board/<boardname>/init.S */
300 ori r7,r7,CFG_CCSRBAR@l
304 li r1,0x0007 /* 8 LAWs, but reserve one for boot-over-rio-or-pci */
306 lwzu r5,0(r6) /* how many windows we actually use */
308 li r2,0x0c28 /* the first pair is reserved for boot-over-rio-or-pci */
322 /* Jump out the last 4K page and continue to 'normal' start */
327 mtspr SRR1,r0 /* Keep things disabled for now */
333 * r3 - 1st arg to board_init(): IMMP pointer
334 * r4 - 2nd arg to board_init(): boot flag
337 .long 0x27051956 /* U-BOOT Magic Number */
338 .globl version_string
340 .ascii U_BOOT_VERSION
341 .ascii " (", __DATE__, " - ", __TIME__, ")"
342 .ascii CONFIG_IDENT_STRING, "\0"
344 . = EXC_OFF_SYS_RESET
347 /* Clear and set up some registers. */
350 mtspr DEC,r0 /* prevent dec exceptions */
351 mttbl r0 /* prevent fit & wdt exceptions */
353 mtspr TSR,r1 /* clear all timer exception status */
354 mtspr TCR,r0 /* disable all */
355 mtspr ESR,r0 /* clear exception syndrome register */
356 mtspr MCSR,r0 /* machine check syndrome register */
357 mtxer r0 /* clear integer exception register */
358 lis r1,0x0002 /* set CE bit (Critical Exceptions) */
359 ori r1,r1,0x1200 /* set ME/DE bit */
360 mtmsr r1 /* change MSR */
363 /* Enable Time Base and Select Time Base Clock */
364 lis r0,HID0_EMCP@h /* Enable machine check */
365 ori r0,r0,0x4000 /* time base is processor clock */
366 #if defined(CONFIG_ENABLE_36BIT_PHYS)
367 ori r0,r0,0x0080 /* enable MAS7 updates */
371 #if defined(CONFIG_ADDR_STREAMING)
378 /* Enable Branch Prediction */
379 #if defined(CONFIG_BTB)
380 li r0,0x201 /* BBFI = 1, BPEN = 1 */
384 #if defined(CFG_INIT_DBCR)
387 mtspr DBSR,r1 /* Clear all status bits */
388 lis r0,CFG_INIT_DBCR@h /* DBCR0[IDM] must be set */
389 ori r0,r0,CFG_INIT_DBCR@l
393 /* L1 DCache is used for initial RAM */
397 mtspr L1CSR0, r2 /* enable/invalidate L1 Dcache */
400 /* Allocate Initial RAM in data cache.
402 lis r3, CFG_INIT_RAM_ADDR@h
403 ori r3, r3, CFG_INIT_RAM_ADDR@l
404 li r2, 512 /* 512*32=16K */
414 /* Calculate absolute address in FLASH and jump there */
415 /*--------------------------------------------------------------*/
416 lis r3, CFG_MONITOR_BASE@h
417 ori r3, r3, CFG_MONITOR_BASE@l
418 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
423 #endif /* CFG_RAMBOOT */
425 /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
426 lis r1,CFG_INIT_RAM_ADDR@h
427 ori r1,r1,CFG_INIT_SP_OFFSET@l
431 stwu r0,-4(r1) /* Terminate call chain */
433 stwu r1,-8(r1) /* Save back chain and move SP */
434 lis r0,RESET_VECTOR@h /* Address of reset vector */
435 ori r0,r0, RESET_VECTOR@l
436 stwu r1,-8(r1) /* Save back chain and move SP */
437 stw r0,+12(r1) /* Save return addr (underflow vect) */
445 /* --FIXME-- machine check with MCSRRn and rfmci */
447 .globl _start_of_vectors
450 /* Critical input. */
451 CRIT_EXCEPTION(0x0100, CritcalInput, CritcalInputException)
453 /* Machine check --FIXME-- Should be MACH_EXCEPTION */
454 CRIT_EXCEPTION(0x0200, MachineCheck, MachineCheckException)
456 /* Data Storage exception. */
457 STD_EXCEPTION(0x0300, DataStorage, UnknownException)
459 /* Instruction Storage exception. */
460 STD_EXCEPTION(0x0400, InstStorage, UnknownException)
462 /* External Interrupt exception. */
463 STD_EXCEPTION(0x0500, ExtInterrupt, UnknownException)
465 /* Alignment exception. */
473 addi r3,r1,STACK_FRAME_OVERHEAD
475 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
476 lwz r6,GOT(transfer_to_handler)
480 .long AlignmentException - _start + EXC_OFF_SYS_RESET
481 .long int_return - _start + EXC_OFF_SYS_RESET
483 /* Program check exception */
487 addi r3,r1,STACK_FRAME_OVERHEAD
489 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
490 lwz r6,GOT(transfer_to_handler)
494 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
495 .long int_return - _start + EXC_OFF_SYS_RESET
497 /* No FPU on MPC85xx. This exception is not supposed to happen.
499 STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
503 * r0 - SYSCALL number
507 addis r11,r0,0 /* get functions table addr */
508 ori r11,r11,0 /* Note: this code is patched in trap_init */
509 addis r12,r0,0 /* get number of functions */
515 rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
519 li r20,0xd00-4 /* Get stack pointer */
521 subi r12,r12,12 /* Adjust stack pointer */
522 li r0,0xc00+_end_back-SystemCall
523 cmplw 0, r0, r12 /* Check stack overflow */
534 li r12,0xc00+_back-SystemCall
542 mfmsr r11 /* Disable interrupts */
546 SYNC /* Some chip revs need this... */
550 li r12,0xd00-4 /* restore regs */
560 addi r12,r12,12 /* Adjust stack pointer */
568 STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
569 STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
570 STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
572 STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
573 STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
575 CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
577 .globl _end_of_vectors
584 * This code finishes saving the registers to the exception frame
585 * and jumps to the appropriate handler for the exception.
586 * Register r21 is pointer into trap frame, r1 has new stack pointer.
588 .globl transfer_to_handler
600 andi. r24,r23,0x3f00 /* get vector offset */
604 mtspr SPRG2,r22 /* r1 is now kernel sp */
606 lwz r24,0(r23) /* virtual address of handler */
607 lwz r23,4(r23) /* where to go when done */
612 rfi /* jump to handler, enable MMU */
615 mfmsr r28 /* Disable interrupts */
619 SYNC /* Some chip revs need this... */
634 lwz r2,_NIP(r1) /* Restore environment */
645 mfmsr r28 /* Disable interrupts */
649 SYNC /* Some chip revs need this... */
664 lwz r2,_NIP(r1) /* Restore environment */
666 mtspr 990,r2 /* SRR2 */
667 mtspr 991,r0 /* SRR3 */
681 blr /* entire I cache */
705 .globl icache_disable
709 ori r1,r1,0xfffffffe@l
718 srwi r3, r3, 31 /* >>31 => select bit 0 */
736 .globl dcache_disable
740 ori r1,r1,0xfffffffe@l
751 srwi r3, r3, 31 /* >>31 => select bit 0 */
774 /*------------------------------------------------------------------------------- */
776 /* Description: Input 8 bits */
777 /*------------------------------------------------------------------------------- */
783 /*------------------------------------------------------------------------------- */
785 /* Description: Output 8 bits */
786 /*------------------------------------------------------------------------------- */
792 /*------------------------------------------------------------------------------- */
793 /* Function: out16 */
794 /* Description: Output 16 bits */
795 /*------------------------------------------------------------------------------- */
801 /*------------------------------------------------------------------------------- */
802 /* Function: out16r */
803 /* Description: Byte reverse and output 16 bits */
804 /*------------------------------------------------------------------------------- */
810 /*------------------------------------------------------------------------------- */
811 /* Function: out32 */
812 /* Description: Output 32 bits */
813 /*------------------------------------------------------------------------------- */
819 /*------------------------------------------------------------------------------- */
820 /* Function: out32r */
821 /* Description: Byte reverse and output 32 bits */
822 /*------------------------------------------------------------------------------- */
828 /*------------------------------------------------------------------------------- */
830 /* Description: Input 16 bits */
831 /*------------------------------------------------------------------------------- */
837 /*------------------------------------------------------------------------------- */
838 /* Function: in16r */
839 /* Description: Input 16 bits and byte reverse */
840 /*------------------------------------------------------------------------------- */
846 /*------------------------------------------------------------------------------- */
848 /* Description: Input 32 bits */
849 /*------------------------------------------------------------------------------- */
855 /*------------------------------------------------------------------------------- */
856 /* Function: in32r */
857 /* Description: Input 32 bits and byte reverse */
858 /*------------------------------------------------------------------------------- */
864 /*------------------------------------------------------------------------------- */
865 /* Function: ppcDcbf */
866 /* Description: Data Cache block flush */
867 /* Input: r3 = effective address */
869 /*------------------------------------------------------------------------------- */
875 /*------------------------------------------------------------------------------- */
876 /* Function: ppcDcbi */
877 /* Description: Data Cache block Invalidate */
878 /* Input: r3 = effective address */
880 /*------------------------------------------------------------------------------- */
886 /*--------------------------------------------------------------------------
888 * Description: Data Cache block zero.
889 * Input: r3 = effective address
891 *-------------------------------------------------------------------------- */
898 /*------------------------------------------------------------------------------- */
899 /* Function: ppcSync */
900 /* Description: Processor Synchronize */
903 /*------------------------------------------------------------------------------- */
909 /*------------------------------------------------------------------------------*/
912 * void relocate_code (addr_sp, gd, addr_moni)
914 * This "function" does not return, instead it continues in RAM
915 * after relocating the monitor code.
919 * r5 = length in bytes
924 mr r1, r3 /* Set new stack pointer */
925 mr r9, r4 /* Save copy of Init Data pointer */
926 mr r10, r5 /* Save copy of Destination Address */
928 mr r3, r5 /* Destination Address */
929 lis r4, CFG_MONITOR_BASE@h /* Source Address */
930 ori r4, r4, CFG_MONITOR_BASE@l
931 lwz r5,GOT(__init_end)
933 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
938 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
944 /* First our own GOT */
946 /* the the one used by the C code */
956 beq cr1,4f /* In place copy is not necessary */
957 beq 7f /* Protect against 0 count */
976 * Now flush the cache: note that we must start from a cache aligned
977 * address. Otherwise we might miss one cache line.
981 beq 7f /* Always flush prefetch queue in any case */
989 sync /* Wait for all dcbst to complete on bus */
995 7: sync /* Wait for all icbi to complete on bus */
999 * We are done. Do not return, instead branch to second part of board
1000 * initialization, now running from RAM.
1003 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
1005 blr /* NEVER RETURNS! */
1010 * Relocation Function, r14 point to got2+0x8000
1012 * Adjust got2 pointers, no need to check for 0, this code
1013 * already puts a few entries in the table.
1015 li r0,__got2_entries@sectoff@l
1016 la r3,GOT(_GOT2_TABLE_)
1017 lwz r11,GOT(_GOT2_TABLE_)
1027 * Now adjust the fixups and the pointers to the fixups
1028 * in case we need to move ourselves again.
1030 2: li r0,__fixup_entries@sectoff@l
1031 lwz r3,GOT(_FIXUP_TABLE_)
1045 * Now clear BSS segment
1047 lwz r3,GOT(__bss_start)
1061 mr r3, r9 /* Init Data pointer */
1062 mr r4, r10 /* Destination Address */
1066 * Copy exception vector code to low memory
1069 * r7: source address, r8: end address, r9: target address
1074 lwz r8, GOT(_end_of_vectors)
1076 li r9, 0x100 /* reset vector always at 0x100 */
1079 bgelr /* return if r7>=r8 - just in case */
1081 mflr r4 /* save link register */
1091 * relocate `hdlr' and `int_return' entries
1093 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
1095 li r7, .L_DataStorage - _start + EXC_OFF_SYS_RESET
1097 li r7, .L_InstStorage - _start + EXC_OFF_SYS_RESET
1099 li r7, .L_ExtInterrupt - _start + EXC_OFF_SYS_RESET
1101 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
1103 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
1105 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
1107 li r7, .L_Decrementer - _start + EXC_OFF_SYS_RESET
1109 li r7, .L_IntervalTimer - _start + EXC_OFF_SYS_RESET
1110 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
1113 addi r7, r7, 0x100 /* next exception vector */
1120 mtlr r4 /* restore link register */
1124 * Function: relocate entries for one exception vector
1127 lwz r0, 0(r7) /* hdlr ... */
1128 add r0, r0, r3 /* ... += dest_addr */
1131 lwz r0, 4(r7) /* int_return ... */
1132 add r0, r0, r3 /* ... += dest_addr */
1137 #ifdef CFG_INIT_RAM_LOCK
1138 .globl unlock_ram_in_cache
1139 unlock_ram_in_cache:
1140 /* invalidate the INIT_RAM section */
1141 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
1142 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
1149 sync /* Wait for all icbi to complete on bus */