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)
165 * r0 - SYSCALL number
169 addis r11,r0,0 /* get functions table addr */
170 ori r11,r11,0 /* Note: this code is patched in trap_init */
171 addis r12,r0,0 /* get number of functions */
177 rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
181 li r20,0xd00-4 /* Get stack pointer */
183 subi r12,r12,12 /* Adjust stack pointer */
184 li r0,0xc00+_end_back-SystemCall
185 cmplw 0, r0, r12 /* Check stack overflow */
196 li r12,0xc00+_back-SystemCall
205 mfmsr r11 /* Disable interrupts */
209 SYNC /* Some chip revs need this... */
213 li r12,0xd00-4 /* restore regs */
223 addi r12,r12,12 /* Adjust stack pointer */
231 STD_EXCEPTION(0xd00, SingleStep, UnknownException)
233 STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
234 STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
237 * On the MPC8xx, this is a software emulation interrupt. It
238 * occurs for all unimplemented and illegal instructions.
240 STD_EXCEPTION(0x1000, SoftEmu, SoftEmuException)
242 STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
243 STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
244 STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
245 STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
247 STD_EXCEPTION(0x1500, Reserved5, UnknownException)
248 STD_EXCEPTION(0x1600, Reserved6, UnknownException)
249 STD_EXCEPTION(0x1700, Reserved7, UnknownException)
250 STD_EXCEPTION(0x1800, Reserved8, UnknownException)
251 STD_EXCEPTION(0x1900, Reserved9, UnknownException)
252 STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
253 STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
255 STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
256 STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
257 STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
258 STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
260 .globl _end_of_vectors
267 /* disable everything */
276 /* init the L2 cache */
277 addis r3, r0, L2_INIT@h
278 ori r3, r3, L2_INIT@l
282 #if defined(CONFIG_ALTIVEC) && defined(CONFIG_74xx)
285 * dssall instruction, gas doesn't have it yet
286 * ...for altivec, data stream stop all this probably
287 * isn't needed unless we warm (software) reboot U-Boot
292 /* invalidate the L2 cache */
293 bl l2cache_invalidate
296 #ifdef CFG_BOARD_ASM_INIT
302 * Calculate absolute address in FLASH and jump there
303 *------------------------------------------------------*/
304 lis r3, CFG_MONITOR_BASE@h
305 ori r3, r3, CFG_MONITOR_BASE@l
306 addi r3, r3, in_flash - _start + EXC_OFF_SYS_RESET
311 /* let the C-code set up the rest */
313 /* Be careful to keep code relocatable ! */
314 /*------------------------------------------------------*/
316 /* perform low-level init */
317 /* sdram init, galileo init, etc */
318 /* r3: NHR bit from HID0 */
325 * Cache must be enabled here for stack-in-cache trick.
326 * This means we need to enable the BATS.
328 * 1) for the EVB, original gt regs need to be mapped
329 * 2) need to have an IBAT for the 0xf region,
330 * we are running there!
331 * Cache should be turned on after BATs, since by default
332 * everything is write-through.
333 * The init-mem BAT can be reused after reloc. The old
334 * gt-regs BAT can be reused after board_init_f calls
335 * board_pre_init (EVB only).
337 #if !defined(CONFIG_BAB7xx) && !defined(CONFIG_ELPPC)
338 /* enable address translation */
342 /* enable and invalidate the data cache */
346 #ifdef CFG_INIT_RAM_LOCK
351 /* set up the stack pointer in our newly created
353 lis r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@h
354 ori r1, r1, (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET)@l
356 li r0, 0 /* Make room for stack frame header and */
357 stwu r0, -4(r1) /* clear final stack frame so that */
358 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
360 GET_GOT /* initialize GOT access */
362 /* run low-level CPU init code (from Flash) */
369 /* run 1st part of board init code (from Flash) */
375 .globl invalidate_bats
377 /* invalidate BATs */
403 /* setup_bats - set them up to some initial state */
409 addis r4, r0, CFG_IBAT0L@h
410 ori r4, r4, CFG_IBAT0L@l
411 addis r3, r0, CFG_IBAT0U@h
412 ori r3, r3, CFG_IBAT0U@l
418 addis r4, r0, CFG_DBAT0L@h
419 ori r4, r4, CFG_DBAT0L@l
420 addis r3, r0, CFG_DBAT0U@h
421 ori r3, r3, CFG_DBAT0U@l
427 addis r4, r0, CFG_IBAT1L@h
428 ori r4, r4, CFG_IBAT1L@l
429 addis r3, r0, CFG_IBAT1U@h
430 ori r3, r3, CFG_IBAT1U@l
436 addis r4, r0, CFG_DBAT1L@h
437 ori r4, r4, CFG_DBAT1L@l
438 addis r3, r0, CFG_DBAT1U@h
439 ori r3, r3, CFG_DBAT1U@l
445 addis r4, r0, CFG_IBAT2L@h
446 ori r4, r4, CFG_IBAT2L@l
447 addis r3, r0, CFG_IBAT2U@h
448 ori r3, r3, CFG_IBAT2U@l
454 addis r4, r0, CFG_DBAT2L@h
455 ori r4, r4, CFG_DBAT2L@l
456 addis r3, r0, CFG_DBAT2U@h
457 ori r3, r3, CFG_DBAT2U@l
463 addis r4, r0, CFG_IBAT3L@h
464 ori r4, r4, CFG_IBAT3L@l
465 addis r3, r0, CFG_IBAT3U@h
466 ori r3, r3, CFG_IBAT3U@l
472 addis r4, r0, CFG_DBAT3L@h
473 ori r4, r4, CFG_DBAT3L@l
474 addis r3, r0, CFG_DBAT3U@h
475 ori r3, r3, CFG_DBAT3U@l
482 addis r4, r0, CFG_IBAT4L@h
483 ori r4, r4, CFG_IBAT4L@l
484 addis r3, r0, CFG_IBAT4U@h
485 ori r3, r3, CFG_IBAT4U@l
491 addis r4, r0, CFG_DBAT4L@h
492 ori r4, r4, CFG_DBAT4L@l
493 addis r3, r0, CFG_DBAT4U@h
494 ori r3, r3, CFG_DBAT4U@l
500 addis r4, r0, CFG_IBAT5L@h
501 ori r4, r4, CFG_IBAT5L@l
502 addis r3, r0, CFG_IBAT5U@h
503 ori r3, r3, CFG_IBAT5U@l
509 addis r4, r0, CFG_DBAT5L@h
510 ori r4, r4, CFG_DBAT5L@l
511 addis r3, r0, CFG_DBAT5U@h
512 ori r3, r3, CFG_DBAT5U@l
518 addis r4, r0, CFG_IBAT6L@h
519 ori r4, r4, CFG_IBAT6L@l
520 addis r3, r0, CFG_IBAT6U@h
521 ori r3, r3, CFG_IBAT6U@l
527 addis r4, r0, CFG_DBAT6L@h
528 ori r4, r4, CFG_DBAT6L@l
529 addis r3, r0, CFG_DBAT6U@h
530 ori r3, r3, CFG_DBAT6U@l
536 addis r4, r0, CFG_IBAT7L@h
537 ori r4, r4, CFG_IBAT7L@l
538 addis r3, r0, CFG_IBAT7U@h
539 ori r3, r3, CFG_IBAT7U@l
545 addis r4, r0, CFG_DBAT7L@h
546 ori r4, r4, CFG_DBAT7L@l
547 addis r3, r0, CFG_DBAT7U@h
548 ori r3, r3, CFG_DBAT7U@l
554 /* bats are done, now invalidate the TLBs */
557 addis r5, 0, 0x4 /* upper bound of 0x00040000 for 7400/750 */
570 .globl enable_addr_trans
572 /* enable address translation */
574 ori r5, r5, (MSR_IR | MSR_DR)
579 .globl disable_addr_trans
581 /* disable address translation */
584 andi. r0, r3, (MSR_IR | MSR_DR)
592 * This code finishes saving the registers to the exception frame
593 * and jumps to the appropriate handler for the exception.
594 * Register r21 is pointer into trap frame, r1 has new stack pointer.
596 .globl transfer_to_handler
607 andi. r24,r23,0x3f00 /* get vector offset */
611 mtspr SPRG2,r22 /* r1 is now kernel sp */
612 lwz r24,0(r23) /* virtual address of handler */
613 lwz r23,4(r23) /* where to go when done */
618 rfi /* jump to handler, enable MMU */
621 mfmsr r28 /* Disable interrupts */
625 SYNC /* Some chip revs need this... */
640 lwz r2,_NIP(r1) /* Restore environment */
659 /*-----------------------------------------------------------------------*/
661 * void relocate_code (addr_sp, gd, addr_moni)
663 * This "function" does not return, instead it continues in RAM
664 * after relocating the monitor code.
668 * r5 = length in bytes
673 mr r1, r3 /* Set new stack pointer */
674 mr r9, r4 /* Save copy of Global Data pointer */
675 mr r10, r5 /* Save copy of Destination Address */
677 mr r3, r5 /* Destination Address */
678 lis r4, CFG_MONITOR_BASE@h /* Source Address */
679 ori r4, r4, CFG_MONITOR_BASE@l
680 lwz r5, GOT(__init_end)
682 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
687 * New GOT-PTR = (old GOT-PTR - CFG_MONITOR_BASE) + Destination Address
693 /* First our own GOT */
695 /* then the one used by the C code */
702 bl board_relocate_rom
704 mr r3, r10 /* Destination Address */
705 lis r4, CFG_MONITOR_BASE@h /* Source Address */
706 ori r4, r4, CFG_MONITOR_BASE@l
707 lwz r5, GOT(__init_end)
709 li r6, CFG_CACHELINE_SIZE /* Cache Line Size */
714 beq cr1,4f /* In place copy is not necessary */
715 beq 7f /* Protect against 0 count */
734 * Now flush the cache: note that we must start from a cache aligned
735 * address. Otherwise we might miss one cache line.
739 beq 7f /* Always flush prefetch queue in any case */
747 sync /* Wait for all dcbst to complete on bus */
753 7: sync /* Wait for all icbi to complete on bus */
757 * We are done. Do not return, instead branch to second part of board
758 * initialization, now running from RAM.
760 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
769 * Relocation Function, r14 point to got2+0x8000
771 * Adjust got2 pointers, no need to check for 0, this code
772 * already puts a few entries in the table.
774 li r0,__got2_entries@sectoff@l
775 la r3,GOT(_GOT2_TABLE_)
776 lwz r11,GOT(_GOT2_TABLE_)
786 * Now adjust the fixups and the pointers to the fixups
787 * in case we need to move ourselves again.
789 2: li r0,__fixup_entries@sectoff@l
790 lwz r3,GOT(_FIXUP_TABLE_)
804 * Now clear BSS segment
806 lwz r3,GOT(__bss_start)
819 mr r3, r10 /* Destination Address */
820 #ifdef CONFIG_AMIGAONEG3SE
821 mr r4, r9 /* Use RAM copy of the global data */
825 /* not reached - end relocate_code */
826 /*-----------------------------------------------------------------------*/
829 * Copy exception vector code to low memory
832 * r7: source address, r8: end address, r9: target address
837 lwz r8, GOT(_end_of_vectors)
839 li r9, 0x100 /* reset vector always at 0x100 */
842 bgelr /* return if r7>=r8 - just in case */
844 mflr r4 /* save link register */
854 * relocate `hdlr' and `int_return' entries
856 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
857 li r8, Alignment - _start + EXC_OFF_SYS_RESET
860 addi r7, r7, 0x100 /* next exception vector */
864 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
867 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
870 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
871 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
874 addi r7, r7, 0x100 /* next exception vector */
878 li r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
879 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
882 addi r7, r7, 0x100 /* next exception vector */
886 /* enable execptions from RAM vectors */
892 mtlr r4 /* restore link register */
896 * Function: relocate entries for one exception vector
899 lwz r0, 0(r7) /* hdlr ... */
900 add r0, r0, r3 /* ... += dest_addr */
903 lwz r0, 4(r7) /* int_return ... */
904 add r0, r0, r3 /* ... += dest_addr */
912 #ifdef CFG_INIT_RAM_LOCK
914 /* Allocate Initial RAM in data cache.
916 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
917 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
918 li r2, ((CFG_INIT_RAM_END & ~31) + \
919 (CFG_INIT_RAM_ADDR & 31) + 31) / 32
926 /* Lock the data cache */
934 .globl unlock_ram_in_cache
936 /* invalidate the INIT_RAM section */
937 lis r3, (CFG_INIT_RAM_ADDR & ~31)@h
938 ori r3, r3, (CFG_INIT_RAM_ADDR & ~31)@l
939 li r2, ((CFG_INIT_RAM_END & ~31) + \
940 (CFG_INIT_RAM_ADDR & 31) + 31) / 32
945 sync /* Wait for all icbi to complete on bus */
948 /* Unlock the data cache and invalidate it */