- Add func.endfunc decoration.
authorAlex Ionescu <aionescu@gmail.com>
Sun, 17 Sep 2006 23:17:07 +0000 (23:17 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Sun, 17 Sep 2006 23:17:07 +0000 (23:17 +0000)
- Add code to wait for SwapBusy == FALSE on SMP.
- Add stub code to check for new PCR fields in 2003. Currently disabled because thread swap code still uses XP fields.
- Check for active DPCs at the end of thread swap, not at the beginning.
- Set PRCB->IdleThread outside of the thread swap routine.
- Don't set the thread state to running inside the swap routine, we already do it outside.

svn path=/trunk/; revision=24180

reactos/ntoskrnl/ke/i386/ctxswitch.S
reactos/ntoskrnl/ke/thrdschd.c

index 6dbcfa6..1aa8481 100644 (file)
@@ -229,6 +229,7 @@ Return:
  *     If a return from a system thread is detected, a bug check will occur.
  *
  *--*/
+ .func KiThreadStartup@156
 .globl _KiThreadStartup@156
 _KiThreadStartup@156:
 
@@ -268,6 +269,7 @@ BadThread:
 
     /* A system thread returned...this is very bad! */
     int 3
+.endfunc
 
 /*++
  * KiSwapContextInternal 
@@ -287,22 +289,32 @@ BadThread:
  *     Absolutely all registers except ESP can be trampled here for maximum code flexibility.
  *
  *--*/
-.globl @KiSwapContextInternal@0
+.func @KiSwapContextInternal@0, @KiSwapContextInternal@0
 @KiSwapContextInternal@0:
 
-    /* Set the Thread to running */
-    mov byte ptr es:[esi+KTHREAD_STATE], Running
-
     /* Save the IRQL */
     push ecx
 
+#ifdef CONFIG_SMP
+GetSwapLock:
+    /* Acquire the swap lock */
+    cmp [esi+KTHREAD_SWAP_BUSY], 0
+    jz NotBusy
+    pause
+    jmp GetSwapLock
+#endif
+
+    /* Increase context switches (use ES for lazy load) */
+    //inc dword ptr es:[ebx+KPCR_CONTEXT_SWITCHES]
+
     /* Save the Exception list */
     push [ebx+KPCR_EXCEPTION_LIST]
 
-    /* DPC shouldn't be active */
-    cmp byte ptr [ebx+KPCR_PRCB_DPC_ROUTINE_ACTIVE], 0
-    jnz BugCheckDpc
+    /* Check for WMI */
+    //cmp dword ptr [ebx+KPCR_PERF_GLOBAL_GROUP_MASK], 0
+    //jnz WmiTrace
 
+AfterTrace:
     /* Switching, disable interrupts now */
     cli
 
@@ -391,7 +403,6 @@ SameProcess:
 
     /* Increase context switches */
     inc dword ptr [esi+KTHREAD_CONTEXT_SWITCHES]
-    //inc dword ptr [esi+KPRC_PRCB_CONTEXT_SWITCHES]
 
     /* Restore exception list */
     pop [ebx+KPCR_EXCEPTION_LIST]
@@ -399,6 +410,10 @@ SameProcess:
     /* Restore IRQL */
     pop ecx
 
+    /* DPC shouldn't be active */
+    cmp byte ptr [ebx+KPCR_PRCB_DPC_ROUTINE_ACTIVE], 0
+    jnz BugCheckDpc
+
     /* Check if kernel APCs are pending */
     cmp byte ptr [esi+KTHREAD_PENDING_KERNEL_APC], 0
     jnz CheckApc
@@ -446,9 +461,18 @@ LdtStuff:
     mov eax, KGDT_LDT
     jmp LoadLdt
 
+WmiTrace:
+
+    /* No WMI support yet */
+    int 3
+
+    /* Jump back */
+    jmp AfterTrace
+
 BugCheckDpc:
     push ATTEMPTED_SWITCH_FROM_DPC
     call _KeBugCheck@4
+.endfunc
 
 /*++
  * KiSwapContext 
@@ -460,7 +484,7 @@ BugCheckDpc:
  *                    switch to.
  *
  * Returns:
- *     The WaitStatus of the Target Thread. NOT YET SUPPORTED.
+ *     The WaitStatus of the Target Thread.
  *
  * Remarks:
  *     This is a wrapper around KiSwapContextInternal which will save all the
@@ -472,7 +496,7 @@ BugCheckDpc:
  *
  *--*/
 .globl @KiSwapContext@8
-.func  @KiSwapContext@8, @KiSwapContext@8
+.func @KiSwapContext@8, @KiSwapContext@8
 @KiSwapContext@8:
     /* Note, we CANNOT touch ebp */
 
@@ -494,9 +518,6 @@ BugCheckDpc:
     /* Get the New Thread */
     mov esi, edx
 
-    /* Save it as Current thread */
-    mov fs:[KPCR_CURRENT_THREAD], esi
-
     /* Get the wait IRQL */
     movzx ecx, byte ptr [edi+KTHREAD_WAIT_IRQL]
 
index fea767e..95a49bd 100644 (file)
@@ -154,6 +154,7 @@ KiDispatchThreadNoLock(ULONG NewThreadStatus)
 \r
             /* Special note for Filip: This will release the Dispatcher DB Lock ;-) -- Alex */\r
             DPRINT("You are : %x, swapping to: %x.\n", OldThread, CurrentThread);\r
+            KeGetCurrentPrcb()->CurrentThread = CurrentThread;\r
             ApcState = KiSwapContext(OldThread, CurrentThread);\r
             DPRINT("You are : %x, swapped from: %x\n", OldThread, CurrentThread);\r
             return ApcState;\r