Merge branch 'master' of git://www.denx.de/git/u-boot-ppc4xx
[platform/kernel/u-boot.git] / cpu / ppc4xx / start.S
index 78d0042..d8df67b 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  * MA 02111-1307 USA
  */
-/*------------------------------------------------------------------------------+ */
-/* */
-/*      This source code has been made available to you by IBM on an AS-IS */
-/*      basis.  Anyone receiving this source is licensed under IBM */
-/*      copyrights to use it in any way he or she deems fit, including */
-/*      copying it, modifying it, compiling it, and redistributing it either */
-/*      with or without modifications.  No license under IBM patents or */
-/*      patent applications is to be implied by the copyright license. */
-/* */
-/*      Any user of this software should understand that IBM cannot provide */
-/*      technical support for this software and will not be responsible for */
-/*      any consequences resulting from the use of this software. */
-/* */
-/*      Any person who transfers this source code or any derivative work */
-/*      must include the IBM copyright notice, this paragraph, and the */
-/*      preceding two paragraphs in the transferred software. */
-/* */
-/*      COPYRIGHT   I B M   CORPORATION 1995 */
-/*      LICENSED MATERIAL  -  PROGRAM PROPERTY OF I B M */
-/*------------------------------------------------------------------------------- */
+/*------------------------------------------------------------------------------+
+ *
+ *      This source code has been made available to you by IBM on an AS-IS
+ *      basis.  Anyone receiving this source is licensed under IBM
+ *      copyrights to use it in any way he or she deems fit, including
+ *      copying it, modifying it, compiling it, and redistributing it either
+ *      with or without modifications.  No license under IBM patents or
+ *      patent applications is to be implied by the copyright license.
+ *
+ *      Any user of this software should understand that IBM cannot provide
+ *      technical support for this software and will not be responsible for
+ *      any consequences resulting from the use of this software.
+ *
+ *      Any person who transfers this source code or any derivative work
+ *      must include the IBM copyright notice, this paragraph, and the
+ *      preceding two paragraphs in the transferred software.
+ *
+ *      COPYRIGHT   I B M   CORPORATION 1995
+ *      LICENSED MATERIAL  -  PROGRAM PROPERTY OF I B M
+ *-------------------------------------------------------------------------------
+ */
 
 /*  U-Boot - Startup Code for AMCC 4xx PowerPC based Embedded Boards
  *
@@ -59,7 +60,6 @@
  *  address and (s)dram will be positioned at address 0
  */
 #include <config.h>
-#include <mpc8xx.h>
 #include <ppc4xx.h>
 #include <version.h>
 
 # endif
 #endif /* CFG_INIT_DCACHE_CS */
 
-#define function_prolog(func_name)      .text; \
+#if (defined(CFG_INIT_RAM_DCACHE) && (CFG_INIT_RAM_END > (4 << 10)))
+#error Only 4k of init-ram is supported - please adjust CFG_INIT_RAM_END!
+#endif
+
+#define function_prolog(func_name)     .text; \
                                        .align 2; \
                                        .globl func_name; \
                                        func_name:
-#define function_epilog(func_name)      .type func_name,@function; \
+#define function_epilog(func_name)     .type func_name,@function; \
                                        .size func_name,.-func_name
 
 /* We don't want the  MMU yet.
@@ -294,11 +298,13 @@ skip_debug_init:
        mtspr   ivor7,r1        /* Floating point unavailable */
        li      r1,0x0c00
        mtspr   ivor8,r1        /* System call */
-       li      r1,0x1000
-       mtspr   ivor10,r1       /* Decrementer (PIT for 440) */
-       li      r1,0x1400
-       mtspr   ivor13,r1       /* Data TLB error */
+       li      r1,0x0a00
+       mtspr   ivor9,r1        /* Auxiliary Processor unavailable */
+       li      r1,0x0900
+       mtspr   ivor10,r1       /* Decrementer */
        li      r1,0x1300
+       mtspr   ivor13,r1       /* Data TLB error */
+       li      r1,0x1400
        mtspr   ivor14,r1       /* Instr TLB error */
        li      r1,0x2000
        mtspr   ivor15,r1       /* Debug */
@@ -503,11 +509,81 @@ version_string:
        .ascii " (", __DATE__, " - ", __TIME__, ")"
        .ascii CONFIG_IDENT_STRING, "\0"
 
-/*
- * Maybe this should be moved somewhere else because the current
- * location (0x100) is where the CriticalInput Execption should be.
- */
        . = EXC_OFF_SYS_RESET
