3 * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
5 * Copyright Freescale Semiconductor, Inc. 2004, 2006.
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,
25 * Based on the MPC83xx code.
29 * U-Boot - Startup Code for MPC512x based Embedded Boards
33 #include <timestamp.h>
36 #define CONFIG_521X 1 /* needed for Linux kernel header files*/
38 #include <asm/immap_512x.h>
39 #include "asm-offsets.h"
41 #include <ppc_asm.tmpl>
44 #include <asm/cache.h>
47 #ifndef CONFIG_IDENT_STRING
48 #define CONFIG_IDENT_STRING "MPC512X"
52 * Floating Point enable, Machine Check and Recoverable Interr.
56 #define MSR_KERNEL (MSR_FP|MSR_RI)
58 #define MSR_KERNEL (MSR_FP|MSR_ME|MSR_RI)
61 /* Macros for manipulating CSx_START/STOP */
62 #define START_REG(start) ((start) >> 16)
63 #define STOP_REG(start, size) (((start) + (size) - 1) >> 16)
66 * Set up GOT: Global Offset Table
68 * Use r12 to access the GOT
71 GOT_ENTRY(_GOT2_TABLE_)
72 GOT_ENTRY(_FIXUP_TABLE_)
75 GOT_ENTRY(_start_of_vectors)
76 GOT_ENTRY(_end_of_vectors)
77 GOT_ENTRY(transfer_to_handler)
81 GOT_ENTRY(__bss_start)
85 * Magic number and version string
87 .long 0x27051956 /* U-Boot Magic Number */
91 .ascii " (", U_BOOT_DATE, " - ", U_BOOT_TIME, ")"
92 .ascii " ", CONFIG_IDENT_STRING, "\0"
101 /* Start from here after reset/power on */
105 .globl _start_of_vectors
109 STD_EXCEPTION(0x200, MachineCheck, MachineCheckException)
111 /* Data Storage exception. */
112 STD_EXCEPTION(0x300, DataStorage, UnknownException)
114 /* Instruction Storage exception. */
115 STD_EXCEPTION(0x400, InstStorage, UnknownException)
117 /* External Interrupt exception. */
118 STD_EXCEPTION(0x500, ExtInterrupt, UnknownException)
120 /* Alignment exception. */
123 EXCEPTION_PROLOG(SRR0, SRR1)
128 addi r3,r1,STACK_FRAME_OVERHEAD
129 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
131 /* Program check exception */
134 EXCEPTION_PROLOG(SRR0, SRR1)
135 addi r3,r1,STACK_FRAME_OVERHEAD
136 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
139 /* Floating Point Unit unavailable exception */
140 STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
143 STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
145 /* Critical interrupt */
146 STD_EXCEPTION(0xa00, Critical, UnknownException)
149 STD_EXCEPTION(0xc00, SystemCall, UnknownException)
151 /* Trace interrupt */
152 STD_EXCEPTION(0xd00, Trace, UnknownException)
154 /* Performance Monitor interrupt */
155 STD_EXCEPTION(0xf00, PerfMon, UnknownException)
157 /* Intruction Translation Miss */
158 STD_EXCEPTION(0x1000, InstructionTLBMiss, UnknownException)
160 /* Data Load Translation Miss */
161 STD_EXCEPTION(0x1100, DataLoadTLBMiss, UnknownException)
163 /* Data Store Translation Miss */
164 STD_EXCEPTION(0x1200, DataStoreTLBMiss, UnknownException)
166 /* Instruction Address Breakpoint */
167 STD_EXCEPTION(0x1300, InstructionAddrBreakpoint, DebugException)
169 /* System Management interrupt */
170 STD_EXCEPTION(0x1400, SystemMgmtInterrupt, UnknownException)
172 .globl _end_of_vectors
177 /* Save msr contents */
180 /* Set IMMR area to our preferred location */
181 lis r4, CONFIG_DEFAULT_IMMR@h
182 lis r3, CONFIG_SYS_IMMR@h
183 ori r3, r3, CONFIG_SYS_IMMR@l
185 mtspr MBAR, r3 /* IMMRBAR is mirrored into the MBAR SPR (311) */
187 /* Initialise the machine */
191 * Set up Local Access Windows:
193 * 1) Boot/CS0 (boot FLASH)
194 * 2) On-chip SRAM (initial stack purposes)
197 /* Boot CS/CS0 window range */
198 lis r3, CONFIG_SYS_IMMR@h
199 ori r3, r3, CONFIG_SYS_IMMR@l
201 lis r4, START_REG(CONFIG_SYS_FLASH_BASE)
202 ori r4, r4, STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE)
206 * The SRAM window has a fixed size (256K), so only the start address
209 lis r4, START_REG(CONFIG_SYS_SRAM_BASE) & 0xff00
213 * According to MPC5121e RM, configuring local access windows should
214 * be followed by a dummy read of the config register that was
215 * modified last and an isync
221 * Set configuration of the Boot/CS0, the SRAM window does not have a
222 * config register so no params can be set for it
224 lis r3, (CONFIG_SYS_IMMR + LPC_OFFSET)@h
225 ori r3, r3, (CONFIG_SYS_IMMR + LPC_OFFSET)@l
227 lis r4, CONFIG_SYS_CS0_CFG@h
228 ori r4, r4, CONFIG_SYS_CS0_CFG@l
229 stw r4, CS0_CONFIG(r3)
231 /* Master enable all CS's */
233 ori r4, r4, CS_CTRL_ME@l
236 lis r4, (CONFIG_SYS_MONITOR_BASE)@h
237 ori r4, r4, (CONFIG_SYS_MONITOR_BASE)@l
238 addi r5, r4, in_flash - _start + EXC_OFF_SYS_RESET
243 lis r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
244 ori r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
246 li r0, 0 /* Make room for stack frame header and */
247 stwu r0, -4(r1) /* clear final stack frame so that */
248 stwu r0, -4(r1) /* stack backtraces terminate cleanly */
250 /* let the C-code set up the rest */
252 /* Be careful to keep code relocatable & stack humble */
253 /*------------------------------------------------------*/
255 GET_GOT /* initialize GOT access */
258 lis r3, CONFIG_SYS_IMMR@h
259 /* run low-level CPU init code (in Flash) */
262 /* run 1st part of board init code (in Flash) */
265 /* NOTREACHED - board_init_f() does not return */
268 * This code finishes saving the registers to the exception frame
269 * and jumps to the appropriate handler for the exception.
270 * Register r21 is pointer into trap frame, r1 has new stack pointer.
272 .globl transfer_to_handler
283 andi. r24,r23,0x3f00 /* get vector offset */
287 lwz r24,0(r23) /* virtual address of handler */
288 lwz r23,4(r23) /* where to go when done */
293 rfi /* jump to handler, enable MMU */
296 mfmsr r28 /* Disable interrupts */
300 SYNC /* Some chip revs need this... */
315 lwz r2,_NIP(r1) /* Restore environment */
326 * This code initialises the machine, it expects original MSR contents to be in r5.
329 /* Initialize machine status; enable machine check interrupt */
330 /*-----------------------------------------------------------*/
332 li r3, MSR_KERNEL /* Set ME and RI flags */
333 rlwimi r3, r5, 0, 25, 25 /* preserve IP bit */
335 rlwimi r3, r5, 0, 21, 22 /* debugger might set SE, BE bits */
339 mtspr SRR1, r3 /* Mirror current MSR state in SRR1 */
341 lis r3, CONFIG_SYS_IMMR@h
343 #if defined(CONFIG_WATCHDOG)
344 /* Initialise the watchdog and reset it */
345 /*--------------------------------------*/
346 lis r4, CONFIG_SYS_WATCHDOG_VALUE
347 ori r4, r4, (SWCRR_SWEN | SWCRR_SWRI | SWCRR_SWPR)
357 /* Disable the watchdog */
358 /*----------------------*/
361 * Check to see if it's enabled for disabling: once disabled by s/w
362 * it's not possible to re-enable it
369 #endif /* CONFIG_WATCHDOG */
371 /* Initialize the Hardware Implementation-dependent Registers */
372 /* HID0 also contains cache control */
373 /*------------------------------------------------------*/
374 lis r3, CONFIG_SYS_HID0_INIT@h
375 ori r3, r3, CONFIG_SYS_HID0_INIT@l
379 lis r3, CONFIG_SYS_HID0_FINAL@h
380 ori r3, r3, CONFIG_SYS_HID0_FINAL@l
384 lis r3, CONFIG_SYS_HID2@h
385 ori r3, r3, CONFIG_SYS_HID2@l
394 * Note: requires that all cache bits in
395 * HID0 are in the low half word.
402 ori r4, r4, HID0_ILOCK
404 ori r4, r3, HID0_ICFI
406 mtspr HID0, r4 /* sets enable and invalidate, clears lock */
408 mtspr HID0, r3 /* clears invalidate */
411 .globl icache_disable
415 ori r4, r4, HID0_ICE|HID0_ILOCK
417 ori r4, r3, HID0_ICFI
419 mtspr HID0, r4 /* sets invalidate, clears enable and lock*/
421 mtspr HID0, r3 /* clears invalidate */
427 rlwinm r3, r3, (31 - HID0_ICE_SHIFT + 1), 31, 31
433 li r5, HID0_DCFI|HID0_DLOCK
435 mtspr HID0, r3 /* no invalidate, unlock */
437 ori r5, r3, HID0_DCFI
438 mtspr HID0, r5 /* enable + invalidate */
439 mtspr HID0, r3 /* enable */
443 .globl dcache_disable
447 ori r4, r4, HID0_DCE|HID0_DLOCK
451 mtspr HID0, r4 /* sets invalidate, clears enable and lock */
453 mtspr HID0, r3 /* clears invalidate */
459 rlwinm r3, r3, (31 - HID0_DCE_SHIFT + 1), 31, 31
467 /*-------------------------------------------------------------------*/
470 * void relocate_code (addr_sp, gd, addr_moni)
472 * This "function" does not return, instead it continues in RAM
473 * after relocating the monitor code.
477 * r5 = length in bytes
482 mr r1, r3 /* Set new stack pointer */
483 mr r9, r4 /* Save copy of Global Data pointer */
484 mr r10, r5 /* Save copy of Destination Address */
487 mr r3, r5 /* Destination Address */
488 lis r4, CONFIG_SYS_MONITOR_BASE@h /* Source Address */
489 ori r4, r4, CONFIG_SYS_MONITOR_BASE@l
490 lwz r5, GOT(__init_end)
492 li r6, CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
497 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE)
498 * + Destination Address
504 /* First our own GOT */
506 /* then the one used by the C code */
515 beq cr1,4f /* In place copy is not necessary */
516 beq 7f /* Protect against 0 count */
545 2: slwi r0,r0,2 /* re copy in reverse order ... y do we needed it? */
553 * Now flush the cache: note that we must start from a cache aligned
554 * address. Otherwise we might miss one cache line.
558 beq 7f /* Always flush prefetch queue in any case */
566 sync /* Wait for all dcbst to complete on bus */
572 7: sync /* Wait for all icbi to complete on bus */
576 * We are done. Do not return, instead branch to second part of board
577 * initialization, now running from RAM.
579 addi r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
585 * Relocation Function, r12 point to got2+0x8000
587 * Adjust got2 pointers, no need to check for 0, this code
588 * already puts a few entries in the table.
590 li r0,__got2_entries@sectoff@l
591 la r3,GOT(_GOT2_TABLE_)
592 lwz r11,GOT(_GOT2_TABLE_)
604 * Now adjust the fixups and the pointers to the fixups
605 * in case we need to move ourselves again.
607 li r0,__fixup_entries@sectoff@l
608 lwz r3,GOT(_FIXUP_TABLE_)
622 * Now clear BSS segment
624 lwz r3,GOT(__bss_start)
637 mr r3, r9 /* Global Data pointer */
638 mr r4, r10 /* Destination Address */
642 * Copy exception vector code to low memory
645 * r7: source address, r8: end address, r9: target address
649 mflr r4 /* save link register */
652 lwz r8, GOT(_end_of_vectors)
654 li r9, 0x100 /* reset vector at 0x100 */
657 bgelr /* return if r7>=r8 - just in case */
667 * relocate `hdlr' and `int_return' entries
669 li r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
670 li r8, Alignment - _start + EXC_OFF_SYS_RESET
673 addi r7, r7, 0x100 /* next exception vector */
677 li r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
680 li r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
683 li r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
684 li r8, SystemCall - _start + EXC_OFF_SYS_RESET
687 addi r7, r7, 0x100 /* next exception vector */
691 li r7, .L_Trace - _start + EXC_OFF_SYS_RESET
692 li r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
695 addi r7, r7, 0x100 /* next exception vector */
699 mfmsr r3 /* now that the vectors have */
700 lis r7, MSR_IP@h /* relocated into low memory */
701 ori r7, r7, MSR_IP@l /* MSR[IP] can be turned off */
702 andc r3, r3, r7 /* (if it was on) */
703 SYNC /* Some chip revs need this... */
707 mtlr r4 /* restore link register */