More MP fiddling
authorJohn Hodge <[email protected]>
Sun, 18 Jul 2010 11:29:57 +0000 (19:29 +0800)
committerJohn Hodge <[email protected]>
Sun, 18 Jul 2010 11:29:57 +0000 (19:29 +0800)
Kernel/arch/x86/include/mp.h
Kernel/arch/x86/proc.asm
Kernel/arch/x86/proc.c
Kernel/include/threads.h

index 3a42c0f..0dd5a1e 100644 (file)
@@ -93,7 +93,7 @@ typedef volatile struct {
 typedef struct {
        Uint32  Val;
        Uint32  Padding[3];
-}      tReg;
+} volatile     tReg;
 
 typedef volatile struct {
        tReg    _unused1[2];
index 41623bd..cefd796 100644 (file)
@@ -97,15 +97,14 @@ SchedulerBase:
        jnz .sendEOI
        %endif
        
-       mov dx, 0x20
        mov al, 0x20
-       out dx, al              ; ACK IRQ
+       out 0x20, al            ; ACK IRQ
        %if USE_MP
        jmp .ret
        
 .sendEOI:
        mov eax, DWORD [gpMP_LocalAPIC]
-       mov DWORD [eax+0x0B0], 1
+       mov DWORD [eax+0x0B0], 0
        %endif
 .ret:
        pop gs
index 0708540..1edfee2 100644 (file)
@@ -342,23 +342,6 @@ void ArchThreads_Init(void)
                gGDT[6+pos].BaseHi = ((Uint)(&gTSSs[pos])) >> 24;
        #if USE_MP
        }
-       
-       // Start APs
-       for( pos = 0; pos < giNumCPUs; pos ++ )
-       {
-               gaCPUs[pos].Current = NULL;
-               if( pos != giProc_BootProcessorID ) {
-                       MP_StartAP( pos );
-               }
-       }
-       
-       Log("Waiting for APs to come up\n");
-       //__asm__ __volatile__ ("xchg %bx, %bx");
-       __asm__ __volatile__ ("sti");
-       while( giNumInitingCPUs )       __asm__ __volatile__ ("hlt");
-       __asm__ __volatile__ ("cli");
-       MM_FinishVirtualInit();
-       //Panic("Uh oh... MP Table Parsing is unimplemented\n");
        #endif
        
        // Load the BSP's TSS
@@ -369,6 +352,7 @@ void ArchThreads_Init(void)
        #else
        gCurrentThread = &gThreadZero;
        #endif
+       gThreadZero.bIsRunning = 1;
        
        #if USE_PAE
        gThreadZero.MemState.PDP[0] = 0;
@@ -439,8 +423,28 @@ void MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode)
  */
 void Proc_Start(void)
 {
+       #if USE_MP
+        int    i;
+       #endif
+       
        // Start Interrupts (and hence scheduler)
        __asm__ __volatile__("sti");
+       
+       #if USE_MP
+       // Start APs
+       for( i = 0; i < giNumCPUs; i ++ )
+       {
+               gaCPUs[i].Current = NULL;
+               if( i != giProc_BootProcessorID ) {
+                       MP_StartAP( i );
+               }
+       }
+       
+       Log("Waiting for APs to come up\n");
+       //__asm__ __volatile__ ("sti");
+       while( giNumInitingCPUs )       __asm__ __volatile__ ("hlt");
+       MM_FinishVirtualInit();
+       #endif
 }
 
 /**
@@ -804,7 +808,15 @@ void Proc_Scheduler(int CPU)
        
        // Check if there is any tasks running
        if(giNumActiveThreads == 0) {
+               #if 0
                Log("No Active threads, sleeping");
+               #endif
+               #if USE_MP
+               if(CPU)
+                       gpMP_LocalAPIC->EOI.Val = 0;
+               else
+               #endif
+                       outb(0x20, 0x20);
                __asm__ __volatile__ ("hlt");
                return;
        }
@@ -851,7 +863,9 @@ void Proc_Scheduler(int CPU)
        
        // Set current thread
        #if USE_MP
+       gaCPUs[CPU].Current->bIsRunning = 0;
        gaCPUs[CPU].Current = thread;
+       thread->bIsRunning = 1;
        #else
        gCurrentThread = thread;
        #endif
index e9cab73..6a14546 100644 (file)
@@ -56,6 +56,9 @@ typedef struct sThread
         int    NumTickets;     //!< Priority - Chance of gaining CPU
        
        Uint    Config[NUM_CFG_ENTRIES];        //!< Per-process configuration
+       
+       // --- proc.c's
+       volatile int    bIsRunning;     //!< Set if the thread is in use (used in MP)
 } tThread;
 
 

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