x86: properly handle lock/rep prefixes when DIET option is enable

v2
Nguyen Anh Quynh 11 years ago
parent 9bcca47a98
commit 288d6b3c8a
  1. 4
      arch/X86/X86GenAsmWriter.inc
  2. 4
      arch/X86/X86GenAsmWriter1.inc
  3. 18
      arch/X86/X86Mapping.c
  4. 2
      arch/X86/X86Mapping.h

@ -12497,9 +12497,11 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)
uint64_t Bits2 = OpInfo2[MCInst_getOpcode(MI)]; uint64_t Bits2 = OpInfo2[MCInst_getOpcode(MI)];
uint64_t Bits = (Bits2 << 32) | Bits1; uint64_t Bits = (Bits2 << 32) | Bits1;
// assert(Bits != 0 && "Cannot print this instruction."); // assert(Bits != 0 && "Cannot print this instruction.");
#ifndef CAPSTONE_DIET
if (!X86_lockrep(MI, O)) if (!X86_lockrep(MI, O))
#ifndef CAPSTONE_DIET
SStream_concat(O, "%s", AsmStrs+(Bits & 16383)-1); SStream_concat(O, "%s", AsmStrs+(Bits & 16383)-1);
#else
;
#endif #endif

@ -12201,9 +12201,11 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI)
uint64_t Bits2 = OpInfo2[MCInst_getOpcode(MI)]; uint64_t Bits2 = OpInfo2[MCInst_getOpcode(MI)];
uint64_t Bits = (Bits2 << 32) | Bits1; uint64_t Bits = (Bits2 << 32) | Bits1;
// assert(Bits != 0 && "Cannot print this instruction."); // assert(Bits != 0 && "Cannot print this instruction.");
#ifndef CAPSTONE_DIET
if (!X86_lockrep(MI, O)) if (!X86_lockrep(MI, O))
#ifndef CAPSTONE_DIET
SStream_concat(O, "%s", AsmStrs+(Bits & 16383)-1); SStream_concat(O, "%s", AsmStrs+(Bits & 16383)-1);
#else
;
#endif #endif

@ -41706,7 +41706,6 @@ x86_reg X86_insn_reg(unsigned int id)
return 0; return 0;
} }
#ifndef CAPSTONE_DIET
// return true if we patch the mnemonic // return true if we patch the mnemonic
bool X86_lockrep(MCInst *MI, SStream *O) bool X86_lockrep(MCInst *MI, SStream *O)
{ {
@ -41718,27 +41717,39 @@ bool X86_lockrep(MCInst *MI, SStream *O)
default: default:
break; break;
case 0xf0: case 0xf0:
#ifndef CAPSTONE_DIET
SStream_concat(O, "lock|"); SStream_concat(O, "lock|");
#endif
break; break;
case 0xf2: case 0xf2:
if (MI->Opcode == X86_MULPDrr) { if (MI->Opcode == X86_MULPDrr) {
MI->Opcode = X86_MULSDrr; MI->Opcode = X86_MULSDrr;
#ifndef CAPSTONE_DIET
SStream_concat(O, "mulsd\t"); SStream_concat(O, "mulsd\t");
#endif
MI->x86_prefix[i] = 0; MI->x86_prefix[i] = 0;
// notify that we already patched mnemonic // notify that we already patched mnemonic
return true; return true;
} else }
#ifndef CAPSTONE_DIET
else
SStream_concat(O, "repne|"); SStream_concat(O, "repne|");
#endif
break; break;
case 0xf3: case 0xf3:
if (MI->Opcode == X86_MULPDrr) { if (MI->Opcode == X86_MULPDrr) {
MI->Opcode = X86_MULSSrr; MI->Opcode = X86_MULSSrr;
#ifndef CAPSTONE_DIET
SStream_concat(O, "mulss\t"); SStream_concat(O, "mulss\t");
#endif
MI->x86_prefix[i] = 0; MI->x86_prefix[i] = 0;
// notify that we already patched mnemonic // notify that we already patched mnemonic
return true; return true;
} else }
#ifndef CAPSTONE_DIET
else
SStream_concat(O, "rep|"); SStream_concat(O, "rep|");
#endif
break; break;
} }
} }
@ -41746,4 +41757,3 @@ bool X86_lockrep(MCInst *MI, SStream *O)
return false; return false;
} }
#endif

@ -39,10 +39,8 @@ x86_reg X86_insn_reg(unsigned int id);
extern uint64_t arch_masks[9]; extern uint64_t arch_masks[9];
#ifndef CAPSTONE_DIET
// handle LOCK/REP/REPNE prefixes // handle LOCK/REP/REPNE prefixes
// return True if we patch mnemonic, like in MULPD case // return True if we patch mnemonic, like in MULPD case
bool X86_lockrep(MCInst *MI, SStream *O); bool X86_lockrep(MCInst *MI, SStream *O);
#endif
#endif #endif

Loading…
Cancel
Save