ppc: proper map internal register ID to public register ID

This commit is contained in:
Nguyen Anh Quynh 2019-05-09 18:26:45 +08:00
parent 63c07ba724
commit 37dda9d4b7
3 changed files with 21 additions and 2 deletions

View File

@ -791,6 +791,11 @@ static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
#ifndef CAPSTONE_DIET
const char *RegName = getRegisterName(reg);
// printf("reg = %u (%s)\n", reg, RegName);
// convert internal register ID to public register ID
reg = PPC_name_reg(RegName);
// The linux and AIX assembler does not take register prefixes.
if (MI->csh->syntax == CS_OPT_SYNTAX_NOREGNAME)
RegName = stripRegisterPrefix(RegName);

View File

@ -13,7 +13,6 @@
#define GET_INSTRINFO_ENUM
#include "PPCGenInstrInfo.inc"
#ifndef CAPSTONE_DIET
// NOTE: this reg_name_maps[] reflects the order of registers in ppc_reg
static const name_map reg_name_maps[] = {
{ PPC_REG_INVALID, NULL },
@ -263,7 +262,6 @@ static const name_map reg_name_maps[] = {
{ PPC_REG_CR6UN, "cr6un" },
{ PPC_REG_CR7UN, "cr7un" },
};
#endif
const char *PPC_reg_name(csh handle, unsigned int reg)
{
@ -295,6 +293,19 @@ const char *PPC_reg_name(csh handle, unsigned int reg)
return NULL;
}
ppc_reg PPC_name_reg(const char *name)
{
unsigned int i;
for(i = 1; i < ARR_SIZE(reg_name_maps); i++) {
if (!strcmp(name, reg_name_maps[i].name))
return reg_name_maps[i].id;
}
// not found
return 0;
}
static const insn_map insns[] = {
// dummy item
{

View File

@ -9,6 +9,9 @@
// return name of regiser in friendly string
const char *PPC_reg_name(csh handle, unsigned int reg);
// return register id, given register name
ppc_reg PPC_name_reg(const char *name);
// given internal insn id, return public instruction info
void PPC_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id);