Skip to content

Commit

Permalink
xtensa: fix memory operand
Browse files Browse the repository at this point in the history
  • Loading branch information
imbillow committed Jun 10, 2024
1 parent 60ada09 commit 11bfcc4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
23 changes: 16 additions & 7 deletions arch/Xtensa/XtensaMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static void set_instr_map_data(MCInst *MI)
operand->type = op->type;
MCOperand *mc = MCInst_getOperand(MI, i);

#define check(_k) if ((op->type & _k) == _k)
#define check(_k) if ((op->type & (_k)) == (_k))
check(CS_OP_IMM)
{
operand->imm = (int32_t)mc->ImmVal;
Expand All @@ -75,8 +75,22 @@ static void set_instr_map_data(MCInst *MI)
{
operand->reg = (uint8_t)mc->RegVal;
}
check(CS_OP_MEM)
check(CS_OP_MEM_REG)
{
operand->mem.base = mc->RegVal;
}
check(CS_OP_MEM_IMM)
{
if (i > 0) {
cs_xtensa_op *prev = (operand - 1);
if (prev->type == CS_OP_MEM_REG &&
prev->access == op->access) {
prev->type = Xtensa_OP_MEM;
prev->mem.disp = mc->ImmVal;
continue;
}
}
operand->mem.disp = mc->ImmVal;
}

detail->op_count++;
Expand Down Expand Up @@ -168,11 +182,6 @@ void Xtensa_reg_access(const cs_insn *insn, cs_regs regs_read,
regs_read[read_count] = (uint16_t)op->mem.base;
read_count++;
}
if ((op->mem.index != Xtensa_REG_INVALID) &&
!arr_exist(regs_read, read_count, op->mem.index)) {
regs_read[read_count] = (uint16_t)op->mem.index;
read_count++;
}
if ((insn->detail->writeback) &&
(op->mem.base != Xtensa_REG_INVALID) &&
!arr_exist(regs_write, write_count, op->mem.base)) {
Expand Down
2 changes: 1 addition & 1 deletion cstool/cstool_xtensa.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void print_insn_detail_xtensa(csh handle, cs_insn *ins, Stream *steam)
"\t\t\t.mem.base: REG = %s\n"
"\t\t\t.mem.disp: 0x%" PRIx8 "\n",
i, cs_reg_name(handle, op->mem.base),
op->mem.index);
op->mem.disp);
check_access(CS_AC_READ) printf("\t\t\t.access: READ\n");
else check_access(CS_AC_WRITE) printf("\t\t\t.access: WRITE\n");
else check_access(CS_AC_READ | CS_AC_WRITE)
Expand Down
12 changes: 7 additions & 5 deletions include/capstone/xtensa.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ Xtensa_FEATURE_HasDensity = 128,
} xtensa_feature;

typedef enum cs_xtensa_op_type {
Xtensa_OP_INVALID = CS_OP_INVALID, ///< = CS_OP_INVALID (Uninitialized).
Xtensa_OP_REG = CS_OP_REG, ///< = CS_OP_REG (Register operand).
Xtensa_OP_IMM = CS_OP_IMM, ///< = CS_OP_IMM (Immediate operand).
Xtensa_OP_MEM = CS_OP_MEM, ///< = CS_OP_MEM (Memory operand).
Xtensa_OP_INVALID = CS_OP_INVALID, ///< = (Uninitialized).
Xtensa_OP_REG = CS_OP_REG, ///< = (Register operand).
Xtensa_OP_IMM = CS_OP_IMM, ///< = (Immediate operand).
Xtensa_OP_MEM = CS_OP_MEM, ///< = (Memory operand).
Xtensa_OP_MEM_REG = CS_OP_MEM_REG, ///< = (Memory Register operand).
Xtensa_OP_MEM_IMM = CS_OP_MEM_IMM, ///< = (Memory Immediate operand).
} cs_xtensa_op_type;

typedef struct cs_xtensa_op_mem {
uint8_t base;
uint8_t index;
uint8_t disp;
} cs_xtensa_op_mem;

typedef struct cs_xtensa_operand {
Expand Down

0 comments on commit 11bfcc4

Please sign in to comment.