[FAST486]
authorAleksandar Andrejevic <aandrejevic@reactos.org>
Sun, 20 Oct 2013 00:55:31 +0000 (00:55 +0000)
committerAleksandar Andrejevic <aandrejevic@reactos.org>
Sun, 20 Oct 2013 00:55:31 +0000 (00:55 +0000)
Create a macro SWAP (swaps two variables) to shorten the code.
Implement the BSWAP instruction.

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

lib/fast486/common.h
lib/fast486/extraops.c
lib/fast486/extraops.h
lib/fast486/opcodes.c

index 4b4a659..2e36df7 100644 (file)
@@ -54,6 +54,7 @@
 {\
     x = !x;\
 }
 {\
     x = !x;\
 }
+#define SWAP(x, y) { (x) ^= (y); (y) ^= (x); (x) ^= (y); }
 
 #define PAGE_ALIGN(x)   ((x) & 0xFFFFF000)
 #define PAGE_OFFSET(x)  ((x) & 0x00000FFF)
 
 #define PAGE_ALIGN(x)   ((x) & 0xFFFFF000)
 #define PAGE_OFFSET(x)  ((x) & 0x00000FFF)
index c9a90d2..6890a66 100644 (file)
@@ -238,14 +238,14 @@ Fast486ExtendedHandlers[FAST486_NUM_OPCODE_HANDLERS] =
     NULL, // Invalid
     NULL, // Invalid
     NULL, // Invalid
     NULL, // Invalid
     NULL, // Invalid
     NULL, // Invalid
-    NULL, // TODO: OPCODE 0xC8 NOT IMPLEMENTED
-    NULL, // TODO: OPCODE 0xC9 NOT IMPLEMENTED
-    NULL, // TODO: OPCODE 0xCA NOT IMPLEMENTED
-    NULL, // TODO: OPCODE 0xCB NOT IMPLEMENTED
-    NULL, // TODO: OPCODE 0xCC NOT IMPLEMENTED
-    NULL, // TODO: OPCODE 0xCD NOT IMPLEMENTED
-    NULL, // TODO: OPCODE 0xCE NOT IMPLEMENTED
-    NULL, // TODO: OPCODE 0xCF NOT IMPLEMENTED
+    Fast486ExtOpcodeBswap,
+    Fast486ExtOpcodeBswap,
+    Fast486ExtOpcodeBswap,
+    Fast486ExtOpcodeBswap,
+    Fast486ExtOpcodeBswap,
+    Fast486ExtOpcodeBswap,
+    Fast486ExtOpcodeBswap,
+    Fast486ExtOpcodeBswap,
     NULL, // Invalid
     NULL, // Invalid
     NULL, // Invalid
     NULL, // Invalid
     NULL, // Invalid
     NULL, // Invalid
@@ -1021,6 +1021,23 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeConditionalSet)
     return Fast486WriteModrmByteOperands(State, &ModRegRm, FALSE, Value);
 }
 
     return Fast486WriteModrmByteOperands(State, &ModRegRm, FALSE, Value);
 }
 
+FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBswap)
+{
+    PUCHAR Pointer;
+
+    NO_LOCK_PREFIX();
+
+    /* Get a pointer to the value */
+    Pointer = (PUCHAR)&State->GeneralRegs[Opcode & 0x07].Long;
+
+    /* Swap the byte order */
+    SWAP(Pointer[0], Pointer[3]);
+    SWAP(Pointer[1], Pointer[2]);
+
+    /* Return success */
+    return TRUE;
+}
+
 FAST486_OPCODE_HANDLER(Fast486OpcodeExtended)
 {
     UCHAR SecondOpcode;
 FAST486_OPCODE_HANDLER(Fast486OpcodeExtended)
 {
     UCHAR SecondOpcode;
index 07a9127..1f2cf2b 100644 (file)
@@ -35,6 +35,7 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBtr);
 FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBtc);
 FAST486_OPCODE_HANDLER(Fast486ExtOpcodeConditionalJmp);
 FAST486_OPCODE_HANDLER(Fast486ExtOpcodeConditionalSet);
 FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBtc);
 FAST486_OPCODE_HANDLER(Fast486ExtOpcodeConditionalJmp);
 FAST486_OPCODE_HANDLER(Fast486ExtOpcodeConditionalSet);
+FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBswap);
 FAST486_OPCODE_HANDLER(Fast486OpcodeExtended);
 
 #endif // _EXTRAOPS_H_
 FAST486_OPCODE_HANDLER(Fast486OpcodeExtended);
 
 #endif // _EXTRAOPS_H_
index 39ec666..db9c90d 100644 (file)
@@ -2743,9 +2743,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm)
     if (!(Opcode & FAST486_OPCODE_WRITE_REG))
     {
         /* Swap the order */
     if (!(Opcode & FAST486_OPCODE_WRITE_REG))
     {
         /* Swap the order */
-        FirstValue ^= SecondValue;
-        SecondValue ^= FirstValue;
-        FirstValue ^= SecondValue;
+        SWAP(FirstValue, SecondValue);
     }
 
     /* Calculate the result */
     }
 
     /* Calculate the result */
@@ -2806,9 +2804,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
-            FirstValue ^= SecondValue;
-            SecondValue ^= FirstValue;
-            FirstValue ^= SecondValue;
+            SWAP(FirstValue, SecondValue);
         }
     
         /* Calculate the result */
         }
     
         /* Calculate the result */
@@ -2846,9 +2842,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm)
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
-            FirstValue ^= SecondValue;
-            SecondValue ^= FirstValue;
-            FirstValue ^= SecondValue;
+            SWAP(FirstValue, SecondValue);
         }
     
         /* Calculate the result */
         }
     
         /* Calculate the result */
@@ -3067,9 +3061,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubByteModrm)
     if (!(Opcode & FAST486_OPCODE_WRITE_REG))
     {
         /* Swap the order */
     if (!(Opcode & FAST486_OPCODE_WRITE_REG))
     {
         /* Swap the order */
-        FirstValue ^= SecondValue;
-        SecondValue ^= FirstValue;
-        FirstValue ^= SecondValue;
+        SWAP(FirstValue, SecondValue);
     }
 
     /* Calculate the result */
     }
 
     /* Calculate the result */
@@ -3138,9 +3130,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm)
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
-            FirstValue ^= SecondValue;
-            SecondValue ^= FirstValue;
-            FirstValue ^= SecondValue;
+            SWAP(FirstValue, SecondValue);
         }
     
         /* Calculate the result */
         }
     
         /* Calculate the result */
@@ -3187,9 +3177,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm)
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
         if (!(Opcode & FAST486_OPCODE_WRITE_REG))
         {
             /* Swap the order */
-            FirstValue ^= SecondValue;
-            SecondValue ^= FirstValue;
-            FirstValue ^= SecondValue;
+            SWAP(FirstValue, SecondValue);
         }
     
         /* Calculate the result */
         }
     
         /* Calculate the result */