-
- #if USE_MP // MP Debug
-// Log("CPU = %i, Thread %p", CPU, thread);
- #endif
-
- // Update Kernel Stack pointer
- gTSSs[CPU].ESP0 = thread->KernelStack-4;
-
- #if 0
- if(thread->SavedState.ESP > 0xC0000000
- && thread->SavedState.ESP < thread->KernelStack-0x2000) {
- Log_Warning("Proc", "Possible bad ESP %p (PID %i)", thread->SavedState.ESP);
- }
- #endif
-
- if( thread->bInstrTrace ) {
- Log("%p Scheduled (EIP = %p)", thread, thread->SavedState.EIP);
- }
-
- // Set thread pointer
- __asm__ __volatile__("mov %0, %%db0\n\t" : : "r"(thread) );
- // Switch threads
- __asm__ __volatile__ (
- "mov %3, %%cr3\n\t" // Set address space
- "mov %0, %%esp\n\t" // Restore ESP
- "mov %1, %%ebp\n\t" // and EBP
- "test %4, %4\n\t"
- "jz 1f\n\t"
- "or %4, 72(%%ebp)\n\t" // or trace flag to eflags (2+2+4+8+2)*4
- "1:"
- "xor %%eax, %%eax\n\t"
- "jmp *%2" : : // And return to where we saved state (Proc_Clone or Proc_Scheduler)
- "r"(thread->SavedState.ESP),
- "r"(thread->SavedState.EBP),
- "r"(thread->SavedState.EIP),
- "r"(thread->MemState.CR3),
- "r"(thread->bInstrTrace&&thread->SavedState.EIP==(Uint)&GetEIP_Sched_ret?0x100:0)
- );
- for(;;); // Shouldn't reach here