+       .globl  _start_of_vectors
+_start_of_vectors:
+
+/* Critical input. */
+       CRIT_EXCEPTION(0x100, CritcalInput, UnknownException)
+
+#ifdef CONFIG_440
+/* Machine check */
+       MCK_EXCEPTION(0x200, MachineCheck, MachineCheckException)
+#else
+       CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
+#endif /* CONFIG_440 */
+
+/* Data Storage exception. */
+       STD_EXCEPTION(0x300, DataStorage, UnknownException)
+
+/* Instruction Storage exception. */
+       STD_EXCEPTION(0x400, InstStorage, UnknownException)
+
+/* External Interrupt exception. */
+       STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
+
+/* Alignment exception. */
+       . = 0x600
+Alignment:
+       EXCEPTION_PROLOG(SRR0, SRR1)
+       mfspr   r4,DAR
+       stw     r4,_DAR(r21)
+       mfspr   r5,DSISR
+       stw     r5,_DSISR(r21)
+       addi    r3,r1,STACK_FRAME_OVERHEAD
+       li      r20,MSR_KERNEL
+       rlwimi  r20,r23,0,16,16         /* copy EE bit from saved MSR */
+       lwz     r6,GOT(transfer_to_handler)
+       mtlr    r6
+       blrl
+.L_Alignment:
+       .long   AlignmentException - _start + _START_OFFSET
+       .long   int_return - _start + _START_OFFSET
+
+/* Program check exception */
+       . = 0x700
+ProgramCheck:
+       EXCEPTION_PROLOG(SRR0, SRR1)
+       addi    r3,r1,STACK_FRAME_OVERHEAD
+       li      r20,MSR_KERNEL
+       rlwimi  r20,r23,0,16,16         /* copy EE bit from saved MSR */
+       lwz     r6,GOT(transfer_to_handler)
+       mtlr    r6
+       blrl
+.L_ProgramCheck:
+       .long   ProgramCheckException - _start + _START_OFFSET
+       .long   int_return - _start + _START_OFFSET
+
+#ifdef CONFIG_440
+       STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
+       STD_EXCEPTION(0x900, Decrementer, DecrementerPITException)
+       STD_EXCEPTION(0xa00, APU, UnknownException)
+#endif
+       STD_EXCEPTION(0xc00, SystemCall, UnknownException)
+
+#ifdef CONFIG_440
+       STD_EXCEPTION(0x1300, DataTLBError, UnknownException)
+       STD_EXCEPTION(0x1400, InstructionTLBError, UnknownException)
+#else
+       STD_EXCEPTION(0x1000, PIT, DecrementerPITException)
+       STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
+       STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
+#endif
+       CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
+
+       .globl  _end_of_vectors
+_end_of_vectors:
+       . = _START_OFFSET
 #endif
        .globl  _start
 _start:
@@ -564,6 +640,33 @@ _start:
        dcbz    r0,r3
        addi    r3,r3,32
        bdnz    ..d_ag
+
+       /*
+        * Lock the init-ram/stack in d-cache, so that other regions
+        * may use d-cache as well
+        * Note, that this current implementation locks exactly 4k
+        * of d-cache, so please make sure that you don't define a
+        * bigger init-ram area. Take a look at the lwmon5 440EPx
+        * implementation as a reference.
+        */
+       msync
+       isync
+       /* 8. set TFLOOR/NFLOOR to 8 (-> 8*16*32 bytes locked -> 4k) */
+       lis     r1,0x0201
+       ori     r1,r1,0xf808
+       mtspr   dvlim,r1
+       lis     r1,0x0808
+       ori     r1,r1,0x0808
+       mtspr   dnv0,r1
+       mtspr   dnv1,r1
+       mtspr   dnv2,r1
+       mtspr   dnv3,r1
+       mtspr   dtv0,r1
+       mtspr   dtv1,r1
+       mtspr   dtv2,r1
+       mtspr   dtv3,r1
+       msync
+       isync
 #endif /* CFG_INIT_RAM_DCACHE */
 
        /* 440EP & 440GR are only 440er PPC's without internal SRAM */
@@ -728,7 +831,7 @@ _start:
        /*----------------------------------------------------------------------- */
        /* Enable two 128MB cachable regions. */
        /*----------------------------------------------------------------------- */
-       addis   r1,r0,0x8000
+       addis   r1,r0,0xc000
        addi    r1,r1,0x0001
        mticcr  r1                      /* instruction cache */
 
@@ -751,12 +854,23 @@ _start:
 /*****************************************************************************/
 #if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
     defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
-    defined(CONFIG_405)
+    defined(CONFIG_405EX) || defined(CONFIG_405)
        /*----------------------------------------------------------------------- */
        /* Clear and set up some registers. */
        /*----------------------------------------------------------------------- */
        addi    r4,r0,0x0000
+#if !defined(CONFIG_405EX)
        mtspr   sgr,r4
+#else
+       /*
+        * On 405EX, completely clearing the SGR leads to PPC hangup
+        * upon PCIe configuration access. The PCIe memory regions
+        * need to be guarded!
+        */
+       lis     r3,0x0000
+       ori     r3,r3,0x7FFC
+       mtspr   sgr,r3
+#endif
        mtspr   dcwr,r4
        mtesr   r4                      /* clear Exception Syndrome Reg */
        mttcr   r4                      /* clear Timer Control Reg */
@@ -779,7 +893,7 @@ _start:
        /*----------------------------------------------------------------------- */
        /* Enable two 128MB cachable regions. */
        /*----------------------------------------------------------------------- */
-       lis     r4,0x8000
+       lis     r4,0xc000
        ori     r4,r4,0x0001
        mticcr  r4                      /* instruction cache */
        isync
@@ -788,12 +902,34 @@ _start:
        ori     r4,r4,0x0000
        mtdccr  r4                      /* data cache */
 
-#if !(defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR))
+#if !(defined(CFG_EBC_PB0AP) && defined(CFG_EBC_PB0CR)) || defined(CONFIG_405EX)
        /*----------------------------------------------------------------------- */
        /* Tune the speed and size for flash CS0  */
        /*----------------------------------------------------------------------- */
        bl      ext_bus_cntlr_init
 #endif
