From f24c301371fbcb5ee42c5118f61f7304cb989746 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 18 Jul 2010 19:29:57 +0800 Subject: [PATCH] More MP fiddling --- Kernel/arch/x86/include/mp.h | 2 +- Kernel/arch/x86/proc.asm | 5 ++-- Kernel/arch/x86/proc.c | 48 +++++++++++++++++++++++------------- Kernel/include/threads.h | 3 +++ 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Kernel/arch/x86/include/mp.h b/Kernel/arch/x86/include/mp.h index 3a42c0f0..0dd5a1e7 100644 --- a/Kernel/arch/x86/include/mp.h +++ b/Kernel/arch/x86/include/mp.h @@ -93,7 +93,7 @@ typedef volatile struct { typedef struct { Uint32 Val; Uint32 Padding[3]; -} tReg; +} volatile tReg; typedef volatile struct { tReg _unused1[2]; diff --git a/Kernel/arch/x86/proc.asm b/Kernel/arch/x86/proc.asm index 41623bdd..cefd7963 100644 --- a/Kernel/arch/x86/proc.asm +++ b/Kernel/arch/x86/proc.asm @@ -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 diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 0708540e..1edfee23 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -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 diff --git a/Kernel/include/threads.h b/Kernel/include/threads.h index e9cab730..6a145466 100644 --- a/Kernel/include/threads.h +++ b/Kernel/include/threads.h @@ -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; -- 2.20.1