x86: simplify code handling LOCK/REP by remembering this prefix status when decoding it

v2
Nguyen Anh Quynh 11 years ago
parent 16837f8431
commit e68ee701c4
  1. 4
      arch/X86/X86Disassembler.c
  2. 2
      arch/X86/X86DisassemblerDecoder.c
  3. 3
      arch/X86/X86DisassemblerDecoder.h
  4. 8
      arch/X86/X86Mapping.c

@ -802,9 +802,7 @@ bool X86_getInstruction(csh ud, const uint8_t *code, size_t code_len,
} }
} }
if (insn.prefixPresent[0xf0] || insn.prefixPresent[0xf2] || instr->x86_lock_rep = insn.x86_lock_rep;
insn.prefixPresent[0xf3])
instr->x86_lock_rep = true;
// save immediate size to print immediate properly // save immediate size to print immediate properly
instr->x86_imm_size = insn.immediateSize; instr->x86_imm_size = insn.immediateSize;

@ -531,6 +531,8 @@ static int readPrefixes(struct InternalInstruction* insn)
dbgprintf(insn, "Found prefix 0x%hhx", byte); dbgprintf(insn, "Found prefix 0x%hhx", byte);
} }
insn->x86_lock_rep = prefixGroups[0];
insn->vectorExtensionType = TYPE_NO_VEX_XOP; insn->vectorExtensionType = TYPE_NO_VEX_XOP;
if (byte == 0x62) { if (byte == 0x62) {

@ -635,6 +635,9 @@ typedef struct InternalInstruction {
uint8_t firstByte; // save the first byte in stream uint8_t firstByte; // save the first byte in stream
uint8_t orgModRM; // save original modRM because we will modify modRM uint8_t orgModRM; // save original modRM because we will modify modRM
// does this instruction contain LOC/REP/REPNE prefix?
bool x86_lock_rep;
/* The SIB byte, used for more complex 32- or 64-bit memory operands */ /* The SIB byte, used for more complex 32- or 64-bit memory operands */
BOOL consumedSIB; BOOL consumedSIB;
uint8_t sib; uint8_t sib;

@ -41723,8 +41723,8 @@ bool X86_lockrep(MCInst *MI, SStream *O)
break; break;
case 0xf2: case 0xf2:
#ifndef CAPSTONE_X86_REDUCE #ifndef CAPSTONE_X86_REDUCE
if (MI->Opcode == X86_MULPDrr) { if (MCInst_getOpcode(MI) == X86_MULPDrr) {
MI->Opcode = X86_MULSDrr; MCInst_setOpcode(MI, X86_MULSDrr);
#ifndef CAPSTONE_DIET #ifndef CAPSTONE_DIET
SStream_concat(O, "mulsd\t"); SStream_concat(O, "mulsd\t");
#endif #endif
@ -41742,8 +41742,8 @@ bool X86_lockrep(MCInst *MI, SStream *O)
break; break;
case 0xf3: case 0xf3:
#ifndef CAPSTONE_X86_REDUCE #ifndef CAPSTONE_X86_REDUCE
if (MI->Opcode == X86_MULPDrr) { if (MCInst_getOpcode(MI) == X86_MULPDrr) {
MI->Opcode = X86_MULSSrr; MCInst_setOpcode(MI, X86_MULSSrr);
#ifndef CAPSTONE_DIET #ifndef CAPSTONE_DIET
SStream_concat(O, "mulss\t"); SStream_concat(O, "mulss\t");
#endif #endif

Loading…
Cancel
Save