gTSSs = &gTSS0;
#if USE_MP
}
+ #endif
// Initialise Double Fault TSS
gGDT[5].LimitLow = sizeof(tTSS);
gGDT[5].BaseMid = (Uint)&gDoubleFault_TSS >> 16;
gGDT[5].BaseHi = (Uint)&gDoubleFault_TSS >> 24;
- // Initialise TSS
+ #if USE_MP
+ // Initialise Normal TSS(s)
for(pos=0;pos<giNumCPUs;pos++)
{
#else
#endif
gTSSs[pos].SS0 = 0x10;
gTSSs[pos].ESP0 = 0; // Set properly by scheduler
+ gGDT[6+pos].BaseLow = ((Uint)(&gTSSs[pos])) & 0xFFFF;
+ gGDT[6+pos].BaseMid = ((Uint)(&gTSSs[pos])) >> 16;
+ gGDT[6+pos].BaseHi = ((Uint)(&gTSSs[pos])) >> 24;
gGDT[6+pos].LimitLow = sizeof(tTSS);
gGDT[6+pos].LimitHi = 0;
gGDT[6+pos].Access = 0x89; // Type
gGDT[6+pos].Flags = 0x4;
- gGDT[6+pos].BaseLow = (Uint)&gTSSs[pos] & 0xFFFF;
- gGDT[6+pos].BaseMid = (Uint)&gTSSs[pos] >> 16;
- gGDT[6+pos].BaseHi = (Uint)&gTSSs[pos] >> 24;
#if USE_MP
}
for(pos=0;pos<giNumCPUs;pos++) {
memcpy(new, &gThreadZero, sizeof(tThread));
// Set Thread ID
new->TID = giNextTID++;
- // Set kernel stack
+ // Create a new worker stack (in PID0's address space)
+ // The stack is relocated by this code
new->KernelStack = MM_NewWorkerStack();
// Get ESP and EBP based in the new stack
__asm__ __volatile__ ("mov %%esp, %0": "=r"(esp));
__asm__ __volatile__ ("mov %%ebp, %0": "=r"(ebp));
- esp = cur->KernelStack - (new->KernelStack - esp);
+ esp = new->KernelStack - (cur->KernelStack - esp);
ebp = new->KernelStack - (cur->KernelStack - ebp);
// Save core machine state
// Set EIP as parent
new->SavedState.EIP = eip;
+ // Mark as active
+ new->Status = THREAD_STAT_ACTIVE;
+ Threads_AddActive( new );
return new->TID;
}
gTSSs[CPU].ESP0 = thread->KernelStack;
// Set address space
- __asm__ __volatile__ ("mov %0, %%cr3"::"a"(gCurrentThread->MemState.CR3));
+ if( gCurrentThread->MemState.CR3 != 0 )
+ __asm__ __volatile__ ("mov %0, %%cr3"::"a"(gCurrentThread->MemState.CR3));
// Switch threads
__asm__ __volatile__ (
"mov %1, %%esp\n\t" // Restore ESP