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 Freescale Semiconductor, Inc. 2004, 2006, 2008.
7 * SPDX-License-Identifier: GPL-2.0+
11 * U-Boot - Startup Code for MPC83xx PowerPC based Embedded Boards
14 #include <asm-offsets.h>
17 #ifndef CONFIG_IDENT_STRING
18 #define CONFIG_IDENT_STRING "MPC83XX"
22 #define CONFIG_83XX 1 /* needed for Linux kernel header files*/
24 #include <ppc_asm.tmpl>
27 #include <asm/cache.h>
29 #include <asm/u-boot.h>
31 /* We don't want the MMU yet.
36 * Floating Point enable, Machine Check and Recoverable Interr.
39 #define MSR_KERNEL (MSR_FP|MSR_RI)
41 #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
44 #if defined(CONFIG_NAND_SPL) || \
45 (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_INIT_MINIMAL))
49 #if !defined(CONFIG_SPL_BUILD) && !defined(CONFIG_NAND_SPL) && \
50 !defined(CONFIG_SYS_RAMBOOT)
51 #define CONFIG_SYS_FLASHBOOT
55 * Set up GOT: Global Offset Table
57 * Use r12 to access the GOT
60 GOT_ENTRY(_GOT2_TABLE_)
61 GOT_ENTRY(__bss_start)
65 GOT_ENTRY(_FIXUP_TABLE_)
67 GOT_ENTRY(_start_of_vectors)
68 GOT_ENTRY(_end_of_vectors)
69 GOT_ENTRY(transfer_to_handler)
74 * The Hard Reset Configuration Word (HRCW) table is in the first 64
75 * (0x40) bytes of flash. It has 8 bytes, but each byte is repeated 8
76 * times so the processor can fetch it out of flash whether the flash
77 * is 8, 16, 32, or 64 bits wide (hardware trickery).
80 #define _HRCW_TABLE_ENTRY(w) \
81 .fill 8,1,(((w)>>24)&0xff); \
82 .fill 8,1,(((w)>>16)&0xff); \
83 .fill 8,1,(((w)>> 8)&0xff); \
84 .fill 8,1,(((w) )&0xff)
86 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_LOW)
87 _HRCW_TABLE_ENTRY(CONFIG_SYS_HRCW_HIGH)
90 * Magic number and version string - put it after the HRCW since it
91 * cannot be first in flash like it is in many other processors.
93 .long 0x27051956 /* U-Boot Magic Number */
97 .ascii U_BOOT_VERSION_STRING, "\0"
101 .globl enable_addr_trans
103 /* enable address translation */
105 ori r5, r5, (MSR_IR | MSR_DR)
110 .globl disable_addr_trans
112 /* disable address translation */
115 andi. r0, r3, (MSR_IR | MSR_DR)
144 #ifndef CONFIG_DEFAULT_IMMR
145 #error CONFIG_DEFAULT_IMMR must be defined
146 #endif /* CONFIG_SYS_DEFAULT_IMMR */
147 #ifndef CONFIG_SYS_IMMR
148 #define CONFIG_SYS_IMMR CONFIG_DEFAULT_IMMR
149 #endif /* CONFIG_SYS_IMMR */
152 * After configuration, a system reset exception is executed using the
153 * vector at offset 0x100 relative to the base set by MSR[IP]. If
154 * MSR[IP] is 0, the base address is 0x00000000. If MSR[IP] is 1, the
155 * base address is 0xfff00000. In the case of a Power On Reset or Hard
156 * Reset, the value of MSR[IP] is determined by the CIP field in the
159 * Other bits in the HRCW set up the Base Address and Port Size in BR0.
160 * This determines the location of the boot ROM (flash or EPROM) in the
161 * processor's address space at boot time. As long as the HRCW is set up
162 * so that we eventually end up executing the code below when the
163 * processor executes the reset exception, the actual values used should
166 * Once we have got here, the address mask in OR0 is cleared so that the
167 * bottom 32K of the boot ROM is effectively repeated all throughout the
168 * processor's address space, after which we can jump to the absolute
169 * address at which the boot ROM was linked at compile time, and proceed
170 * to initialise the memory controller without worrying if the rug will
171 * be pulled out from under us, so to speak (it will be fine as long as
172 * we configure BR0 with the same boot ROM link address).
174 . = EXC_OFF_SYS_RESET
177 _start: /* time t 0 */
178 lis r4, CONFIG_DEFAULT_IMMR@h
181 mfmsr r5 /* save msr contents */
183 /* 83xx manuals prescribe a specific sequence for updating IMMRBAR. */
187 lis r3, CONFIG_SYS_IMMR@h
188 ori r3, r3, CONFIG_SYS_IMMR@l
194 lwz r6, 0(r7) /* Arbitrary external load */
200 /* Initialise the E300 processor core */
201 /*------------------------------------------*/
203 #if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_MPC83XX_WAIT_FOR_NAND)) || \
204 defined(CONFIG_NAND_SPL)
205 /* The FCM begins execution after only the first page
206 * is loaded. Wait for the rest before branching
207 * to another flash page.
209 1: lwz r6, 0x50b0(r3)
216 #ifdef CONFIG_SYS_FLASHBOOT
218 /* Inflate flash location so it appears everywhere, calculate */
219 /* the absolute address in final location of the FLASH, jump */
220 /* there and deflate the flash size back to minimal size */
221 /*------------------------------------------------------------*/
223 lis r4, (CONFIG_SYS_MONITOR_BASE)@h
224 ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
225 addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
229 #if 1 /* Remapping flash with LAW0. */
230 bl remap_flash_by_law0
232 #endif /* CONFIG_SYS_FLASHBOOT */
239 * Cache must be enabled here for stack-in-cache trick.
240 * This means we need to enable the BATS.
242 * 1) for the EVB, original gt regs need to be mapped
243 * 2) need to have an IBAT for the 0xf region,
244 * we are running there!
245 * Cache should be turned on after BATs, since by default
246 * everything is write-through.
247 * The init-mem BAT can be reused after reloc. The old
248 * gt-regs BAT can be reused after board_init_f calls
249 * board_early_init_f (EVB only).
251 /* enable address translation */
255 /* enable the data cache */
258 #ifdef CONFIG_SYS_INIT_RAM_LOCK
263 /* set up the stack pointer in our newly created
265 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
266 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
268 li r0, 0 /* Make room for stack frame header and */
269 stwu r0, -4(r1) /* clear final stack frame so that */
270 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
273 /* let the C-code set up the rest */
275 /* Be careful to keep code relocatable & stack humble */
276 /*------------------------------------------------------*/
278 GET_GOT /* initialize GOT access */
281 lis r3, CONFIG_SYS_IMMR@h
282 /* run low-level CPU init code (in Flash)*/
285 /* run 1st part of board init code (in Flash)*/
288 /* NOTREACHED - board_init_f() does not return */
295 .globl _start_of_vectors
299 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
301 /* Data Storage exception. */
302 STD_EXCEPTION(0x300, DataStorage, UnknownException)
304 /* Instruction Storage exception. */
305 STD_EXCEPTION(0x400, InstStorage, UnknownException)
307 /* External Interrupt exception. */
309 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
312 /* Alignment exception. */
315 EXCEPTION_PROLOG(SRR0, SRR1)
320 addi r3,r1,STACK_FRAME_OVERHEAD
321 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
323 /* Program check exception */
326 EXCEPTION_PROLOG(SRR0, SRR1)
327 addi r3,r1,STACK_FRAME_OVERHEAD
328 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
331 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
333 /* I guess we could implement decrementer, and may have
334 * to someday for timekeeping.
336 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
338 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
339 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
340 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
341 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
343 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
344 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
346 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
347 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
348 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
352 * This exception occurs when the program counter matches the
353 * Instruction Address Breakpoint Register (IABR).
355 * I want the cpu to halt if this occurs so I can hunt around
356 * with the debugger and look at things.
358 * When DEBUG is defined, both machine check enable (in the MSR)
359 * and checkstop reset enable (in the reset mode register) are
360 * turned off and so a checkstop condition will result in the cpu
363 * I force the cpu into a checkstop condition by putting an illegal
364 * instruction here (at least this is the theory).
366 * well - that didnt work, so just do an infinite loop!
370 STD_EXCEPTION(0x1300, InstructionBreakpoint, DebugException)
372 STD_EXCEPTION(0x1400, SMI, UnknownException)
374 STD_EXCEPTION(0x1500, Trap_15, UnknownException)
375 STD_EXCEPTION(0x1600, Trap_16, UnknownException)
376 STD_EXCEPTION(0x1700, Trap_17, UnknownException)
377 STD_EXCEPTION(0x1800, Trap_18, UnknownException)
378 STD_EXCEPTION(0x1900, Trap_19, UnknownException)
379 STD_EXCEPTION(0x1a00, Trap_1a, UnknownException)
380 STD_EXCEPTION(0x1b00, Trap_1b, UnknownException)
381 STD_EXCEPTION(0x1c00, Trap_1c, UnknownException)
382 STD_EXCEPTION(0x1d00, Trap_1d, UnknownException)
383 STD_EXCEPTION(0x1e00, Trap_1e, UnknownException)
384 STD_EXCEPTION(0x1f00, Trap_1f, UnknownException)
385 STD_EXCEPTION(0x2000, Trap_20, UnknownException)
386 STD_EXCEPTION(0x2100, Trap_21, UnknownException)
387 STD_EXCEPTION(0x2200, Trap_22, UnknownException)
388 STD_EXCEPTION(0x2300, Trap_23, UnknownException)
389 STD_EXCEPTION(0x2400, Trap_24, UnknownException)
390 STD_EXCEPTION(0x2500, Trap_25, UnknownException)
391 STD_EXCEPTION(0x2600, Trap_26, UnknownException)
392 STD_EXCEPTION(0x2700, Trap_27, UnknownException)
393 STD_EXCEPTION(0x2800, Trap_28, UnknownException)
394 STD_EXCEPTION(0x2900, Trap_29, UnknownException)
395 STD_EXCEPTION(0x2a00, Trap_2a, UnknownException)
396 STD_EXCEPTION(0x2b00, Trap_2b, UnknownException)
397 STD_EXCEPTION(0x2c00, Trap_2c, UnknownException)
398 STD_EXCEPTION(0x2d00, Trap_2d, UnknownException)
399 STD_EXCEPTION(0x2e00, Trap_2e, UnknownException)
400 STD_EXCEPTION(0x2f00, Trap_2f, UnknownException)
403 .globl _end_of_vectors
409 * This code finishes saving the registers to the exception frame
410 * and jumps to the appropriate handler for the exception.
411 * Register r21 is pointer into trap frame, r1 has new stack pointer.
413 .globl transfer_to_handler
424 andi. r24,r23,0x3f00 /* get vector offset */
428 lwz r24,0(r23) /* virtual address of handler */
429 lwz r23,4(r23) /* where to go when done */
434 rfi /* jump to handler, enable MMU */
437 mfmsr r28 /* Disable interrupts */
441 SYNC /* Some chip revs need this... */
456 lwz r2,_NIP(r1) /* Restore environment */
465 #endif /* !MINIMAL_SPL */
468 * This code initialises the E300 processor core
469 * (conforms to PowerPC 603e spec)
470 * Note: expects original MSR contents to be in r5.
472 .globl init_e300_core
473 init_e300_core: /* time t 10 */
474 /* Initialize machine status; enable machine check interrupt */
475 /*-----------------------------------------------------------*/
477 li r3, MSR_KERNEL /* Set ME and RI flags */
478 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit set by HRCW */
480 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE & BE bits */
482 SYNC /* Some chip revs need this... */
485 mtspr SRR1, r3 /* Make SRR1 match MSR */
488 lis r3, CONFIG_SYS_IMMR@h
489 #if defined(CONFIG_WATCHDOG)
490 /* Initialise the Watchdog values and reset it (if req) */
491 /*------------------------------------------------------*/
492 lis r4, CONFIG_SYS_WATCHDOG_VALUE
493 ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
503 /* Disable Watchdog */
504 /*-------------------*/
506 /* Check to see if its enabled for disabling
507 once disabled by SW you can't re-enable */
513 #endif /* CONFIG_WATCHDOG */
515 #if defined(CONFIG_MASK_AER_AO)
516 /* Write the Arbiter Event Enable to mask Address Only traps. */
517 /* This prevents the dcbz instruction from being trapped when */
518 /* HID0_ABE Address Broadcast Enable is set and the MEMORY */
519 /* COHERENCY bit is set in the WIMG bits, which is often */
520 /* needed for PCI operation. */
522 rlwinm r0, r4, 0, ~AER_AO
524 #endif /* CONFIG_MASK_AER_AO */
526 /* Initialize the Hardware Implementation-dependent Registers */
527 /* HID0 also contains cache control */
528 /* - force invalidation of data and instruction caches */
529 /*------------------------------------------------------*/
531 lis r3, CONFIG_SYS_HID0_INIT@h
532 ori r3, r3, (CONFIG_SYS_HID0_INIT | HID0_ICFI | HID0_DCFI)@l
536 lis r3, CONFIG_SYS_HID0_FINAL@h
537 ori r3, r3, (CONFIG_SYS_HID0_FINAL & ~(HID0_ICFI | HID0_DCFI))@l
541 lis r3, CONFIG_SYS_HID2@h
542 ori r3, r3, CONFIG_SYS_HID2@l
547 /*------------------------------*/
550 /* setup_bats - set them up to some initial state */
556 addis r4, r0, CONFIG_SYS_IBAT0L@h
557 ori r4, r4, CONFIG_SYS_IBAT0L@l
558 addis r3, r0, CONFIG_SYS_IBAT0U@h
559 ori r3, r3, CONFIG_SYS_IBAT0U@l
564 addis r4, r0, CONFIG_SYS_DBAT0L@h
565 ori r4, r4, CONFIG_SYS_DBAT0L@l
566 addis r3, r0, CONFIG_SYS_DBAT0U@h
567 ori r3, r3, CONFIG_SYS_DBAT0U@l
572 addis r4, r0, CONFIG_SYS_IBAT1L@h
573 ori r4, r4, CONFIG_SYS_IBAT1L@l
574 addis r3, r0, CONFIG_SYS_IBAT1U@h
575 ori r3, r3, CONFIG_SYS_IBAT1U@l
580 addis r4, r0, CONFIG_SYS_DBAT1L@h
581 ori r4, r4, CONFIG_SYS_DBAT1L@l
582 addis r3, r0, CONFIG_SYS_DBAT1U@h
583 ori r3, r3, CONFIG_SYS_DBAT1U@l
588 addis r4, r0, CONFIG_SYS_IBAT2L@h
589 ori r4, r4, CONFIG_SYS_IBAT2L@l
590 addis r3, r0, CONFIG_SYS_IBAT2U@h
591 ori r3, r3, CONFIG_SYS_IBAT2U@l
596 addis r4, r0, CONFIG_SYS_DBAT2L@h
597 ori r4, r4, CONFIG_SYS_DBAT2L@l
598 addis r3, r0, CONFIG_SYS_DBAT2U@h
599 ori r3, r3, CONFIG_SYS_DBAT2U@l
604 addis r4, r0, CONFIG_SYS_IBAT3L@h
605 ori r4, r4, CONFIG_SYS_IBAT3L@l
606 addis r3, r0, CONFIG_SYS_IBAT3U@h
607 ori r3, r3, CONFIG_SYS_IBAT3U@l
612 addis r4, r0, CONFIG_SYS_DBAT3L@h
613 ori r4, r4, CONFIG_SYS_DBAT3L@l
614 addis r3, r0, CONFIG_SYS_DBAT3U@h
615 ori r3, r3, CONFIG_SYS_DBAT3U@l
619 #ifdef CONFIG_HIGH_BATS
621 addis r4, r0, CONFIG_SYS_IBAT4L@h
622 ori r4, r4, CONFIG_SYS_IBAT4L@l
623 addis r3, r0, CONFIG_SYS_IBAT4U@h
624 ori r3, r3, CONFIG_SYS_IBAT4U@l
629 addis r4, r0, CONFIG_SYS_DBAT4L@h
630 ori r4, r4, CONFIG_SYS_DBAT4L@l
631 addis r3, r0, CONFIG_SYS_DBAT4U@h
632 ori r3, r3, CONFIG_SYS_DBAT4U@l
637 addis r4, r0, CONFIG_SYS_IBAT5L@h
638 ori r4, r4, CONFIG_SYS_IBAT5L@l
639 addis r3, r0, CONFIG_SYS_IBAT5U@h
640 ori r3, r3, CONFIG_SYS_IBAT5U@l
645 addis r4, r0, CONFIG_SYS_DBAT5L@h
646 ori r4, r4, CONFIG_SYS_DBAT5L@l
647 addis r3, r0, CONFIG_SYS_DBAT5U@h
648 ori r3, r3, CONFIG_SYS_DBAT5U@l
653 addis r4, r0, CONFIG_SYS_IBAT6L@h
654 ori r4, r4, CONFIG_SYS_IBAT6L@l
655 addis r3, r0, CONFIG_SYS_IBAT6U@h
656 ori r3, r3, CONFIG_SYS_IBAT6U@l
661 addis r4, r0, CONFIG_SYS_DBAT6L@h
662 ori r4, r4, CONFIG_SYS_DBAT6L@l
663 addis r3, r0, CONFIG_SYS_DBAT6U@h
664 ori r3, r3, CONFIG_SYS_DBAT6U@l
669 addis r4, r0, CONFIG_SYS_IBAT7L@h
670 ori r4, r4, CONFIG_SYS_IBAT7L@l
671 addis r3, r0, CONFIG_SYS_IBAT7U@h
672 ori r3, r3, CONFIG_SYS_IBAT7U@l
677 addis r4, r0, CONFIG_SYS_DBAT7L@h
678 ori r4, r4, CONFIG_SYS_DBAT7L@l
679 addis r3, r0, CONFIG_SYS_DBAT7U@h
680 ori r3, r3, CONFIG_SYS_DBAT7U@l
687 /* invalidate all tlb's
689 * From the 603e User Manual: "The 603e provides the ability to
690 * invalidate a TLB entry. The TLB Invalidate Entry (tlbie)
691 * instruction invalidates the TLB entry indexed by the EA, and
692 * operates on both the instruction and data TLBs simultaneously
693 * invalidating four TLB entries (both sets in each TLB). The
694 * index corresponds to bits 15-19 of the EA. To invalidate all
695 * entries within both TLBs, 32 tlbie instructions should be
696 * issued, incrementing this field by one each time."
698 * "Note that the tlbia instruction is not implemented on the
701 * bits 15-19 correspond to addresses 0x00000000 to 0x0001F000
702 * incrementing by 0x1000 each time. The code below is sort of
703 * based on code in "flush_tlbs" from arch/powerpc/kernel/head.S
719 * Note: requires that all cache bits in
720 * HID0 are in the low half word.
727 li r4, HID0_ICFI|HID0_ILOCK
729 ori r4, r3, HID0_ICFI
731 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
733 mtspr HID0, r3 /* clears invalidate */
736 .globl icache_disable
740 ori r4, r4, HID0_ICE|HID0_ICFI|HID0_ILOCK
743 mtspr HID0, r3 /* clears invalidate, enable and lock */
749 rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
751 #endif /* !MINIMAL_SPL */
756 li r5, HID0_DCFI|HID0_DLOCK
760 mtspr HID0, r3 /* enable, no invalidate */
763 .globl dcache_disable
766 bl flush_dcache /* uses r3 and r5 */
768 li r5, HID0_DCE|HID0_DLOCK
770 ori r5, r3, HID0_DCFI
772 mtspr HID0, r5 /* sets invalidate, clears enable and lock */
774 mtspr HID0, r3 /* clears invalidate */
781 rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
787 lis r5, CONFIG_SYS_CACHELINE_SIZE
791 lis r5, CONFIG_SYS_CACHELINE_SIZE
796 /*-------------------------------------------------------------------*/
799 * void relocate_code (addr_sp, gd, addr_moni)
801 * This "function" does not return, instead it continues in RAM
802 * after relocating the monitor code.
806 * r5 = length in bytes
811 mr r1, r3 /* Set new stack pointer */
812 mr r9, r4 /* Save copy of Global Data pointer */
813 mr r10, r5 /* Save copy of Destination Address */
816 mr r3, r5 /* Destination Address */
817 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
818 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
819 lwz r5, GOT(__bss_start)
821 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
826 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
827 * + Destination Address
833 /* First our own GOT */
835 /* then the one used by the C code */
845 beq cr1,4f /* In place copy is not necessary */
846 beq 7f /* Protect against 0 count */
875 2: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
883 * Now flush the cache: note that we must start from a cache aligned
884 * address. Otherwise we might miss one cache line.
888 beq 7f /* Always flush prefetch queue in any case */
896 sync /* Wait for all dcbst to complete on bus */
902 7: sync /* Wait for all icbi to complete on bus */
906 * We are done. Do not return, instead branch to second part of board
907 * initialization, now running from RAM.
909 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
916 * Relocation Function, r12 point to got2+0x8000
918 * Adjust got2 pointers, no need to check for 0, this code
919 * already puts a few entries in the table.
921 li r0,__got2_entries@sectoff@l
922 la r3,GOT(_GOT2_TABLE_)
923 lwz r11,GOT(_GOT2_TABLE_)
936 * Now adjust the fixups and the pointers to the fixups
937 * in case we need to move ourselves again.
939 li r0,__fixup_entries@sectoff@l
940 lwz r3,GOT(_FIXUP_TABLE_)
958 * Now clear BSS segment
960 lwz r3,GOT(__bss_start)
961 #if defined(CONFIG_HYMOD)
963 * For HYMOD - the environment is the very last item in flash.
964 * The real .bss stops just before environment starts, so only
965 * clear up to that point.
967 * taken from mods for FADS board
969 lwz r4,GOT(environment)
971 lwz r4,GOT(__bss_end)
985 mr r3, r9 /* Global Data pointer */
986 mr r4, r10 /* Destination Address */
991 * Copy exception vector code to low memory
994 * r7: source address, r8: end address, r9: target address
998 mflr r4 /* save link register */
1001 lwz r8, GOT(_end_of_vectors)
1003 li r9, 0x100 /* reset vector always at 0x100 */
1006 bgelr /* return if r7>=r8 - just in case */
1016 * relocate `hdlr' and `int_return' entries
1018 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
1019 li r8, Alignment - _start + EXC_OFF_SYS_RESET
1022 addi r7, r7, 0x100 /* next exception vector */
1026 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
1029 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
1032 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
1033 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
1036 addi r7, r7, 0x100 /* next exception vector */
1040 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
1041 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
1044 addi r7, r7, 0x100 /* next exception vector */
1048 mfmsr r3 /* now that the vectors have */
1049 lis r7, MSR_IP@h /* relocated into low memory */
1050 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
1051 andc r3, r3, r7 /* (if it was on) */
1052 SYNC /* Some chip revs need this... */
1056 mtlr r4 /* restore link register */
1059 #endif /* !MINIMAL_SPL */
1061 #ifdef CONFIG_SYS_INIT_RAM_LOCK
1063 /* Allocate Initial RAM in data cache.
1065 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1066 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
1067 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
1068 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
1075 /* Lock the data cache */
1077 ori r0, r0, HID0_DLOCK
1084 .globl unlock_ram_in_cache
1085 unlock_ram_in_cache:
1086 /* invalidate the INIT_RAM section */
1087 lis r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@h
1088 ori r3, r3, (CONFIG_SYS_INIT_RAM_ADDR & ~31)@l
1089 li r4, ((CONFIG_SYS_INIT_RAM_SIZE & ~31) + \
1090 (CONFIG_SYS_INIT_RAM_ADDR & 31) + 31) / 32
1096 sync /* Wait for all icbi to complete on bus */
1099 /* Unlock the data cache and invalidate it */
1101 li r5, HID0_DLOCK|HID0_DCFI
1102 andc r3, r3, r5 /* no invalidate, unlock */
1103 ori r5, r3, HID0_DCFI /* invalidate, unlock */
1105 mtspr HID0, r5 /* invalidate, unlock */
1107 mtspr HID0, r3 /* no invalidate, unlock */
1109 #endif /* !MINIMAL_SPL */
1110 #endif /* CONFIG_SYS_INIT_RAM_LOCK */
1112 #ifdef CONFIG_SYS_FLASHBOOT
1114 /* When booting from ROM (Flash or EPROM), clear the */
1115 /* Address Mask in OR0 so ROM appears everywhere */
1116 /*----------------------------------------------------*/
1117 lis r3, (CONFIG_SYS_IMMR)@h /* r3 <= CONFIG_SYS_IMMR */
1119 li r5, 0x7fff /* r5 <= 0x00007FFFF */
1121 stw r4, OR0@l(r3) /* OR0 <= OR0 & 0x00007FFFF */
1123 /* As MPC8349E User's Manual presented, when RCW[BMS] is set to 0,
1124 * system will boot from 0x0000_0100, and the LBLAWBAR0[BASE_ADDR]
1125 * reset value is 0x00000; when RCW[BMS] is set to 1, system will boot
1126 * from 0xFFF0_0100, and the LBLAWBAR0[BASE_ADDR] reset value is
1127 * 0xFF800. From the hard resetting to here, the processor fetched and
1128 * executed the instructions one by one. There is not absolutely
1129 * jumping happened. Laterly, the u-boot code has to do an absolutely
1130 * jumping to tell the CPU instruction fetching component what the
1131 * u-boot TEXT base address is. Because the TEXT base resides in the
1132 * boot ROM memory space, to garantee the code can run smoothly after
1133 * that jumping, we must map in the entire boot ROM by Local Access
1134 * Window. Sometimes, we desire an non-0x00000 or non-0xFF800 starting
1135 * address for boot ROM, such as 0xFE000000. In this case, the default
1136 * LBIU Local Access Widow 0 will not cover this memory space. So, we
1137 * need another window to map in it.
1139 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1140 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1141 stw r4, LBLAWBAR1(r3) /* LBLAWBAR1 <= CONFIG_SYS_FLASH_BASE */
1143 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR1 */
1144 lis r4, (0x80000012)@h
1145 ori r4, r4, (0x80000012)@l
1146 li r5, CONFIG_SYS_FLASH_SIZE
1147 1: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1151 stw r4, LBLAWAR1(r3) /* LBLAWAR1 <= 8MB Flash Size */
1152 /* Wait for HW to catch up */
1153 lwz r4, LBLAWAR1(r3)
1158 /* Though all the LBIU Local Access Windows and LBC Banks will be
1159 * initialized in the C code, we'd better configure boot ROM's
1160 * window 0 and bank 0 correctly at here.
1162 remap_flash_by_law0:
1163 /* Initialize the BR0 with the boot ROM starting address. */
1167 lis r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@h
1168 ori r5, r5, (CONFIG_SYS_FLASH_BASE & 0xFFFF8000)@l
1170 stw r5, BR0(r3) /* r5 <= (CONFIG_SYS_FLASH_BASE & 0xFFFF8000) | (BR0 & 0x00007FFF) */
1173 lis r5, ~((CONFIG_SYS_FLASH_SIZE << 4) - 1)
1177 lis r4, (CONFIG_SYS_FLASH_BASE)@h
1178 ori r4, r4, (CONFIG_SYS_FLASH_BASE)@l
1179 stw r4, LBLAWBAR0(r3) /* LBLAWBAR0 <= CONFIG_SYS_FLASH_BASE */
1181 /* Store 0x80000012 + log2(CONFIG_SYS_FLASH_SIZE) into LBLAWAR0 */
1182 lis r4, (0x80000012)@h
1183 ori r4, r4, (0x80000012)@l
1184 li r5, CONFIG_SYS_FLASH_SIZE
1185 1: srawi. r5, r5, 1 /* r5 = r5 >> 1 */
1188 stw r4, LBLAWAR0(r3) /* LBLAWAR0 <= Flash Size */
1192 stw r4, LBLAWBAR1(r3)
1193 stw r4, LBLAWAR1(r3) /* Off LBIU LAW1 */
1194 /* Wait for HW to catch up */
1195 lwz r4, LBLAWAR1(r3)
1199 #endif /* CONFIG_SYS_FLASHBOOT */