2 * Copyright (C) 2003 Motorola,Inc.
3 * Xianghua Xiao<X.Xiao@motorola.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 Motorola 85xx PowerPC based Embedded Boards
26 * The processor starts at 0xfffffffc and the code is first executed in the
27 * last 4K page(0xfffff000-0xffffffff) in flash/rom.
35 #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
37 #include <ppc_asm.tmpl>
40 #include <asm/cache.h>
43 #ifndef CONFIG_IDENT_STRING
44 #define CONFIG_IDENT_STRING ""
48 #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
51 * Set up GOT: Global Offset Table
53 * Use r14 to access the GOT
56 GOT_ENTRY(_GOT2_TABLE_)
57 GOT_ENTRY(_FIXUP_TABLE_)
60 GOT_ENTRY(_start_of_vectors)
61 GOT_ENTRY(_end_of_vectors)
62 GOT_ENTRY(transfer_to_handler)
66 GOT_ENTRY(__bss_start)
70 * e500 Startup -- after reset only the last 4KB of the effective
71 * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
72 * section is located at THIS LAST page and basically does three
73 * things: clear some registers, set up exception tables and
74 * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
75 * continue the boot procedure.
77 * Once the boot rom is mapped by TLB entries we can proceed
78 * with normal startup.
86 #if defined(CONFIG_MPC85xx_REV1)
91 /* Clear and set up some registers. Note: Some registers need strict
92 * synchronization by sync/mbar/msync/isync when being "mtspr".
93 * BookE: isync before PID,tlbivax,tlbwe
94 * BookE: isync after MSR,PID; msync_isync after tlbivax & tlbwe
95 * E500: msync,isync before L1CSR0
96 * E500: isync after BBEAR,BBTAR,BUCSR,DBCR0,DBCR1,HID0,HID1,L1CSR0
97 * L1CSR1, MAS[0,1,2,3,4,6],MMUCSR0, PID[0,1,2],SPEFCSR
100 /* invalidate d-cache */
108 /* disable d-cache */
113 /* invalidate i-cache */
119 /* disable i-cache */
124 /* clear registers */
150 mtspr DBSR,r1 /* Clear all valid bits */
162 mtspr BUCSR,r0 /* disable branch prediction */
175 /* Setup interrupt vectors */
179 mtspr IVOR0,r1 /* 0: Critical input */
181 mtspr IVOR1,r1 /* 1: Machine check */
183 mtspr IVOR2,r1 /* 2: Data storage */
185 mtspr IVOR3,r1 /* 3: Instruction storage */
187 mtspr IVOR4,r1 /* 4: External interrupt */
189 mtspr IVOR5,r1 /* 5: Alignment */
191 mtspr IVOR6,r1 /* 6: Program check */
193 mtspr IVOR7,r1 /* 7: floating point unavailable */
195 mtspr IVOR8,r1 /* 8: System call */
196 /* 9: Auxiliary processor unavailable(unsupported) */
198 mtspr IVOR10,r1 /* 10: Decrementer */
200 mtspr IVOR13,r1 /* 13: Data TLB error */
202 mtspr IVOR14,r1 /* 14: Instruction TLB error */
204 mtspr IVOR15,r1 /* 15: Debug */
206 /* invalidate MMU L1/L2 */
207 /* Note: before invalidate MMU L1/L2, we read TLB1 Entry 0 and then
208 * write it back immediately to fixup a bug(Errata CPU4) for this initial
209 * TLB1 entry 0,otherwise the TLB1 entry 0 will be invalidated.
211 #if defined(CONFIG_MPC85xx_REV1)
222 /* After reset, CCSRBAR is located at CFG_CCSRBAR_DEFAULT, i.e.
223 * 0xff700000-0xff800000. We need add a TLB1 entry for this 1MB
224 * region before we can access any CCSR registers such as L2
225 * registers, Local Access Registers,etc. We will also re-allocate
226 * CFG_CCSRBAR_DEFAULT to CFG_CCSRBAR immediately after TLB1 setup.
228 * Please refer to board-specif directory for TLB1 entry configuration.
229 * (e.g. board/<yourboard>/init.S)
234 li r1,0x000f /* max 16 TLB1 entries */
236 lwzu r4,0(r5) /* how many TLB1 entries we actually use */
256 #if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
257 /* Special sequence needed to update CCSRBAR itself */
258 lis r4, CFG_CCSRBAR_DEFAULT@h
259 ori r4, r4, CFG_CCSRBAR_DEFAULT@l
261 lis r5, CFG_CCSRBAR@h
262 ori r5, r5, CFG_CCSRBAR@l
272 lis r3, CFG_CCSRBAR@h
273 lwz r5, CFG_CCSRBAR@l(r3)
277 /* invalidate all TLB0 entries */
281 #if defined(CONFIG_MPC85xx_REV1) /* Errata CPU6 */
285 /* set up local access windows, defined at board/<boardname>/init.S */
287 ori r7,r7,CFG_CCSRBAR@l
291 #if defined(CONFIG_RAM_AS_FLASH)
294 li r1,0x0007 /*we have 8 LAWs, but reseve one for boot-over-rio-or-pci */
297 lwzu r5,0(r6) /* how many windows we actually use */
299 #if defined(CONFIG_RAM_AS_FLASH)
303 li r2,0x0c28 /* the first pair is reserved for boot-over-rio-or-pci */
318 /* Jump out the last 4K page and continue to 'normal' start */
323 mtspr SRR1,r0 /* Keep things disabled for now */
329 * r3 - 1st arg to board_init(): IMMP pointer
330 * r4 - 2nd arg to board_init(): boot flag
333 .long 0x27051956 /* U-BOOT Magic Number */
334 .globl version_string
336 .ascii U_BOOT_VERSION
337 .ascii " (", __DATE__, " - ", __TIME__, ")"
338 .ascii CONFIG_IDENT_STRING, "\0"
340 . = EXC_OFF_SYS_RESET
343 /* Clear and set up some registers. */
346 mtspr DEC,r0 /* prevent dec exceptions */
347 mttbl r0 /* prevent fit & wdt exceptions */
349 mtspr TSR,r1 /* clear all timer exception status */
350 mtspr TCR,r0 /* disable all */
351 mtspr ESR,r0 /* clear exception syndrome register */
352 mtspr MCSR,r0 /* machine check syndrome register */
353 mtxer r0 /* clear integer exception register */
354 lis r1,0x0002 /* set CE bit (Critical Exceptions) */
355 ori r1,r1,0x1200 /* set ME/DE bit */
356 mtmsr r1 /* change MSR */
359 /* Enable Time Base and Select Time Base Clock */
360 li r0,0x4000 /* time base is processor clock */
364 #if defined(CONFIG_ADDR_STREAMING)
370 /* Enable Branch Prediction */
371 #if defined(CONFIG_BTB)
372 li r0,0x201 /* BBFI = 1, BPEN = 1 */
377 #if defined(CFG_INIT_DBCR)
380 mtspr dbsr,r1 /* Clear all status bits */
381 lis r0,CFG_INIT_DBCR@h /* DBCR0[IDM] must be set */
382 ori r0,r0,CFG_INIT_DBCR@l
387 /* L1 DCache is used for initial RAM */
393 mtspr L1CSR0, r2 /* enable/invalidate L1 Dcache */
396 /* Allocate Initial RAM in data cache.
398 lis r3, CFG_INIT_RAM_ADDR@h
399 ori r3, r3, CFG_INIT_RAM_ADDR@l
400 li r2, 512 /* 512*32=16K */
410 /* Calculate absolute address in FLASH and jump there */
411 /*--------------------------------------------------------------*/
412 lis r3, CFG_MONITOR_BASE@h
413 ori r3, r3, CFG_MONITOR_BASE@l
414 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
419 #endif /* CFG_RAMBOOT */
421 /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
422 lis r1,CFG_INIT_RAM_ADDR@h
423 ori r1,r1,CFG_INIT_SP_OFFSET@l
427 stwu r0,-4(r1) /* Terminate call chain */
429 stwu r1,-8(r1) /* Save back chain and move SP */
430 lis r0,RESET_VECTOR@h /* Address of reset vector */
431 ori r0,r0, RESET_VECTOR@l
432 stwu r1,-8(r1) /* Save back chain and move SP */
433 stw r0,+12(r1) /* Save return addr (underflow vect) */
442 /* --FIXME-- machine check with MCSRRn and rfmci */
444 .globl _start_of_vectors
447 /* Critical input. */
448 CRIT_EXCEPTION(0x0100, CritcalInput, CritcalInputException)
450 /* Machine check --FIXME-- Should be MACH_EXCEPTION */
451 CRIT_EXCEPTION(0x0200, MachineCheck, MachineCheckException)
453 /* Data Storage exception. */
454 STD_EXCEPTION(0x0300, DataStorage, UnknownException)
456 /* Instruction Storage exception. */
457 STD_EXCEPTION(0x0400, InstStorage, UnknownException)
459 /* External Interrupt exception. */
460 STD_EXCEPTION(0x0500, ExtInterrupt, UnknownException)
462 /* Alignment exception. */
470 addi r3,r1,STACK_FRAME_OVERHEAD
472 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
473 lwz r6,GOT(transfer_to_handler)
477 .long AlignmentException - _start + EXC_OFF_SYS_RESET
478 .long int_return - _start + EXC_OFF_SYS_RESET
480 /* Program check exception */
484 addi r3,r1,STACK_FRAME_OVERHEAD
486 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
487 lwz r6,GOT(transfer_to_handler)
491 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
492 .long int_return - _start + EXC_OFF_SYS_RESET
494 /* No FPU on MPC85xx. This exception is not supposed to happen.
496 STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
497 STD_EXCEPTION(0x0900, Decrementer, timer_interrupt)
498 STD_EXCEPTION(0x0a00, Trap_0a, UnknownException)
499 STD_EXCEPTION(0x0b00, Trap_0b, 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(0xd00, SingleStep, UnknownException)
570 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
571 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
573 STD_EXCEPTION(0x1000, PIT, PITException)
575 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
576 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
577 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
578 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
580 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
581 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
582 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
583 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
584 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
585 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
586 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
588 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
589 STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
590 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
591 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
593 CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
595 .globl _end_of_vectors
602 * This code finishes saving the registers to the exception frame
603 * and jumps to the appropriate handler for the exception.
604 * Register r21 is pointer into trap frame, r1 has new stack pointer.
606 .globl transfer_to_handler
618 andi. r24,r23,0x3f00 /* get vector offset */
622 mtspr SPRG2,r22 /* r1 is now kernel sp */
624 lwz r24,0(r23) /* virtual address of handler */
625 lwz r23,4(r23) /* where to go when done */
630 rfi /* jump to handler, enable MMU */
633 mfmsr r28 /* Disable interrupts */
637 SYNC /* Some chip revs need this... */
652 lwz r2,_NIP(r1) /* Restore environment */
663 mfmsr r28 /* Disable interrupts */
667 SYNC /* Some chip revs need this... */
682 lwz r2,_NIP(r1) /* Restore environment */
684 mtspr 990,r2 /* SRR2 */
685 mtspr 991,r0 /* SRR3 */
699 blr /* entire I cache */
723 .globl icache_disable
727 ori r1,r1,0xfffffffe@l
736 srwi r3, r3, 31 /* >>31 => select bit 0 */
754 .globl dcache_disable
758 ori r1,r1,0xfffffffe@l
769 srwi r3, r3, 31 /* >>31 => select bit 0 */
787 /*------------------------------------------------------------------------------- */
789 /* Description: Input 8 bits */
790 /*------------------------------------------------------------------------------- */
796 /*------------------------------------------------------------------------------- */
798 /* Description: Output 8 bits */
799 /*------------------------------------------------------------------------------- */
805 /*------------------------------------------------------------------------------- */
806 /* Function: out16 */
807 /* Description: Output 16 bits */
808 /*------------------------------------------------------------------------------- */
814 /*------------------------------------------------------------------------------- */
815 /* Function: out16r */
816 /* Description: Byte reverse and output 16 bits */
817 /*------------------------------------------------------------------------------- */
823 /*------------------------------------------------------------------------------- */
824 /* Function: out32 */
825 /* Description: Output 32 bits */
826 /*------------------------------------------------------------------------------- */
832 /*------------------------------------------------------------------------------- */
833 /* Function: out32r */
834 /* Description: Byte reverse and output 32 bits */
835 /*------------------------------------------------------------------------------- */
841 /*------------------------------------------------------------------------------- */
843 /* Description: Input 16 bits */
844 /*------------------------------------------------------------------------------- */
850 /*------------------------------------------------------------------------------- */
851 /* Function: in16r */
852 /* Description: Input 16 bits and byte reverse */
853 /*------------------------------------------------------------------------------- */
859 /*------------------------------------------------------------------------------- */
861 /* Description: Input 32 bits */
862 /*------------------------------------------------------------------------------- */
868 /*------------------------------------------------------------------------------- */
869 /* Function: in32r */
870 /* Description: Input 32 bits and byte reverse */
871 /*------------------------------------------------------------------------------- */
877 /*------------------------------------------------------------------------------- */
878 /* Function: ppcDcbf */
879 /* Description: Data Cache block flush */
880 /* Input: r3 = effective address */
882 /*------------------------------------------------------------------------------- */
888 /*------------------------------------------------------------------------------- */
889 /* Function: ppcDcbi */
890 /* Description: Data Cache block Invalidate */
891 /* Input: r3 = effective address */
893 /*------------------------------------------------------------------------------- */
899 /*------------------------------------------------------------------------------- */
900 /* Function: ppcSync */
901 /* Description: Processor Synchronize */
904 /*------------------------------------------------------------------------------- */
910 /*------------------------------------------------------------------------------*/
913 * void relocate_code (addr_sp, gd, addr_moni)
915 * This "function" does not return, instead it continues in RAM
916 * after relocating the monitor code.
920 * r5 = length in bytes
925 mr r1, r3 /* Set new stack pointer */
926 mr r9, r4 /* Save copy of Init Data pointer */
927 mr r10, r5 /* Save copy of Destination Address */
929 mr r3, r5 /* Destination Address */
930 lis r4, CFG_MONITOR_BASE@h /* Source Address */
931 ori r4, r4, CFG_MONITOR_BASE@l
932 lwz r5,GOT(__init_end)
934 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
939 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
945 /* First our own GOT */
947 /* the the one used by the C code */
957 beq cr1,4f /* In place copy is not necessary */
958 beq 7f /* Protect against 0 count */
977 * Now flush the cache: note that we must start from a cache aligned
978 * address. Otherwise we might miss one cache line.
982 beq 7f /* Always flush prefetch queue in any case */
990 sync /* Wait for all dcbst to complete on bus */
996 7: sync /* Wait for all icbi to complete on bus */
1000 * We are done. Do not return, instead branch to second part of board
1001 * initialization, now running from RAM.
1004 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
1006 blr /* NEVER RETURNS! */
1011 * Relocation Function, r14 point to got2+0x8000
1013 * Adjust got2 pointers, no need to check for 0, this code
1014 * already puts a few entries in the table.
1016 li r0,__got2_entries@sectoff@l
1017 la r3,GOT(_GOT2_TABLE_)
1018 lwz r11,GOT(_GOT2_TABLE_)
1028 * Now adjust the fixups and the pointers to the fixups
1029 * in case we need to move ourselves again.
1031 2: li r0,__fixup_entries@sectoff@l
1032 lwz r3,GOT(_FIXUP_TABLE_)
1046 * Now clear BSS segment
1048 lwz r3,GOT(__bss_start)
1062 mr r3, r9 /* Init Data pointer */
1063 mr r4, r10 /* Destination Address */
1067 * Copy exception vector code to low memory
1070 * r7: source address, r8: end address, r9: target address
1075 lwz r8, GOT(_end_of_vectors)
1077 li r9, 0x100 /* reset vector always at 0x100 */
1080 bgelr /* return if r7>=r8 - just in case */
1082 mflr r4 /* save link register */
1092 * relocate `hdlr' and `int_return' entries
1094 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
1095 li r8, Alignment - _start + EXC_OFF_SYS_RESET
1098 addi r7, r7, 0x100 /* next exception vector */
1102 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
1105 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
1108 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
1109 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
1112 addi r7, r7, 0x100 /* next exception vector */
1116 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
1117 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
1120 addi r7, r7, 0x100 /* next exception vector */
1124 mtlr r4 /* restore link register */
1128 * Function: relocate entries for one exception vector
1131 lwz r0, 0(r7) /* hdlr ... */
1132 add r0, r0, r3 /* ... += dest_addr */
1135 lwz r0, 4(r7) /* int_return ... */
1136 add r0, r0, r3 /* ... += dest_addr */
1141 #ifdef CFG_INIT_RAM_LOCK
1142 .globl unlock_ram_in_cache
1143 unlock_ram_in_cache:
1144 /* invalidate the INIT_RAM section */
1145 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
1146 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
1153 sync /* Wait for all icbi to complete on bus */