[SOFT386]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Thu, 29 Aug 2013 17:48:32 +0000 (17:48 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Thu, 29 Aug 2013 17:48:32 +0000 (17:48 +0000)
Implement the CLC, STC, CLI, STI, CLD and STD instructions.

svn path=/branches/ntvdm/; revision=59876

lib/soft386/opcodes.c
lib/soft386/opcodes.h

index 3460e03..af5407b 100644 (file)
@@ -272,12 +272,12 @@ Soft386OpcodeHandlers[SOFT386_NUM_OPCODE_HANDLERS] =
     NULL, // TODO: OPCODE 0xF5 NOT SUPPORTED
     NULL, // TODO: OPCODE 0xF6 NOT SUPPORTED
     NULL, // TODO: OPCODE 0xF7 NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xF8 NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xF9 NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xFA NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xFB NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xFC NOT SUPPORTED
-    NULL, // TODO: OPCODE 0xFD NOT SUPPORTED
+    Soft386OpcodeClearCarry,
+    Soft386OpcodeSetCarry,
+    Soft386OpcodeClearInt,
+    Soft386OpcodeSetInt,
+    Soft386OpcodeClearDir,
+    Soft386OpcodeSetDir,
     NULL, // TODO: OPCODE 0xFE NOT SUPPORTED
     NULL, // TODO: OPCODE 0xFF NOT SUPPORTED
 };
@@ -740,3 +740,117 @@ Soft386OpcodeShortConditionalJmp(PSOFT386_STATE State, UCHAR Opcode)
     /* Return success */
     return TRUE;
 }
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeClearCarry(PSOFT386_STATE State, UCHAR Opcode)
+{
+    /* Make sure this is the right instruction */
+    ASSERT(Opcode == 0xF8);
+
+    /* Clear CF and return success */
+    State->Flags.Cf = FALSE;
+    return TRUE;
+}
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeSetCarry(PSOFT386_STATE State, UCHAR Opcode)
+{
+    /* Make sure this is the right instruction */
+    ASSERT(Opcode == 0xF9);
+
+    /* Set CF and return success*/
+    State->Flags.Cf = TRUE;
+    return TRUE;
+}
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeClearInt(PSOFT386_STATE State, UCHAR Opcode)
+{
+    /* Make sure this is the right instruction */
+    ASSERT(Opcode == 0xFA);
+
+    /* Check for protected mode */
+    if (State->ControlRegisters[SOFT386_REG_CR0] & SOFT386_CR0_PE)
+    {
+        /* Check IOPL */
+        if (State->Flags.Iopl >= State->SegmentRegs[SOFT386_REG_CS].Dpl)
+        {
+            /* Clear the interrupt flag */
+            State->Flags.If = FALSE;
+        }
+        else
+        {
+            /* General Protection Fault */
+            Soft386Exception(State, SOFT386_EXCEPTION_GP);
+            return FALSE;
+        }
+    }
+    else
+    {
+        /* Just clear the interrupt flag */
+        State->Flags.If = FALSE;
+    }
+
+    /* Return success */
+    return TRUE;
+}
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeSetInt(PSOFT386_STATE State, UCHAR Opcode)
+{
+    /* Make sure this is the right instruction */
+    ASSERT(Opcode == 0xFB);
+
+    /* Check for protected mode */
+    if (State->ControlRegisters[SOFT386_REG_CR0] & SOFT386_CR0_PE)
+    {
+        /* Check IOPL */
+        if (State->Flags.Iopl >= State->SegmentRegs[SOFT386_REG_CS].Dpl)
+        {
+            /* Set the interrupt flag */
+            State->Flags.If = TRUE;
+        }
+        else
+        {
+            /* General Protection Fault */
+            Soft386Exception(State, SOFT386_EXCEPTION_GP);
+            return FALSE;
+        }
+    }
+    else
+    {
+        /* Just set the interrupt flag */
+        State->Flags.If = TRUE;
+    }
+
+    /* Return success */
+    return TRUE;
+}
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeClearDir(PSOFT386_STATE State, UCHAR Opcode)
+{
+    /* Make sure this is the right instruction */
+    ASSERT(Opcode == 0xFC);
+
+    /* Clear DF and return success */
+    State->Flags.Df = FALSE;
+    return TRUE;
+}
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeSetDir(PSOFT386_STATE State, UCHAR Opcode)
+{
+    /* Make sure this is the right instruction */
+    ASSERT(Opcode == 0xFD);
+
+    /* Set DF and return success*/
+    State->Flags.Df = TRUE;
+    return TRUE;
+}
index 663fd4f..d4ede99 100644 (file)
@@ -87,4 +87,52 @@ Soft386OpcodeShortConditionalJmp
     UCHAR Opcode
 );
 
+BOOLEAN
+FASTCALL
+Soft386OpcodeClearCarry
+(
+    PSOFT386_STATE State,
+    UCHAR Opcode
+);
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeSetCarry
+(
+    PSOFT386_STATE State,
+    UCHAR Opcode
+);
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeClearInt
+(
+    PSOFT386_STATE State,
+    UCHAR Opcode
+);
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeSetInt
+(
+    PSOFT386_STATE State,
+    UCHAR Opcode
+);
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeClearDir
+(
+    PSOFT386_STATE State,
+    UCHAR Opcode
+);
+
+BOOLEAN
+FASTCALL
+Soft386OpcodeSetDir
+(
+    PSOFT386_STATE State,
+    UCHAR Opcode
+);
+
 #endif // _OPCODES_H_