Merge branch 'master' of git://www.denx.de/git/u-boot-mips
[oweals/u-boot.git] / cpu / mpc86xx / start.S
index 412745bdaeacf5921c44032d70b98beb4d9dc596..c39dc4681d77e94f6212f77cb3ecb1bd6645f652 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004 Freescale Semiconductor.
+ * Copyright 2004, 2007 Freescale Semiconductor.
  * Srikanth Srinivasan <srikanth.srinivaan@freescale.com>
  *
  * See file CREDITS for list of people who contributed to this
 #define CONFIG_IDENT_STRING ""
 #endif
 
-/* We don't want the  MMU yet.
-*/
-#undef MSR_KERNEL
-/* Machine Check and Recoverable Interr. */
-#define MSR_KERNEL ( MSR_ME | MSR_RI )
+/*
+ * Need MSR_DR | MSR_IR enabled to access I/O (printf) in exceptions
+ */
 
 /*
  * Set up GOT: Global Offset Table
@@ -195,17 +193,21 @@ boot_warm:
        bl      secondary_cpu_setup
 #endif
 
+1:
+#ifdef CFG_RAMBOOT
        /* disable everything */
-1:     li      r0, 0
+       li      r0, 0
        mtspr   HID0, r0
        sync
        mtmsr   0
+#endif
+
        bl      invalidate_bats
        sync
 
 #ifdef CFG_L2
        /* init the L2 cache */
-       addis   r3, r0, L2_INIT@h
+       lis     r3, L2_INIT@h
        ori     r3, r3, L2_INIT@l
        mtspr   l2cr, r3
        /* invalidate the L2 cache */
@@ -233,77 +235,8 @@ in_flash:
        bl      enable_ext_addr
 
        /* setup the bats */
-       bl      setup_bats
-       sync
-
-#if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
-       /* setup ccsrbar */
-       bl      setup_ccsrbar
-#endif
-
-
-       /* -- MPC8641 Rev 1.0 MCM Errata fixups -- */
-
-       /* skip fixups if not Rev 1.0 */
-       mfspr   r4, SVR
-       rlwinm  r4,r4,0,24,31
-       cmpwi   r4,0x10
-       bne     1f
-
-       lis     r3,MCM_ABCR@ha
-       lwz     r4,MCM_ABCR@l(r3)       /* ABCR -> r4 */
-
-       /* set ABCR[A_STRM_CNT] = 0 */
-       rlwinm  r4,r4,0,0,29
-
-       /* set ABCR[ARB_POLICY] to 0x1 (round-robin) */
-       addi    r0,r0,1
-       rlwimi  r4,r0,12,18,19
-
-       stw     r4,MCM_ABCR@l(r3)       /* r4 -> ABCR */
-       sync
-
-       /* Set DBCR[ERD_DIS] */
-       lis     r3,MCM_DBCR@ha
-       lwz     r4,MCM_DBCR@l(r3)
-       oris    r4, r4, 0x4000
-       stw     r4,MCM_DBCR@l(r3)
-       sync
-1:
-       /* setup the law entries */
-       bl      law_entry
-       sync
-
-
-#if (EMULATOR_RUN == 1)
-       /* On the emulator we want to adjust these ASAP */
-       /* otherwise things are sloooow */
-       /* Setup OR0 (LALE FIX)*/
-       lis     r3, CFG_CCSRBAR@h
-       ori     r3, r3, 0x5004
-       li      r4, 0x0FF3
-       stw     r4, 0(r3)
-       sync
+       bl      early_bats
 
-       /* Setup LCRR */
-       lis     r3, CFG_CCSRBAR@h
-       ori     r3, r3, 0x50D4
-       lis     r4, 0x8000
-       ori     r4, r4, 0x0002
-       stw     r4, 0(r3)
-       sync
-#endif
-#if 1
-       /* make sure timer enabled in guts register too */
-       lis     r3, CFG_CCSRBAR@h
-       oris    r3,r3, 0xE
-       ori     r3,r3,0x0070
-       lwz     r4, 0(r3)
-       lis     r5,0xFFFC
-       ori     r5,r5,0x5FFF
-       and     r4,r4,r5
-       stw     r4,0(r3)
-#endif
        /*
         * Cache must be enabled here for stack-in-cache trick.
         * This means we need to enable the BATS.
@@ -340,14 +273,22 @@ in_flash:
 
        GET_GOT                 /* initialize GOT access        */
 
