Print this page
_locore_start needs to set up an 8-byte aligned stack
Sadly, during removal of special early-boot stacks
(027eb01d0ff8f66be55208b58ecd7cb2b7b27714) the stack passed into mlsetup
lost its 8-byte aligned-ness.


 106         /*
 107          * Set up our curthread pointer
 108          */
 109         ldr     r0, =t0
 110         mcr     p15, 0, r0, c13, c0, 4
 111 
 112         /*
 113          * Go ahead now and enable unaligned access, the L1 I/D caches.
 114          *
 115          * Bit 2 is for the D cache
 116          * Bit 12 is for the I cache
 117          * Bit 22 is for unaligned access
 118          */
 119         mrc     p15, 0, r0, c1, c0, 0
 120         orr     r0, #0x02
 121         orr     r0, #0x1000
 122         orr     r0, #0x400000
 123         mcr     p15, 0, r0, c1, c0, 0
 124 
 125         /*
 126          * mlsetup() takes the struct regs as an argument. main doesn't take any
 127          * and should never return. After the push below, we should have a
 128          * 8-byte aligned stack pointer. This is why we subtracted four earlier
 129          * on if we were 8-byte aligned.




 130          */
 131         mov     r9,#0
 132         push    { r9 }

 133         mov     r0, sp
 134         bl      mlsetup
 135         bl      main
 136         /* NOTREACHED */
 137         ldr     r0,=__return_from_main
 138         ldr     r0,[r0]
 139         bl      panic
 140         SET_SIZE(_locore_start)
 141 
 142 __return_from_main:
 143         .string "main() returned"
 144 #endif  /* __lint */


 106         /*
 107          * Set up our curthread pointer
 108          */
 109         ldr     r0, =t0
 110         mcr     p15, 0, r0, c13, c0, 4
 111 
 112         /*
 113          * Go ahead now and enable unaligned access, the L1 I/D caches.
 114          *
 115          * Bit 2 is for the D cache
 116          * Bit 12 is for the I cache
 117          * Bit 22 is for unaligned access
 118          */
 119         mrc     p15, 0, r0, c1, c0, 0
 120         orr     r0, #0x02
 121         orr     r0, #0x1000
 122         orr     r0, #0x400000
 123         mcr     p15, 0, r0, c1, c0, 0
 124 
 125         /*
 126          * mlsetup() takes the struct regs as an argument. main doesn't take
 127          * any and should never return. Currently, we have an 8-byte aligned
 128          * stack.  We want to push a zero frame pointer to terminate any
 129          * stack walking, but that would cause us to end up with only a
 130          * 4-byte aligned stack.  So, to keep things nice and correct, we
 131          * push a zero value twice - it's similar to a typical function
 132          * entry:
 133          *      push { r9, lr }
 134          */
 135         mov     r9,#0
 136         push    { r9 }          /* link register */
 137         push    { r9 }          /* frame pointer */
 138         mov     r0, sp
 139         bl      mlsetup
 140         bl      main
 141         /* NOTREACHED */
 142         ldr     r0,=__return_from_main
 143         ldr     r0,[r0]
 144         bl      panic
 145         SET_SIZE(_locore_start)
 146 
 147 __return_from_main:
 148         .string "main() returned"
 149 #endif  /* __lint */