Author: aandrejevic
Date: Thu Sep 19 23:24:05 2013
New Revision: 60229
URL:
http://svn.reactos.org/svn/reactos?rev=60229&view=rev
Log:
[SOFT386]
Implement the RET instruction.
Modified:
branches/ntvdm/lib/soft386/opcodes.c
branches/ntvdm/lib/soft386/opcodes.h
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] Thu Sep 19 23:24:05 2013
@@ -218,7 +218,7 @@
Soft386OpcodeMovRegImm,
NULL, // TODO: OPCODE 0xC0 NOT SUPPORTED
NULL, // TODO: OPCODE 0xC1 NOT SUPPORTED
- Soft386OpcodeRetImm,
+ Soft386OpcodeRet,
Soft386OpcodeRet,
Soft386OpcodeLes,
Soft386OpcodeLds,
@@ -4166,20 +4166,50 @@
return FALSE;
}
-SOFT386_OPCODE_HANDLER(Soft386OpcodeRetImm)
-{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
-
- return FALSE;
-}
-
SOFT386_OPCODE_HANDLER(Soft386OpcodeRet)
{
- // TODO: NOT IMPLEMENTED
- UNIMPLEMENTED;
-
- return FALSE;
+ ULONG ReturnAddress;
+ USHORT BytesToPop = 0;
+ BOOLEAN Size = State->SegmentRegs[SOFT386_REG_CS].Size;
+
+ /* Make sure this is the right instruction */
+ ASSERT((Opcode & 0xFE) == 0xC2);
+
+ if (State->PrefixFlags & SOFT386_PREFIX_LOCK)
+ {
+ /* Invalid prefix */
+ Soft386Exception(State, SOFT386_EXCEPTION_UD);
+ return FALSE;
+ }
+
+ if (State->PrefixFlags == SOFT386_PREFIX_OPSIZE)
+ {
+ /* The OPSIZE prefix toggles the size */
+ Size = !Size;
+ }
+
+ if (Opcode == 0xC2)
+ {
+ /* Fetch the number of bytes to pop after the return */
+ if (!Soft386FetchWord(State, &BytesToPop)) return FALSE;
+ }
+
+ /* Pop the return address */
+ if (!Soft386StackPop(State, &ReturnAddress)) return FALSE;
+
+ /* Return to the calling procedure, and if necessary, pop the parameters */
+ if (Size)
+ {
+ State->InstPtr.Long = ReturnAddress;
+ State->GeneralRegs[SOFT386_REG_ESP].Long += BytesToPop;
+ }
+ else
+ {
+ State->InstPtr.LowWord = LOWORD(ReturnAddress);
+ State->GeneralRegs[SOFT386_REG_ESP].LowWord += BytesToPop;
+ }
+
+ return TRUE;
}
SOFT386_OPCODE_HANDLER(Soft386OpcodeLes)
Modified: branches/ntvdm/lib/soft386/opcodes.h
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/lib/soft386/opcodes.h?rev…
==============================================================================
--- branches/ntvdm/lib/soft386/opcodes.h [iso-8859-1] (original)
+++ branches/ntvdm/lib/soft386/opcodes.h [iso-8859-1] Thu Sep 19 23:24:05 2013
@@ -115,7 +115,6 @@
SOFT386_OPCODE_HANDLER(Soft386OpcodePopFlags);
SOFT386_OPCODE_HANDLER(Soft386OpcodeSahf);
SOFT386_OPCODE_HANDLER(Soft386OpcodeLahf);
-SOFT386_OPCODE_HANDLER(Soft386OpcodeRetImm);
SOFT386_OPCODE_HANDLER(Soft386OpcodeRet);
SOFT386_OPCODE_HANDLER(Soft386OpcodeLes);
SOFT386_OPCODE_HANDLER(Soft386OpcodeLds);