Author: aandrejevic
Date: Sun Sep 29 18:39:59 2013
New Revision: 60455
URL:
http://svn.reactos.org/svn/reactos?rev=60455&view=rev
Log:
[SOFT386]
Implement opcode group 0xD0 (instructions ROL, ROR, RCL, RCR, SHL, SHR, SAL, SAR).
Modified:
branches/ntvdm/lib/soft386/opgroups.c
Modified: branches/ntvdm/lib/soft386/opgroups.c
URL:
http://svn.reactos.org/svn/reactos/branches/ntvdm/lib/soft386/opgroups.c?re…
==============================================================================
--- branches/ntvdm/lib/soft386/opgroups.c [iso-8859-1] (original)
+++ branches/ntvdm/lib/soft386/opgroups.c [iso-8859-1] Sun Sep 29 18:39:59 2013
@@ -347,8 +347,134 @@
SOFT386_OPCODE_HANDLER(Soft386OpcodeGroupD0)
{
- UNIMPLEMENTED;
- return FALSE; // TODO: NOT IMPLEMENTED
+ UCHAR Result, Dummy, Value;
+ SOFT386_MOD_REG_RM ModRegRm;
+ BOOLEAN AddressSize = State->SegmentRegs[SOFT386_REG_CS].Size;
+
+ if (State->PrefixFlags & SOFT386_PREFIX_ADSIZE)
+ {
+ /* The ADSIZE prefix toggles the size */
+ AddressSize = !AddressSize;
+ }
+
+ if (!Soft386ParseModRegRm(State, AddressSize, &ModRegRm))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
+
+ /* Read the operands */
+ if (!Soft386ReadModrmByteOperands(State, &ModRegRm, &Dummy, &Value))
+ {
+ /* Exception occurred */
+ return FALSE;
+ }
+
+ /* Check which operation is this */
+ switch (ModRegRm.Register)
+ {
+ /* ROL */
+ case 0:
+ {
+ Result = (Value << 1) | (Value >> 7);
+
+ /* Update CF and OF */
+ State->Flags.Cf = Value >> 7;
+ State->Flags.Of = ((Result & SIGN_FLAG_BYTE) ? TRUE : FALSE)
+ ^ (State->Flags.Cf ? TRUE : FALSE);
+
+ break;
+ }
+
+ /* ROR */
+ case 1:
+ {
+ Result = (Value >> 1) | (Value << 7);
+
+ /* Update CF and OF */
+ State->Flags.Cf = Value & 1;
+ State->Flags.Of = ((Result & SIGN_FLAG_BYTE) ? TRUE : FALSE)
+ ^ ((Result & (SIGN_FLAG_BYTE >> 1)) ? TRUE :
FALSE);
+
+ break;
+ }
+
+ /* RCL */
+ case 2:
+ {
+ Result = (Value << 1) | (State->Flags.Cf ? 1 : 0);
+
+ /* Update CF and OF */
+ State->Flags.Cf = (Value & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Of = ((Result & SIGN_FLAG_BYTE) ? TRUE : FALSE)
+ ^ (State->Flags.Cf ? TRUE : FALSE);
+
+ break;
+ }
+
+ /* RCR */
+ case 3:
+ {
+ Result = (Value >> 1) | (State->Flags.Cf ? SIGN_FLAG_BYTE : 0);
+
+ /* Update CF and OF */
+ State->Flags.Cf = Value & 1;
+ State->Flags.Of = ((Result & SIGN_FLAG_BYTE) ? TRUE : FALSE)
+ ^ ((Result & (SIGN_FLAG_BYTE >> 1)) ? TRUE :
FALSE);
+
+ break;
+ }
+
+ /* SHL/SAL */
+ case 4:
+ case 6:
+ {
+ Result = Value << 1;
+
+ /* Update CF and OF */
+ State->Flags.Cf = (Value & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Of = ((Result & SIGN_FLAG_BYTE) ? TRUE : FALSE)
+ ^ (State->Flags.Cf ? TRUE : FALSE);
+
+ break;
+ }
+
+ /* SHR */
+ case 5:
+ {
+ Result = Value >> 1;
+
+ /* Update CF and OF */
+ State->Flags.Cf = Value & 1;
+ State->Flags.Of = (Value & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+
+ break;
+ }
+
+ /* SAR */
+ case 7:
+ {
+ Result = (Value >> 1) | (Value & SIGN_FLAG_BYTE);
+
+ /* Update CF and OF */
+ State->Flags.Cf = Value & 1;
+ State->Flags.Of = FALSE;
+
+ break;
+ }
+ }
+
+ /* Update ZF, SF and PF */
+ State->Flags.Zf = (Result == 0) ? TRUE : FALSE;
+ State->Flags.Sf = (Result & SIGN_FLAG_BYTE) ? TRUE : FALSE;
+ State->Flags.Pf = Soft386CalculateParity(Result);
+
+ /* Write back the result */
+ return Soft386WriteModrmByteOperands(State,
+ &ModRegRm,
+ FALSE,
+ Value);
+
}
SOFT386_OPCODE_HANDLER(Soft386OpcodeGroupD1)