3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 /* U-Boot - Startup Code for PowerPC based Embedded Boards
29 * The processor starts at 0xfff00100 and the code is executed
30 * from flash. The code is organized to be at an other address
31 * in memory, but as long we don't jump around before relocating.
32 * board_init lies at a quite high address and when the cpu has
33 * jumped there, everything is ok.
39 #include <ppc_asm.tmpl>
42 #include <asm/cache.h>
45 #include <galileo/gt64260R.h>
47 #ifndef CONFIG_IDENT_STRING
48 #define CONFIG_IDENT_STRING ""
51 /* We don't want the MMU yet.
54 /* Machine Check and Recoverable Interr. */
55 #define MSR_KERNEL ( MSR_ME | MSR_RI )
58 * Set up GOT: Global Offset Table
60 * Use r14 to access the GOT
63 GOT_ENTRY(_GOT2_TABLE_)
64 GOT_ENTRY(_FIXUP_TABLE_)
67 GOT_ENTRY(_start_of_vectors)
68 GOT_ENTRY(_end_of_vectors)
69 GOT_ENTRY(transfer_to_handler)
73 GOT_ENTRY(__bss_start)
77 * r3 - 1st arg to board_init(): IMMP pointer
78 * r4 - 2nd arg to board_init(): boot flag
81 .long 0x27051956 /* U-Boot Magic Number */
85 .ascii " (", __DATE__, " - ", __TIME__, ")"
86 .ascii CONFIG_IDENT_STRING, "\0"
91 li r21, BOOTFLAG_COLD /* Normal Power-On: Boot from FLASH */
95 . = EXC_OFF_SYS_RESET + 0x10
99 li r21, BOOTFLAG_WARM /* Software reboot */
103 /* the boot code is located below the exception table */
105 .globl _start_of_vectors
109 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
111 /* Data Storage exception. "Never" generated on the 860. */
112 STD_EXCEPTION(0x300, DataStorage, UnknownException)
114 /* Instruction Storage exception. "Never" generated on the 860. */
115 STD_EXCEPTION(0x400, InstStorage, UnknownException)
117 /* External Interrupt exception. */
118 STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
120 /* Alignment exception. */
128 addi r3,r1,STACK_FRAME_OVERHEAD
130 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
131 lwz r6,GOT(transfer_to_handler)
135 .long AlignmentException - _start + EXC_OFF_SYS_RESET
136 .long int_return - _start + EXC_OFF_SYS_RESET
138 /* Program check exception */
142 addi r3,r1,STACK_FRAME_OVERHEAD
144 rlwimi r20,r23,0,16,16 /* copy EE bit from saved MSR */
145 lwz r6,GOT(transfer_to_handler)
149 .long ProgramCheckException - _start + EXC_OFF_SYS_RESET
150 .long int_return - _start + EXC_OFF_SYS_RESET
152 /* No FPU on MPC8xx. This exception is not supposed to happen.
154 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
156 /* I guess we could implement decrementer, and may have
157 * to someday for timekeeping.
159 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
160 STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
161 STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
162 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
163 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
165 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
166 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
169 * On the MPC8xx, this is a software emulation interrupt. It
170 * occurs for all unimplemented and illegal instructions.
172 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
174 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
175 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
176 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
177 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
179 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
180 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
181 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
182 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
183 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
184 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
185 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
187 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
188 STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
189 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
190 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
192 .globl _end_of_vectors
199 /* disable everything */
208 /* init the L2 cache */
209 addis r3, r0, L2_INIT@h
210 ori r3, r3, L2_INIT@l
214 #if defined(CONFIG_ALTIVEC) && defined(CONFIG_74xx)
217 * dssall instruction, gas doesn't have it yet
218 * ...for altivec, data stream stop all this probably
219 * isn't needed unless we warm (software) reboot U-Boot
224 /* invalidate the L2 cache */
225 bl l2cache_invalidate
228 #ifdef CFG_BOARD_ASM_INIT
234 * Calculate absolute address in FLASH and jump there
235 *------------------------------------------------------*/
236 lis r3, CFG_MONITOR_BASE@h
237 ori r3, r3, CFG_MONITOR_BASE@l
238 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
243 /* let the C-code set up the rest */
245 /* Be careful to keep code relocatable ! */
246 /*------------------------------------------------------*/
248 /* perform low-level init */
249 /* sdram init, galileo init, etc */
250 /* r3: NHR bit from HID0 */
257 * Cache must be enabled here for stack-in-cache trick.
258 * This means we need to enable the BATS.
260 * 1) for the EVB, original gt regs need to be mapped
261 * 2) need to have an IBAT for the 0xf region,
262 * we are running there!
263 * Cache should be turned on after BATs, since by default
264 * everything is write-through.
265 * The init-mem BAT can be reused after reloc. The old
266 * gt-regs BAT can be reused after board_init_f calls
267 * board_pre_init (EVB only).
269 #if !defined(CONFIG_BAB7xx) && !defined(CONFIG_ELPPC)
270 /* enable address translation */
274 /* enable and invalidate the data cache */
278 #ifdef CFG_INIT_RAM_LOCK
283 /* set up the stack pointer in our newly created
285 lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
286 ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
288 li r0, 0 /* Make room for stack frame header and */
289 stwu r0, -4(r1) /* clear final stack frame so that */
290 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
292 GET_GOT /* initialize GOT access */
294 /* run low-level CPU init code (from Flash) */
301 /* run 1st part of board init code (from Flash) */
307 .globl invalidate_bats
309 /* invalidate BATs */
335 /* setup_bats - set them up to some initial state */
341 addis r4, r0, CFG_IBAT0L@h
342 ori r4, r4, CFG_IBAT0L@l
343 addis r3, r0, CFG_IBAT0U@h
344 ori r3, r3, CFG_IBAT0U@l
350 addis r4, r0, CFG_DBAT0L@h
351 ori r4, r4, CFG_DBAT0L@l
352 addis r3, r0, CFG_DBAT0U@h
353 ori r3, r3, CFG_DBAT0U@l
359 addis r4, r0, CFG_IBAT1L@h
360 ori r4, r4, CFG_IBAT1L@l
361 addis r3, r0, CFG_IBAT1U@h
362 ori r3, r3, CFG_IBAT1U@l
368 addis r4, r0, CFG_DBAT1L@h
369 ori r4, r4, CFG_DBAT1L@l
370 addis r3, r0, CFG_DBAT1U@h
371 ori r3, r3, CFG_DBAT1U@l
377 addis r4, r0, CFG_IBAT2L@h
378 ori r4, r4, CFG_IBAT2L@l
379 addis r3, r0, CFG_IBAT2U@h
380 ori r3, r3, CFG_IBAT2U@l
386 addis r4, r0, CFG_DBAT2L@h
387 ori r4, r4, CFG_DBAT2L@l
388 addis r3, r0, CFG_DBAT2U@h
389 ori r3, r3, CFG_DBAT2U@l
395 addis r4, r0, CFG_IBAT3L@h
396 ori r4, r4, CFG_IBAT3L@l
397 addis r3, r0, CFG_IBAT3U@h
398 ori r3, r3, CFG_IBAT3U@l
404 addis r4, r0, CFG_DBAT3L@h
405 ori r4, r4, CFG_DBAT3L@l
406 addis r3, r0, CFG_DBAT3U@h
407 ori r3, r3, CFG_DBAT3U@l
414 addis r4, r0, CFG_IBAT4L@h
415 ori r4, r4, CFG_IBAT4L@l
416 addis r3, r0, CFG_IBAT4U@h
417 ori r3, r3, CFG_IBAT4U@l
423 addis r4, r0, CFG_DBAT4L@h
424 ori r4, r4, CFG_DBAT4L@l
425 addis r3, r0, CFG_DBAT4U@h
426 ori r3, r3, CFG_DBAT4U@l
432 addis r4, r0, CFG_IBAT5L@h
433 ori r4, r4, CFG_IBAT5L@l
434 addis r3, r0, CFG_IBAT5U@h
435 ori r3, r3, CFG_IBAT5U@l
441 addis r4, r0, CFG_DBAT5L@h
442 ori r4, r4, CFG_DBAT5L@l
443 addis r3, r0, CFG_DBAT5U@h
444 ori r3, r3, CFG_DBAT5U@l
450 addis r4, r0, CFG_IBAT6L@h
451 ori r4, r4, CFG_IBAT6L@l
452 addis r3, r0, CFG_IBAT6U@h
453 ori r3, r3, CFG_IBAT6U@l
459 addis r4, r0, CFG_DBAT6L@h
460 ori r4, r4, CFG_DBAT6L@l
461 addis r3, r0, CFG_DBAT6U@h
462 ori r3, r3, CFG_DBAT6U@l
468 addis r4, r0, CFG_IBAT7L@h
469 ori r4, r4, CFG_IBAT7L@l
470 addis r3, r0, CFG_IBAT7U@h
471 ori r3, r3, CFG_IBAT7U@l
477 addis r4, r0, CFG_DBAT7L@h
478 ori r4, r4, CFG_DBAT7L@l
479 addis r3, r0, CFG_DBAT7U@h
480 ori r3, r3, CFG_DBAT7U@l
486 /* bats are done, now invalidate the TLBs */
489 addis r5, 0, 0x4 /* upper bound of 0x00040000 for 7400/750 */
502 .globl enable_addr_trans
504 /* enable address translation */
506 ori r5, r5, (MSR_IR | MSR_DR)
511 .globl disable_addr_trans
513 /* disable address translation */
516 andi. r0, r3, (MSR_IR | MSR_DR)
524 * This code finishes saving the registers to the exception frame
525 * and jumps to the appropriate handler for the exception.
526 * Register r21 is pointer into trap frame, r1 has new stack pointer.
528 .globl transfer_to_handler
539 andi. r24,r23,0x3f00 /* get vector offset */
543 mtspr SPRG2,r22 /* r1 is now kernel sp */
544 lwz r24,0(r23) /* virtual address of handler */
545 lwz r23,4(r23) /* where to go when done */
550 rfi /* jump to handler, enable MMU */
553 mfmsr r28 /* Disable interrupts */
557 SYNC /* Some chip revs need this... */
572 lwz r2,_NIP(r1) /* Restore environment */
591 /*-----------------------------------------------------------------------*/
593 * void relocate_code (addr_sp, gd, addr_moni)
595 * This "function" does not return, instead it continues in RAM
596 * after relocating the monitor code.
600 * r5 = length in bytes
605 mr r1, r3 /* Set new stack pointer */
606 mr r9, r4 /* Save copy of Global Data pointer */
607 mr r10, r5 /* Save copy of Destination Address */
609 mr r3, r5 /* Destination Address */
610 lis r4, CFG_MONITOR_BASE@h /* Source Address */
611 ori r4, r4, CFG_MONITOR_BASE@l
612 lwz r5, GOT(__init_end)
614 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
619 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
625 /* First our own GOT */
627 /* then the one used by the C code */
634 bl board_relocate_rom
636 mr r3, r10 /* Destination Address */
637 lis r4, CFG_MONITOR_BASE@h /* Source Address */
638 ori r4, r4, CFG_MONITOR_BASE@l
639 lwz r5, GOT(__init_end)
641 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
646 beq cr1,4f /* In place copy is not necessary */
647 beq 7f /* Protect against 0 count */
666 * Now flush the cache: note that we must start from a cache aligned
667 * address. Otherwise we might miss one cache line.
671 beq 7f /* Always flush prefetch queue in any case */
679 sync /* Wait for all dcbst to complete on bus */
685 7: sync /* Wait for all icbi to complete on bus */
689 * We are done. Do not return, instead branch to second part of board
690 * initialization, now running from RAM.
692 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
701 * Relocation Function, r14 point to got2+0x8000
703 * Adjust got2 pointers, no need to check for 0, this code
704 * already puts a few entries in the table.
706 li r0,__got2_entries@sectoff@l
707 la r3,GOT(_GOT2_TABLE_)
708 lwz r11,GOT(_GOT2_TABLE_)
718 * Now adjust the fixups and the pointers to the fixups
719 * in case we need to move ourselves again.
721 2: li r0,__fixup_entries@sectoff@l
722 lwz r3,GOT(_FIXUP_TABLE_)
736 * Now clear BSS segment
738 lwz r3,GOT(__bss_start)
751 mr r3, r10 /* Destination Address */
752 #ifdef CONFIG_AMIGAONEG3SE
753 mr r4, r9 /* Use RAM copy of the global data */
757 /* not reached - end relocate_code */
758 /*-----------------------------------------------------------------------*/
761 * Copy exception vector code to low memory
764 * r7: source address, r8: end address, r9: target address
769 lwz r8, GOT(_end_of_vectors)
771 li r9, 0x100 /* reset vector always at 0x100 */
774 bgelr /* return if r7>=r8 - just in case */
776 mflr r4 /* save link register */
786 * relocate `hdlr' and `int_return' entries
788 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
789 li r8, Alignment - _start + EXC_OFF_SYS_RESET
792 addi r7, r7, 0x100 /* next exception vector */
796 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
799 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
802 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
803 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
806 addi r7, r7, 0x100 /* next exception vector */
810 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
811 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
814 addi r7, r7, 0x100 /* next exception vector */
818 /* enable execptions from RAM vectors */
824 mtlr r4 /* restore link register */
828 * Function: relocate entries for one exception vector
831 lwz r0, 0(r7) /* hdlr ... */
832 add r0, r0, r3 /* ... += dest_addr */
835 lwz r0, 4(r7) /* int_return ... */
836 add r0, r0, r3 /* ... += dest_addr */
844 #ifdef CFG_INIT_RAM_LOCK
846 /* Allocate Initial RAM in data cache.
848 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
849 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
850 li r2, ((CFG_INIT_RAM_END & ~31) + \
851 (CFG_INIT_RAM_ADDR & 31) + 31) / 32
858 /* Lock the data cache */
866 .globl unlock_ram_in_cache
868 /* invalidate the INIT_RAM section */
869 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
870 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
871 li r2, ((CFG_INIT_RAM_END & ~31) + \
872 (CFG_INIT_RAM_ADDR & 31) + 31) / 32
877 sync /* Wait for all icbi to complete on bus */
880 /* Unlock the data cache and invalidate it */