From 9487ec09a7702a6467d497c66197c9e54537c564 Mon Sep 17 00:00:00 2001 From: PatrickvL Date: Mon, 24 Sep 2018 12:52:31 +0200 Subject: [PATCH] X86 : Implemented NEG opcode --- src/CxbxKrnl/EmuX86.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/CxbxKrnl/EmuX86.cpp b/src/CxbxKrnl/EmuX86.cpp index 83ea3918e..375a18265 100644 --- a/src/CxbxKrnl/EmuX86.cpp +++ b/src/CxbxKrnl/EmuX86.cpp @@ -1016,6 +1016,34 @@ bool EmuX86_Opcode_MOVZX(LPEXCEPTION_POINTERS e, _DInst& info) return true; } +bool EmuX86_Opcode_NEG(LPEXCEPTION_POINTERS e, _DInst& info) +{ + // NEG reads and writes the same operand : + OperandAddress opAddr; + if (!EmuX86_Operand_Addr_ForReadWrite(e, info, 0, OUT opAddr)) + return false; + + uint32_t dest = EmuX86_Addr_Read(opAddr); + uint32_t src = dest; + + // NEG Destination + uint32_t result = 0-dest; + + // Write back the result + EmuX86_Addr_Write(opAddr, result); + + // The OF, SF, ZF, AF, CF, and PF flags are set according to the result. + EmuX86_SetFlags_OSZAPC(e, + /*EMUX86_EFLAG_OF*/OF_Sub(result, src, dest), + /*EMUX86_EFLAG_SF*/SFCalc(result), + /*EMUX86_EFLAG_ZF*/ZFCalc(result), + /*EMUX86_EFLAG_AF*/AFCalc(result, src, dest), + /*EMUX86_EFLAG_PF*/PFCalc(result), + /*EMUX86_EFLAG_CF*/(dest != 0)); + + return true; +} + bool EmuX86_Opcode_NOT(LPEXCEPTION_POINTERS e, _DInst& info) { // NOT reads and writes the same operand : @@ -2783,6 +2811,9 @@ bool EmuX86_DecodeException(LPEXCEPTION_POINTERS e) case I_MOVZX: if (EmuX86_Opcode_MOVZX(e, info)) break; goto opcode_error; + case I_NEG: + if (EmuX86_Opcode_NEG(e, info)) break; + goto opcode_error; case I_NOT: if (EmuX86_Opcode_NOT(e, info)) break; goto opcode_error;