[FAST486]
[reactos.git] / lib / fast486 / opgroups.c
index 27950cd..754a9d8 100644 (file)
@@ -167,8 +167,7 @@ Fast486RotateOperation(PFAST486_STATE State,
     /* Normalize the count */
     Count &= 0x1F;
 
-    if (Operation <= 1) Count %= Bits;
-    else if (Operation <= 3) Count %= Bits + 1;
+    if ((Operation == 2) || (Operation == 3)) Count %= Bits + 1;
 
     /* If the count is zero, do nothing */
     if (Count == 0) return Value;
@@ -179,6 +178,7 @@ Fast486RotateOperation(PFAST486_STATE State,
         /* ROL */
         case 0:
         {
+            Count %= Bits;
             Result = (Value << Count) | (Value >> (Bits - Count));
 
             /* Update CF and OF */
@@ -192,6 +192,7 @@ Fast486RotateOperation(PFAST486_STATE State,
         /* ROR */
         case 1:
         {
+            Count %= Bits;
             Result = (Value >> Count) | (Value << (Bits - Count));
 
             /* Update CF and OF */
@@ -485,23 +486,26 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeGroup8F)
     TOGGLE_OPSIZE(OperandSize);
     TOGGLE_ADSIZE(AddressSize);
 
-    if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
+    /* Pop a value from the stack - this must be done first */
+    if (!Fast486StackPop(State, &Value))
     {
         /* Exception occurred */
         return FALSE;
     }
 
-    if (ModRegRm.Register != 0)
+    if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
     {
-        /* Invalid */
-        Fast486Exception(State, FAST486_EXCEPTION_UD);
+        /* Exception occurred - restore SP */
+        if (OperandSize) State->GeneralRegs[FAST486_REG_ESP].Long -= sizeof(ULONG);
+        else State->GeneralRegs[FAST486_REG_ESP].LowWord -= sizeof(USHORT);
+
         return FALSE;
     }
 
-    /* Pop a value from the stack */
-    if (!Fast486StackPop(State, &Value))
+    if (ModRegRm.Register != 0)
     {
-        /* Exception occurred */
+        /* Invalid */
+        Fast486Exception(State, FAST486_EXCEPTION_UD);
         return FALSE;
     }
 
@@ -1920,7 +1924,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeGroup0FBA)
     }
 
     /* Normalize the bit number */
-    BitNumber &= (1 << DataSize) - 1;
+    BitNumber %= DataSize;
 
     if (OperandSize)
     {