/* INCLUDES *******************************************************************/
-// #define WIN32_NO_STATUS
-// #define _INC_WINDOWS
#include <windef.h>
-#include <limits.h>
// #define NDEBUG
#include <debug.h>
#include "opgroups.h"
#include "extraops.h"
#include "common.h"
+#include "fpu.h"
/* PUBLIC VARIABLES ***********************************************************/
Fast486OpcodeAad,
Fast486OpcodeSalc,
Fast486OpcodeXlat,
- NULL, // TODO: OPCODE 0xD8 NOT SUPPORTED
- NULL, // TODO: OPCODE 0xD9 NOT SUPPORTED
- NULL, // TODO: OPCODE 0xDA NOT SUPPORTED
- NULL, // TODO: OPCODE 0xDB NOT SUPPORTED
- NULL, // TODO: OPCODE 0xDC NOT SUPPORTED
- NULL, // TODO: OPCODE 0xDD NOT SUPPORTED
- NULL, // TODO: OPCODE 0xDE NOT SUPPORTED
- NULL, // TODO: OPCODE 0xDF NOT SUPPORTED
+ Fast486FpuOpcodeD8,
+ Fast486FpuOpcodeD9,
+ Fast486FpuOpcodeDA,
+ Fast486FpuOpcodeDB,
+ Fast486FpuOpcodeDC,
+ Fast486FpuOpcodeDD,
+ Fast486FpuOpcodeDE,
+ Fast486FpuOpcodeDF,
Fast486OpcodeLoop,
Fast486OpcodeLoop,
Fast486OpcodeLoop,
{
Value = ++State->GeneralRegs[Opcode & 0x07].Long;
- State->Flags.Of = (Value == SIGN_FLAG_LONG) ? TRUE : FALSE;
- State->Flags.Sf = (Value & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Of = (Value == SIGN_FLAG_LONG);
+ State->Flags.Sf = ((Value & SIGN_FLAG_LONG) != 0);
}
else
{
Value = ++State->GeneralRegs[Opcode & 0x07].LowWord;
- State->Flags.Of = (Value == SIGN_FLAG_WORD) ? TRUE : FALSE;
- State->Flags.Sf = (Value & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Of = (Value == SIGN_FLAG_WORD);
+ State->Flags.Sf = ((Value & SIGN_FLAG_WORD) != 0);
}
- State->Flags.Zf = (Value == 0) ? TRUE : FALSE;
- State->Flags.Af = ((Value & 0x0F) == 0) ? TRUE : FALSE;
+ State->Flags.Zf = (Value == 0);
+ State->Flags.Af = ((Value & 0x0F) == 0);
State->Flags.Pf = Fast486CalculateParity(LOBYTE(Value));
/* Return success */
{
Value = --State->GeneralRegs[Opcode & 0x07].Long;
- State->Flags.Of = (Value == (SIGN_FLAG_LONG - 1)) ? TRUE : FALSE;
- State->Flags.Sf = (Value & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Of = (Value == (SIGN_FLAG_LONG - 1));
+ State->Flags.Sf = ((Value & SIGN_FLAG_LONG) != 0);
}
else
{
Value = --State->GeneralRegs[Opcode & 0x07].LowWord;
- State->Flags.Of = (Value == (SIGN_FLAG_WORD - 1)) ? TRUE : FALSE;
- State->Flags.Sf = (Value & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Of = (Value == (SIGN_FLAG_WORD - 1));
+ State->Flags.Sf = ((Value & SIGN_FLAG_WORD) != 0);
}
- State->Flags.Zf = (Value == 0) ? TRUE : FALSE;
- State->Flags.Af = ((Value & 0x0F) == 0x0F) ? TRUE : FALSE;
+ State->Flags.Zf = (Value == 0);
+ State->Flags.Af = ((Value & 0x0F) == 0x0F);
State->Flags.Pf = Fast486CalculateParity(LOBYTE(Value));
/* Return success */
FAST486_OPCODE_HANDLER(Fast486OpcodePopReg)
{
ULONG Value;
- BOOLEAN Size = State->SegmentRegs[FAST486_REG_SS].Size;
+ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
TOGGLE_OPSIZE(Size);
NO_LOCK_PREFIX();
{
BOOLEAN Jump = FALSE;
CHAR Offset = 0;
+ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */
ASSERT((Opcode & 0xF0) == 0x70);
+ TOGGLE_OPSIZE(Size);
+
/* Fetch the offset */
if (!Fast486FetchByte(State, (PUCHAR)&Offset))
{
if (Jump)
{
- /* Move the instruction pointer */
+ /* Move the instruction pointer */
State->InstPtr.Long += Offset;
+
+ if (!Size)
+ {
+ /* Clear the top half of EIP */
+ State->InstPtr.Long &= 0xFFFF;
+ }
}
/* Return success */
}
/* Halt */
- while (State->IntStatus != FAST486_INT_SIGNAL) State->IdleCallback(State);
+ // TODO: Halt the CPU until an interrupt occurs, using IdleCallback if needed.
/* Return success */
return TRUE;
}
/* Read a byte from the I/O port */
- State->IoReadCallback(State, Port, &Data, sizeof(UCHAR));
+ State->IoReadCallback(State, Port, &Data, 1, sizeof(UCHAR));
/* Store the result in AL */
State->GeneralRegs[FAST486_REG_EAX].LowByte = Data;
ULONG Data;
/* Read a dword from the I/O port */
- State->IoReadCallback(State, Port, &Data, sizeof(ULONG));
+ State->IoReadCallback(State, Port, &Data, 1, sizeof(ULONG));
/* Store the value in EAX */
State->GeneralRegs[FAST486_REG_EAX].Long = Data;
USHORT Data;
/* Read a word from the I/O port */
- State->IoReadCallback(State, Port, &Data, sizeof(USHORT));
+ State->IoReadCallback(State, Port, &Data, 1, sizeof(USHORT));
/* Store the value in AX */
State->GeneralRegs[FAST486_REG_EAX].LowWord = Data;
/* Read the value from AL */
Data = State->GeneralRegs[FAST486_REG_EAX].LowByte;
-
+
/* Write the byte to the I/O port */
- State->IoWriteCallback(State, Port, &Data, sizeof(UCHAR));
+ State->IoWriteCallback(State, Port, &Data, 1, sizeof(UCHAR));
return TRUE;
}
ULONG Data = State->GeneralRegs[FAST486_REG_EAX].Long;
/* Write a dword to the I/O port */
- State->IoReadCallback(State, Port, &Data, sizeof(ULONG));
+ State->IoWriteCallback(State, Port, &Data, 1, sizeof(ULONG));
}
else
{
USHORT Data = State->GeneralRegs[FAST486_REG_EAX].LowWord;
/* Write a word to the I/O port */
- State->IoWriteCallback(State, Port, &Data, sizeof(USHORT));
+ State->IoWriteCallback(State, Port, &Data, 1, sizeof(USHORT));
}
return TRUE;
FAST486_OPCODE_HANDLER(Fast486OpcodeShortJump)
{
CHAR Offset = 0;
+ BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
+
+ TOGGLE_OPSIZE(Size);
/* Make sure this is the right instruction */
ASSERT(Opcode == 0xEB);
return FALSE;
}
- /* Move the instruction pointer */
+ /* Move the instruction pointer */
State->InstPtr.Long += Offset;
+ if (!Size)
+ {
+ /* Clear the top half of EIP */
+ State->InstPtr.Long &= 0xFFFF;
+ }
+
return TRUE;
}
State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE))
&& ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue + SecondValue;
State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG))
&& ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue + SecondValue;
State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD))
&& ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE))
&& ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG))
&& ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
State->Flags.Cf = (Result < FirstValue) && (Result < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD))
&& ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Af = ((((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) != 0);
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue | SecondValue;
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue | SecondValue;
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue & SecondValue;
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue & SecondValue;
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue ^ SecondValue;
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue ^ SecondValue;
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* The result is discarded */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue & SecondValue;
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
}
else
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue & SecondValue;
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
}
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* The result is discarded */
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
}
else
/* Update the flags */
State->Flags.Cf = FALSE;
State->Flags.Of = FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
}
/* Exception occurred */
return FALSE;
}
-
+
/* Write the value from the register to the R/M */
if (!Fast486WriteModrmWordOperands(State,
&ModRegRm,
State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE))
&& ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue + SecondValue + State->Flags.Cf;
State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG))
&& ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Calculate the result */
Result = FirstValue + SecondValue + State->Flags.Cf;
State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD))
&& ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) == (SecondValue & SIGN_FLAG_BYTE))
&& ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) == (SecondValue & SIGN_FLAG_LONG))
&& ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
State->Flags.Cf = State->Flags.Cf || ((Result < FirstValue) && (Result < SecondValue));
State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) == (SecondValue & SIGN_FLAG_WORD))
&& ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
- State->Flags.Af = (((FirstValue & 0x0F) + (SecondValue & 0x0F)) & 0x10) ? TRUE : FALSE;
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
Result = FirstValue - SecondValue - Carry;
/* Update the flags */
- State->Flags.Cf = FirstValue < (SecondValue + 1);
+ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE))
&& ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
- State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + 1) & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Swap the order */
SWAP(FirstValue, SecondValue);
}
-
+
/* Calculate the result */
Result = FirstValue - SecondValue - Carry;
/* Update the flags */
- State->Flags.Cf = FirstValue < (SecondValue + Carry);
+ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG))
&& ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
- State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + 1) & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
/* Exception occurred */
return FALSE;
}
-
+
/* Check if this is the instruction that writes to R/M */
if (!(Opcode & FAST486_OPCODE_WRITE_REG))
{
/* Swap the order */
SWAP(FirstValue, SecondValue);
}
-
+
/* Calculate the result */
Result = FirstValue - SecondValue - Carry;
/* Update the flags */
- State->Flags.Cf = FirstValue < (SecondValue + Carry);
+ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD))
&& ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
- State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + 1) & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
Result = FirstValue - SecondValue - Carry;
/* Update the flags */
- State->Flags.Cf = FirstValue < (SecondValue + Carry);
+ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE))
&& ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
- State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + 1) & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
Result = FirstValue - SecondValue - Carry;
/* Update the flags */
- State->Flags.Cf = FirstValue < (SecondValue + Carry);
+ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG))
&& ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
- State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + Carry) & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
Result = FirstValue - SecondValue - Carry;
/* Update the flags */
- State->Flags.Cf = FirstValue < (SecondValue + Carry);
+ State->Flags.Cf = Carry ? (FirstValue <= SecondValue) : (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD))
&& ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
- State->Flags.Af = (FirstValue & 0x0F) < ((SecondValue + Carry) & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Af = ((FirstValue ^ SecondValue ^ Result) & 0x10) != 0;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Write back the result */
State->Flags.Cf = TRUE;
}
+ Value = State->GeneralRegs[FAST486_REG_EAX].LowByte;
+
+ /* Update the flags */
+ State->Flags.Sf = (Value & SIGN_FLAG_BYTE) != 0;
+ State->Flags.Zf = (Value == 0);
+ State->Flags.Pf = Fast486CalculateParity(Value);
+
return TRUE;
}
Result = FirstValue - SecondValue;
/* Update the flags */
- State->Flags.Cf = FirstValue < SecondValue;
+ State->Flags.Cf = (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE))
&& ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */
/* Swap the order */
SWAP(FirstValue, SecondValue);
}
-
+
/* Calculate the result */
Result = FirstValue - SecondValue;
/* Update the flags */
- State->Flags.Cf = FirstValue < SecondValue;
+ State->Flags.Cf = (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG))
&& ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */
/* Exception occurred */
return FALSE;
}
-
+
/* Check if this is the instruction that writes to R/M */
if (!(Opcode & FAST486_OPCODE_WRITE_REG))
{
/* Swap the order */
SWAP(FirstValue, SecondValue);
}
-
+
/* Calculate the result */
Result = FirstValue - SecondValue;
/* Update the flags */
- State->Flags.Cf = FirstValue < SecondValue;
+ State->Flags.Cf = (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD))
&& ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */
Result = FirstValue - SecondValue;
/* Update the flags */
- State->Flags.Cf = FirstValue < SecondValue;
+ State->Flags.Cf = (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_BYTE) != (SecondValue & SIGN_FLAG_BYTE))
&& ((FirstValue & SIGN_FLAG_BYTE) != (Result & SIGN_FLAG_BYTE));
State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */
Result = FirstValue - SecondValue;
/* Update the flags */
- State->Flags.Cf = FirstValue < SecondValue;
+ State->Flags.Cf = (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_LONG) != (SecondValue & SIGN_FLAG_LONG))
&& ((FirstValue & SIGN_FLAG_LONG) != (Result & SIGN_FLAG_LONG));
State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_LONG) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_LONG) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */
Result = FirstValue - SecondValue;
/* Update the flags */
- State->Flags.Cf = FirstValue < SecondValue;
+ State->Flags.Cf = (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SIGN_FLAG_WORD) != (SecondValue & SIGN_FLAG_WORD))
&& ((FirstValue & SIGN_FLAG_WORD) != (Result & SIGN_FLAG_WORD));
State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SIGN_FLAG_WORD) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SIGN_FLAG_WORD) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Check if this is not a CMP */
State->Flags.Cf = TRUE;
}
+ Value = State->GeneralRegs[FAST486_REG_EAX].LowByte;
+
+ /* Update the flags */
+ State->Flags.Sf = (Value & SIGN_FLAG_BYTE) != 0;
+ State->Flags.Zf = (Value == 0);
+ State->Flags.Pf = Fast486CalculateParity(Value);
+
return TRUE;
}
if (((Value & 0x0F) > 9) || State->Flags.Af)
{
/* Correct it */
- State->GeneralRegs[FAST486_REG_EAX].LowByte += 0x06;
+ State->GeneralRegs[FAST486_REG_EAX].LowWord += 0x06;
State->GeneralRegs[FAST486_REG_EAX].HighByte++;
/* Set CF and AF */
if (((Value & 0x0F) > 9) || State->Flags.Af)
{
/* Correct it */
- State->GeneralRegs[FAST486_REG_EAX].LowByte -= 0x06;
+ State->GeneralRegs[FAST486_REG_EAX].LowWord -= 0x06;
State->GeneralRegs[FAST486_REG_EAX].HighByte--;
/* Set CF and AF */
FAST486_OPCODE_HANDLER(Fast486OpcodeBound)
{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
+ BOOLEAN OperandSize, AddressSize;
+ FAST486_MOD_REG_RM ModRegRm;
+ FAST486_SEG_REGS Segment = FAST486_REG_DS;
- return FALSE;
+ OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
+
+ NO_LOCK_PREFIX();
+ TOGGLE_OPSIZE(OperandSize);
+ TOGGLE_ADSIZE(AddressSize);
+
+ if (!Fast486ParseModRegRm(State, AddressSize, &ModRegRm))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
+
+ if (!ModRegRm.Memory)
+ {
+ /* Invalid */
+ Fast486Exception(State, FAST486_EXCEPTION_UD);
+ return FALSE;
+ }
+
+ /* Check for the segment override */
+ if (State->PrefixFlags & FAST486_PREFIX_SEG)
+ {
+ /* Use the override segment instead */
+ Segment = State->SegmentOverride;
+ }
+
+ if (OperandSize)
+ {
+ LONG Index, LowerBound, UpperBound;
+
+ /* Read the operands */
+ if (!Fast486ReadModrmDwordOperands(State,
+ &ModRegRm,
+ (PULONG)&Index,
+ (PULONG)&LowerBound))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
+
+ if (!Fast486ReadMemory(State,
+ Segment,
+ ModRegRm.MemoryAddress + sizeof(ULONG),
+ FALSE,
+ &UpperBound,
+ sizeof(ULONG)))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
+
+ if ((Index < LowerBound) || (Index > UpperBound))
+ {
+ /* Out of bounds */
+ Fast486Exception(State, FAST486_EXCEPTION_BR);
+ return FALSE;
+ }
+ }
+ else
+ {
+ SHORT Index, LowerBound, UpperBound;
+
+ /* Read the operands */
+ if (!Fast486ReadModrmWordOperands(State,
+ &ModRegRm,
+ (PUSHORT)&Index,
+ (PUSHORT)&LowerBound))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
+
+ if (!Fast486ReadMemory(State,
+ Segment,
+ ModRegRm.MemoryAddress + sizeof(USHORT),
+ FALSE,
+ &UpperBound,
+ sizeof(USHORT)))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
+
+ if ((Index < LowerBound) || (Index > UpperBound))
+ {
+ /* Out of bounds */
+ Fast486Exception(State, FAST486_EXCEPTION_BR);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
}
FAST486_OPCODE_HANDLER(Fast486OpcodeArpl)
BOOLEAN OperandSize, AddressSize;
FAST486_MOD_REG_RM ModRegRm;
LONG Multiplier;
- LONGLONG Product;
/* Make sure this is the right instruction */
ASSERT((Opcode & 0xFD) == 0x69);
if (OperandSize)
{
LONG RegValue, Multiplicand;
+ LONGLONG Product;
/* Read the operands */
if (!Fast486ReadModrmDwordOperands(State,
/* Multiply */
Product = (LONGLONG)Multiplicand * (LONGLONG)Multiplier;
+
+ /* Check for carry/overflow */
+ State->Flags.Cf = State->Flags.Of = ((Product < MINLONG) || (Product > MAXLONG));
+
+ /* Write-back the result */
+ return Fast486WriteModrmDwordOperands(State,
+ &ModRegRm,
+ TRUE,
+ (ULONG)((LONG)Product));
}
else
{
SHORT RegValue, Multiplicand;
+ LONG Product;
/* Read the operands */
if (!Fast486ReadModrmWordOperands(State,
}
/* Multiply */
- Product = (LONGLONG)Multiplicand * (LONGLONG)Multiplier;
- }
+ Product = (LONG)Multiplicand * (LONG)Multiplier;
- /* Check for carry/overflow */
- if ((Product < LONG_MIN) || (Product > LONG_MAX))
- {
- State->Flags.Cf = State->Flags.Of = TRUE;
- }
- else State->Flags.Cf = State->Flags.Of = FALSE;
+ /* Check for carry/overflow */
+ State->Flags.Cf = State->Flags.Of = ((Product < MINSHORT) || (Product > MAXSHORT));
- /* Write-back the result */
- return Fast486WriteModrmDwordOperands(State,
- &ModRegRm,
- TRUE,
- (ULONG)((LONG)Product));
+ /* Write-back the result */
+ return Fast486WriteModrmWordOperands(State,
+ &ModRegRm,
+ TRUE,
+ (USHORT)((SHORT)Product));
+ }
}
FAST486_OPCODE_HANDLER(Fast486OpcodePushByteImm)
if (Opcode & FAST486_OPCODE_WRITE_REG) Result = SecondValue;
else Result = FirstValue;
-
+
/* Write back the result */
return Fast486WriteModrmDwordOperands(State,
&ModRegRm,
/* Exception occurred */
return FALSE;
}
-
+
if (Opcode & FAST486_OPCODE_WRITE_REG) Result = SecondValue;
else Result = FirstValue;
if (OperandSize)
{
- ULONG Dummy, Selector;
+ ULONG Selector;
- if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, &Dummy, &Selector))
+ if (!Fast486ReadModrmDwordOperands(State, &ModRegRm, NULL, &Selector))
{
/* Exception occurred */
return FALSE;
}
else
{
- USHORT Dummy, Selector;
+ USHORT Selector;
- if (!Fast486ReadModrmWordOperands(State, &ModRegRm, &Dummy, &Selector))
+ if (!Fast486ReadModrmWordOperands(State, &ModRegRm, NULL, &Selector))
{
/* Exception occurred */
return FALSE;
{
BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
INT Cpl = Fast486GetCurrentPrivLevel(State);
- ULONG NewFlags;
+ FAST486_FLAGS_REG NewFlags;
NO_LOCK_PREFIX();
TOGGLE_OPSIZE(Size);
/* Pop the new flags */
- if (!Fast486StackPop(State, &NewFlags))
+ if (!Fast486StackPop(State, &NewFlags.Long))
{
/* Exception occurred */
return FALSE;
}
- if (!State->Flags.Vm)
+ /* Check for VM86 mode when IOPL is not 3 */
+ if (State->Flags.Vm && (State->Flags.Iopl != 3))
{
- /* Check the current privilege level */
- if (Cpl == 0)
- {
- /* Supervisor */
-
- /* Set the flags */
- if (Size)
- {
- /* Memorize the old state of RF */
- BOOLEAN OldRf = State->Flags.Rf;
-
- State->Flags.Long = NewFlags;
-
- /* Restore VM and RF */
- State->Flags.Vm = FALSE;
- State->Flags.Rf = OldRf;
-
- /* Clear VIF and VIP */
- State->Flags.Vif = State->Flags.Vip = FALSE;
- }
- else State->Flags.LowWord = LOWORD(NewFlags);
-
- /* Restore the reserved bits */
- State->Flags.AlwaysSet = TRUE;
- State->Flags.Reserved0 = FALSE;
- State->Flags.Reserved1 = FALSE;
- }
- else
- {
- /* User */
-
- /* Memorize the old state of IF and IOPL */
- BOOLEAN OldIf = State->Flags.If;
- UINT OldIopl = State->Flags.Iopl;
-
- /* Set the flags */
- if (Size)
- {
- /* Memorize the old state of RF */
- BOOLEAN OldRf = State->Flags.Rf;
-
- State->Flags.Long = NewFlags;
-
- /* Restore VM and RF */
- State->Flags.Vm = FALSE;
- State->Flags.Rf = OldRf;
-
- /* Clear VIF and VIP */
- State->Flags.Vif = State->Flags.Vip = FALSE;
- }
- else State->Flags.LowWord = LOWORD(NewFlags);
-
- /* Restore the reserved bits and IOPL */
- State->Flags.AlwaysSet = TRUE;
- State->Flags.Reserved0 = FALSE;
- State->Flags.Reserved1 = FALSE;
- State->Flags.Iopl = OldIopl;
-
- /* Check if the user doesn't have the privilege to change IF */
- if (Cpl > State->Flags.Iopl)
- {
- /* Restore IF */
- State->Flags.If = OldIf;
- }
- }
+ /* Call the VM86 monitor */
+ Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0);
+ return FALSE;
}
- else
- {
- /* Check the IOPL */
- if (State->Flags.Iopl == 3)
- {
- if (Size)
- {
- /* Memorize the old state of RF, VIF and VIP */
- BOOLEAN OldRf = State->Flags.Rf;
- BOOLEAN OldVif = State->Flags.Vif;
- BOOLEAN OldVip = State->Flags.Vip;
-
- State->Flags.Long = NewFlags;
-
- /* Restore VM, RF, VIF and VIP */
- State->Flags.Vm = TRUE;
- State->Flags.Rf = OldRf;
- State->Flags.Vif = OldVif;
- State->Flags.Vip = OldVip;
- }
- else State->Flags.LowWord = LOWORD(NewFlags);
- /* Restore the reserved bits and IOPL */
- State->Flags.AlwaysSet = TRUE;
- State->Flags.Reserved0 = FALSE;
- State->Flags.Reserved1 = FALSE;
- State->Flags.Iopl = 3;
- }
- else
- {
- /* Call the VM86 monitor */
- Fast486ExceptionWithErrorCode(State, FAST486_EXCEPTION_GP, 0);
- }
-
- }
+ State->Flags.Cf = NewFlags.Cf;
+ State->Flags.Pf = NewFlags.Pf;
+ State->Flags.Af = NewFlags.Af;
+ State->Flags.Zf = NewFlags.Zf;
+ State->Flags.Sf = NewFlags.Sf;
+ State->Flags.Tf = NewFlags.Tf;
+ State->Flags.Df = NewFlags.Df;
+ State->Flags.Of = NewFlags.Of;
+ State->Flags.Nt = NewFlags.Nt;
+ State->Flags.Ac = NewFlags.Ac;
+
+ if (Cpl == 0) State->Flags.Iopl = NewFlags.Iopl;
+ if (Cpl <= State->Flags.Iopl) State->Flags.If = NewFlags.If;
return TRUE;
}
State->Flags.AlwaysSet = TRUE;
State->Flags.Reserved0 = State->Flags.Reserved1 = FALSE;
- return FALSE;
+ return TRUE;
}
FAST486_OPCODE_HANDLER(Fast486OpcodeLahf)
/* Set AH to the low-order byte of FLAGS */
State->GeneralRegs[FAST486_REG_EAX].HighByte = LOBYTE(State->Flags.Long);
- return FALSE;
+ return TRUE;
}
FAST486_OPCODE_HANDLER(Fast486OpcodeRet)
OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
+ TOGGLE_OPSIZE(OperandSize);
TOGGLE_ADSIZE(AddressSize);
/* Get the operands */
&& (ModRegRm.SecondRegister == FAST486_REG_ESP)
&& (State->BopCallback != NULL))
{
- USHORT BopCode;
+ UCHAR BopCode;
/* Fetch the BOP code */
- if (!Fast486FetchWord(State, &BopCode))
+ if (!Fast486FetchByte(State, &BopCode))
{
/* Exception occurred */
return FALSE;
FAST486_OPCODE_HANDLER(Fast486OpcodeIret)
{
- INT i;
+ FAST486_SEG_REGS i;
ULONG InstPtr, CodeSel, StackPtr, StackSel;
FAST486_FLAGS_REG NewFlags;
BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
Cpl = Fast486GetCurrentPrivLevel(State);
/* Check segment security */
- for (i = 0; i <= FAST486_NUM_SEG_REGS; i++)
+ for (i = 0; i < FAST486_NUM_SEG_REGS; i++)
{
/* Don't check CS or SS */
if ((i == FAST486_REG_CS) || (i == FAST486_REG_SS)) continue;
State->GeneralRegs[FAST486_REG_EAX].LowByte = Value %= Base;
/* Update flags */
- State->Flags.Zf = (Value == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Value & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Af = FALSE;
+ State->Flags.Zf = (Value == 0);
+ State->Flags.Sf = ((Value & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Value);
return TRUE;
/* Adjust */
Value += State->GeneralRegs[FAST486_REG_EAX].HighByte * Base;
- State->GeneralRegs[FAST486_REG_EAX].LowByte = Value;
+ State->GeneralRegs[FAST486_REG_EAX].LowWord = Value;
/* Update flags */
- State->Flags.Zf = (Value == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Value & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Af = FALSE;
+ State->Flags.Zf = (Value == 0);
+ State->Flags.Sf = ((Value & SIGN_FLAG_BYTE) != 0);
State->Flags.Pf = Fast486CalculateParity(Value);
return TRUE;
/* Read a byte from DS:[(E)BX + AL] */
if (!Fast486ReadMemory(State,
FAST486_REG_DS,
- AddressSize ? State->GeneralRegs[FAST486_REG_EBX].Long
- : State->GeneralRegs[FAST486_REG_EBX].LowWord
+ (AddressSize ? State->GeneralRegs[FAST486_REG_EBX].Long
+ : State->GeneralRegs[FAST486_REG_EBX].LowWord)
+ State->GeneralRegs[FAST486_REG_EAX].LowByte,
FALSE,
&Value,
ASSERT((Opcode >= 0xE0) && (Opcode <= 0xE2));
NO_LOCK_PREFIX();
- TOGGLE_OPSIZE(Size);
+ TOGGLE_ADSIZE(Size);
if (Size) Condition = ((--State->GeneralRegs[FAST486_REG_ECX].Long) != 0);
else Condition = ((--State->GeneralRegs[FAST486_REG_ECX].LowWord) != 0);
if (Condition)
{
/* Move the instruction pointer */
- State->InstPtr.Long += Offset;
+ if (Size) State->InstPtr.Long += Offset;
+ else State->InstPtr.LowWord += Offset;
}
return TRUE;
ASSERT(Opcode == 0xE3);
NO_LOCK_PREFIX();
- TOGGLE_OPSIZE(Size);
+ TOGGLE_ADSIZE(Size);
if (Size) Condition = (State->GeneralRegs[FAST486_REG_ECX].Long == 0);
else Condition = (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0);
if (Condition)
{
- /* Move the instruction pointer */
- State->InstPtr.Long += Offset;
+ /* Move the instruction pointer */
+ if (Size) State->InstPtr.Long += Offset;
+ else State->InstPtr.LowWord += Offset;
}
return TRUE;
return FALSE;
}
- /* Move the instruction pointer */
+ /* Move the instruction pointer */
State->InstPtr.Long += Offset;
}
else
return FALSE;
}
- /* Move the instruction pointer */
+ /* Move the instruction pointer */
State->InstPtr.LowWord += Offset;
}
return FALSE;
}
- /* Move the instruction pointer */
+ /* Move the instruction pointer */
State->InstPtr.Long += Offset;
}
else
return FALSE;
}
- /* Move the instruction pointer */
- State->InstPtr.LowWord += Offset;
+ /* Move the instruction pointer */
+ State->InstPtr.Long += Offset;
+
+ /* Clear the top half of EIP */
+ State->InstPtr.Long &= 0xFFFF;
}
return TRUE;
return FALSE;
}
- /* Load new (E)IP */
- if (Size) State->InstPtr.Long = Offset;
- else State->InstPtr.LowWord = LOWORD(Offset);
+ /* Load new EIP */
+ State->InstPtr.Long = Offset;
return TRUE;
}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovAlOffset)
{
- BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
+ BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
ULONG Offset;
/* Make sure this is the right instruction */
ASSERT(Opcode == 0xA0);
- TOGGLE_OPSIZE(Size);
+ TOGGLE_ADSIZE(AddressSize);
- if (Size)
+ if (AddressSize)
{
if (!Fast486FetchDword(State, &Offset))
{
FAST486_OPCODE_HANDLER(Fast486OpcodeMovEaxOffset)
{
- BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
+ BOOLEAN OperandSize, AddressSize;
+
+ OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */
ASSERT(Opcode == 0xA1);
- TOGGLE_OPSIZE(Size);
+ TOGGLE_OPSIZE(OperandSize);
+ TOGGLE_ADSIZE(AddressSize);
- if (Size)
+ if (AddressSize)
{
ULONG Offset;
}
/* Read from memory */
- return Fast486ReadMemory(State,
- (State->PrefixFlags & FAST486_PREFIX_SEG) ?
- State->SegmentOverride : FAST486_REG_DS,
- Offset,
- FALSE,
- &State->GeneralRegs[FAST486_REG_EAX].Long,
- sizeof(ULONG));
+ if (OperandSize)
+ {
+ return Fast486ReadMemory(State,
+ (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+ State->SegmentOverride : FAST486_REG_DS,
+ Offset,
+ FALSE,
+ &State->GeneralRegs[FAST486_REG_EAX].Long,
+ sizeof(ULONG));
+ }
+ else
+ {
+ return Fast486ReadMemory(State,
+ (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+ State->SegmentOverride : FAST486_REG_DS,
+ Offset,
+ FALSE,
+ &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+ sizeof(USHORT));
+ }
}
else
{
}
/* Read from memory */
- return Fast486ReadMemory(State,
- (State->PrefixFlags & FAST486_PREFIX_SEG) ?
- State->SegmentOverride : FAST486_REG_DS,
- Offset,
- FALSE,
- &State->GeneralRegs[FAST486_REG_EAX].LowWord,
- sizeof(USHORT));
+ if (OperandSize)
+ {
+ return Fast486ReadMemory(State,
+ (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+ State->SegmentOverride : FAST486_REG_DS,
+ Offset,
+ FALSE,
+ &State->GeneralRegs[FAST486_REG_EAX].Long,
+ sizeof(ULONG));
+ }
+ else
+ {
+ return Fast486ReadMemory(State,
+ (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+ State->SegmentOverride : FAST486_REG_DS,
+ Offset,
+ FALSE,
+ &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+ sizeof(USHORT));
+ }
}
}
FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetAl)
{
- BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
+ BOOLEAN AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
ULONG Offset;
/* Make sure this is the right instruction */
ASSERT(Opcode == 0xA2);
- TOGGLE_OPSIZE(Size);
+ TOGGLE_ADSIZE(AddressSize);
- if (Size)
+ if (AddressSize)
{
if (!Fast486FetchDword(State, &Offset))
{
FAST486_OPCODE_HANDLER(Fast486OpcodeMovOffsetEax)
{
- BOOLEAN Size = State->SegmentRegs[FAST486_REG_CS].Size;
+ BOOLEAN OperandSize, AddressSize;
+
+ OperandSize = AddressSize = State->SegmentRegs[FAST486_REG_CS].Size;
/* Make sure this is the right instruction */
ASSERT(Opcode == 0xA3);
- TOGGLE_OPSIZE(Size);
+ TOGGLE_OPSIZE(OperandSize);
+ TOGGLE_ADSIZE(AddressSize);
- if (Size)
+ if (AddressSize)
{
ULONG Offset;
}
/* Write to memory */
- return Fast486WriteMemory(State,
- (State->PrefixFlags & FAST486_PREFIX_SEG) ?
- State->SegmentOverride : FAST486_REG_DS,
- Offset,
- &State->GeneralRegs[FAST486_REG_EAX].Long,
- sizeof(ULONG));
+ if (OperandSize)
+ {
+ return Fast486WriteMemory(State,
+ (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+ State->SegmentOverride : FAST486_REG_DS,
+ Offset,
+ &State->GeneralRegs[FAST486_REG_EAX].Long,
+ sizeof(ULONG));
+ }
+ else
+ {
+ return Fast486WriteMemory(State,
+ (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+ State->SegmentOverride : FAST486_REG_DS,
+ Offset,
+ &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+ sizeof(USHORT));
+ }
}
else
{
}
/* Write to memory */
- return Fast486WriteMemory(State,
- (State->PrefixFlags & FAST486_PREFIX_SEG) ?
- State->SegmentOverride : FAST486_REG_DS,
- Offset,
- &State->GeneralRegs[FAST486_REG_EAX].LowWord,
- sizeof(USHORT));
+ if (OperandSize)
+ {
+ return Fast486WriteMemory(State,
+ (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+ State->SegmentOverride : FAST486_REG_DS,
+ Offset,
+ &State->GeneralRegs[FAST486_REG_EAX].Long,
+ sizeof(ULONG));
+ }
+ else
+ {
+ return Fast486WriteMemory(State,
+ (State->PrefixFlags & FAST486_PREFIX_SEG) ?
+ State->SegmentOverride : FAST486_REG_DS,
+ Offset,
+ &State->GeneralRegs[FAST486_REG_EAX].LowWord,
+ sizeof(USHORT));
+ }
}
}
Segment = State->SegmentOverride;
}
+ if (State->PrefixFlags & FAST486_PREFIX_REP)
+ {
+ if ((AddressSize && (State->GeneralRegs[FAST486_REG_ECX].Long == 0))
+ || (!AddressSize && (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0)))
+ {
+ /* Do nothing */
+ return TRUE;
+ }
+ }
+
/* Calculate the size */
if (Opcode == 0xA4) DataSize = sizeof(UCHAR);
else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
- if (State->PrefixFlags & FAST486_PREFIX_REP)
+ /* Read from the source operand */
+ if (!Fast486ReadMemory(State,
+ Segment,
+ AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long
+ : State->GeneralRegs[FAST486_REG_ESI].LowWord,
+ FALSE,
+ &Data,
+ DataSize))
{
- UCHAR Block[STRING_BLOCK_SIZE];
- ULONG Count = OperandSize ? State->GeneralRegs[FAST486_REG_ECX].Long
- : State->GeneralRegs[FAST486_REG_ECX].LowWord;
+ /* Exception occurred */
+ return FALSE;
+ }
- /* Clear the memory block */
- RtlZeroMemory(Block, sizeof(Block));
+ /* Write to the destination operand */
+ if (!Fast486WriteMemory(State,
+ FAST486_REG_ES,
+ AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long
+ : State->GeneralRegs[FAST486_REG_EDI].LowWord,
+ &Data,
+ DataSize))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
- /* Transfer until finished */
- while (Count)
+ /* Increment/decrement ESI and EDI */
+ if (AddressSize)
+ {
+ if (!State->Flags.Df)
{
- ULONG Processed = min(Count, STRING_BLOCK_SIZE / DataSize);
-
- /* Simulate the 16-bit wrap-around of SI and DI in 16-bit address mode */
- if (!AddressSize)
- {
- ULONG MaxBytesSrc = State->Flags.Df
- ? (ULONG)State->GeneralRegs[FAST486_REG_ESI].LowWord
- : (0x10000 - (ULONG)State->GeneralRegs[FAST486_REG_ESI].LowWord);
- ULONG MaxBytesDest = State->Flags.Df
- ? (ULONG)State->GeneralRegs[FAST486_REG_EDI].LowWord
- : (0x10000 - (ULONG)State->GeneralRegs[FAST486_REG_EDI].LowWord);
-
-
- Processed = min(Processed, min(MaxBytesSrc, MaxBytesDest) / DataSize);
- if (Processed == 0) Processed = 1;
- }
-
- if (State->Flags.Df)
- {
- /* Reduce ESI and EDI by the number of bytes to transfer */
- if (AddressSize)
- {
- State->GeneralRegs[FAST486_REG_ESI].Long -= Processed * DataSize;
- State->GeneralRegs[FAST486_REG_EDI].Long -= Processed * DataSize;
- }
- else
- {
- State->GeneralRegs[FAST486_REG_ESI].LowWord -= Processed * DataSize;
- State->GeneralRegs[FAST486_REG_EDI].LowWord -= Processed * DataSize;
- }
- }
-
- /* Read from memory */
- if (!Fast486ReadMemory(State,
- Segment,
- AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long
- : State->GeneralRegs[FAST486_REG_ESI].LowWord,
- FALSE,
- Block,
- Processed * DataSize))
- {
- /* Set ECX */
- if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
- else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
-
- /* Exception occurred */
- return FALSE;
- }
-
- /* Write to memory */
- if (!Fast486WriteMemory(State,
- FAST486_REG_ES,
- AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long
- : State->GeneralRegs[FAST486_REG_EDI].LowWord,
- Block,
- Processed * DataSize))
- {
- /* Set ECX */
- if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
- else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
-
- /* Exception occurred */
- return FALSE;
- }
-
- if (!State->Flags.Df)
- {
- /* Increase ESI and EDI by the number of bytes transfered */
- if (AddressSize)
- {
- State->GeneralRegs[FAST486_REG_ESI].Long += Processed * DataSize;
- State->GeneralRegs[FAST486_REG_EDI].Long += Processed * DataSize;
- }
- else
- {
- State->GeneralRegs[FAST486_REG_ESI].LowWord += Processed * DataSize;
- State->GeneralRegs[FAST486_REG_EDI].LowWord += Processed * DataSize;
- }
- }
-
- /* Reduce the total count by the number processed in this run */
- Count -= Processed;
+ State->GeneralRegs[FAST486_REG_ESI].Long += DataSize;
+ State->GeneralRegs[FAST486_REG_EDI].Long += DataSize;
+ }
+ else
+ {
+ State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize;
+ State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
}
-
- /* Clear ECX */
- if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
- else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0;
}
else
{
- /* Read from the source operand */
- if (!Fast486ReadMemory(State,
- FAST486_REG_DS,
- AddressSize ? State->GeneralRegs[FAST486_REG_ESI].Long
- : State->GeneralRegs[FAST486_REG_ESI].LowWord,
- FALSE,
- &Data,
- DataSize))
+ if (!State->Flags.Df)
{
- /* Exception occurred */
- return FALSE;
+ State->GeneralRegs[FAST486_REG_ESI].LowWord += DataSize;
+ State->GeneralRegs[FAST486_REG_EDI].LowWord += DataSize;
}
-
- /* Write to the destination operand */
- if (!Fast486WriteMemory(State,
- FAST486_REG_ES,
- AddressSize ? State->GeneralRegs[FAST486_REG_EDI].Long
- : State->GeneralRegs[FAST486_REG_EDI].LowWord,
- &Data,
- DataSize))
+ else
{
- /* Exception occurred */
- return FALSE;
+ State->GeneralRegs[FAST486_REG_ESI].LowWord -= DataSize;
+ State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize;
}
+ }
- /* Increment/decrement ESI and EDI */
- if (OperandSize)
+ // FIXME: This method is slow!
+ if (State->PrefixFlags & FAST486_PREFIX_REP)
+ {
+ if (AddressSize)
{
- if (!State->Flags.Df)
- {
- State->GeneralRegs[FAST486_REG_ESI].Long += DataSize;
- State->GeneralRegs[FAST486_REG_EDI].Long += DataSize;
- }
- else
+ if (--State->GeneralRegs[FAST486_REG_ECX].Long)
{
- State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize;
- State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
+ /* Repeat the instruction */
+ State->InstPtr = State->SavedInstPtr;
}
}
else
{
- if (!State->Flags.Df)
+ if (--State->GeneralRegs[FAST486_REG_ECX].LowWord)
{
- State->GeneralRegs[FAST486_REG_ESI].LowWord += DataSize;
- State->GeneralRegs[FAST486_REG_EDI].LowWord += DataSize;
- }
- else
- {
- State->GeneralRegs[FAST486_REG_ESI].LowWord -= DataSize;
- State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize;
+ /* Repeat the instruction */
+ State->InstPtr = State->SavedInstPtr;
}
}
}
Segment = State->SegmentOverride;
}
+ if ((State->PrefixFlags & FAST486_PREFIX_REP)
+ || (State->PrefixFlags & FAST486_PREFIX_REPNZ))
+ {
+ if ((AddressSize && (State->GeneralRegs[FAST486_REG_ECX].Long == 0))
+ || (!AddressSize && (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0)))
+ {
+ /* Do nothing */
+ return TRUE;
+ }
+ }
+
/* Calculate the size */
if (Opcode == 0xA6) DataSize = sizeof(UCHAR);
else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
/* Calculate the mask and sign flag */
- DataMask = (1 << (DataSize * 8)) - 1;
SignFlag = 1 << ((DataSize * 8) - 1);
+ DataMask = SignFlag | (SignFlag - 1);
/* Read from the first source operand */
if (!Fast486ReadMemory(State,
Result = (FirstValue - SecondValue) & DataMask;
/* Update the flags */
- State->Flags.Cf = FirstValue < SecondValue;
+ State->Flags.Cf = (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SignFlag) != (SecondValue & SignFlag))
&& ((FirstValue & SignFlag) != (Result & SignFlag));
State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SignFlag) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SignFlag) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Increment/decrement ESI and EDI */
- if (OperandSize)
+ if (AddressSize)
{
if (!State->Flags.Df)
{
|| (State->PrefixFlags & FAST486_PREFIX_REPNZ))
{
BOOLEAN Repeat = TRUE;
-
- if (OperandSize)
+
+ if (AddressSize)
{
if ((--State->GeneralRegs[FAST486_REG_ECX].Long) == 0)
{
if (State->PrefixFlags & FAST486_PREFIX_REP)
{
UCHAR Block[STRING_BLOCK_SIZE];
- ULONG Count = OperandSize ? State->GeneralRegs[FAST486_REG_ECX].Long
+ ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long
: State->GeneralRegs[FAST486_REG_ECX].LowWord;
/* Fill the memory block with the data */
if (State->Flags.Df)
{
- /* Reduce EDI by the number of bytes to transfer */
- if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long -= Processed * DataSize;
- else State->GeneralRegs[FAST486_REG_EDI].LowWord -= Processed * DataSize;
+ /* Set EDI to the starting location */
+ if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long -= (Processed - 1) * DataSize;
+ else State->GeneralRegs[FAST486_REG_EDI].LowWord -= (Processed - 1) * DataSize;
}
/* Write to memory */
Processed * DataSize))
{
/* Set ECX */
- if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
+ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
/* Exception occurred */
if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long += Processed * DataSize;
else State->GeneralRegs[FAST486_REG_EDI].LowWord += Processed * DataSize;
}
+ else
+ {
+ /* Reduce EDI */
+ if (AddressSize) State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
+ else State->GeneralRegs[FAST486_REG_EDI].LowWord -= DataSize;
+ }
/* Reduce the total count by the number processed in this run */
Count -= Processed;
}
/* Clear ECX */
- if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
+ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0;
}
else
}
/* Increment/decrement EDI */
- if (OperandSize)
+ if (AddressSize)
{
if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].Long += DataSize;
else State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
if (State->PrefixFlags & FAST486_PREFIX_REP)
{
- ULONG Count = OperandSize ? State->GeneralRegs[FAST486_REG_ECX].Long
+ ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long
: State->GeneralRegs[FAST486_REG_ECX].LowWord;
/* If the count is 0, do nothing */
if (AddressSize) State->GeneralRegs[FAST486_REG_ESI].Long -= (Count - 1) * DataSize;
else State->GeneralRegs[FAST486_REG_ESI].LowWord -= (Count - 1) * DataSize;
}
+
+ /* Clear ECX */
+ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
+ else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0;
}
/* Read from the source operand */
}
/* Increment/decrement ESI */
- if (OperandSize)
+ if (AddressSize)
{
if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_ESI].Long += DataSize;
else State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize;
TOGGLE_OPSIZE(OperandSize);
TOGGLE_ADSIZE(AddressSize);
+ if ((State->PrefixFlags & FAST486_PREFIX_REP)
+ || (State->PrefixFlags & FAST486_PREFIX_REPNZ))
+ {
+ if ((AddressSize && (State->GeneralRegs[FAST486_REG_ECX].Long == 0))
+ || (!AddressSize && (State->GeneralRegs[FAST486_REG_ECX].LowWord == 0)))
+ {
+ /* Do nothing */
+ return TRUE;
+ }
+ }
+
/* Calculate the size */
if (Opcode == 0xAE) DataSize = sizeof(UCHAR);
else DataSize = OperandSize ? sizeof(ULONG) : sizeof(USHORT);
/* Calculate the mask and sign flag */
- DataMask = (1 << (DataSize * 8)) - 1;
SignFlag = 1 << ((DataSize * 8) - 1);
+ DataMask = SignFlag | (SignFlag - 1);
/* Read from the source operand */
if (!Fast486ReadMemory(State,
Result = (FirstValue - SecondValue) & DataMask;
/* Update the flags */
- State->Flags.Cf = FirstValue < SecondValue;
+ State->Flags.Cf = (FirstValue < SecondValue);
State->Flags.Of = ((FirstValue & SignFlag) != (SecondValue & SignFlag))
&& ((FirstValue & SignFlag) != (Result & SignFlag));
State->Flags.Af = (FirstValue & 0x0F) < (SecondValue & 0x0F);
- State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
- State->Flags.Sf = (Result & SignFlag) ? TRUE : FALSE;
+ State->Flags.Zf = (Result == 0);
+ State->Flags.Sf = ((Result & SignFlag) != 0);
State->Flags.Pf = Fast486CalculateParity(Result);
/* Increment/decrement EDI */
- if (OperandSize)
+ if (AddressSize)
{
if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].Long += DataSize;
else State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
|| (State->PrefixFlags & FAST486_PREFIX_REPNZ))
{
BOOLEAN Repeat = TRUE;
-
- if (OperandSize)
+
+ if (AddressSize)
{
if ((--State->GeneralRegs[FAST486_REG_ECX].Long) == 0)
{
if (State->PrefixFlags & FAST486_PREFIX_REP)
{
UCHAR Block[STRING_BLOCK_SIZE];
- ULONG Count = OperandSize ? State->GeneralRegs[FAST486_REG_ECX].Long
+ ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long
: State->GeneralRegs[FAST486_REG_ECX].LowWord;
/* Clear the memory block */
State->IoReadCallback(State,
State->GeneralRegs[FAST486_REG_EDX].LowWord,
Block,
- Processed * DataSize);
+ Processed,
+ DataSize);
if (State->Flags.Df)
{
Processed * DataSize))
{
/* Set ECX */
- if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
+ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
/* Exception occurred */
}
/* Clear ECX */
- if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
+ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0;
}
else
State->IoReadCallback(State,
State->GeneralRegs[FAST486_REG_EDX].LowWord,
&Data,
+ 1,
DataSize);
/* Write to the destination operand */
}
/* Increment/decrement EDI */
- if (OperandSize)
+ if (AddressSize)
{
if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_EDI].Long += DataSize;
else State->GeneralRegs[FAST486_REG_EDI].Long -= DataSize;
if (State->PrefixFlags & FAST486_PREFIX_REP)
{
UCHAR Block[STRING_BLOCK_SIZE];
- ULONG Count = OperandSize ? State->GeneralRegs[FAST486_REG_ECX].Long
+ ULONG Count = AddressSize ? State->GeneralRegs[FAST486_REG_ECX].Long
: State->GeneralRegs[FAST486_REG_ECX].LowWord;
/* Clear the memory block */
Processed * DataSize))
{
/* Set ECX */
- if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
+ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = Count;
else State->GeneralRegs[FAST486_REG_ECX].LowWord = LOWORD(Count);
/* Exception occurred */
State->IoWriteCallback(State,
State->GeneralRegs[FAST486_REG_EDX].LowWord,
Block,
- Processed * DataSize);
+ Processed,
+ DataSize);
if (!State->Flags.Df)
{
}
/* Clear ECX */
- if (OperandSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
+ if (AddressSize) State->GeneralRegs[FAST486_REG_ECX].Long = 0;
else State->GeneralRegs[FAST486_REG_ECX].LowWord = 0;
}
else
State->IoWriteCallback(State,
State->GeneralRegs[FAST486_REG_EDX].LowWord,
&Data,
+ 1,
DataSize);
/* Increment/decrement ESI */
- if (OperandSize)
+ if (AddressSize)
{
if (!State->Flags.Df) State->GeneralRegs[FAST486_REG_ESI].Long += DataSize;
else State->GeneralRegs[FAST486_REG_ESI].Long -= DataSize;