diff --git a/lib/fast486/common.h b/lib/fast486/common.h index 4b4a659d00a..2e36df77654 100644 --- a/lib/fast486/common.h +++ b/lib/fast486/common.h @@ -54,6 +54,7 @@ {\ x = !x;\ } +#define SWAP(x, y) { (x) ^= (y); (y) ^= (x); (x) ^= (y); } #define PAGE_ALIGN(x) ((x) & 0xFFFFF000) #define PAGE_OFFSET(x) ((x) & 0x00000FFF) diff --git a/lib/fast486/extraops.c b/lib/fast486/extraops.c index c9a90d2e33d..6890a66941f 100644 --- a/lib/fast486/extraops.c +++ b/lib/fast486/extraops.c @@ -238,14 +238,14 @@ Fast486ExtendedHandlers[FAST486_NUM_OPCODE_HANDLERS] = 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 @@ -1021,6 +1021,23 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeConditionalSet) 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; diff --git a/lib/fast486/extraops.h b/lib/fast486/extraops.h index 07a9127ae11..1f2cf2b33d9 100644 --- a/lib/fast486/extraops.h +++ b/lib/fast486/extraops.h @@ -35,6 +35,7 @@ FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBtr); FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBtc); FAST486_OPCODE_HANDLER(Fast486ExtOpcodeConditionalJmp); FAST486_OPCODE_HANDLER(Fast486ExtOpcodeConditionalSet); +FAST486_OPCODE_HANDLER(Fast486ExtOpcodeBswap); FAST486_OPCODE_HANDLER(Fast486OpcodeExtended); #endif // _EXTRAOPS_H_ diff --git a/lib/fast486/opcodes.c b/lib/fast486/opcodes.c index 39ec666c030..db9c90dda98 100644 --- a/lib/fast486/opcodes.c +++ b/lib/fast486/opcodes.c @@ -2743,9 +2743,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbByteModrm) if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ - FirstValue ^= SecondValue; - SecondValue ^= FirstValue; - FirstValue ^= SecondValue; + SWAP(FirstValue, SecondValue); } /* Calculate the result */ @@ -2806,9 +2804,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm) if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ - FirstValue ^= SecondValue; - SecondValue ^= FirstValue; - FirstValue ^= SecondValue; + SWAP(FirstValue, SecondValue); } /* Calculate the result */ @@ -2846,9 +2842,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeSbbModrm) if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ - FirstValue ^= SecondValue; - SecondValue ^= FirstValue; - FirstValue ^= SecondValue; + SWAP(FirstValue, SecondValue); } /* Calculate the result */ @@ -3067,9 +3061,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubByteModrm) if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ - FirstValue ^= SecondValue; - SecondValue ^= FirstValue; - FirstValue ^= SecondValue; + SWAP(FirstValue, SecondValue); } /* Calculate the result */ @@ -3138,9 +3130,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm) if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ - FirstValue ^= SecondValue; - SecondValue ^= FirstValue; - FirstValue ^= SecondValue; + SWAP(FirstValue, SecondValue); } /* Calculate the result */ @@ -3187,9 +3177,7 @@ FAST486_OPCODE_HANDLER(Fast486OpcodeCmpSubModrm) if (!(Opcode & FAST486_OPCODE_WRITE_REG)) { /* Swap the order */ - FirstValue ^= SecondValue; - SecondValue ^= FirstValue; - FirstValue ^= SecondValue; + SWAP(FirstValue, SecondValue); } /* Calculate the result */