[FAST486]
[reactos.git] / lib / fast486 / common.c
index 871d77d..36f026e 100644 (file)
@@ -65,7 +65,8 @@ Fast486ReadMemory(PFAST486_STATE State,
             return FALSE;
         }
 
-        if (GET_SEGMENT_RPL(CachedDescriptor->Selector) > CachedDescriptor->Dpl)
+        if ((!InstFetch && (GET_SEGMENT_RPL(CachedDescriptor->Selector) > CachedDescriptor->Dpl))
+            || (Fast486GetCurrentPrivLevel(State) > CachedDescriptor->Dpl))
         {
             Fast486Exception(State, FAST486_EXCEPTION_GP);
             return FALSE;
@@ -117,7 +118,6 @@ Fast486WriteMemory(PFAST486_STATE State,
     {
         /* Write beyond limit */
         Fast486Exception(State, FAST486_EXCEPTION_GP);
-
         return FALSE;
     }
 
@@ -132,7 +132,8 @@ Fast486WriteMemory(PFAST486_STATE State,
             return FALSE;
         }
 
-        if (GET_SEGMENT_RPL(CachedDescriptor->Selector) > CachedDescriptor->Dpl)
+        if ((GET_SEGMENT_RPL(CachedDescriptor->Selector) > CachedDescriptor->Dpl)
+            || (Fast486GetCurrentPrivLevel(State) > CachedDescriptor->Dpl))
         {
             Fast486Exception(State, FAST486_EXCEPTION_GP);
             return FALSE;
@@ -177,7 +178,7 @@ Fast486InterruptInternal(PFAST486_STATE State,
         {
             /* Read the TSS */
             if (!Fast486ReadLinearMemory(State,
-                                         State->Tss.Address,
+                                         State->TaskReg.Base,
                                          &Tss,
                                          sizeof(Tss)))
             {
@@ -238,6 +239,14 @@ Fast486InterruptInternal(PFAST486_STATE State,
             if (!Fast486StackPush(State, OldEsp)) return FALSE;
         }
     }
+    else
+    {
+        if (State->SegmentRegs[FAST486_REG_CS].Size)
+        {
+            /* Set OPSIZE, because INT always pushes 16-bit values in real mode */
+            State->PrefixFlags |= FAST486_PREFIX_OPSIZE;
+        }
+    }
 
     /* Push EFLAGS */
     if (!Fast486StackPush(State, State->Flags.Long)) return FALSE;
@@ -330,8 +339,18 @@ Fast486ExceptionWithErrorCode(PFAST486_STATE State,
         && (State->ControlRegisters[FAST486_REG_CR0] & FAST486_CR0_PE))
     {
         /* Push the error code */
-        Fast486StackPush(State, ErrorCode);
+        if (!Fast486StackPush(State, ErrorCode))
+        {
+            /*
+             * If this function failed, that means Fast486Exception
+             * was called again, so just return in this case.
+             */
+            return;
+        }
     }
+
+    /* Reset the exception count */
+    State->ExceptionCount = 0;
 }
 
 /* EOF */