From e9878785da9b460ddacc94d56ad81478f3811488 Mon Sep 17 00:00:00 2001 From: Alexis Engelke Date: Sun, 3 Feb 2019 20:31:27 +0100 Subject: [PATCH] Replace FD_OP with FD_OT to avoid macro collision --- decode.c | 20 ++++++++++---------- fadec.h | 22 +++++++++++----------- format.c | 10 +++++----- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/decode.c b/decode.c index e8e294a..44fe76c 100644 --- a/decode.c +++ b/decode.c @@ -229,7 +229,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, FdInstr* instr, #if defined(ARCH_X86_64) reg_idx += prefixes & PREFIX_REXR ? 8 : 0; #endif - out_o2->type = FD_OP_REG; + out_o2->type = FD_OT_REG; out_o2->reg = reg_idx; } @@ -239,7 +239,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, FdInstr* instr, #if defined(ARCH_X86_64) reg_idx += prefixes & PREFIX_REXB ? 8 : 0; #endif - out_o1->type = FD_OP_REG; + out_o1->type = FD_OT_REG; out_o1->reg = reg_idx; return off; } @@ -289,7 +289,7 @@ decode_modrm(const uint8_t* buffer, int len, DecodeMode mode, FdInstr* instr, instr->disp = 0; } - out_o1->type = FD_OP_MEM; + out_o1->type = FD_OT_MEM; instr->idx_scale = scale; // If there was no SIB byte. @@ -508,7 +508,7 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address, if (DESC_HAS_IMPLICIT(desc)) { FdOp* operand = &instr->operands[DESC_IMPLICIT_IDX(desc)]; - operand->type = FD_OP_REG; + operand->type = FD_OT_REG; operand->reg = 0; } @@ -539,14 +539,14 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address, #if defined(ARCH_X86_64) reg_idx += prefixes & PREFIX_REXB ? 8 : 0; #endif - operand->type = FD_OP_REG; + operand->type = FD_OT_REG; operand->reg = reg_idx; } if (UNLIKELY(DESC_HAS_VEXREG(desc))) { FdOp* operand = &instr->operands[DESC_VEXREG_IDX(desc)]; - operand->type = FD_OP_REG; + operand->type = FD_OT_REG; operand->reg = vex_operand; } @@ -554,14 +554,14 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address, if (imm_control == 1) { FdOp* operand = &instr->operands[DESC_IMM_IDX(desc)]; - operand->type = FD_OP_IMM; + operand->type = FD_OT_IMM; operand->size = 1; instr->imm = 1; } else if (imm_control == 2) { FdOp* operand = &instr->operands[DESC_IMM_IDX(desc)]; - operand->type = FD_OP_MEM; + operand->type = FD_OT_MEM; operand->reg = FD_REG_NONE; operand->size = op_size; instr->idx_reg = FD_REG_NONE; @@ -658,12 +658,12 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address, if (UNLIKELY(imm_control == 5)) { - operand->type = FD_OP_REG; + operand->type = FD_OT_REG; operand->reg = (instr->imm & 0xf0) >> 4; } else { - operand->type = FD_OP_IMM; + operand->type = FD_OT_IMM; } } diff --git a/fadec.h b/fadec.h index 22ebdbe..3fae6fe 100644 --- a/fadec.h +++ b/fadec.h @@ -43,10 +43,10 @@ enum { }; typedef enum { - FD_OP_NONE = 0, - FD_OP_REG = 1, - FD_OP_IMM = 2, - FD_OP_MEM = 3, + FD_OT_NONE = 0, + FD_OT_REG = 1, + FD_OT_IMM = 2, + FD_OT_MEM = 3, } FdOpType; typedef struct { @@ -144,12 +144,12 @@ void fd_format(const FdInstr* instr, char* buf, size_t len); * purpose register with an index in the range 4-7, it needs to be determined * explicitly whether a high-byte register is accessed (using FD_OP_REG_HIGH). * If that is the case, the index needs to be decreased by 4. - * Only valid if FD_OP_TYPE == FD_OP_REG **/ + * Only valid if FD_OP_TYPE == FD_OT_REG **/ #define FD_OP_REG(instr,idx) ((FdReg) (instr)->operands[idx].reg) /** Returns whether the accessed register is a actually high-byte register when * used on a general purpose instruction. In that case, the register index has * to be decreased by 4. - * Only valid if FD_OP_TYPE == FD_OP_REG and the operand refers to a general + * Only valid if FD_OP_TYPE == FD_OT_REG and the operand refers to a general * purpose register (depends on the instruction type) **/ #define FD_OP_REG_HIGH(instr,idx) ( \ (instr)->operands[idx].size == 1 && \ @@ -160,23 +160,23 @@ void fd_format(const FdInstr* instr, char* buf, size_t len); * if the memory operand has no base register. This is the only case where the * 64-bit register RIP can be returned, in which case the operand also has no * scaled index register. - * Only valid if FD_OP_TYPE == FD_OP_MEM **/ + * Only valid if FD_OP_TYPE == FD_OT_MEM **/ #define FD_OP_BASE(instr,idx) ((FdReg) (instr)->operands[idx].reg) /** Gets the index of the index register from a memory operand, or FD_REG_NONE, * if the memory operand has no scaled index register. - * Only valid if FD_OP_TYPE == FD_OP_MEM **/ + * Only valid if FD_OP_TYPE == FD_OT_MEM **/ #define FD_OP_INDEX(instr,idx) ((FdReg) (instr)->idx_reg) /** Gets the scale of the index register from a memory operand when existent. * This does /not/ return the scale in an absolute value but returns the amount * of bits the index register is shifted to the left (i.e. the value in in the * range 0-3). The actual scale can be computed easily using 1<idx_scale) /** Gets the sign-extended displacement of a memory operand. - * Only valid if FD_OP_TYPE == FD_OP_MEM **/ + * Only valid if FD_OP_TYPE == FD_OT_MEM **/ #define FD_OP_DISP(instr,idx) ((instr)->disp) /** Gets the (sign-extended) encoded constant for an immediate operand. - * Only valid if FD_OP_TYPE == FD_OP_IMM **/ + * Only valid if FD_OP_TYPE == FD_OT_IMM **/ #define FD_OP_IMM(instr,idx) ((instr)->imm) #endif diff --git a/format.c b/format.c index e9485d2..d1a4aba 100644 --- a/format.c +++ b/format.c @@ -52,7 +52,7 @@ fd_format(const FdInstr* instr, char* buffer, size_t len) for (int i = 0; i < 4; i++) { FdOpType op_type = FD_OP_TYPE(instr, i); - if (op_type == FD_OP_NONE) + if (op_type == FD_OT_NONE) break; const char* op_type_name = "reg\0imm\0mem" + op_type * 4 - 4; @@ -64,13 +64,13 @@ fd_format(const FdInstr* instr, char* buffer, size_t len) bool has_base; bool has_idx; bool has_disp; - case FD_OP_REG: + case FD_OT_REG: if (FD_OP_REG_HIGH(instr, i)) FMT_CONCAT(buf, end, "r%uh", FD_OP_REG(instr, i) - 4); else FMT_CONCAT(buf, end, "r%u", FD_OP_REG(instr, i)); break; - case FD_OP_IMM: + case FD_OT_IMM: immediate = FD_OP_IMM(instr, i); if (FD_OP_SIZE(instr, i) == 1) immediate &= 0xff; @@ -80,7 +80,7 @@ fd_format(const FdInstr* instr, char* buffer, size_t len) immediate &= 0xffffffff; FMT_CONCAT(buf, end, "0x%lx", immediate); break; - case FD_OP_MEM: + case FD_OT_MEM: has_base = FD_OP_BASE(instr, i) != FD_REG_NONE; has_idx = FD_OP_INDEX(instr, i) != FD_REG_NONE; has_disp = FD_OP_DISP(instr, i) != 0; @@ -102,7 +102,7 @@ fd_format(const FdInstr* instr, char* buffer, size_t len) else if (has_disp || (!has_base && !has_idx)) FMT_CONCAT(buf, end, "0x%lx", FD_OP_DISP(instr, i)); break; - case FD_OP_NONE: + case FD_OT_NONE: default: break; }