+       /* setup the rest of the bats */
+       bl      setup_bats
+       bl      clear_tlbs
+       sync
+
+#if (CFG_CCSRBAR_DEFAULT != CFG_CCSRBAR)
+       /* setup ccsrbar */
+       bl      setup_ccsrbar
+#endif
+
        /* run low-level CPU init code     (from Flash) */
        bl      cpu_init_f
        sync
 
 #ifdef RUN_DIAG
 
-       /* Sri:  Code to run the diagnostic automatically */
-
        /* Load PX_AUX register address in r4 */
        lis     r4, 0xf810
        ori     r4, r4, 0x6
@@ -392,6 +333,7 @@ diag_done:
        .globl  invalidate_bats
 invalidate_bats:
 
+       li      r0, 0
        /* invalidate BATs */
        mtspr   IBAT0U, r0
        mtspr   IBAT1U, r0
@@ -418,6 +360,7 @@ invalidate_bats:
 
 
        /* setup_bats - set them up to some initial state */
+       /* Skip any BATS setup in early_bats */
        .globl  setup_bats
 setup_bats:
 
@@ -513,42 +456,6 @@ setup_bats:
        mtspr   DBAT4U, r3
        isync
 
-       /* IBAT 5 */
-       addis   r4, r0, CFG_IBAT5L@h
-       ori     r4, r4, CFG_IBAT5L@l
-       addis   r3, r0, CFG_IBAT5U@h
-       ori     r3, r3, CFG_IBAT5U@l
-       mtspr   IBAT5L, r4
-       mtspr   IBAT5U, r3
-       isync
-
-       /* DBAT 5 */
-       addis   r4, r0, CFG_DBAT5L@h
-       ori     r4, r4, CFG_DBAT5L@l
-       addis   r3, r0, CFG_DBAT5U@h
-       ori     r3, r3, CFG_DBAT5U@l
-       mtspr   DBAT5L, r4
-       mtspr   DBAT5U, r3
-       isync
-
-       /* IBAT 6 */
-       addis   r4, r0, CFG_IBAT6L@h
-       ori     r4, r4, CFG_IBAT6L@l
-       addis   r3, r0, CFG_IBAT6U@h
-       ori     r3, r3, CFG_IBAT6U@l
-       mtspr   IBAT6L, r4
-       mtspr   IBAT6U, r3
-       isync
-
-       /* DBAT 6 */
-       addis   r4, r0, CFG_DBAT6L@h
-       ori     r4, r4, CFG_DBAT6L@l
-       addis   r3, r0, CFG_DBAT6U@h
-       ori     r3, r3, CFG_DBAT6U@l
-       mtspr   DBAT6L, r4
-       mtspr   DBAT6U, r3
-       isync
-
        /* IBAT 7 */
        addis   r4, r0, CFG_IBAT7L@h
        ori     r4, r4, CFG_IBAT7L@l
@@ -567,18 +474,65 @@ setup_bats:
        mtspr   DBAT7U, r3
        isync
 
-1:
-       addis   r3, 0, 0x0000
-       addis   r5, 0, 0x4      /* upper bound of 0x00040000 for 7400/750 */
+       sync
+       blr
+
+/*
+ * early_bats:
+ *
+ * Set up bats needed early on - this is usually the BAT for the
+ * stack-in-cache and the Flash
+ */
+       .globl  early_bats
+early_bats:
+       /* IBAT 5 */
+       lis     r4, CFG_IBAT5L@h
+       ori     r4, r4, CFG_IBAT5L@l
+       lis     r3, CFG_IBAT5U@h
+       ori     r3, r3, CFG_IBAT5U@l
+       mtspr   IBAT5L, r4
+       mtspr   IBAT5U, r3
        isync
 
