More work on x86_64 port of usermode
[tpg/acess2.git] / Kernel / arch / x86 / proc.c
index 55b9b17..a204b49 100644 (file)
@@ -47,7 +47,6 @@ extern tShortSpinlock glThreadListLock;
 extern int     giNumCPUs;
 extern int     giNextTID;
 extern tThread gThreadZero;
-extern tThread *Threads_CloneTCB(Uint *Err, Uint Flags);
 extern void    Isr8(void);     // Double Fault
 extern void    Proc_ReturnToUser(tVAddr Handler, Uint Argument, tVAddr KernelStack);
 
@@ -57,11 +56,14 @@ void        ArchThreads_Init(void);
 void   MP_StartAP(int CPU);
 void   MP_SendIPI(Uint8 APICID, int Vector, int DeliveryMode);
 #endif
-void   Proc_Start(void);
-tThread        *Proc_GetCurThread(void);
+//void Proc_Start(void);
+//tThread      *Proc_GetCurThread(void);
 void   Proc_ChangeStack(void);
- int   Proc_Clone(Uint *Err, Uint Flags);
+// int Proc_Clone(Uint *Err, Uint Flags);
+Uint   Proc_MakeUserStack(void);
+void   Proc_StartUser(Uint Entrypoint, Uint *Bases, int ArgC, char **ArgV, char **EnvP, int DataSize);
 void   Proc_StartProcess(Uint16 SS, Uint Stack, Uint Flags, Uint16 CS, Uint IP);
+ int   Proc_Demote(Uint *Err, int Dest, tRegs *Regs);
 void   Proc_CallFaultHandler(tThread *Thread);
 void   Proc_Scheduler(int CPU);
 
@@ -448,7 +450,7 @@ void Proc_Start(void)
                        for(;;) HALT(); // Just yeilds
                }
                gaCPUs[i].IdleThread = Threads_GetThread(tid);
-               gaCPUs[i].IdleThread->ThreadName = "Idle Thread";
+               gaCPUs[i].IdleThread->ThreadName = (char*)"Idle Thread";
                Threads_SetPriority( gaCPUs[i].IdleThread, -1 );        // Never called randomly
                gaCPUs[i].IdleThread->Quantum = 1;      // 1 slice quantum
                
@@ -471,7 +473,7 @@ void Proc_Start(void)
        if(Proc_Clone(0, 0) == 0)
        {
                gpIdleThread = Proc_GetCurThread();
-               gpIdleThread->ThreadName = "Idle Thread";
+               gpIdleThread->ThreadName = strdup("Idle Thread");
                Threads_SetPriority( gpIdleThread, -1 );        // Never called randomly
                gpIdleThread->Quantum = 1;      // 1 slice quantum
                for(;;) HALT(); // Just yeilds
@@ -649,14 +651,11 @@ int Proc_SpawnWorker(void)
        cur = Proc_GetCurThread();
        
        // Create new thread
-       new = malloc( sizeof(tThread) );
+       new = Threads_CloneThreadZero();
        if(!new) {
                Warning("Proc_SpawnWorker - Out of heap space!\n");
                return -1;
        }
-       memcpy(new, &gThreadZero, sizeof(tThread));
-       // Set Thread ID
-       new->TID = giNextTID++;
        // Create a new worker stack (in PID0's address space)
        // - The stack is relocated by this function
        new->KernelStack = MM_NewWorkerStack();
@@ -925,13 +924,6 @@ void Proc_Scheduler(int CPU)
        // Update Kernel Stack pointer
        gTSSs[CPU].ESP0 = thread->KernelStack-4;
        
-       // Set address space
-       #if USE_PAE
-       # error "Todo: Implement PAE Address space switching"
-       #else
-       __asm__ __volatile__ ("mov %0, %%cr3" : : "a" (thread->MemState.CR3));
-       #endif
-       
        #if 0
        if(thread->SavedState.ESP > 0xC0000000
        && thread->SavedState.ESP < thread->KernelStack-0x2000) {
@@ -939,14 +931,20 @@ void Proc_Scheduler(int CPU)
        }
        #endif
        
+       #if USE_PAE
+       # error "Todo: Implement PAE Address space switching"
+       #else
        // Switch threads
        __asm__ __volatile__ (
+               "mov %4, %%cr3\n\t"     // Set address space
                "mov %1, %%esp\n\t"     // Restore ESP
                "mov %2, %%ebp\n\t"     // and EBP
                "jmp *%3" : :   // And return to where we saved state (Proc_Clone or Proc_Scheduler)
                "a"(SWITCH_MAGIC), "b"(thread->SavedState.ESP),
-               "d"(thread->SavedState.EBP), "c"(thread->SavedState.EIP)
+               "d"(thread->SavedState.EBP), "c"(thread->SavedState.EIP),
+               "r"(thread->MemState.CR3)
                );
+       #endif
        for(;;);        // Shouldn't reach here
 }
 

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