AcessNative - Fixing Fixing Fixing
[tpg/acess2.git] / Kernel / arch / x86 / vm8086.c
index 469ab43..7181351 100644 (file)
@@ -40,7 +40,7 @@ struct sVM8086_InternalData
 // === PROTOTYPES ===
  int   VM8086_Install(char **Arguments);
 void   VM8086_GPF(tRegs *Regs);
-tVM8086        *VM8086_Init(void);
+//tVM8086      *VM8086_Init(void);
 
 // === GLOBALS ===
 MODULE_DEFINE(0, 0x100, VM8086, VM8086_Install, NULL, NULL);
@@ -83,7 +83,12 @@ int VM8086_Install(char **Arguments)
                        MM_Map( i * 0x1000, i * 0x1000 );       MM_DerefPhys( i * 0x1000 );
                }
                MM_Map( 0x9F000, 0x9F000 );     // Stack / EBDA
-               MM_Allocate( 0x100000 );        // System Stack / Stub
+               // System Stack / Stub
+               if( MM_Allocate( 0x100000 ) == 0 ) {
+                       Log_Error("VM8086", "Unable to allocate memory for stack/stub");
+                       gVM8086_WorkerPID = 0;
+                       Threads_Exit(0, 1);
+               }
                
                *(Uint8*)(0x100000) = VM8086_OP_IRET;
                *(Uint8*)(0x100001) = 0x07;     // POP ES
@@ -133,6 +138,11 @@ int VM8086_Install(char **Arguments)
        while( gpVM8086_State != NULL )
                Threads_Yield();        // Yield to allow the child to initialise
        
+       // Worker killed itself
+       if( gVM8086_WorkerPID != pid ) {
+               return MODULE_ERR_MISC;
+       }
+       
        return MODULE_ERR_OK;
 }
 
@@ -153,17 +163,14 @@ void VM8086_GPF(tRegs *Regs)
                //Log_Log("VM8086", "gpVM8086_State = %p, gVM8086_CallingThread = %i",
                //      gpVM8086_State, gVM8086_CallingThread);
                if( gpVM8086_State ) {
-                        int    ret;
                        gpVM8086_State->AX = Regs->eax; gpVM8086_State->CX = Regs->ecx;
                        gpVM8086_State->DX = Regs->edx; gpVM8086_State->BX = Regs->ebx;
                        gpVM8086_State->BP = Regs->ebp;
                        gpVM8086_State->SI = Regs->esi; gpVM8086_State->DI = Regs->edi;
                        gpVM8086_State->DS = Regs->ds;  gpVM8086_State->ES = Regs->es;
                        gpVM8086_State = NULL;
-                       // Ensure the caller wakes
-                       while( (ret = Threads_WakeTID(gVM8086_CallingThread)) == -EALREADY) {
-                               Threads_Yield();
-                       }
+                       // Wake the caller
+                       Threads_WakeTID(gVM8086_CallingThread);
                }
                
                //Log_Log("VM8086", "Waiting for something to do");

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