* Code cleanup:
[oweals/u-boot.git] / cpu / mpc8260 / start.S
index 10a8988ee855925fd0f05ffce10064bc5dc2b203..d3fd8652dc873f635d40f3afbe6aefb654959199 100644 (file)
@@ -66,8 +66,9 @@
        GOT_ENTRY(_end_of_vectors)
        GOT_ENTRY(transfer_to_handler)
 
+       GOT_ENTRY(__init_end)
        GOT_ENTRY(_end)
-       GOT_ENTRY(.bss)
+       GOT_ENTRY(__bss_start)
 #if defined(CONFIG_HYMOD)
        GOT_ENTRY(environment)
 #endif
@@ -160,6 +161,7 @@ _hrcw_table:
        .globl  _start
 _start:
        li      r21, BOOTFLAG_COLD      /* Normal Power-On: Boot from FLASH*/
+       nop
        b       boot_cold
 
        . = EXC_OFF_SYS_RESET + 0x10
@@ -170,6 +172,18 @@ _start_warm:
        b       boot_warm
 
 boot_cold:
+#if defined(CONFIG_MPC8260ADS)
+       lis     r3, CFG_DEFAULT_IMMR@h
+       nop
+       lwz     r4, 0(r3)
+       nop
+       rlwinm  r4, r4, 0, 8, 5
+       nop
+       oris    r4, r4, 0x0200
+       nop
+       stw     r4, 0(r3)
+       nop
+#endif /* CONFIG_MPC8260ADS */
 boot_warm:
        mfmsr   r5                      /* save msr contents            */
 
@@ -324,7 +338,14 @@ SystemCall:
        add     r11,r11,r0
        lwz     r11,0(r11)
 
-       li      r12,0xd00-4*3           /* save LR & SRRx */
+       li      r20,0xd00-4             /* Get stack pointer */
+       lwz     r12,0(r20)
+       subi    r12,r12,12              /* Adjust stack pointer */
+       li      r0,0xc00+_end_back-SystemCall
+       cmplw   0, r0, r12              /* Check stack overflow */
+       bgt     1f
+       stw     r12,0(r20)
+
        mflr    r0
        stw     r0,0(r12)
        mfspr   r0,SRR0
@@ -349,7 +370,9 @@ _back:
        mtmsr   r11
        SYNC
 
-       li      r12,0xd00-4*3           /* restore regs */
+       li      r12,0xd00-4             /* restore regs */
+       lwz     r12,0(r12)
+
        lwz     r11,0(r12)
        mtlr    r11
        lwz     r11,4(r12)
@@ -357,8 +380,13 @@ _back:
        lwz     r11,8(r12)
        mtspr   SRR1,r11
 
+       addi    r12,r12,12              /* Adjust stack pointer */
+       li      r20,0xd00-4
+       stw     r12,0(r20)
+
        SYNC
        rfi
+_end_back:
 
        STD_EXCEPTION(0xd00, SingleStep, UnknownException)
 
@@ -849,8 +877,8 @@ relocate_code:
        mr      r3,  r5                         /* Destination Address  */
        lis     r4, CFG_MONITOR_BASE@h          /* Source      Address  */
        ori     r4, r4, CFG_MONITOR_BASE@l
-       lis     r5, CFG_MONITOR_LEN@h           /* Length in Bytes      */
-       ori     r5, r5, CFG_MONITOR_LEN@l
+       lwz     r5, GOT(__init_end)
+       sub     r5, r5, r4
        li      r6, CFG_CACHELINE_SIZE          /* Cache Line Size      */
 
        /*
@@ -938,8 +966,8 @@ in_ram:
        /*
         * Relocation Function, r14 point to got2+0x8000
         *
-         * Adjust got2 pointers, no need to check for 0, this code
-         * already puts a few entries in the table.
+        * Adjust got2 pointers, no need to check for 0, this code
+        * already puts a few entries in the table.
         */
        li      r0,__got2_entries@sectoff@l
        la      r3,GOT(_GOT2_TABLE_)
@@ -953,7 +981,7 @@ in_ram:
        bdnz    1b
 
        /*
-         * Now adjust the fixups and the pointers to the fixups
+        * Now adjust the fixups and the pointers to the fixups
         * in case we need to move ourselves again.
         */
 2:     li      r0,__fixup_entries@sectoff@l
@@ -973,7 +1001,7 @@ clear_bss:
        /*
         * Now clear BSS segment
         */
-       lwz     r3,GOT(.bss)
+       lwz     r3,GOT(__bss_start)
 #if defined(CONFIG_HYMOD)
        /*
         * For HYMOD - the environment is the very last item in flash.
@@ -1002,12 +1030,6 @@ clear_bss:
        mr      r4, r10         /* Destination Address          */
        bl      board_init_r
 
-       /* Problems accessing "end" in C, so do it here */
-       .globl  get_endaddr
-get_endaddr:
-       lwz     r3,GOT(_end)
-       blr
-
        /*
         * Copy exception vector code to low memory
         *
@@ -1019,7 +1041,7 @@ trap_init:
        lwz     r7, GOT(_start)
        lwz     r8, GOT(_end_of_vectors)
 
-       rlwinm  r9, r7, 0, 18, 31       /* _start & 0x3FFF      */
+       li      r9, 0x100               /* reset vector always at 0x100 */
 
        cmplw   0, r7, r8
        bgelr                           /* return if r7>=r8 - just in case */