jz NotBusy
pause
jmp GetSwapLock
-#endif
NotBusy:
+#endif
/* Increase context switches (use ES for lazy load) */
inc dword ptr es:[ebx+KPCR_CONTEXT_SWITCHES]
/* Check NPX State */
cmp byte ptr [edi+KTHREAD_NPX_STATE], NPX_STATE_LOADED
jz NpxLoaded
+SetStack:
#endif
-SetStack:
/* Set new stack */
mov [edi+KTHREAD_KERNEL_STACK], esp
test [ebp+KPROCESS_ACTIVE_PROCESSORS], ecx
jz WrongActiveCpu
test [eax+KPROCESS_ACTIVE_PROCESSORS], ecx
- jz WrongActiveCpu
+ jnz WrongActiveCpu
#endif
#endif
#ifdef CONFIG_SMP
NpxLoaded:
- /* FIXME: TODO */
- int 3
+ /* Mask out FPU flags */
+ and edx, ~(CR0_MP + CR0_EM + CR0_TS)
+
+ /* Get the NPX Frame */
+ mov ecx, [edi+KTHREAD_INITIAL_STACK]
+ sub ecx, NPX_FRAME_LENGTH
+
+ /* Check if we have a new CR0 */
+ cmp ebp, edx
+ jz Cr0Equal
+
+ /* We do, update it */
+ mov cr0, edx
+ mov ebp, edx
+
+Cr0Equal:
+
+ /* Save the NPX State */
+ fxsave [ecx]
+ mov byte ptr [edi+KTHREAD_NPX_STATE], NPX_STATE_NOT_LOADED
+
+ /* Clear the NPX Thread */
+ mov dword ptr [ebx+KPCR_NPX_THREAD], 0
/* Jump back */
jmp SetStack
#ifdef CONFIG_SMP
SameThread:
- /* Clear the next thread, and put the thready as ready after lock release */
+ /* Clear the next thread, and put the thread as ready after lock release */
and dword ptr [ebx+KPCR_PRCB_NEXT_THREAD], 0
and dword ptr [ebx+KPCR_PRCB_PRCB_LOCK], 0
and byte ptr [edi+KTHREAD_STATE_], Ready
/* Sanity check */
#if DBG
- test dword ptr [edx+KPROCESS_ACTIVE_PROCESSORS], 0
+ test [edx+KPROCESS_ACTIVE_PROCESSORS], ecx
jz WrongCpu1
- test dword ptr [eax+KPROCESS_ACTIVE_PROCESSORS], 0
+ test [eax+KPROCESS_ACTIVE_PROCESSORS], ecx
jnz WrongCpu2
#endif
#endif