Author: aandrejevic
Date: Sun Sep 15 18:02:41 2013
New Revision: 60144
URL:
http://svn.reactos.org/svn/reactos?rev=60144&view=rev
Log:
[SOFT386]
Implement LAHF, SAHF, LEA and PUSH imm16/32
Modified:
branches/ntvdm/lib/soft386/opcodes.c
Modified: branches/ntvdm/lib/soft386/opcodes.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/lib/soft386/opcodes.c?rev…
==============================================================================
--- branches/ntvdm/lib/soft386/opcodes.c [iso-8859-1] (original)
+++ branches/ntvdm/lib/soft386/opcodes.c [iso-8859-1] Sun Sep 15 18:02:41 2013
@@ -3627,23 +3627,65 @@
SOFT386_OPCODE_HANDLER(Soft386OpcodePushImm)
{
+ BOOLEAN Size = State->SegmentRegs[SOFT386_REG_CS].Size;
+
+ /* Make sure this is the right instruction */
+ ASSERT(Opcode == 0x68);
+
+ if (State->PrefixFlags == SOFT386_PREFIX_OPSIZE)
+ {
+ /* The OPSIZE prefix toggles the size */
+ Size = !Size;
+ }
+ else
+ {
+ /* Invalid prefix */
+ Soft386Exception(State, SOFT386_EXCEPTION_UD);
+ return FALSE;
+ }
+
+ if (Size)
+ {
+ ULONG Data;
+
+ if (!Soft386FetchDword(State, &Data))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
+
+ /* Call the internal API */
+ return Soft386StackPush(State, Data);
+ }
+ else
+ {
+ USHORT Data;
+
+ if (!Soft386FetchWord(State, &Data))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
+
+ /* Call the internal API */
+ return Soft386StackPush(State, Data);
+ }
+}
+
+SOFT386_OPCODE_HANDLER(Soft386OpcodeImulModrmImm)
+{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeImulModrmImm)
-{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
-
- return FALSE;
-}
-
SOFT386_OPCODE_HANDLER(Soft386OpcodePushByteImm)
{
UCHAR Data;
+
+ /* Make sure this is the right instruction */
+ ASSERT(Opcode == 0x6A);
if (!Soft386FetchByte(State, &Data))
{
@@ -3811,10 +3853,57 @@
SOFT386_OPCODE_HANDLER(Soft386OpcodeLea)
{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
-
- return FALSE;
+ SOFT386_MOD_REG_RM ModRegRm;
+ BOOLEAN OperandSize, AddressSize;
+
+ /* Make sure this is the right instruction */
+ ASSERT(Opcode == 0x8D);
+
+ OperandSize = AddressSize = State->SegmentRegs[SOFT386_REG_CS].Size;
+
+ if (State->PrefixFlags & SOFT386_PREFIX_ADSIZE)
+ {
+ /* The ADSIZE prefix toggles the address size */
+ AddressSize = !AddressSize;
+ }
+
+ if (State->PrefixFlags & SOFT386_PREFIX_OPSIZE)
+ {
+ /* The OPSIZE prefix toggles the operand size */
+ OperandSize = !OperandSize;
+ }
+
+ /* Get the operands */
+ if (!Soft386ParseModRegRm(State, AddressSize, &ModRegRm))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
+
+ /* The second operand must be memory */
+ if (!ModRegRm.Memory)
+ {
+ /* Invalid */
+ Soft386Exception(State, SOFT386_EXCEPTION_UD);
+ return FALSE;
+ }
+
+ /* Write the address to the register */
+ if (OperandSize)
+ {
+ return Soft386WriteModrmDwordOperands(State,
+ &ModRegRm,
+ TRUE,
+ ModRegRm.MemoryAddress);
+ }
+ else
+ {
+ return Soft386WriteModrmWordOperands(State,
+ &ModRegRm,
+ TRUE,
+ ModRegRm.MemoryAddress);
+
+ }
}
SOFT386_OPCODE_HANDLER(Soft386OpcodeMovLoadSeg)
@@ -3936,13 +4025,40 @@
SOFT386_OPCODE_HANDLER(Soft386OpcodeSahf)
{
+ /* Make sure this is the right instruction */
+ ASSERT(Opcode == 0x9E);
+
+ /* Set the low-order byte of FLAGS to AH */
+ State->Flags.Long &= 0xFFFFFF00;
+ State->Flags.Long |= State->GeneralRegs[SOFT386_REG_EAX].HighByte;
+
+ /* Restore the reserved bits of FLAGS */
+ State->Flags.AlwaysSet = TRUE;
+ State->Flags.Reserved0 = State->Flags.Reserved1 = FALSE;
+
+ return FALSE;
+}
+
+SOFT386_OPCODE_HANDLER(Soft386OpcodeLahf)
+{
+ /* Make sure this is the right instruction */
+ ASSERT(Opcode == 0x9F);
+
+ /* Set AH to the low-order byte of FLAGS */
+ State->GeneralRegs[SOFT386_REG_EAX].HighByte = LOBYTE(State->Flags.Long);
+
+ return FALSE;
+}
+
+SOFT386_OPCODE_HANDLER(Soft386OpcodeRetImm)
+{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeLahf)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeRet)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -3950,7 +4066,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeRetImm)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeLes)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -3958,7 +4074,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeRet)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeLds)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -3966,7 +4082,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeLes)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeEnter)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -3974,7 +4090,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeLds)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeLeave)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -3982,7 +4098,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeEnter)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeRetFarImm)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -3990,7 +4106,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeLeave)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeRetFar)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -3998,7 +4114,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeRetFarImm)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeInt3)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4006,7 +4122,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeRetFar)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeInt)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4014,7 +4130,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeInt3)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeIntOverflow)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4022,7 +4138,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeInt)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeIret)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4030,7 +4146,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeIntOverflow)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeAam)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4038,7 +4154,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeIret)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeAad)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4046,7 +4162,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeAam)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeXlat)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4054,7 +4170,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeAad)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeLoopnz)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4062,7 +4178,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeXlat)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeLoopz)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4070,7 +4186,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeLoopnz)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeLoop)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4078,7 +4194,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeLoopz)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeJecxz)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4086,7 +4202,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeLoop)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeCall)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4094,7 +4210,7 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeJecxz)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeJmp)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
@@ -4102,26 +4218,10 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeCall)
+SOFT386_OPCODE_HANDLER(Soft386OpcodeJmpAbs)
{
// TODO: NOT IMPLEMENTED
UNIMPLEMENTED;
return FALSE;
}
-
-SOFT386_OPCODE_HANDLER(Soft386OpcodeJmp)
-{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
-
- return FALSE;
-}
-
-SOFT386_OPCODE_HANDLER(Soft386OpcodeJmpAbs)
-{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
-
- return FALSE;
-}