VM8086 Support, Starting on VESA Driver
[tpg/acess2.git] / Kernel / arch / x86 / proc.c
index 9ad06a5..b2f7f8f 100644 (file)
@@ -15,6 +15,7 @@
 
 // === CONSTANTS ===
 #define        SWITCH_MAGIC    0xFFFACE55      // There is no code in this area
+// Base is 1193182
 #define TIMER_DIVISOR  11931   //~100Hz
 
 // === IMPORTS ===
@@ -47,11 +48,13 @@ 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_Scheduler();
 
 // === GLOBALS ===
 // --- Multiprocessing ---
 #if USE_MP
+volatile int   giNumInitingCPUs = 0;
 tMPInfo        *gMPFloatPtr = NULL;
 tAPIC  *gpMP_LocalAPIC = NULL;
 Uint8  gaAPIC_to_CPU[256] = {0};
@@ -244,7 +247,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 +263,7 @@ void ArchThreads_Init()
        #else
        giNumCPUs = 1;
        gTSSs = &gTSS0;
+       MM_FinishVirtualInit();
        #endif
        
        // Initialise Double Fault TSS
@@ -325,6 +333,7 @@ void MP_StartAP(int CPU)
        *(Uint16*)(KERNEL_BASE|0x469) = 0xFFFF;
        outb(0x70, 0x0F);       outb(0x71, 0x0A);       // Warm Reset
        MP_SendIPI(gaCPUs[CPU].APICID, 0, 5);
+       giNumInitingCPUs ++;
 }
 
 void MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode)
@@ -594,13 +603,18 @@ void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **
        while(*Bases)
                *--stack = *Bases++;
        *--stack = 0;   // Return Address
-       delta = (Uint)stack;    // Reuse delta to save SP
        
-       *--stack = ss;          //Stack Segment
-       *--stack = delta;       //Stack Pointer
-       *--stack = 0x0202;      //EFLAGS (Resvd (0x2) and IF (0x20))
-       *--stack = cs;          //Code Segment
-       *--stack = Entrypoint;  //EIP
+       Proc_StartProcess(ss, (Uint)stack, 0x202, cs, Entrypoint);
+}
+
+void Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP)
+{
+       Uint    *stack = (void*)Stack;
+       *--stack = SS;          //Stack Segment
+       *--stack = Stack;       //Stack Pointer
+       *--stack = Flags;       //EFLAGS (Resvd (0x2) and IF (0x20))
+       *--stack = CS;          //Code Segment
+       *--stack = IP;  //EIP
        //PUSHAD
        *--stack = 0xAAAAAAAA;  // eax
        *--stack = 0xCCCCCCCC;  // ecx
@@ -611,10 +625,10 @@ void Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **
        *--stack = 0x51515151;  // esi
        *--stack = 0xB4B4B4B4;  // ebp
        //Individual PUSHs
-       *--stack = ss;  // ds
-       *--stack = ss;  // es
-       *--stack = ss;  // fs
-       *--stack = ss;  // gs
+       *--stack = SS;  // ds
+       *--stack = SS;  // es
+       *--stack = SS;  // fs
+       *--stack = SS;  // gs
        
        __asm__ __volatile__ (
        "mov %%eax,%%esp;\n\t"  // Set stack pointer
@@ -739,7 +753,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

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