+#if !(defined(CFG_INIT_DCACHE_CS) || defined(CFG_TEMP_STACK_OCM))
+       /*
+        * Boards like the Kilauea (405EX) don't have OCM and can't use
+        * DCache for init-ram. So setup stack here directly after the
+        * SDRAM is initialized.
+        */
+       lis     r1, CFG_INIT_RAM_ADDR@h
+       ori     r1,r1,CFG_INIT_SP_OFFSET /* set up the stack in SDRAM */
+
+       li      r0, 0                   /* Make room for stack frame header and */
+       stwu    r0, -4(r1)              /* clear final stack frame so that      */
+       stwu    r0, -4(r1)              /* stack backtraces terminate cleanly   */
+       /*
+        * Set up a dummy frame to store reset vector as return address.
+        * this causes stack underflow to reset board.
+        */
+       stwu    r1, -8(r1)              /* Save back chain and move SP */
+       lis     r0, RESET_VECTOR@h      /* Address of reset vector */
+       ori     r0, r0, RESET_VECTOR@l
+       stwu    r1, -8(r1)              /* Save back chain and move SP */
+       stw     r0, +12(r1)             /* Save return addr (underflow vect) */
+#endif /* !(CFG_INIT_DCACHE_CS || !CFG_TEM_STACK_OCM) */
 
 #if defined(CONFIG_405EP)
        /*----------------------------------------------------------------------- */
@@ -817,21 +953,21 @@ _start:
         */
        lis     r3,CFG_OCM_DATA_ADDR@h  /* OCM location */
        ori     r3,r3,CFG_OCM_DATA_ADDR@l
-       ori     r3,r3,0x8270    /* 32K Offset, 16K for Bank 1, R/W/Enable */
+       ori     r3,r3,0x0270            /* 16K for Bank 1, R/W/Enable */
        mtdcr   ocmplb3cr1,r3           /* Set PLB Access */
        ori     r3,r3,0x4000            /* Add 0x4000 for bank 2 */
        mtdcr   ocmplb3cr2,r3           /* Set PLB Access */
        isync
 
-       lis     r3,CFG_OCM_DATA_ADDR@h  /* OCM location */
+       lis     r3,CFG_OCM_DATA_ADDR@h  /* OCM location */
        ori     r3,r3,CFG_OCM_DATA_ADDR@l
-       ori     r3,r3,0x0270            /* 16K for Bank 1, R/W/Enable */
-       mtdcr   ocmdscr1, r3            /* Set Data Side */
-       mtdcr   ocmiscr1, r3            /* Set Instruction Side */
+       ori     r3,r3,0x0270            /* 16K for Bank 1, R/W/Enable */
+       mtdcr   ocmdscr1, r3            /* Set Data Side */
+       mtdcr   ocmiscr1, r3            /* Set Instruction Side */
        ori     r3,r3,0x4000            /* Add 0x4000 for bank 2 */
-       mtdcr   ocmdscr2, r3            /* Set Data Side */
-       mtdcr   ocmiscr2, r3            /* Set Instruction Side */
-       addis   r3,0,0x0800             /* OCM Data Parity Disable - 1 Wait State */
+       mtdcr   ocmdscr2, r3            /* Set Data Side */
+       mtdcr   ocmiscr2, r3            /* Set Instruction Side */
+       addis   r3,0,0x0800             /* OCM Data Parity Disable - 1 Wait State */
        mtdcr   ocmdsisdpc,r3
 
        isync
@@ -850,7 +986,7 @@ _start:
        mtdcr   ocmdscntl, r4           /* set data-side IRAM config */
        isync
 
-       lis     r3,CFG_OCM_DATA_ADDR@h  /* OCM location */
+       lis     r3,CFG_OCM_DATA_ADDR@h  /* OCM location */
        ori     r3,r3,CFG_OCM_DATA_ADDR@l
        mtdcr   ocmdsarc, r3
        addis   r4, 0, 0xC000           /* OCM data area enabled */
@@ -911,7 +1047,7 @@ start_ram:
        ori     r4,r4,0xa000
        mtdcr   ebccfgd,r4
 
-       /* turn on data chache for this region */
+       /* turn on data cache for this region */
        lis     r4,0x0080
        mtdccr  r4
 
@@ -977,30 +1113,6 @@ start_ram:
        /*----------------------------------------------------------------------- */
        bl      sdram_init
 
-       /*
-        * Setup temporary stack pointer only for boards
-        * that do not use SDRAM SPD I2C stuff since it
-        * is already initialized to use DCACHE or OCM
-        * stacks.
-        */
-#if !(defined(CFG_INIT_DCACHE_CS) || defined(CFG_TEMP_STACK_OCM))
-       lis     r1, CFG_INIT_RAM_ADDR@h
-       ori     r1,r1,CFG_INIT_SP_OFFSET /* set up the stack in SDRAM */
-
-       li      r0, 0                   /* Make room for stack frame header and */
-       stwu    r0, -4(r1)              /* clear final stack frame so that      */
-       stwu    r0, -4(r1)              /* stack backtraces terminate cleanly   */
-       /*
-        * Set up a dummy frame to store reset vector as return address.
-        * this causes stack underflow to reset board.
-        */
-       stwu    r1, -8(r1)              /* Save back chain and move SP */
-       lis     r0, RESET_VECTOR@h      /* Address of reset vector */
-       ori     r0, r0, RESET_VECTOR@l
-       stwu    r1, -8(r1)              /* Save back chain and move SP */
-       stw     r0, +12(r1)             /* Save return addr (underflow vect) */
-#endif /* !(CFG_INIT_DCACHE_CS || !CFG_TEM_STACK_OCM) */
-
 #ifdef CONFIG_NAND_SPL
        bl      nand_boot               /* will not return */
 #else
