]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/arm/cswitch.s
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / arm / cswitch.s
index 7c3812dd01e68996edc7de03e0016cac88e7e759..f7c8dcbd690a93dccc4363912cd7758278f74ae0 100644 (file)
@@ -87,7 +87,7 @@ LEXT(machine_load_context)
        and             r2, r2, #3                                                      // Extract cpu number
        orr             r1, r1, r2                                                      // 
        mcr             p15, 0, r1, c13, c0, 3                          // Write TPIDRURO
-       ldr             r1, [r0, TH_CTH_DATA]
+       mov             r1, #0
        mcr             p15, 0, r1, c13, c0, 2                          // Write TPIDRURW
        mov             r7, #0                                                          // Clear frame pointer
        ldr             r3, [r0, TH_KSTACKPTR]                          // Get kernel stack top
@@ -97,10 +97,12 @@ LEXT(machine_load_context)
        bx              lr                                                                      // Return
 
 /*
- *     void Call_continuation( void (*continuation)(void), 
- *                             void *param, 
- *                             wait_result_t wresult, 
- *                             vm_offset_t stack_ptr)
+ *  typedef void (*thread_continue_t)(void *param, wait_result_t)
+ *
+ *     void Call_continuation( thread_continue_t continuation,
+ *                                     void *param, 
+ *                                         wait_result_t wresult,
+ *                          bool enable interrupts)
  */
        .text
        .align  5
@@ -110,10 +112,21 @@ LEXT(Call_continuation)
        mrc             p15, 0, r9, c13, c0, 4                          // Read TPIDRPRW
        ldr             sp, [r9, TH_KSTACKPTR]                          // Set stack pointer
        mov             r7, #0                                                          // Clear frame pointer
-       mov             r6,r0                                                           // Load continuation
-       mov             r0,r1                                                           // Set first parameter
-       mov             r1,r2                                                           // Set wait result arg
-       blx             r6                                                                      // Branch to continuation
+
+       mov             r4,r0                                                           // Load continuation
+       mov             r5,r1                                                           // continuation parameter
+       mov             r6,r2                                                           // Set wait result arg
+
+    teq     r3, #0
+    beq     1f
+    mov     r0, #1
+    bl _ml_set_interrupts_enabled
+1:
+    
+       mov             r0,r5                                                           // Set first parameter
+       mov             r1,r6                                                           // Set wait result arg
+       blx             r4                                                                      // Branch to continuation
+
        mrc             p15, 0, r0, c13, c0, 4                          // Read TPIDRPRW
        LOAD_ADDR_PC(thread_terminate)
        b               .                                                                       // Not reach
@@ -133,7 +146,8 @@ LEXT(Switch_context)
        bne             switch_threads                                          // No need to save GPR/NEON state if we are
 #if     __ARM_VFP__
        mov             r1, r2                                                          // r2 will be clobbered by the save, so preserve it
-       add             r3, r0, ACT_KVFP                                        // Get the kernel VFP save area for the old thread...
+       ldr             r3, [r0, TH_KSTACKPTR]                          // Get old kernel stack top
+       add             r3, r3, SS_KVFP                                         // Get the kernel VFP save area for the old thread...
        save_vfp_registers                                                      // ...and save our VFP state to it
        mov             r2, r1                                                          // Restore r2 (the new thread pointer)
 #endif /* __ARM_VFP__ */
@@ -141,6 +155,8 @@ LEXT(Switch_context)
        add             r3, r3, SS_R4
        stmia           r3!, {r4-r14}                                   // Save general registers to pcb
 switch_threads:
+       ldr             r3, [r2, ACT_CPUDATAP]
+       str             r2, [r3, CPU_ACTIVE_THREAD]
        ldr             r3, [r2, TH_KSTACKPTR]                          // get kernel stack top
        mcr             p15, 0, r2, c13, c0, 4                          // Write TPIDRPRW
        ldr             r6, [r2, TH_CTH_SELF]
@@ -148,13 +164,14 @@ switch_threads:
        and             r5, r5, #3                                                      // Extract cpu number
        orr             r6, r6, r5
        mcr             p15, 0, r6, c13, c0, 3                          // Write TPIDRURO
-       ldr             r6, [r2, TH_CTH_DATA]
+       mov             r6, #0
        mcr             p15, 0, r6, c13, c0, 2                          // Write TPIDRURW
 load_reg:      
        add             r3, r3, SS_R4
        ldmia   r3!, {r4-r14}                                           // Restore new thread status
 #if     __ARM_VFP__
-       add             r3, r2, ACT_KVFP                                        // Get the kernel VFP save area for the new thread...
+       ldr             r3, [r2, TH_KSTACKPTR]                          // get kernel stack top
+       add             r3, r3, SS_KVFP                                         // Get the kernel VFP save area for the new thread...
        load_vfp_registers                                                      // ...and load the saved state
 #endif /* __ARM_VFP__ */
        bx              lr                                                                      // Return
@@ -170,7 +187,8 @@ load_reg:
 LEXT(Shutdown_context)
        mrc             p15, 0, r9, c13, c0, 4                          // Read TPIDRPRW
 #if __ARM_VFP__
-       add             r3, r9, ACT_KVFP                                        // Get the kernel VFP save area for the current thread...
+       ldr             r3, [r9, TH_KSTACKPTR]                          // get kernel stack top
+       add             r3, r3, SS_KVFP                                         // Get the kernel VFP save area for the current thread...
        save_vfp_registers                                                      // ...and save our VFP state to it
 #endif
        ldr             r3, [r9, TH_KSTACKPTR]                          // Get kernel stack top
@@ -194,7 +212,8 @@ LEXT(Idle_context)
 
        mrc             p15, 0, r9, c13, c0, 4                          // Read TPIDRPRW
 #if    __ARM_VFP__
-       add             r3, r9, ACT_KVFP                                        // Get the kernel VFP save area for the current thread...
+       ldr             r3, [r9, TH_KSTACKPTR]                          // get kernel stack top
+       add             r3, r3, SS_KVFP                                         // Get the kernel VFP save area for the current thread...
        save_vfp_registers                                                      // ...and save our VFP state to it
 #endif
        ldr             r3, [r9, TH_KSTACKPTR]                          // Get kernel stack top
@@ -220,7 +239,8 @@ LEXT(Idle_load_context)
        add             r3, r3, SS_R4
        ldmia   r3!, {r4-r14}                                           // Restore new thread status
 #if __ARM_VFP__
-       add             r3, r9, ACT_KVFP                                        // Get the kernel VFP save area for the current thread...
+       ldr             r3, [r9, TH_KSTACKPTR]                          // get kernel stack top
+       add             r3, r3, SS_KVFP                                         // Get the kernel VFP save area for the current thread...
        load_vfp_registers                                                      // ...and load the saved state
 #endif
        bx              lr                                                                      // Return