instrs: Fix decoding of XCHG r8, rax

Opcode 90 is only a NOP if there is no REX.B.
This commit is contained in:
Alexis Engelke
2020-06-14 13:34:47 +02:00
parent c3df15e19b
commit 80ec7ed960
3 changed files with 21 additions and 1 deletions

View File

@@ -608,6 +608,21 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address,
}
}
if (instr->type == FDI_XCHG_NOP)
{
// Only 4890, 90, and 6690 are true NOPs.
if (instr->operands[0].reg == 0 && instr->operands[1].reg == 0)
{
instr->operands[0].type = FD_OT_NONE;
instr->operands[1].type = FD_OT_NONE;
instr->type = FDI_NOP;
}
else
{
instr->type = FDI_XCHG;
}
}
if ((prefixes & PREFIX_LOCK) && !desc->lock)
return FD_ERR_UD;
if ((prefixes & PREFIX_LOCK) && instr->operands[0].type != FD_OT_MEM)

View File

@@ -143,7 +143,9 @@
8d RM GP GP - - LEA MUSTMEM
8e RM SREG GP - - MOV_G2S
8f/0 M GP - - - POP DEF64
90 NP - - - - NOP
# Against frequent belief, only, XCHG (r/e)AX, (r)AX with 90 is NOP.
# As a lacking REX.B cannot be specified here, this is hardcoded.
90 OA GP GP - - XCHG_NOP
91 OA GP GP - - XCHG
92 OA GP GP - - XCHG
93 OA GP GP - - XCHG

View File

@@ -11,3 +11,6 @@ decode f2660f10c1 [SSE_MOVSD reg8:r0 reg8:r1]
decode f3660f10c1 [SSE_MOVSS reg4:r0 reg4:r1]
decode f3f2660f10c1 [SSE_MOVSD reg8:r0 reg8:r1]
decode f266f3660f10c1 [SSE_MOVSS reg4:r0 reg4:r1]
decode64 4890 [NOP]
decode64 4990 [XCHG reg8:r8 reg8:r0]
decode64 6690 [NOP]