@@ -1017,107 +1129,6 @@ start_ram:
 
 
 #ifndef CONFIG_NAND_SPL
-/*****************************************************************************/
-       .globl  _start_of_vectors
-_start_of_vectors:
-
-#if 0
-/*TODO Fixup _start above so we can do this*/
-/* Critical input. */
-       CRIT_EXCEPTION(0x100, CritcalInput, CritcalInputException)
-#endif
-
-/* Machine check */
-       CRIT_EXCEPTION(0x200, MachineCheck, MachineCheckException)
-
-/* Data Storage exception. */
-       STD_EXCEPTION(0x300, DataStorage, UnknownException)
-
-/* Instruction Storage exception. */
-       STD_EXCEPTION(0x400, InstStorage, UnknownException)
-
-/* External Interrupt exception. */
-       STD_EXCEPTION(0x500, ExtInterrupt, external_interrupt)
-
-/* Alignment exception. */
-       . = 0x600
-Alignment:
-       EXCEPTION_PROLOG
-       mfspr   r4,DAR
-       stw     r4,_DAR(r21)
-       mfspr   r5,DSISR
-       stw     r5,_DSISR(r21)
-       addi    r3,r1,STACK_FRAME_OVERHEAD
-       li      r20,MSR_KERNEL
-       rlwimi  r20,r23,0,16,16         /* copy EE bit from saved MSR */
-       lwz     r6,GOT(transfer_to_handler)
-       mtlr    r6
-       blrl
-.L_Alignment:
-       .long   AlignmentException - _start + EXC_OFF_SYS_RESET
-       .long   int_return - _start + EXC_OFF_SYS_RESET
-
-/* Program check exception */
-       . = 0x700
-ProgramCheck:
-       EXCEPTION_PROLOG
-       addi    r3,r1,STACK_FRAME_OVERHEAD
-       li      r20,MSR_KERNEL
-       rlwimi  r20,r23,0,16,16         /* copy EE bit from saved MSR */
-       lwz     r6,GOT(transfer_to_handler)
-       mtlr    r6
-       blrl
-.L_ProgramCheck:
-       .long   ProgramCheckException - _start + EXC_OFF_SYS_RESET
-       .long   int_return - _start + EXC_OFF_SYS_RESET
-
-       /* No FPU on MPC8xx.  This exception is not supposed to happen.
-       */
-       STD_EXCEPTION(0x800, FPUnavailable, UnknownException)
-
-       /* I guess we could implement decrementer, and may have
-        * to someday for timekeeping.
-        */
-       STD_EXCEPTION(0x900, Decrementer, timer_interrupt)
-       STD_EXCEPTION(0xa00, Trap_0a, UnknownException)
-       STD_EXCEPTION(0xb00, Trap_0b, UnknownException)
-       STD_EXCEPTION(0xc00, SystemCall, UnknownException)
-       STD_EXCEPTION(0xd00, SingleStep, UnknownException)
-
-       STD_EXCEPTION(0xe00, Trap_0e, UnknownException)
-       STD_EXCEPTION(0xf00, Trap_0f, UnknownException)
-
-       /* On the MPC8xx, this is a software emulation interrupt.  It occurs
-        * for all unimplemented and illegal instructions.
-        */
-       STD_EXCEPTION(0x1000, PIT, PITException)
-
-       STD_EXCEPTION(0x1100, InstructionTLBMiss, UnknownException)
-       STD_EXCEPTION(0x1200, DataTLBMiss, UnknownException)
-       STD_EXCEPTION(0x1300, InstructionTLBError, UnknownException)
-       STD_EXCEPTION(0x1400, DataTLBError, UnknownException)
-
-       STD_EXCEPTION(0x1500, Reserved5, UnknownException)
-       STD_EXCEPTION(0x1600, Reserved6, UnknownException)
-       STD_EXCEPTION(0x1700, Reserved7, UnknownException)
-       STD_EXCEPTION(0x1800, Reserved8, UnknownException)
-       STD_EXCEPTION(0x1900, Reserved9, UnknownException)
-       STD_EXCEPTION(0x1a00, ReservedA, UnknownException)
-       STD_EXCEPTION(0x1b00, ReservedB, UnknownException)
-
-       STD_EXCEPTION(0x1c00, DataBreakpoint, UnknownException)
-       STD_EXCEPTION(0x1d00, InstructionBreakpoint, UnknownException)
-       STD_EXCEPTION(0x1e00, PeripheralBreakpoint, UnknownException)
-       STD_EXCEPTION(0x1f00, DevPortBreakpoint, UnknownException)
-
-       CRIT_EXCEPTION(0x2000, DebugBreakpoint, DebugException )
-
-       .globl  _end_of_vectors
-_end_of_vectors:
-
-
-       . = 0x2100
-
 /*
  * This code finishes saving the registers to the exception frame
  * and jumps to the appropriate handler for the exception.
@@ -1133,28 +1144,12 @@ transfer_to_handler:
        SAVE_4GPRS(8, r21)
        SAVE_8GPRS(12, r21)
        SAVE_8GPRS(24, r21)
-#if 0
-       andi.   r23,r23,MSR_PR
-       mfspr   r23,SPRG3               /* if from user, fix up tss.regs */
-       beq     2f
-       addi    r24,r1,STACK_FRAME_OVERHEAD
-       stw     r24,PT_REGS(r23)
-2:     addi    r2,r23,-TSS             /* set r2 to current */
-       tovirt(r2,r2,r23)
-#endif
        mflr    r23
        andi.   r24,r23,0x3f00          /* get vector offset */
        stw     r24,TRAP(r21)
        li      r22,0
        stw     r22,RESULT(r21)
        mtspr   SPRG2,r22               /* r1 is now kernel sp */
