X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Kernel%2Farch%2Fx86%2Fproc.c;h=e98841618b0a3a10fd827cf3788b28dc2b4cffae;hb=7a6a1cbc62289d64d604fb2cb204d21659c4905e;hp=9ad06a53dc8fea253327f9388afb6905d7b933ae;hpb=8d062ceb17eb6cfb2e3db8af6794d38391c245d3;p=tpg%2Facess2.git diff --git a/Kernel/arch/x86/proc.c b/Kernel/arch/x86/proc.c index 9ad06a53..e9884161 100644 --- a/Kernel/arch/x86/proc.c +++ b/Kernel/arch/x86/proc.c @@ -4,6 +4,7 @@ */ #include #include +#include #include #include #if USE_MP @@ -15,10 +16,12 @@ // === CONSTANTS === #define SWITCH_MAGIC 0xFFFACE55 // There is no code in this area +// Base is 1193182 #define TIMER_DIVISOR 11931 //~100Hz // === IMPORTS === extern tGDT gGDT[]; +extern tIDT gIDT[]; extern void APStartup(); // 16-bit AP startup code extern Uint GetEIP(); // start.asm extern Uint32 gaInitPageDir[1024]; // start.asm @@ -35,7 +38,8 @@ extern tThread *gDeleteThreads; extern tThread *Threads_GetNextToRun(int CPU); extern void Threads_Dump(); extern tThread *Threads_CloneTCB(Uint *Err, Uint Flags); -extern void Isr7(); +extern void Isr8(); // Double Fault +extern void Proc_AlterUserReturnAddr(); // === PROTOTYPES === void ArchThreads_Init(); @@ -47,11 +51,14 @@ void Proc_Start(); tThread *Proc_GetCurThread(); void Proc_ChangeStack(); int Proc_Clone(Uint *Err, Uint Flags); +void Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP); +void Proc_CallFaultHandler(tThread *Thread); void Proc_Scheduler(); // === GLOBALS === // --- Multiprocessing --- #if USE_MP +volatile int giNumInitingCPUs = 0; tMPInfo *gMPFloatPtr = NULL; tAPIC *gpMP_LocalAPIC = NULL; Uint8 gaAPIC_to_CPU[256] = {0}; @@ -69,7 +76,12 @@ char gaDoubleFaultStack[1024]; tTSS gDoubleFault_TSS = { .ESP0 = (Uint)&gaDoubleFaultStack[1023], .SS0 = 0x10, - .EIP = (Uint)Isr7 + .CR3 = (Uint)gaInitPageDir - KERNEL_BASE, + .EIP = (Uint)Isr8, + .ESP = (Uint)&gaDoubleFaultStack[1023], + .CS = 0x08, .SS = 0x10, + .DS = 0x10, .ES = 0x10, + .FS = 0x10, .GS = 0x10, }; // === CODE === @@ -244,7 +256,11 @@ void ArchThreads_Init() if( giNumCPUs > MAX_CPUS ) { Warning("Too many CPUs detected (%i), only using %i of them", giNumCPUs, MAX_CPUS); + giNumCPUs = MAX_CPUS; } + + while( giNumInitingCPUs ) + MM_FinishVirtualInit(); Panic("Uh oh... MP Table Parsing is unimplemented\n"); } @@ -256,6 +272,7 @@ void ArchThreads_Init() #else giNumCPUs = 1; gTSSs = &gTSS0; + MM_FinishVirtualInit(); #endif // Initialise Double Fault TSS @@ -269,6 +286,17 @@ void ArchThreads_Init() gGDT[5].BaseMid = (Uint)&gDoubleFault_TSS >> 16; gGDT[5].BaseHi = (Uint)&gDoubleFault_TSS >> 24; + Log_Debug("Proc", "gIDT[8] = {OffsetLo:%04x, CS:%04x, Flags:%04x, OffsetHi:%04x}", + gIDT[8].OffsetLo, gIDT[8].CS, gIDT[8].Flags, gIDT[8].OffsetHi); + gIDT[8].OffsetLo = 0; + gIDT[8].CS = 5<<3; + gIDT[8].Flags = 0x8500; + gIDT[8].OffsetHi = 0; + Log_Debug("Proc", "gIDT[8] = {OffsetLo:%04x, CS:%04x, Flags:%04x, OffsetHi:%04x}", + gIDT[8].OffsetLo, gIDT[8].CS, gIDT[8].Flags, gIDT[8].OffsetHi); + + //__asm__ __volatile__ ("xchg %bx, %bx"); + #if USE_MP // Initialise Normal TSS(s) for(pos=0;posFaultHandler)); + for(;;); +} + /** * \fn void Proc_Scheduler(int CPU) * \brief Swap current thread and clears dead threads @@ -739,7 +785,7 @@ void Proc_Scheduler(int CPU) #endif // Update Kernel Stack pointer - gTSSs[CPU].ESP0 = thread->KernelStack; + gTSSs[CPU].ESP0 = thread->KernelStack-4; // Set address space #if USE_PAE @@ -747,6 +793,14 @@ void Proc_Scheduler(int CPU) #else __asm__ __volatile__ ("mov %0, %%cr3"::"a"(thread->MemState.CR3)); #endif + + #if 0 + if(thread->SavedState.ESP > 0xC0000000 + && thread->SavedState.ESP < thread->KernelStack-0x2000) { + Log_Warning("Proc", "Possible bad ESP %p (PID %i)", thread->SavedState.ESP); + } + #endif + // Switch threads __asm__ __volatile__ ( "mov %1, %%esp\n\t" // Restore ESP