+ Log(" Just created (unknown %p)", Thread->SavedState.EIP);
+}
+
+void Proc_Reschedule(void)
+{
+ tThread *nextthread, *curthread;
+ int cpu = GetCPUNum();
+
+ // TODO: Wait for it?
+ if(IS_LOCKED(&glThreadListLock)) return;
+
+ curthread = Proc_GetCurThread();
+
+ nextthread = Threads_GetNextToRun(cpu, curthread);
+
+ if(!nextthread)
+ nextthread = gaCPUs[cpu].IdleThread;
+ if(!nextthread || nextthread == curthread)
+ return ;
+
+ #if DEBUG_TRACE_SWITCH
+ LogF("\nSwitching to task %i, CR3 = 0x%x, EIP = %p, ESP = %p\n",
+ nextthread->TID,
+ nextthread->MemState.CR3,
+ nextthread->SavedState.EIP,
+ nextthread->SavedState.ESP
+ );
+ #endif
+
+ // Update CPU state
+ gaCPUs[cpu].Current = nextthread;
+ gTSSs[cpu].ESP0 = nextthread->KernelStack-4;
+ __asm__ __volatile__("mov %0, %%db0\n\t" : : "r"(nextthread) );
+
+ SwitchTasks(
+ nextthread->SavedState.ESP, &curthread->SavedState.ESP,
+ nextthread->SavedState.EIP, &curthread->SavedState.EIP,
+ nextthread->MemState.CR3
+ );
+ return ;