Skip to content

Commit

Permalink
Merge pull request capstone-engine#2121 from Rot127/arm-implicit-reads
Browse files Browse the repository at this point in the history
[ARM] Add CPSR implicit read for every instruction with predicate
  • Loading branch information
kabeor authored Jul 23, 2023
2 parents 94b63af + 235ac3c commit c4947a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
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
2 changes: 2 additions & 0 deletions arch/ARM/ARMMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,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

0 comments on commit c4947a9

Please sign in to comment.