+       /* DBAT 5 */
+       lis     r4, CFG_DBAT5L@h
+       ori     r4, r4, CFG_DBAT5L@l
+       lis     r3, CFG_DBAT5U@h
+       ori     r3, r3, CFG_DBAT5U@l
+       mtspr   DBAT5L, r4
+       mtspr   DBAT5U, r3
+       isync
+
+       /* IBAT 6 */
+       lis     r4, CFG_IBAT6L@h
+       ori     r4, r4, CFG_IBAT6L@l
+       lis     r3, CFG_IBAT6U@h
+       ori     r3, r3, CFG_IBAT6U@l
+       mtspr   IBAT6L, r4
+       mtspr   IBAT6U, r3
+       isync
+
+       /* DBAT 6 */
+       lis     r4, CFG_DBAT6L@h
+       ori     r4, r4, CFG_DBAT6L@l
+       lis     r3, CFG_DBAT6U@h
+       ori     r3, r3, CFG_DBAT6U@l
+       mtspr   DBAT6L, r4
+       mtspr   DBAT6U, r3
+       isync
+       blr
+
+       .globl clear_tlbs
+clear_tlbs:
+       addis   r3, 0, 0x0000
+       addis   r5, 0, 0x4
+       isync
 tlblp:
-       tlbie   r3
+       tlbie   r3
        sync
-       addi    r3, r3, 0x1000
-       cmp     0, 0, r3, r5
+       addi    r3, r3, 0x1000
+       cmp     0, 0, r3, r5
        blt tlblp
-
        blr
 
        .globl enable_addr_trans
@@ -766,50 +720,6 @@ in32r:
        lwbrx   r3,r0,r3
        blr
 
-/*
- * Function:   ppcDcbf
- * Description:        Data Cache block flush
- * Input:      r3 = effective address
- * Output:     none.
- */
-       .globl  ppcDcbf
-ppcDcbf:
-       dcbf    r0,r3
-       blr
-
-/*
- * Function:   ppcDcbi
- * Description:        Data Cache block Invalidate
- * Input:      r3 = effective address
- * Output:     none.
- */
-       .globl  ppcDcbi
-ppcDcbi:
-       dcbi    r0,r3
-       blr
-
-/*
- * Function:   ppcDcbz
- * Description:        Data Cache block zero.
- * Input:      r3 = effective address
- * Output:     none.
- */
-       .globl  ppcDcbz
-ppcDcbz:
-       dcbz    r0,r3
-       blr
-
-/*
- * Function:   ppcSync
- * Description:        Processor Synchronize
- * Input:      none.
- * Output:     none.
- */
-       .globl  ppcSync
-ppcSync:
-       sync
-       blr
-
 /*
  * void relocate_code (addr_sp, gd, addr_moni)
  *
@@ -826,7 +736,7 @@ relocate_code:
 
        mr      r1,  r3         /* Set new stack pointer                */
        mr      r9,  r4         /* Save copy of Global Data pointer     */
-       mr      r29, r9         /* Save for DECLARE_GLOBAL_DATA_PTR     */
+       mr      r2 r9         /* Save for DECLARE_GLOBAL_DATA_PTR     */
        mr      r10, r5         /* Save copy of Destination Address     */
 
        mr      r3,  r5                         /* Destination Address  */
@@ -1040,6 +950,7 @@ trap_init:
        mfmsr   r7
        li      r8,MSR_IP
        andc    r7,r7,r8
+       ori     r7,r7,MSR_ME            /* Enable Machine Check */
        mtmsr   r7
 
        mtlr    r4                      /* restore link register        */
@@ -1224,8 +1135,9 @@ secondary_cpu_setup:
        sync
        isync
 
-       /*SYNCBE|ABE in HID1*/
+       /* MCP|SYNCBE|ABE in HID1 */
        mfspr   r4, HID1
+       oris    r4, r4, 0x8000
        ori     r4, r4, 0x0C00
        mtspr   HID1, r4
        sync