2 * Copyright 2004, 2007-2011 Freescale Semiconductor, Inc.
3 * Copyright (C) 2003 Motorola,Inc.
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.
31 #include <asm-offsets.h>
36 #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
38 #include <ppc_asm.tmpl>
41 #include <asm/cache.h>
45 #define MSR_KERNEL ( MSR_ME ) /* Machine Check */
48 * Set up GOT: Global Offset Table
50 * Use r12 to access the GOT
53 GOT_ENTRY(_GOT2_TABLE_)
54 GOT_ENTRY(_FIXUP_TABLE_)
56 #ifndef CONFIG_NAND_SPL
58 GOT_ENTRY(_start_of_vectors)
59 GOT_ENTRY(_end_of_vectors)
60 GOT_ENTRY(transfer_to_handler)
64 GOT_ENTRY(__bss_end__)
65 GOT_ENTRY(__bss_start)
69 * e500 Startup -- after reset only the last 4KB of the effective
70 * address space is mapped in the MMU L2 TLB1 Entry0. The .bootpg
71 * section is located at THIS LAST page and basically does three
72 * things: clear some registers, set up exception tables and
73 * add more TLB entries for 'larger spaces'(e.g. the boot rom) to
74 * continue the boot procedure.
76 * Once the boot rom is mapped by TLB entries we can proceed
77 * with normal startup.
86 #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_E500MC)
87 /* ISBC uses L2 as stack.
88 * Disable L2 cache here so that u-boot can enable it later
89 * as part of it's normal flow
92 /* Check if L2 is enabled */
95 ori r2, r2, L2CSR0_L2E@l
101 lis r2,(L2CSR0_L2FL)@h
102 ori r2, r2, (L2CSR0_L2FL)@l
109 mfspr r3, SPRN_L2CSR0
113 mfspr r3, SPRN_L2CSR0
115 ori r2, r2, L2CSR0_L2E@l
125 /* clear registers/arrays not reset by hardware */
129 mtspr L1CSR0,r0 /* invalidate d-cache */
130 mtspr L1CSR1,r0 /* invalidate i-cache */
133 mtspr DBSR,r1 /* Clear all valid bits */
136 * Enable L1 Caches early
140 #if defined(CONFIG_E500MC) && defined(CONFIG_SYS_CACHE_STASHING)
141 /* set stash id to (coreID) * 2 + 32 + L1 CT (0) */
146 /* Enable/invalidate the I-Cache */
147 lis r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@h
148 ori r2,r2,(L1CSR1_ICFI|L1CSR1_ICLFR)@l
155 lis r3,(L1CSR1_CPE|L1CSR1_ICE)@h
156 ori r3,r3,(L1CSR1_CPE|L1CSR1_ICE)@l
161 andi. r1,r3,L1CSR1_ICE@l
164 /* Enable/invalidate the D-Cache */
165 lis r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@h
166 ori r2,r2,(L1CSR0_DCFI|L1CSR0_DCLFR)@l
173 lis r3,(L1CSR0_CPE|L1CSR0_DCE)@h
174 ori r3,r3,(L1CSR0_CPE|L1CSR0_DCE)@l
179 andi. r1,r3,L1CSR0_DCE@l
182 /* Setup interrupt vectors */
183 lis r1,CONFIG_SYS_MONITOR_BASE@h
187 mtspr IVOR0,r1 /* 0: Critical input */
189 mtspr IVOR1,r1 /* 1: Machine check */
191 mtspr IVOR2,r1 /* 2: Data storage */
193 mtspr IVOR3,r1 /* 3: Instruction storage */
195 mtspr IVOR4,r1 /* 4: External interrupt */
197 mtspr IVOR5,r1 /* 5: Alignment */
199 mtspr IVOR6,r1 /* 6: Program check */
201 mtspr IVOR7,r1 /* 7: floating point unavailable */
203 mtspr IVOR8,r1 /* 8: System call */
204 /* 9: Auxiliary processor unavailable(unsupported) */
206 mtspr IVOR10,r1 /* 10: Decrementer */
208 mtspr IVOR11,r1 /* 11: Interval timer */
210 mtspr IVOR12,r1 /* 12: Watchdog timer */
212 mtspr IVOR13,r1 /* 13: Data TLB error */
214 mtspr IVOR14,r1 /* 14: Instruction TLB error */
216 mtspr IVOR15,r1 /* 15: Debug */
218 /* Clear and set up some registers. */
221 mtspr DEC,r0 /* prevent dec exceptions */
222 mttbl r0 /* prevent fit & wdt exceptions */
224 mtspr TSR,r1 /* clear all timer exception status */
225 mtspr TCR,r0 /* disable all */
226 mtspr ESR,r0 /* clear exception syndrome register */
227 mtspr MCSR,r0 /* machine check syndrome register */
228 mtxer r0 /* clear integer exception register */
230 #ifdef CONFIG_SYS_BOOK3E_HV
231 mtspr MAS8,r0 /* make sure MAS8 is clear */
234 /* Enable Time Base and Select Time Base Clock */
235 lis r0,HID0_EMCP@h /* Enable machine check */
236 #if defined(CONFIG_ENABLE_36BIT_PHYS)
237 ori r0,r0,HID0_ENMAS7@l /* Enable MAS7 */
239 #ifndef CONFIG_E500MC
240 ori r0,r0,HID0_TBEN@l /* Enable Timebase */
244 #ifndef CONFIG_E500MC
245 li r0,(HID1_ASTME|HID1_ABE)@l /* Addr streaming & broadcast */
248 cmpwi r3,0x50@l /* if we are rev 5.0 or greater set MBDD */
250 /* Set MBDD bit also */
251 ori r0, r0, HID1_MBDD@l
256 #ifdef CONFIG_SYS_FSL_ERRATUM_CPU_A003999
262 /* Enable Branch Prediction */
263 #if defined(CONFIG_BTB)
264 lis r0,BUCSR_ENABLE@h
265 ori r0,r0,BUCSR_ENABLE@l
269 #if defined(CONFIG_SYS_INIT_DBCR)
272 mtspr DBSR,r1 /* Clear all status bits */
273 lis r0,CONFIG_SYS_INIT_DBCR@h /* DBCR0[IDM] must be set */
274 ori r0,r0,CONFIG_SYS_INIT_DBCR@l
278 #ifdef CONFIG_MPC8569
279 #define CONFIG_SYS_LBC_ADDR (CONFIG_SYS_CCSRBAR_DEFAULT + 0x5000)
280 #define CONFIG_SYS_LBCR_ADDR (CONFIG_SYS_LBC_ADDR + 0xd0)
282 /* MPC8569 Rev.0 silcon needs to set bit 13 of LBCR to allow elBC to
283 * use address space which is more than 12bits, and it must be done in
284 * the 4K boot page. So we set this bit here.
287 /* create a temp mapping TLB0[0] for LBCR */
288 lis r6,FSL_BOOKE_MAS0(0, 0, 0)@h
289 ori r6,r6,FSL_BOOKE_MAS0(0, 0, 0)@l
291 lis r7,FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@h
292 ori r7,r7,FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@l
294 lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G)@h
295 ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_LBC_ADDR, MAS2_I|MAS2_G)@l
297 lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_LBC_ADDR, 0,
298 (MAS3_SX|MAS3_SW|MAS3_SR))@h
299 ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_LBC_ADDR, 0,
300 (MAS3_SX|MAS3_SW|MAS3_SR))@l
310 /* Set LBCR register */
311 lis r4,CONFIG_SYS_LBCR_ADDR@h
312 ori r4,r4,CONFIG_SYS_LBCR_ADDR@l
314 lis r5,CONFIG_SYS_LBC_LBCR@h
315 ori r5,r5,CONFIG_SYS_LBC_LBCR@l
319 /* invalidate this temp TLB */
320 lis r4,CONFIG_SYS_LBC_ADDR@h
321 ori r4,r4,CONFIG_SYS_LBC_ADDR@l
325 #endif /* CONFIG_MPC8569 */
328 * Search for the TLB that covers the code we're executing, and shrink it
329 * so that it covers only this 4K page. That will ensure that any other
330 * TLB we create won't interfere with it. We assume that the TLB exists,
331 * which is why we don't check the Valid bit of MAS1.
333 * This is necessary, for example, when booting from the on-chip ROM,
334 * which (oddly) creates a single 4GB TLB that covers CCSR and DDR.
335 * If we don't shrink this TLB now, then we'll accidentally delete it
336 * in "purge_old_ccsr_tlb" below.
338 bl nexti /* Find our address */
339 nexti: mflr r1 /* R1 = our PC */
341 mtspr MAS6, r2 /* Assume the current PID and AS are 0 */
344 tlbsx 0, r1 /* This must succeed */
346 /* Set the size of the TLB to 4KB */
349 andc r3, r3, r2 /* Clear the TSIZE bits */
350 ori r3, r3, MAS1_TSIZE(BOOKE_PAGESZ_4K)@l
354 * Set the base address of the TLB to our PC. We assume that
355 * virtual == physical. We also assume that MAS2_EPN == MAS3_RPN.
358 ori r3, r3, MAS2_EPN@l /* R3 = MAS2_EPN */
360 and r1, r1, r3 /* Our PC, rounded down to the nearest page */
365 mtspr MAS2, r2 /* Set the EPN to our PC base address */
370 mtspr MAS3, r2 /* Set the RPN to our PC base address */
377 * Relocate CCSR, if necessary. We relocate CCSR if (obviously) the default
378 * location is not where we want it. This typically happens on a 36-bit
379 * system, where we want to move CCSR to near the top of 36-bit address space.
381 * To move CCSR, we create two temporary TLBs, one for the old location, and
382 * another for the new location. On CoreNet systems, we also need to create
383 * a special, temporary LAW.
385 * As a general rule, TLB0 is used for short-term TLBs, and TLB1 is used for
386 * long-term TLBs, so we use TLB0 here.
388 #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS)
390 #if !defined(CONFIG_SYS_CCSRBAR_PHYS_HIGH) || !defined(CONFIG_SYS_CCSRBAR_PHYS_LOW)
391 #error "CONFIG_SYS_CCSRBAR_PHYS_HIGH and CONFIG_SYS_CCSRBAR_PHYS_LOW) must be defined."
395 lis r8, CONFIG_SYS_CCSRBAR@h
396 ori r8, r8, CONFIG_SYS_CCSRBAR@l
397 lis r9, (CONFIG_SYS_CCSRBAR + 0x1000)@h
398 ori r9, r9, (CONFIG_SYS_CCSRBAR + 0x1000)@l
401 * In a multi-stage boot (e.g. NAND boot), a previous stage may have
402 * created a TLB for CCSR, which will interfere with our relocation
403 * code. Since we're going to create a new TLB for CCSR anyway,
404 * it should be safe to delete this old TLB here. We have to search
409 mtspr MAS6, r1 /* Search the current address space and PID */
414 andis. r2, r1, MAS1_VALID@h /* Check for the Valid bit */
415 beq 1f /* Skip if no TLB found */
417 rlwinm r1, r1, 0, 1, 31 /* Clear Valid bit */
426 * Create a TLB for the new location of CCSR. Register R8 is reserved
427 * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR).
429 lis r0, FSL_BOOKE_MAS0(0, 0, 0)@h
430 ori r0, r0, FSL_BOOKE_MAS0(0, 0, 0)@l
431 lis r1, FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@h
432 ori r1, r1, FSL_BOOKE_MAS1(1, 0, 0, 0, BOOKE_PAGESZ_4K)@l
433 lis r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@h
434 ori r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@l
435 lis r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@h
436 ori r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_PHYS_LOW, 0, (MAS3_SW|MAS3_SR))@l
437 lis r7, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
438 ori r7, r7, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
449 * Create a TLB for the current location of CCSR. Register R9 is reserved
450 * for the virtual address of this TLB (CONFIG_SYS_CCSRBAR + 0x1000).
453 lis r0, FSL_BOOKE_MAS0(0, 1, 0)@h
454 ori r0, r0, FSL_BOOKE_MAS0(0, 1, 0)@l
455 lis r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@h
456 ori r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@l
457 lis r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_DEFAULT, 0, (MAS3_SW|MAS3_SR))@h
458 ori r3, r3, FSL_BOOKE_MAS3(CONFIG_SYS_CCSRBAR_DEFAULT, 0, (MAS3_SW|MAS3_SR))@l
459 li r7, 0 /* The default CCSR address is always a 32-bit number */
461 /* MAS1 is the same as above */
470 * We have a TLB for what we think is the current (old) CCSR. Let's
471 * verify that, otherwise we won't be able to move it.
472 * CONFIG_SYS_CCSRBAR_DEFAULT is always a 32-bit number, so we only
473 * need to compare the lower 32 bits of CCSRBAR on CoreNet systems.
476 lis r0, CONFIG_SYS_CCSRBAR_DEFAULT@h
477 ori r0, r0, CONFIG_SYS_CCSRBAR_DEFAULT@l
478 #ifdef CONFIG_FSL_CORENET
479 lwz r1, 4(r9) /* CCSRBARL */
481 lwz r1, 0(r9) /* CCSRBAR, shifted right by 12 */
488 * If the value we read from CCSRBARL is not what we expect, then
489 * enter an infinite loop. This will at least allow a debugger to
490 * halt execution and examine TLBs, etc. There's no point in going
494 bne infinite_debug_loop
496 #ifdef CONFIG_FSL_CORENET
498 #define CCSR_LAWBARH0 (CONFIG_SYS_CCSRBAR + 0x1000)
499 #define LAW_EN 0x80000000
500 #define LAW_SIZE_4K 0xb
501 #define CCSRBAR_LAWAR (LAW_EN | (0x1e << 20) | LAW_SIZE_4K)
502 #define CCSRAR_C 0x80000000 /* Commit */
506 * On CoreNet systems, we create the temporary LAW using a special LAW
507 * target ID of 0x1e. LAWBARH is at offset 0xc00 in CCSR.
509 lis r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
510 ori r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
511 lis r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
512 ori r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
513 lis r2, CCSRBAR_LAWAR@h
514 ori r2, r2, CCSRBAR_LAWAR@l
516 stw r0, 0xc00(r9) /* LAWBARH0 */
517 stw r1, 0xc04(r9) /* LAWBARL0 */
519 stw r2, 0xc08(r9) /* LAWAR0 */
522 * Read back from LAWAR to ensure the update is complete. e500mc
523 * cores also require an isync.
525 lwz r0, 0xc08(r9) /* LAWAR0 */
529 * Read the current CCSRBARH and CCSRBARL using load word instructions.
530 * Follow this with an isync instruction. This forces any outstanding
531 * accesses to configuration space to completion.
534 lwz r0, 0(r9) /* CCSRBARH */
535 lwz r0, 4(r9) /* CCSRBARL */
539 * Write the new values for CCSRBARH and CCSRBARL to their old
540 * locations. The CCSRBARH has a shadow register. When the CCSRBARH
541 * has a new value written it loads a CCSRBARH shadow register. When
542 * the CCSRBARL is written, the CCSRBARH shadow register contents
543 * along with the CCSRBARL value are loaded into the CCSRBARH and
544 * CCSRBARL registers, respectively. Follow this with a sync
548 lis r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@h
549 ori r0, r0, CONFIG_SYS_CCSRBAR_PHYS_HIGH@l
550 lis r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@h
551 ori r1, r1, CONFIG_SYS_CCSRBAR_PHYS_LOW@l
553 ori r2, r2, CCSRAR_C@l
555 stw r0, 0(r9) /* Write to CCSRBARH */
556 sync /* Make sure we write to CCSRBARH first */
557 stw r1, 4(r9) /* Write to CCSRBARL */
561 * Write a 1 to the commit bit (C) of CCSRAR at the old location.
562 * Follow this with a sync instruction.
567 /* Delete the temporary LAW */
576 #else /* #ifdef CONFIG_FSL_CORENET */
580 * Read the current value of CCSRBAR using a load word instruction
581 * followed by an isync. This forces all accesses to configuration
588 /* CONFIG_SYS_CCSRBAR_PHYS right shifted by 12 */
589 #define CCSRBAR_PHYS_RS12 ((CONFIG_SYS_CCSRBAR_PHYS_HIGH << 20) | \
590 (CONFIG_SYS_CCSRBAR_PHYS_LOW >> 12))
592 /* Write the new value to CCSRBAR. */
593 lis r0, CCSRBAR_PHYS_RS12@h
594 ori r0, r0, CCSRBAR_PHYS_RS12@l
599 * The manual says to perform a load of an address that does not
600 * access configuration space or the on-chip SRAM using an existing TLB,
601 * but that doesn't appear to be necessary. We will do the isync,
607 * Read the contents of CCSRBAR from its new location, followed by
613 #endif /* #ifdef CONFIG_FSL_CORENET */
615 /* Delete the temporary TLBs */
617 lis r0, FSL_BOOKE_MAS0(0, 0, 0)@h
618 ori r0, r0, FSL_BOOKE_MAS0(0, 0, 0)@l
620 lis r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@h
621 ori r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR, (MAS2_I|MAS2_G))@l
629 lis r0, FSL_BOOKE_MAS0(0, 1, 0)@h
630 ori r0, r0, FSL_BOOKE_MAS0(0, 1, 0)@l
631 lis r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@h
632 ori r2, r2, FSL_BOOKE_MAS2(CONFIG_SYS_CCSRBAR + 0x1000, (MAS2_I|MAS2_G))@l
638 #endif /* #if (CONFIG_SYS_CCSRBAR_DEFAULT != CONFIG_SYS_CCSRBAR_PHYS) */
640 create_init_ram_area:
641 lis r6,FSL_BOOKE_MAS0(1, 15, 0)@h
642 ori r6,r6,FSL_BOOKE_MAS0(1, 15, 0)@l
644 #if !defined(CONFIG_SYS_RAMBOOT) && !defined(CONFIG_SECURE_BOOT)
645 /* create a temp mapping in AS=1 to the 4M boot window */
646 lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_4M)@h
647 ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_4M)@l
649 lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE & 0xffc00000, (MAS2_I|MAS2_G))@h
650 ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE & 0xffc00000, (MAS2_I|MAS2_G))@l
652 /* The 85xx has the default boot window 0xff800000 - 0xffffffff */
653 lis r9,FSL_BOOKE_MAS3(0xffc00000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
654 ori r9,r9,FSL_BOOKE_MAS3(0xffc00000, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
655 #elif !defined(CONFIG_SYS_RAMBOOT) && defined(CONFIG_SECURE_BOOT)
656 /* create a temp mapping in AS = 1 for Flash mapping
657 * created by PBL for ISBC code
659 lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@h
660 ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@l
662 lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@h
663 ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@l
665 lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_PBI_FLASH_WINDOW, 0,
666 (MAS3_SX|MAS3_SW|MAS3_SR))@h
667 ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_PBI_FLASH_WINDOW, 0,
668 (MAS3_SX|MAS3_SW|MAS3_SR))@l
671 * create a temp mapping in AS=1 to the 1M CONFIG_SYS_MONITOR_BASE space, the main
672 * image has been relocated to CONFIG_SYS_MONITOR_BASE on the second stage.
674 lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@h
675 ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_1M)@l
677 lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@h
678 ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_MONITOR_BASE, (MAS2_I|MAS2_G))@l
680 lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_MONITOR_BASE, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
681 ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_MONITOR_BASE, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
692 /* create a temp mapping in AS=1 to the stack */
693 lis r6,FSL_BOOKE_MAS0(1, 14, 0)@h
694 ori r6,r6,FSL_BOOKE_MAS0(1, 14, 0)@l
696 lis r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@h
697 ori r7,r7,FSL_BOOKE_MAS1(1, 1, 0, 1, BOOKE_PAGESZ_16K)@l
699 lis r8,FSL_BOOKE_MAS2(CONFIG_SYS_INIT_RAM_ADDR, 0)@h
700 ori r8,r8,FSL_BOOKE_MAS2(CONFIG_SYS_INIT_RAM_ADDR, 0)@l
702 #if defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW) && \
703 defined(CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH)
704 lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, 0,
705 (MAS3_SX|MAS3_SW|MAS3_SR))@h
706 ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR_PHYS_LOW, 0,
707 (MAS3_SX|MAS3_SW|MAS3_SR))@l
708 li r10,CONFIG_SYS_INIT_RAM_ADDR_PHYS_HIGH
711 lis r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@h
712 ori r9,r9,FSL_BOOKE_MAS3(CONFIG_SYS_INIT_RAM_ADDR, 0, (MAS3_SX|MAS3_SW|MAS3_SR))@l
723 lis r6,MSR_IS|MSR_DS@h
724 ori r6,r6,MSR_IS|MSR_DS@l
726 ori r7,r7,switch_as@l
733 /* L1 DCache is used for initial RAM */
735 /* Allocate Initial RAM in data cache.
737 lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
738 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
741 /* cache size * 1024 / (2 * L1 line size) */
742 slwi r2, r2, (10 - 1 - L1_CACHE_SHIFT)
748 addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
751 /* Jump out the last 4K page and continue to 'normal' start */
752 #ifdef CONFIG_SYS_RAMBOOT
755 /* Calculate absolute address in FLASH and jump there */
756 /*--------------------------------------------------------------*/
757 lis r3,CONFIG_SYS_MONITOR_BASE@h
758 ori r3,r3,CONFIG_SYS_MONITOR_BASE@l
759 addi r3,r3,_start_cont - _start + _START_OFFSET
767 .long 0x27051956 /* U-BOOT Magic Number */
768 .globl version_string
770 .ascii U_BOOT_VERSION_STRING, "\0"
775 /* Setup the stack in initial RAM,could be L2-as-SRAM or L1 dcache*/
776 lis r1,CONFIG_SYS_INIT_RAM_ADDR@h
777 ori r1,r1,CONFIG_SYS_INIT_SP_OFFSET@l
781 stwu r0,-4(r1) /* Terminate call chain */
783 stwu r1,-8(r1) /* Save back chain and move SP */
784 lis r0,RESET_VECTOR@h /* Address of reset vector */
785 ori r0,r0,RESET_VECTOR@l
786 stwu r1,-8(r1) /* Save back chain and move SP */
787 stw r0,+12(r1) /* Save return addr (underflow vect) */
792 /* switch back to AS = 0 */
793 lis r3,(MSR_CE|MSR_ME|MSR_DE)@h
794 ori r3,r3,(MSR_CE|MSR_ME|MSR_DE)@l
802 /* NOTREACHED - board_init_f() does not return */
804 #ifndef CONFIG_NAND_SPL
805 . = EXC_OFF_SYS_RESET
806 .globl _start_of_vectors
809 /* Critical input. */
810 CRIT_EXCEPTION(0x0100, CriticalInput, CritcalInputException)
813 MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
815 /* Data Storage exception. */
816 STD_EXCEPTION(0x0300, DataStorage, UnknownException)
818 /* Instruction Storage exception. */
819 STD_EXCEPTION(0x0400, InstStorage, UnknownException)
821 /* External Interrupt exception. */
822 STD_EXCEPTION(0x0500, ExtInterrupt, ExtIntException)
824 /* Alignment exception. */
827 EXCEPTION_PROLOG(SRR0, SRR1)
832 addi r3,r1,STACK_FRAME_OVERHEAD
833 EXC_XFER_TEMPLATE(Alignment, AlignmentException, MSR_KERNEL, COPY_EE)
835 /* Program check exception */
838 EXCEPTION_PROLOG(SRR0, SRR1)
839 addi r3,r1,STACK_FRAME_OVERHEAD
840 EXC_XFER_TEMPLATE(ProgramCheck, ProgramCheckException,
843 /* No FPU on MPC85xx. This exception is not supposed to happen.
845 STD_EXCEPTION(0x0800, FPUnavailable, UnknownException)
849 * r0 - SYSCALL number
853 addis r11,r0,0 /* get functions table addr */
854 ori r11,r11,0 /* Note: this code is patched in trap_init */
855 addis r12,r0,0 /* get number of functions */
861 rlwinm r0,r0,2,0,31 /* fn_addr = fn_tbl[r0] */
865 li r20,0xd00-4 /* Get stack pointer */
867 subi r12,r12,12 /* Adjust stack pointer */
868 li r0,0xc00+_end_back-SystemCall
869 cmplw 0,r0,r12 /* Check stack overflow */
880 li r12,0xc00+_back-SystemCall
888 mfmsr r11 /* Disable interrupts */
892 SYNC /* Some chip revs need this... */
896 li r12,0xd00-4 /* restore regs */
906 addi r12,r12,12 /* Adjust stack pointer */
914 STD_EXCEPTION(0x0a00, Decrementer, timer_interrupt)
915 STD_EXCEPTION(0x0b00, IntervalTimer, UnknownException)
916 STD_EXCEPTION(0x0c00, WatchdogTimer, UnknownException)
918 STD_EXCEPTION(0x0d00, DataTLBError, UnknownException)
919 STD_EXCEPTION(0x0e00, InstructionTLBError, UnknownException)
921 CRIT_EXCEPTION(0x0f00, DebugBreakpoint, DebugException )
923 .globl _end_of_vectors
927 . = . + (0x100 - ( . & 0xff )) /* align for debug */
930 * This code finishes saving the registers to the exception frame
931 * and jumps to the appropriate handler for the exception.
932 * Register r21 is pointer into trap frame, r1 has new stack pointer.
934 .globl transfer_to_handler
946 andi. r24,r23,0x3f00 /* get vector offset */
950 mtspr SPRG2,r22 /* r1 is now kernel sp */
952 lwz r24,0(r23) /* virtual address of handler */
953 lwz r23,4(r23) /* where to go when done */
958 rfi /* jump to handler, enable MMU */
961 mfmsr r28 /* Disable interrupts */
965 SYNC /* Some chip revs need this... */
980 lwz r2,_NIP(r1) /* Restore environment */
991 mfmsr r28 /* Disable interrupts */
995 SYNC /* Some chip revs need this... */
1010 lwz r2,_NIP(r1) /* Restore environment */
1021 mfmsr r28 /* Disable interrupts */
1025 SYNC /* Some chip revs need this... */
1040 lwz r2,_NIP(r1) /* Restore environment */
1042 mtspr SPRN_MCSRR0,r2
1043 mtspr SPRN_MCSRR1,r0
1054 .globl invalidate_icache
1057 ori r0,r0,L1CSR1_ICFI
1062 blr /* entire I cache */
1064 .globl invalidate_dcache
1067 ori r0,r0,L1CSR0_DCFI
1074 .globl icache_enable
1077 bl invalidate_icache
1087 .globl icache_disable
1091 ori r3,r3,L1CSR1_ICE
1097 .globl icache_status
1100 andi. r3,r3,L1CSR1_ICE
1103 .globl dcache_enable
1106 bl invalidate_dcache
1118 .globl dcache_disable
1122 ori r4,r4,L1CSR0_DCE
1128 .globl dcache_status
1131 andi. r3,r3,L1CSR0_DCE
1154 /*------------------------------------------------------------------------------- */
1156 /* Description: Input 8 bits */
1157 /*------------------------------------------------------------------------------- */
1163 /*------------------------------------------------------------------------------- */
1164 /* Function: out8 */
1165 /* Description: Output 8 bits */
1166 /*------------------------------------------------------------------------------- */
1173 /*------------------------------------------------------------------------------- */
1174 /* Function: out16 */
1175 /* Description: Output 16 bits */
1176 /*------------------------------------------------------------------------------- */
1183 /*------------------------------------------------------------------------------- */
1184 /* Function: out16r */
1185 /* Description: Byte reverse and output 16 bits */
1186 /*------------------------------------------------------------------------------- */
1193 /*------------------------------------------------------------------------------- */
1194 /* Function: out32 */
1195 /* Description: Output 32 bits */
1196 /*------------------------------------------------------------------------------- */
1203 /*------------------------------------------------------------------------------- */
1204 /* Function: out32r */
1205 /* Description: Byte reverse and output 32 bits */
1206 /*------------------------------------------------------------------------------- */
1213 /*------------------------------------------------------------------------------- */
1214 /* Function: in16 */
1215 /* Description: Input 16 bits */
1216 /*------------------------------------------------------------------------------- */
1222 /*------------------------------------------------------------------------------- */
1223 /* Function: in16r */
1224 /* Description: Input 16 bits and byte reverse */
1225 /*------------------------------------------------------------------------------- */
1231 /*------------------------------------------------------------------------------- */
1232 /* Function: in32 */
1233 /* Description: Input 32 bits */
1234 /*------------------------------------------------------------------------------- */
1240 /*------------------------------------------------------------------------------- */
1241 /* Function: in32r */
1242 /* Description: Input 32 bits and byte reverse */
1243 /*------------------------------------------------------------------------------- */
1248 #endif /* !CONFIG_NAND_SPL */
1250 /*------------------------------------------------------------------------------*/
1253 * void write_tlb(mas0, mas1, mas2, mas3, mas7)
1261 #ifdef CONFIG_ENABLE_36BIT_PHYS
1265 #ifdef CONFIG_SYS_BOOK3E_HV
1275 * void relocate_code (addr_sp, gd, addr_moni)
1277 * This "function" does not return, instead it continues in RAM
1278 * after relocating the monitor code.
1282 * r5 = length in bytes
1283 * r6 = cachelinesize
1285 .globl relocate_code
1287 mr r1,r3 /* Set new stack pointer */
1288 mr r9,r4 /* Save copy of Init Data pointer */
1289 mr r10,r5 /* Save copy of Destination Address */
1292 mr r3,r5 /* Destination Address */
1293 lis r4,CONFIG_SYS_MONITOR_BASE@h /* Source Address */
1294 ori r4,r4,CONFIG_SYS_MONITOR_BASE@l
1295 lwz r5,GOT(__init_end)
1297 li r6,CONFIG_SYS_CACHELINE_SIZE /* Cache Line Size */
1302 * New GOT-PTR = (old GOT-PTR - CONFIG_SYS_MONITOR_BASE) + Destination Address
1308 /* First our own GOT */
1310 /* the the one used by the C code */
1320 beq cr1,4f /* In place copy is not necessary */
1321 beq 7f /* Protect against 0 count */
1340 * Now flush the cache: note that we must start from a cache aligned
1341 * address. Otherwise we might miss one cache line.
1345 beq 7f /* Always flush prefetch queue in any case */
1353 sync /* Wait for all dcbst to complete on bus */
1359 7: sync /* Wait for all icbi to complete on bus */
1363 * Re-point the IVPR at RAM
1368 * We are done. Do not return, instead branch to second part of board
1369 * initialization, now running from RAM.
1372 addi r0,r10,in_ram - _start + _START_OFFSET
1374 blr /* NEVER RETURNS! */
1379 * Relocation Function, r12 point to got2+0x8000
1381 * Adjust got2 pointers, no need to check for 0, this code
1382 * already puts a few entries in the table.
1384 li r0,__got2_entries@sectoff@l
1385 la r3,GOT(_GOT2_TABLE_)
1386 lwz r11,GOT(_GOT2_TABLE_)
1398 * Now adjust the fixups and the pointers to the fixups
1399 * in case we need to move ourselves again.
1401 li r0,__fixup_entries@sectoff@l
1402 lwz r3,GOT(_FIXUP_TABLE_)
1418 * Now clear BSS segment
1420 lwz r3,GOT(__bss_start)
1421 lwz r4,GOT(__bss_end__)
1434 mr r3,r9 /* Init Data pointer */
1435 mr r4,r10 /* Destination Address */
1438 #ifndef CONFIG_NAND_SPL
1440 * Copy exception vector code to low memory
1443 * r7: source address, r8: end address, r9: target address
1447 mflr r4 /* save link register */
1449 lwz r7,GOT(_start_of_vectors)
1450 lwz r8,GOT(_end_of_vectors)
1452 li r9,0x100 /* reset vector always at 0x100 */
1455 bgelr /* return if r7>=r8 - just in case */
1465 * relocate `hdlr' and `int_return' entries
1467 li r7,.L_CriticalInput - _start + _START_OFFSET
1469 li r7,.L_MachineCheck - _start + _START_OFFSET
1471 li r7,.L_DataStorage - _start + _START_OFFSET
1473 li r7,.L_InstStorage - _start + _START_OFFSET
1475 li r7,.L_ExtInterrupt - _start + _START_OFFSET
1477 li r7,.L_Alignment - _start + _START_OFFSET
1479 li r7,.L_ProgramCheck - _start + _START_OFFSET
1481 li r7,.L_FPUnavailable - _start + _START_OFFSET
1483 li r7,.L_Decrementer - _start + _START_OFFSET
1485 li r7,.L_IntervalTimer - _start + _START_OFFSET
1486 li r8,_end_of_vectors - _start + _START_OFFSET
1489 addi r7,r7,0x100 /* next exception vector */
1496 mtlr r4 /* restore link register */
1499 .globl unlock_ram_in_cache
1500 unlock_ram_in_cache:
1501 /* invalidate the INIT_RAM section */
1502 lis r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@h
1503 ori r3,r3,(CONFIG_SYS_INIT_RAM_ADDR & ~(CONFIG_SYS_CACHELINE_SIZE-1))@l
1506 slwi r4,r4,(10 - 1 - L1_CACHE_SHIFT)
1509 addi r3,r3,CONFIG_SYS_CACHELINE_SIZE
1513 /* Invalidate the TLB entries for the cache */
1514 lis r3,CONFIG_SYS_INIT_RAM_ADDR@h
1515 ori r3,r3,CONFIG_SYS_INIT_RAM_ADDR@l
1528 mfspr r3,SPRN_L1CFG0
1530 rlwinm r5,r3,9,3 /* Extract cache block size */
1531 twlgti r5,1 /* Only 32 and 64 byte cache blocks
1532 * are currently defined.
1535 subfic r6,r5,2 /* r6 = log2(1KiB / cache block size) -
1536 * log2(number of ways)
1538 slw r5,r4,r5 /* r5 = cache block size */
1540 rlwinm r7,r3,0,0xff /* Extract number of KiB in the cache */
1541 mulli r7,r7,13 /* An 8-way cache will require 13
1546 /* save off HID0 and set DCFA */
1548 ori r9,r8,HID0_DCFA@l
1555 1: lwz r3,0(r4) /* Load... */
1563 1: dcbf 0,r4 /* ...and flush. */
1576 #include "fixed_ivor.S"
1578 #endif /* !CONFIG_NAND_SPL */