Disabled Debug
[tpg/acess2.git] / Kernel / arch / x86 / proc.c
index 448eab2..76e96c9 100644 (file)
@@ -10,6 +10,9 @@
 # include <mp.h>
 #endif
 
+// === FLAGS ===
+#define DEBUG_TRACE_SWITCH     0
+
 // === CONSTANTS ===
 #define        SWITCH_MAGIC    0xFFFACE55      // There is no code in this area
 #define TIMER_DIVISOR  11931   //~100Hz
@@ -24,10 +27,12 @@ extern int  giNumCPUs;
 extern int     giNextTID;
 extern int     giTotalTickets;
 extern int     giNumActiveThreads;
+extern tThread gThreadZero;
 extern tThread *gActiveThreads;
 extern tThread *gSleepingThreads;
 extern tThread *gDeleteThreads;
 extern tThread *Threads_GetNextToRun(int CPU);
+extern void    Threads_Dump();
 
 // === PROTOTYPES ===
 void   ArchThreads_Init();
@@ -39,7 +44,7 @@ void  Proc_Scheduler();
 // === GLOBALS ===
 // --- Current State ---
 #if USE_MP
-tThread        **gCurrentThread = NULL;
+tThread        *gCurrentThread[MAX_CPUS] = {NULL};
 #else
 tThread        *gCurrentThread = NULL;
 #endif
@@ -124,6 +129,20 @@ void ArchThreads_Init()
        }
        #endif
        
+       #if USE_MP
+       gCurrentThread[0] = &gThreadZero;
+       #else
+       gCurrentThread = &gThreadZero;
+       #endif
+       
+       #if USE_PAE
+       gThreadZero.MemState.PDP[0] = 0;
+       gThreadZero.MemState.PDP[1] = 0;
+       gThreadZero.MemState.PDP[2] = 0;
+       #else
+       gThreadZero.MemState.CR3 = (Uint)gaInitPageDir - KERNEL_BASE;
+       #endif
+       
        // Set timer frequency
        outb(0x43, 0x34);       // Set Channel 0, Low/High, Rate Generator
        outb(0x40, TIMER_DIVISOR&0xFF); // Low Byte of Divisor
@@ -134,7 +153,14 @@ void ArchThreads_Init()
        
        // Change Stacks
        Proc_ChangeStack();
-       
+}
+
+/**
+ * \fn void Proc_Start()
+ * \brief Start process scheduler
+ */
+void Proc_Start()
+{
        // Start Interrupts (and hence scheduler)
        __asm__ __volatile__("sti");
 }
@@ -283,12 +309,9 @@ int Proc_Clone(Uint *Err, Uint Flags)
        newThread->SavedState.EIP = eip;
        
        // Lock list and add to active
-       LOCK( &giThreadListLock );
-       newThread->Next = gActiveThreads;
-       gActiveThreads = newThread;
-       giNumActiveThreads ++;
-       giTotalTickets += newThread->NumTickets;
-       RELEASE( &giThreadListLock );
+       Threads_AddActive(newThread);
+       
+       Threads_Dump();
        
        return newThread->TID;
 }
@@ -442,7 +465,7 @@ void Proc_Scheduler(int CPU)
        
        // Check if there is any tasks running
        if(giNumActiveThreads == 0) {
-               Log("No Active threads, sleeping\n");
+               Log("No Active threads, sleeping");
                __asm__ __volatile__ ("hlt");
                return;
        }
@@ -472,6 +495,14 @@ void Proc_Scheduler(int CPU)
                return;
        }
        
+       #if DEBUG_TRACE_SWITCH
+       Log("Switching to task %i, CR3 = 0x%x, EIP = %p",
+               thread->TID,
+               thread->MemState.CR3,
+               thread->SavedState.EIP
+               );
+       #endif
+       
        // Set current thread
        gCurrentThread = thread;
        

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