From 288d6b3c8a2aced399c5bf26dd5bfcd5f94bf687 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Wed, 7 May 2014 12:26:55 +0800 Subject: [PATCH] x86: properly handle lock/rep prefixes when DIET option is enable --- arch/X86/X86GenAsmWriter.inc | 4 +++- arch/X86/X86GenAsmWriter1.inc | 4 +++- arch/X86/X86Mapping.c | 18 ++++++++++++++---- arch/X86/X86Mapping.h | 2 -- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/arch/X86/X86GenAsmWriter.inc b/arch/X86/X86GenAsmWriter.inc index 4715e16b..7b78658e 100644 --- a/arch/X86/X86GenAsmWriter.inc +++ b/arch/X86/X86GenAsmWriter.inc @@ -12497,9 +12497,11 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI) uint64_t Bits2 = OpInfo2[MCInst_getOpcode(MI)]; uint64_t Bits = (Bits2 << 32) | Bits1; // assert(Bits != 0 && "Cannot print this instruction."); -#ifndef CAPSTONE_DIET if (!X86_lockrep(MI, O)) +#ifndef CAPSTONE_DIET SStream_concat(O, "%s", AsmStrs+(Bits & 16383)-1); +#else + ; #endif diff --git a/arch/X86/X86GenAsmWriter1.inc b/arch/X86/X86GenAsmWriter1.inc index 0edafc9e..1c288c6e 100644 --- a/arch/X86/X86GenAsmWriter1.inc +++ b/arch/X86/X86GenAsmWriter1.inc @@ -12201,9 +12201,11 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI) uint64_t Bits2 = OpInfo2[MCInst_getOpcode(MI)]; uint64_t Bits = (Bits2 << 32) | Bits1; // assert(Bits != 0 && "Cannot print this instruction."); -#ifndef CAPSTONE_DIET if (!X86_lockrep(MI, O)) +#ifndef CAPSTONE_DIET SStream_concat(O, "%s", AsmStrs+(Bits & 16383)-1); +#else + ; #endif diff --git a/arch/X86/X86Mapping.c b/arch/X86/X86Mapping.c index ea360113..8fc481a5 100644 --- a/arch/X86/X86Mapping.c +++ b/arch/X86/X86Mapping.c @@ -41706,7 +41706,6 @@ x86_reg X86_insn_reg(unsigned int id) return 0; } -#ifndef CAPSTONE_DIET // return true if we patch the mnemonic bool X86_lockrep(MCInst *MI, SStream *O) { @@ -41718,27 +41717,39 @@ bool X86_lockrep(MCInst *MI, SStream *O) default: break; case 0xf0: +#ifndef CAPSTONE_DIET SStream_concat(O, "lock|"); +#endif break; case 0xf2: if (MI->Opcode == X86_MULPDrr) { MI->Opcode = X86_MULSDrr; +#ifndef CAPSTONE_DIET SStream_concat(O, "mulsd\t"); +#endif MI->x86_prefix[i] = 0; // notify that we already patched mnemonic return true; - } else + } +#ifndef CAPSTONE_DIET + else SStream_concat(O, "repne|"); +#endif break; case 0xf3: if (MI->Opcode == X86_MULPDrr) { MI->Opcode = X86_MULSSrr; +#ifndef CAPSTONE_DIET SStream_concat(O, "mulss\t"); +#endif MI->x86_prefix[i] = 0; // notify that we already patched mnemonic return true; - } else + } +#ifndef CAPSTONE_DIET + else SStream_concat(O, "rep|"); +#endif break; } } @@ -41746,4 +41757,3 @@ bool X86_lockrep(MCInst *MI, SStream *O) return false; } -#endif diff --git a/arch/X86/X86Mapping.h b/arch/X86/X86Mapping.h index 1c7a22c9..4fbeffef 100644 --- a/arch/X86/X86Mapping.h +++ b/arch/X86/X86Mapping.h @@ -39,10 +39,8 @@ x86_reg X86_insn_reg(unsigned int id); extern uint64_t arch_masks[9]; -#ifndef CAPSTONE_DIET // handle LOCK/REP/REPNE prefixes // return True if we patch mnemonic, like in MULPD case bool X86_lockrep(MCInst *MI, SStream *O); -#endif #endif