Cleaned up some more debug
[tpg/acess2.git] / Kernel / arch / x86 / proc.c
index d7f460f..2d68d65 100644 (file)
@@ -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<giNumCPUs;pos++)
        {
        #else
@@ -131,13 +133,13 @@ void ArchThreads_Init()
        #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++) {
@@ -337,13 +339,14 @@ int Proc_SpawnWorker()
        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
@@ -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);

UCC git Repository :: git.ucc.asn.au