Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ void map_add_implicit_write(MCInst *MI, uint32_t Reg)
}
}

/// Adds a register to the implicit read register list.
/// It will not add the same register twice.
void map_add_implicit_read(MCInst *MI, uint32_t Reg)
{
if (!MI->flat_insn->detail)
return;

uint16_t *regs_read = MI->flat_insn->detail->regs_read;
for (int i = 0; i < MAX_IMPL_W_REGS; ++i) {
if (i == MI->flat_insn->detail->regs_read_count) {
regs_read[i] = Reg;
MI->flat_insn->detail->regs_read_count++;
return;
}
if (regs_read[i] == Reg)
return;
}
}

/// Removes a register from the implicit write register list.
void map_remove_implicit_write(MCInst *MI, uint32_t Reg)
{
Expand Down Expand Up @@ -160,7 +179,8 @@ void map_implicit_writes(MCInst *MI, const insn_map *imap)
}

/// Adds a given group to @MI->flat_insn.
void add_group(MCInst *MI, unsigned /* arch_group */ group) {
void add_group(MCInst *MI, unsigned /* arch_group */ group)
{
#ifndef CAPSTONE_DIET
if (!MI->flat_insn->detail)
return;
Expand Down
7 changes: 4 additions & 3 deletions Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ typedef struct insn_map {
unsigned short mapid; // The Capstone instruction id
#ifndef CAPSTONE_DIET
uint16_t regs_use[MAX_IMPL_R_REGS]; ///< list of implicit registers used by
///< this instruction
///< this instruction
uint16_t regs_mod[MAX_IMPL_W_REGS]; ///< list of implicit registers modified
///< by this instruction
///< by this instruction
unsigned char groups
[MAX_NUM_GROUPS]; ///< list of group this instruction belong to
bool branch; // branch instruction?
Expand All @@ -47,7 +47,7 @@ typedef struct {
uint8_t /* cs_ac_type */ access; ///< The access type (read, write)
uint8_t /* cs_data_type */
dtypes[MAX_NO_DATA_TYPES]; ///< List of op types. Terminated by
///< CS_DATA_TYPE_LAST
///< CS_DATA_TYPE_LAST
} mapping_op;

#define MAX_NO_INSN_MAP_OPS 16
Expand Down Expand Up @@ -98,6 +98,7 @@ int name2id(const name_map *map, int max, const char *name);
const char *id2name(const name_map *map, int max, const unsigned int id);

void map_add_implicit_write(MCInst *MI, uint32_t Reg);
void map_add_implicit_read(MCInst *MI, uint32_t Reg);
void map_remove_implicit_write(MCInst *MI, uint32_t Reg);

void map_implicit_reads(MCInst *MI, const insn_map *imap);
Expand Down
5 changes: 4 additions & 1 deletion arch/ARM/ARMMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,8 @@ static void add_cs_detail_general(MCInst *MI, arm_op_group op_group,
return;
}
ARM_get_detail(MI)->cc = CC;
if (CC != ARMCC_AL)
map_add_implicit_read(MI, ARM_REG_CPSR);
break;
}
case ARM_OP_GROUP_VPTPredicateOperand: {
Expand Down Expand Up @@ -1042,7 +1044,8 @@ static void add_cs_detail_general(MCInst *MI, arm_op_group op_group,
SYSm);
if (TheReg) {
ARM_set_detail_op_sysreg(
MI, TheReg->sysreg.mclasssysreg, IsOutReg);
MI, TheReg->sysreg.mclasssysreg,
IsOutReg);
return;
}

Expand Down