X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Farch%2Fx86%2Fproc.c;h=f68e6635854835d9a4c4fb123c91b3f691a32538;hb=d0b4559f2936f6d9f06be0f7c3c51527a480ec0d;hp=8d856086930cd6670baf830527ce5269d2038027;hpb=934d0f535e1929fd90ae0606e77794484aa55284;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/arch/x86/proc.c b/KernelLand/Kernel/arch/x86/proc.c index 8d856086..f68e6635 100644 --- a/KernelLand/Kernel/arch/x86/proc.c +++ b/KernelLand/Kernel/arch/x86/proc.c @@ -18,6 +18,7 @@ #define DEBUG_TRACE_SWITCH 0 #define DEBUG_DISABLE_DOUBLEFAULT 1 #define DEBUG_VERY_SLOW_PERIOD 0 +#define DEBUG_NOPREEMPT 1 // === CONSTANTS === // Base is 1193182 @@ -466,7 +467,6 @@ void Proc_IdleThread(void *Ptr) */ void Proc_Start(void) { - int tid; #if USE_MP int i; #endif @@ -478,7 +478,7 @@ void Proc_Start(void) if(i) gaCPUs[i].Current = NULL; // Create Idle Task - tid = Proc_NewKThread(Proc_IdleThread, &gaCPUs[i]); + Proc_NewKThread(Proc_IdleThread, &gaCPUs[i]); // Start the AP if( i != giProc_BootProcessorID ) { @@ -495,8 +495,7 @@ void Proc_Start(void) while( giNumInitingCPUs ) __asm__ __volatile__ ("hlt"); #else // Create Idle Task - tid = Proc_NewKThread(Proc_IdleThread, &gaCPUs[0]); -// gaCPUs[0].IdleThread = Threads_GetThread(tid); + Proc_NewKThread(Proc_IdleThread, &gaCPUs[0]); // Set current task gaCPUs[0].Current = &gThreadZero; @@ -587,9 +586,8 @@ void Proc_ClearThread(tThread *Thread) tTID Proc_NewKThread(void (*Fcn)(void*), void *Data) { Uint esp; - tThread *newThread, *cur; + tThread *newThread; - cur = Proc_GetCurThread(); newThread = Threads_CloneTCB(0); if(!newThread) return -1; @@ -665,7 +663,7 @@ tPID Proc_Clone(Uint Flags) * \fn int Proc_SpawnWorker(void) * \brief Spawns a new worker thread */ -int Proc_SpawnWorker(void (*Fcn)(void*), void *Data) +tThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data) { tThread *new; Uint stack_contents[4]; @@ -674,7 +672,7 @@ int Proc_SpawnWorker(void (*Fcn)(void*), void *Data) new = Threads_CloneThreadZero(); if(!new) { Warning("Proc_SpawnWorker - Out of heap space!\n"); - return -1; + return NULL; } // Create the stack contents @@ -696,7 +694,7 @@ int Proc_SpawnWorker(void (*Fcn)(void*), void *Data) new->Status = THREAD_STAT_PREINIT; Threads_AddActive( new ); - return new->TID; + return new; } /** @@ -710,7 +708,7 @@ Uint Proc_MakeUserStack(void) // Check Prospective Space for( i = USER_STACK_SZ >> 12; i--; ) - if( MM_GetPhysAddr( base + (i<<12) ) != 0 ) + if( MM_GetPhysAddr( (void*)(base + (i<<12)) ) != 0 ) break; if(i != -1) return 0; @@ -862,6 +860,10 @@ void Proc_DumpThreadCPUState(tThread *Thread) __asm__ __volatile__ ("mov %%ebp, %0" : "=r" (stack)); while( maxBacktraceDistance -- ) { + if( !CheckMem(stack, 8) ) { + regs = NULL; + break; + } // [ebp] = oldEbp // [ebp+4] = retaddr @@ -978,14 +980,26 @@ void Proc_Reschedule(void) */ void Proc_Scheduler(int CPU) { + #if USE_MP + if( GetCPUNum() ) + gpMP_LocalAPIC->EOI.Val = 0; + else + #endif + outb(0x20, 0x20); + __asm__ __volatile__ ("sti"); + + // Call the timer update code + Timer_CallTimers(); + + #if !DEBUG_NOPREEMPT // If two ticks happen within the same task, and it's not an idle task, swap if( gaCPUs[CPU].Current->TID > giNumCPUs && gaCPUs[CPU].Current == gaCPUs[CPU].LastTimerThread ) { Proc_Reschedule(); } + gaCPUs[CPU].LastTimerThread = gaCPUs[CPU].Current; - // Call the timer update code - Timer_CallTimers(); + #endif } // === EXPORTS ===