From 8572c15973e34f0c05dee4a81ec37bbc4bd826b5 Mon Sep 17 00:00:00 2001 From: Alexis Engelke Date: Mon, 10 Feb 2020 20:33:00 +0100 Subject: [PATCH] Handle RVMR encodings correctly in 32-bit mode The most significant bit in the immediate is ingored in 32-bit mode. --- decode.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/decode.c b/decode.c index 6a21d9d..1f2e15f 100644 --- a/decode.c +++ b/decode.c @@ -536,9 +536,24 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address, #endif off += addr_size; } + else if (UNLIKELY(imm_control == 5)) + { + FdOp* operand = &instr->operands[DESC_IMM_IDX(desc)]; + operand->type = FD_OT_REG; + + if (UNLIKELY(off + 1 > len)) + return FD_ERR_PARTIAL; + uint8_t reg = (uint8_t) LOAD_LE_1(&buffer[off]); + off += 1; + + if (mode == DECODE_32) + reg &= 0x7f; + operand->reg = reg >> 4; + } else if (imm_control != 0) { FdOp* operand = &instr->operands[DESC_IMM_IDX(desc)]; + operand->type = FD_OT_IMM; uint8_t imm_size; if (DESC_IMM_BYTE(desc)) @@ -588,16 +603,6 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address, operand->size = 8; #endif } - - if (UNLIKELY(imm_control == 5)) - { - operand->type = FD_OT_REG; - operand->reg = (instr->imm & 0xf0) >> 4; - } - else - { - operand->type = FD_OT_IMM; - } } if ((prefixes & PREFIX_LOCK) && !desc->lock)