Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PPC] Expose instruction formats #2276

Merged
merged 3 commits into from
Feb 23, 2024
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
13 changes: 13 additions & 0 deletions Mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ void map_groups(MCInst *MI, const insn_map *imap)
#endif // CAPSTONE_DIET
}

/// Returns the pointer to the supllementary information in
/// the instruction mapping table @imap or NULL in case of failure.
const void *map_get_suppl_info(MCInst *MI, const insn_map *imap)
{
#ifndef CAPSTONE_DIET
if (!MI->flat_insn->detail)
return NULL;

unsigned Opcode = MCInst_getOpcode(MI);
return &imap[Opcode].suppl_info;
#endif // CAPSTONE_DIET
}

// Search for the CS instruction id for the given @MC_Opcode in @imap.
// return -1 if none is found.
unsigned int find_cs_id(unsigned MC_Opcode, const insn_map *imap,
Expand Down
2 changes: 2 additions & 0 deletions Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ void map_groups(MCInst *MI, const insn_map *imap);

void map_cs_id(MCInst *MI, const insn_map *imap, unsigned int imap_size);

const void *map_get_suppl_info(MCInst *MI, const insn_map *imap);

#define DECL_get_detail_op(arch, ARCH) \
cs_##arch##_op *ARCH##_get_detail_op(MCInst *MI, int offset);

Expand Down
4 changes: 4 additions & 0 deletions arch/PowerPC/PPCMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ void PPC_set_instr_map_data(MCInst *MI, const uint8_t *Bytes, size_t BytesLen)
map_groups(MI, ppc_insns);
PPC_add_branch_predicates(MI, Bytes, BytesLen);
PPC_check_updates_cr0(MI);
const ppc_suppl_info *suppl_info = map_get_suppl_info(MI, ppc_insns);
if (suppl_info) {
PPC_get_detail(MI)->format = suppl_info->form;
}
}

/// Inialize PPCs detail.
Expand Down
1 change: 1 addition & 0 deletions bindings/python/capstone/ppc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class CsPpc(ctypes.Structure):
_fields_ = (
('bc', PpcBC),
('update_cr0', ctypes.c_bool),
('format', ctypes.c_uint32),
('op_count', ctypes.c_uint8),
('operands', PpcOp * 8),
)
Expand Down
Loading
Loading