-#if 0
-       addi    r24,r2,TASK_STRUCT_SIZE /* check for kernel stack overflow */
-       cmplw   0,r1,r2
-       cmplw   1,r1,r24
-       crand   1,1,4
-       bgt     stack_ovf               /* if r2 < r1 < r2+TASK_STRUCT_SIZE */
-#endif
        lwz     r24,0(r23)              /* virtual address of handler */
        lwz     r23,4(r23)              /* where to go when done */
        mtspr   SRR0,r24
@@ -1215,112 +1210,52 @@ crit_return:
        REST_GPR(31, r1)
        lwz     r2,_NIP(r1)     /* Restore environment */
        lwz     r0,_MSR(r1)
-       mtspr   990,r2          /* SRR2 */
-       mtspr   991,r0          /* SRR3 */
+       mtspr   csrr0,r2
+       mtspr   csrr1,r0
        lwz     r0,GPR0(r1)
        lwz     r2,GPR2(r1)
        lwz     r1,GPR1(r1)
        SYNC
        rfci
 
-/* Cache functions.
-*/
-flush_dcache:
-       addis   r9,r0,0x0002            /* set mask for EE and CE msr bits */
-       ori     r9,r9,0x8000
-       mfmsr   r12                     /* save msr */
-       andc    r9,r12,r9
-       mtmsr   r9                      /* disable EE and CE */
-       addi    r10,r0,0x0001           /* enable data cache for unused memory */
-       mfdccr  r9                      /* region 0xF8000000-0xFFFFFFFF via */
-       or      r10,r10,r9              /* bit 31 in dccr */
-       mtdccr  r10
-
-       /* do loop for # of congruence classes. */
-       lis     r10,(CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@ha       /* TBS: for large cache sizes */
-       ori     r10,r10,(CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@l
-       lis     r11,(CFG_DCACHE_SIZE / 2)@ha /* D cache set size - 2 way sets */
-       ori     r11,r11,(CFG_DCACHE_SIZE / 2)@l /* D cache set size - 2 way sets */
-       mtctr   r10
-       addi    r10,r0,(0xE000-0x10000) /* start at 0xFFFFE000 */
-       add     r11,r10,r11             /* add to get to other side of cache line */
-..flush_dcache_loop:
-       lwz     r3,0(r10)               /* least recently used side */
-       lwz     r3,0(r11)               /* the other side */
-       dccci   r0,r11                  /* invalidate both sides */
-       addi    r10,r10,CFG_CACHELINE_SIZE /* bump to next line */
-       addi    r11,r11,CFG_CACHELINE_SIZE /* bump to next line */
-       bdnz    ..flush_dcache_loop
-       sync                            /* allow memory access to complete */
-       mtdccr  r9                      /* restore dccr */
-       mtmsr   r12                     /* restore msr */
-       blr
-
-       .globl  icache_enable
-icache_enable:
-       mflr    r8
-       bl      invalidate_icache
-       mtlr    r8
-       isync
-       addis   r3,r0, 0x8000         /* set bit 0 */
-       mticcr  r3
-       blr
-
-       .globl  icache_disable
-icache_disable:
-       addis   r3,r0, 0x0000         /* clear bit 0 */
-       mticcr  r3
-       isync
-       blr
-
-       .globl  icache_status
-icache_status:
-       mficcr  r3
-       srwi    r3, r3, 31      /* >>31 => select bit 0 */
-       blr
-
-       .globl  dcache_enable
-dcache_enable:
-       mflr    r8
-       bl      invalidate_dcache
-       mtlr    r8
-       isync
-       addis   r3,r0, 0x8000         /* set bit 0 */
-       mtdccr  r3
-       blr
-
-       .globl  dcache_disable
-dcache_disable:
-       mflr    r8
-       bl      flush_dcache
-       mtlr    r8
-       addis   r3,r0, 0x0000         /* clear bit 0 */
-       mtdccr  r3
-       blr
+#ifdef CONFIG_440
+mck_return:
+       mfmsr   r28             /* Disable interrupts */
+       li      r4,0
+       ori     r4,r4,MSR_EE
+       andc    r28,r28,r4
+       SYNC                    /* Some chip revs need this... */
+       mtmsr   r28
+       SYNC
+       lwz     r2,_CTR(r1)
+       lwz     r0,_LINK(r1)
+       mtctr   r2
+       mtlr    r0
+       lwz     r2,_XER(r1)
+       lwz     r0,_CCR(r1)
+       mtspr   XER,r2
+       mtcrf   0xFF,r0
+       REST_10GPRS(3, r1)
+       REST_10GPRS(13, r1)
+       REST_8GPRS(23, r1)
+       REST_GPR(31, r1)
+       lwz     r2,_NIP(r1)     /* Restore environment */
+       lwz     r0,_MSR(r1)
+       mtspr   mcsrr0,r2
+       mtspr   mcsrr1,r0
+       lwz     r0,GPR0(r1)
+       lwz     r2,GPR2(r1)
+       lwz     r1,GPR1(r1)
+       SYNC
+       rfmci
+#endif /* CONFIG_440 */
 
-       .globl  dcache_status
-dcache_status:
-       mfdccr  r3
-       srwi    r3, r3, 31      /* >>31 => select bit 0 */
-       blr
 
        .globl get_pvr
 get_pvr:
        mfspr   r3, PVR
        blr
 
-#if !defined(CONFIG_440)
-       .globl wr_pit
-wr_pit:
-       mtspr   pit, r3
-       blr
-#endif
-
-       .globl wr_tcr
-wr_tcr:
-       mtspr   tcr, r3
-       blr
-
 /*------------------------------------------------------------------------------- */
 /* Function:    out16 */
 /* Description:         Output 16 bits */
@@ -1375,39 +1310,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:    ppcSync */
-/* Description:         Processor Synchronize */
-/* Input:       none. */
-/* Output:      none. */
-/*------------------------------------------------------------------------------- */
-       .globl  ppcSync
-ppcSync:
-       sync
-       blr
-
 /*
  * void relocate_code (addr_sp, gd, addr_moni)
  *
@@ -1421,6 +1323,51 @@ ppcSync:
  */
        .globl  relocate_code
 relocate_code:
+#ifdef CONFIG_4xx_DCACHE
+       /*
+        * We need to flush the Init Data before the dcache will be
+        * invalidated
+        */
+
+       /* save regs */
+       mr      r9,r3
+       mr      r10,r4
+       mr      r11,r5
+
+       mr      r3,r4
+       addi    r4,r4,0x200     /* should be enough for init data */
+       bl      flush_dcache_range
+
+       /* restore regs */
+       mr      r3,r9
+       mr      r4,r10
+       mr      r5,r11
+#endif
+
+#ifdef CFG_INIT_RAM_DCACHE
+       /*
+        * Unlock the previously locked d-cache
+        */
+       msync
+       isync
+       /* set TFLOOR/NFLOOR to 0 again */
+       lis     r6,0x0001
+       ori     r6,r6,0xf800
+       mtspr   dvlim,r6
+       lis     r6,0x0000
+       ori     r6,r6,0x0000
+       mtspr   dnv0,r6
+       mtspr   dnv1,r6
+       mtspr   dnv2,r6
+       mtspr   dnv3,r6
+       mtspr   dtv0,r6
+       mtspr   dtv1,r6
+       mtspr   dtv2,r6
+       mtspr   dtv3,r6
+       msync
+       isync
+#endif /* CFG_INIT_RAM_DCACHE */
+
 #if defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
     defined(CONFIG_440EPX) || defined(CONFIG_440GRX) || \
     defined(CONFIG_440SP) || defined(CONFIG_440SPE)
@@ -1432,7 +1379,11 @@ relocate_code:
        dccci   0,0                     /* Invalidate data cache, now no longer our stack */
        sync
        isync
-       addi    r1,r0,0x0000            /* TLB entry #0 */
+#ifdef CFG_TLB_FOR_BOOT_FLASH
+       addi    r1,r0,CFG_TLB_FOR_BOOT_FLASH    /* Use defined TLB */
+#else
+       addi    r1,r0,0x0000            /* Default TLB entry is #0 */
+#endif
        tlbre   r0,r1,0x0002            /* Read contents */
        ori     r0,r0,0x0c00            /* Or in the inhibit, write through bit */
        tlbwe   r0,r1,0x0002            /* Save it out */
@@ -1448,7 +1399,7 @@ relocate_code:
        ori     r4, r4, CFG_MONITOR_BASE@l
        lwz     r5, GOT(__init_end)
        sub     r5, r5, r4
-       li      r6, CFG_CACHELINE_SIZE          /* Cache Line Size      */
+       li      r6, L1_CACHE_BYTES              /* Cache Line Size      */
 
        /*
         * Fix GOT pointer:
@@ -1518,7 +1469,7 @@ relocate_code:
  * initialization, now running from RAM.
  */
 
-       addi    r0, r10, in_ram - _start + EXC_OFF_SYS_RESET
+       addi    r0, r10, in_ram - _start + _START_OFFSET
        mtlr    r0
        blr                             /* NEVER RETURNS! */
 
@@ -1566,16 +1517,25 @@ clear_bss:
        lwz     r4,GOT(_end)
 
        cmplw   0, r3, r4
-       beq     6f
+       beq     7f
 
        li      r0, 0
-5:
+
+       andi.   r5, r4, 3
+       beq     6f
+       sub     r4, r4, r5
+       mtctr   r5
+       mr      r5, r4
+5:     stb     r0, 0(r5)
+       addi    r5, r5, 1
+       bdnz    5b
+6:
        stw     r0, 0(r3)
        addi    r3, r3, 4
        cmplw   0, r3, r4
-       bne     5b
-6:
+       bne     6b
 
+7:
        mr      r3, r9          /* Init Data pointer            */
        mr      r4, r10         /* Destination Address          */
        bl      board_init_r
@@ -1588,7 +1548,7 @@ clear_bss:
         */
        .globl  trap_init
 trap_init:
-       lwz     r7, GOT(_start)
+       lwz     r7, GOT(_start_of_vectors)
        lwz     r8, GOT(_end_of_vectors)
 
        li      r9, 0x100               /* reset vector always at 0x100 */
@@ -1608,35 +1568,48 @@ trap_init:
        /*
         * relocate `hdlr' and `int_return' entries
         */
-       li      r7, .L_MachineCheck - _start + EXC_OFF_SYS_RESET
-       li      r8, Alignment - _start + EXC_OFF_SYS_RESET
+       li      r7, .L_MachineCheck - _start + _START_OFFSET
+       li      r8, Alignment - _start + _START_OFFSET
 2:
        bl      trap_reloc
-       addi    r7, r7, 0x100           /* next exception vector        */
+       addi    r7, r7, 0x100           /* next exception vector */
        cmplw   0, r7, r8
        blt     2b
 
-       li      r7, .L_Alignment - _start + EXC_OFF_SYS_RESET
+       li      r7, .L_Alignment - _start + _START_OFFSET
        bl      trap_reloc
 
-       li      r7, .L_ProgramCheck - _start + EXC_OFF_SYS_RESET
+       li      r7, .L_ProgramCheck - _start + _START_OFFSET
        bl      trap_reloc
 
-       li      r7, .L_FPUnavailable - _start + EXC_OFF_SYS_RESET
-       li      r8, SystemCall - _start + EXC_OFF_SYS_RESET
-3:
+#ifdef CONFIG_440
+       li      r7, .L_FPUnavailable - _start + _START_OFFSET
        bl      trap_reloc
-       addi    r7, r7, 0x100           /* next exception vector        */
-       cmplw   0, r7, r8
-       blt     3b
 
-       li      r7, .L_SingleStep - _start + EXC_OFF_SYS_RESET
-       li      r8, _end_of_vectors - _start + EXC_OFF_SYS_RESET
-4:
+       li      r7, .L_Decrementer - _start + _START_OFFSET
+       bl      trap_reloc
+
+       li      r7, .L_APU - _start + _START_OFFSET
+       bl      trap_reloc
+
+       li      r7, .L_InstructionTLBError - _start + _START_OFFSET
+       bl      trap_reloc
+
+       li      r7, .L_DataTLBError - _start + _START_OFFSET
+       bl      trap_reloc
+#else /* CONFIG_440 */
+       li      r7, .L_PIT - _start + _START_OFFSET
+       bl      trap_reloc
+
+       li      r7, .L_InstructionTLBMiss - _start + _START_OFFSET
+       bl      trap_reloc
+
+       li      r7, .L_DataTLBMiss - _start + _START_OFFSET
+       bl      trap_reloc
+#endif /* CONFIG_440 */
+
+       li      r7, .L_DebugBreakpoint - _start + _START_OFFSET
        bl      trap_reloc
-       addi    r7, r7, 0x100           /* next exception vector        */
-       cmplw   0, r7, r8
-       blt     4b
 
 #if !defined(CONFIG_440)
        addi    r7,r0,0x1000            /* set ME bit (Machine Exceptions) */
@@ -1679,13 +1652,13 @@ trap_reloc:
 +----------------------------------------------------------------------------*/
        function_prolog(dcbz_area)
        rlwinm. r5,r4,0,27,31
-       rlwinm  r5,r4,27,5,31
-       beq     ..d_ra2
-       addi    r5,r5,0x0001
-..d_ra2:mtctr   r5
-..d_ag2:dcbz    r0,r3
-       addi    r3,r3,32
-       bdnz    ..d_ag2
+       rlwinm  r5,r4,27,5,31
+       beq     ..d_ra2
+       addi    r5,r5,0x0001
+..d_ra2:mtctr  r5
+..d_ag2:dcbz   r0,r3
+       addi    r3,r3,32
+       bdnz    ..d_ag2
        sync
        blr
        function_epilog(dcbz_area)
@@ -1694,26 +1667,28 @@ trap_reloc:
 | dflush.  Assume 32K at vector address is cachable.
 +----------------------------------------------------------------------------*/
        function_prolog(dflush)
-       mfmsr   r9
-       rlwinm  r8,r9,0,15,13
-       rlwinm  r8,r8,0,17,15
-       mtmsr   r8
-       addi    r3,r0,0x0000
-       mtspr   dvlim,r3
-       mfspr   r3,ivpr
-       addi    r4,r0,1024
-       mtctr   r4
+       mfmsr   r9
+       rlwinm  r8,r9,0,15,13
+       rlwinm  r8,r8,0,17,15
+       mtmsr   r8
+       mfspr   r8,dvlim
+       addi    r3,r0,0x0000
+       mtspr   dvlim,r3
+       mfspr   r3,ivpr
+       addi    r4,r0,1024
+       mtctr   r4
 ..dflush_loop:
-       lwz     r6,0x0(r3)
-       addi    r3,r3,32
-       bdnz    ..dflush_loop
-       addi    r3,r3,-32
-       mtctr   r4
-..ag:   dcbf    r0,r3
-       addi    r3,r3,-32
-       bdnz    ..ag
+       lwz     r6,0x0(r3)
+       addi    r3,r3,32
+       bdnz    ..dflush_loop
+       addi    r3,r3,-32
+       mtctr   r4
+..ag:  dcbf    r0,r3
+       addi    r3,r3,-32
+       bdnz    ..ag
+       mtspr   dvlim,r8
        sync
-       mtmsr   r9
+       mtmsr   r9
        blr
        function_epilog(dflush)
 #endif /* CONFIG_440 */
@@ -1755,23 +1730,6 @@ in32:
        lwz     3,0x0000(3)
        blr
 
-invalidate_icache:
-       iccci   r0,r0                   /* for 405, iccci invalidates the */
-       blr                             /*   entire I cache */
-
-invalidate_dcache:
-       addi    r6,0,0x0000             /* clear GPR 6 */
-       /* Do loop for # of dcache congruence classes. */
-       lis     r7, (CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@ha       /* TBS for large sized cache */
-       ori     r7, r7, (CFG_DCACHE_SIZE / CFG_CACHELINE_SIZE / 2)@l
-                                       /* NOTE: dccci invalidates both */
-       mtctr   r7                      /* ways in the D cache */
-..dcloop:
-       dccci   0,r6                    /* invalidate line */
-       addi    r6,r6, CFG_CACHELINE_SIZE /* bump to next line */
-       bdnz    ..dcloop
-       blr
-
 /**************************************************************************/
 /* PPC405EP specific stuff                                               */
 /**************************************************************************/
@@ -1857,28 +1815,6 @@ ppc405ep_init:
        mtdcr   ebccfgd,r3
 #endif
 
-#ifndef CFG_CPC0_PCI
-       li      r3,CPC0_PCI_HOST_CFG_EN
-#ifdef CONFIG_BUBINGA
-       /*
-       !-----------------------------------------------------------------------
-       ! Check FPGA for PCI internal/external arbitration
-       !   If board is set to internal arbitration, update cpc0_pci
-       !-----------------------------------------------------------------------
-       */
-       addis   r5,r0,FPGA_REG1@h      /* set offset for FPGA_REG1 */
-       ori     r5,r5,FPGA_REG1@l
-       lbz     r5,0x0(r5)              /* read to get PCI arb selection */
-       andi.   r6,r5,FPGA_REG1_PCI_INT_ARB  /* using internal arbiter ?*/
-       beq     ..pci_cfg_set             /* if not set, then bypass reg write*/
-#endif
-       ori     r3,r3,CPC0_PCI_ARBIT_EN
-#else /* CFG_CPC0_PCI */
-       li      r3,CFG_CPC0_PCI
-#endif /* CFG_CPC0_PCI */
-..pci_cfg_set:
-       mtdcr   CPC0_PCI, r3             /* Enable internal arbiter*/
-
        /*
        !-----------------------------------------------------------------------
        ! Check to see if chip is in bypass mode.
@@ -1934,11 +1870,50 @@ ppc405ep_init:
 ..no_pllset:
 #endif /* CONFIG_BUBINGA */
 
+#ifdef CONFIG_TAIHU
+       mfdcr   r4, CPC0_BOOT
+       andi.   r5, r4, CPC0_BOOT_SEP@l
+       bne     strap_1                 /* serial eeprom present */
+       addis   r5,0,CPLD_REG0_ADDR@h
+       ori     r5,r5,CPLD_REG0_ADDR@l
+       andi.   r5, r5, 0x10
+       bne     _pci_66mhz
+#endif /* CONFIG_TAIHU */
+
+#if defined(CONFIG_ZEUS)
+       mfdcr   r4, CPC0_BOOT
+       andi.   r5, r4, CPC0_BOOT_SEP@l
+       bne     strap_1         /* serial eeprom present */
+       lis     r3,0x0000
+       addi    r3,r3,0x3030
+       lis     r4,0x8042
+       addi    r4,r4,0x223e
+       b       1f
+strap_1:
+       mfdcr   r3, CPC0_PLLMR0
+       mfdcr   r4, CPC0_PLLMR1
+       b       1f
+#endif
+
        addis   r3,0,PLLMR0_DEFAULT@h       /* PLLMR0 default value */
        ori     r3,r3,PLLMR0_DEFAULT@l     /* */
        addis   r4,0,PLLMR1_DEFAULT@h       /* PLLMR1 default value */
        ori     r4,r4,PLLMR1_DEFAULT@l     /* */
 
+#ifdef CONFIG_TAIHU
+       b       1f
+_pci_66mhz:
+       addis   r3,0,PLLMR0_DEFAULT_PCI66@h
+       ori     r3,r3,PLLMR0_DEFAULT_PCI66@l
+       addis   r4,0,PLLMR1_DEFAULT_PCI66@h
+       ori     r4,r4,PLLMR1_DEFAULT_PCI66@l
+       b       1f
+strap_1:
+       mfdcr   r3, CPC0_PLLMR0
+       mfdcr   r4, CPC0_PLLMR1
+#endif /* CONFIG_TAIHU */
+
+1:
        b       pll_write                 /* Write the CPC0_PLLMR with new value */
 
 pll_done: