From 2f399d995b59a522c2739c0ab163c501c082cafb Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Tue, 19 Apr 2022 09:23:49 +0200 Subject: x86: correct and simplify NOP disassembly It's not just REX.W which is ignored with opcode 0x90. The same goes for REX.R and REX.X as well as empty REX. None of these are forms of "xchg %eax,%eax" (which would mean zero-extending %eax to %rax), so they also shouldn't be disassembled this way. While there simplify things: A single hook function suffices, thus making it unnecessary to keep two expressions in sync. And checking ins->address_mode for mode_64bit also is unnecessary, as "rex" can be non-zero only in that case anyway. --- opcodes/i386-dis.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'opcodes/i386-dis.c') diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c index 101eeea..1e32663 100644 --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -98,8 +98,7 @@ static void VPCOM_Fixup (instr_info *, int, int); static void OP_0f07 (instr_info *, int, int); static void OP_Monitor (instr_info *, int, int); static void OP_Mwait (instr_info *, int, int); -static void NOP_Fixup1 (instr_info *, int, int); -static void NOP_Fixup2 (instr_info *, int, int); +static void NOP_Fixup (instr_info *, int, int); static void OP_3DNowSuffix (instr_info *, int, int); static void CMP_Fixup (instr_info *, int, int); static void BadOp (instr_info *); @@ -2913,9 +2912,9 @@ static const struct dis386 reg_table[][8] = { static const struct dis386 prefix_table[][4] = { /* PREFIX_90 */ { - { "xchgS", { { NOP_Fixup1, eAX_reg }, { NOP_Fixup2, eAX_reg } }, 0 }, + { "xchgS", { { NOP_Fixup, 0 }, { NOP_Fixup, 1 } }, 0 }, { "pause", { XX }, 0 }, - { "xchgS", { { NOP_Fixup1, eAX_reg }, { NOP_Fixup2, eAX_reg } }, 0 }, + { "xchgS", { { NOP_Fixup, 0 }, { NOP_Fixup, 1 } }, 0 }, { NULL, { { NULL, 0 } }, PREFIX_IGNORED } }, @@ -12724,25 +12723,14 @@ OP_0f07 (instr_info *ins, int bytemode, int sizeflag) 32bit mode and "xchg %rax,%rax" in 64bit mode. */ static void -NOP_Fixup1 (instr_info *ins, int bytemode, int sizeflag) +NOP_Fixup (instr_info *ins, int opnd, int sizeflag) { - if ((ins->prefixes & PREFIX_DATA) != 0 - || (ins->rex != 0 - && ins->rex != 0x48 - && ins->address_mode == mode_64bit)) - OP_REG (ins, bytemode, sizeflag); - else + if ((ins->prefixes & PREFIX_DATA) == 0 && (ins->rex & REX_B) == 0) strcpy (ins->obuf, "nop"); -} - -static void -NOP_Fixup2 (instr_info *ins, int bytemode, int sizeflag) -{ - if ((ins->prefixes & PREFIX_DATA) != 0 - || (ins->rex != 0 - && ins->rex != 0x48 - && ins->address_mode == mode_64bit)) - OP_IMREG (ins, bytemode, sizeflag); + else if (opnd == 0) + OP_REG (ins, eAX_reg, sizeflag); + else + OP_IMREG (ins, eAX_reg, sizeflag); } static const char *const Suffix3DNow[] = { -- cgit v1.1