X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Fproc.c;h=2d68d65e993601f400fc7bd7ae2d86baa3ed1b87;hb=709179721ccc250f5d09f5bfc13f65df6cac6fed;hp=d7f460fa24b4c370d8e57c7580f6af9a3a5c350f;hpb=5fc81fa5e050f48374a6aff5636f3e60313dfc78;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index d7f460fa..2d68d65e 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -113,6 +113,7 @@ void ArchThreads_Init() gTSSs = &gTSS0; #if USE_MP } + #endif // Initialise Double Fault TSS gGDT[5].LimitLow = sizeof(tTSS); @@ -123,7 +124,8 @@ void ArchThreads_Init() 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> 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;posTID = 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 @@ -357,6 +360,9 @@ int Proc_SpawnWorker() // Set EIP as parent new->SavedState.EIP = eip; + // Mark as active + new->Status = THREAD_STAT_ACTIVE; + Threads_AddActive( new ); return new->TID; } @@ -557,7 +563,8 @@ void Proc_Scheduler(int CPU) 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 @@ -568,3 +575,6 @@ void Proc_Scheduler(int CPU) ); for(;;); // Shouldn't reach here } + +// === EXPORTS === +EXPORT(Proc_SpawnWorker);