Kernel/x86 - Cleaning up and implmented address space nuking
[tpg/acess2.git] / Kernel / arch / x86 / proc.c
index 1cd1106..c804971 100644 (file)
 # include <mp.h>
 #endif
 #include <hal_proc.h>
+#include <arch_int.h>
 
 // === FLAGS ===
-#define DEBUG_TRACE_SWITCH     1
+#define DEBUG_TRACE_SWITCH     0
 #define DEBUG_DISABLE_DOUBLEFAULT      1
-#define DEBUG_VERY_SLOW_SWITCH 0
+#define DEBUG_VERY_SLOW_PERIOD 0
 
 // === CONSTANTS ===
 // Base is 1193182
@@ -165,6 +166,7 @@ void ArchThreads_Init(void)
        {
                 int    i;
                tMPTable_Ent    *ents;
+               #if DUMP_MP_TABLE
                Log("gMPFloatPtr = %p", gMPFloatPtr);
                Log("*gMPFloatPtr = {");
                Log("\t.Sig = 0x%08x", gMPFloatPtr->Sig);
@@ -178,8 +180,10 @@ void ArchThreads_Init(void)
                        gMPFloatPtr->Features[4]
                        );
                Log("}");
-               
+               #endif          
+
                mptable = (void*)( KERNEL_BASE|gMPFloatPtr->MPConfig );
+               #if DUMP_MP_TABLE
                Log("mptable = %p", mptable);
                Log("*mptable = {");
                Log("\t.Sig = 0x%08x", mptable->Sig);
@@ -195,6 +199,7 @@ void ArchThreads_Init(void)
                Log("\t.ExtendedTableLen = 0x%04x", mptable->ExtendedTableLen);
                Log("\t.ExtendedTableChecksum = 0x%02x", mptable->ExtendedTableChecksum);
                Log("}");
+               #endif
                
                gpMP_LocalAPIC = (void*)MM_MapHWPages(mptable->LocalAPICMemMap, 1);
                
@@ -208,13 +213,14 @@ void ArchThreads_Init(void)
                        {
                        case 0: // Processor
                                entSize = 20;
+                               #if DUMP_MP_TABLE
                                Log("%i: Processor", i);
                                Log("\t.APICID = %i", ents->Proc.APICID);
                                Log("\t.APICVer = 0x%02x", ents->Proc.APICVer);
                                Log("\t.CPUFlags = 0x%02x", ents->Proc.CPUFlags);
                                Log("\t.CPUSignature = 0x%08x", ents->Proc.CPUSignature);
                                Log("\t.FeatureFlags = 0x%08x", ents->Proc.FeatureFlags);
-                               
+                               #endif
                                
                                if( !(ents->Proc.CPUFlags & 1) ) {
                                        Log("DISABLED");
@@ -240,7 +246,7 @@ void ArchThreads_Init(void)
                                
                                break;
                        
-                       #if DUMP_MP_TABLES
+                       #if DUMP_MP_TABLE >= 2
                        case 1: // Bus
                                entSize = 8;
                                Log("%i: Bus", i);
@@ -565,7 +571,7 @@ void Proc_ChangeStack(void)
 
 void Proc_ClearThread(tThread *Thread)
 {
-       Log_Warning("Proc", "TODO: Nuke address space etc");
+       MM_ClearSpace(Thread->MemState.CR3);
        if(Thread->SavedState.SSE) {
                free(Thread->SavedState.SSE);
                Thread->SavedState.SSE = NULL;
@@ -582,6 +588,7 @@ int Proc_NewKThread(void (*Fcn)(void*), void *Data)
        if(!newThread)  return -1;
        
        // Set CR3
+       MM_RefPhys( cur->MemState.CR3 );
        newThread->MemState.CR3 = cur->MemState.CR3;
 
        // Create new KStack
@@ -942,11 +949,22 @@ void Proc_Reschedule(void)
                Proc_DisableSSE();
        }
 
-       SwitchTasks(
-               nextthread->SavedState.ESP, &curthread->SavedState.ESP,
-               nextthread->SavedState.EIP, &curthread->SavedState.EIP,
-               nextthread->MemState.CR3
-               );
+       if( curthread )
+       {
+               SwitchTasks(
+                       nextthread->SavedState.ESP, &curthread->SavedState.ESP,
+                       nextthread->SavedState.EIP, &curthread->SavedState.EIP,
+                       nextthread->MemState.CR3
+                       );
+       }
+       else
+       {
+               SwitchTasks(
+                       nextthread->SavedState.ESP, 0,
+                       nextthread->SavedState.EIP, 0,
+                       nextthread->MemState.CR3
+                       );
+       }
 
        return ;
 }
@@ -957,6 +975,7 @@ void Proc_Reschedule(void)
  */
 void Proc_Scheduler(int CPU)
 {
+#if 0
        tThread *thread;
        
        // If the spinlock is set, let it complete
@@ -989,7 +1008,6 @@ void Proc_Scheduler(int CPU)
                        regs->eflags &= ~0x100; // Clear TF
        }
 
-#if 0
        // TODO: Ack timer?
        #if USE_MP
        if( GetCPUNum() )

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