diff --git a/arch/PowerPC/PPCInstPrinter.c b/arch/PowerPC/PPCInstPrinter.c index 4a671b8a..ef2015e3 100644 --- a/arch/PowerPC/PPCInstPrinter.c +++ b/arch/PowerPC/PPCInstPrinter.c @@ -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); diff --git a/arch/PowerPC/PPCMapping.c b/arch/PowerPC/PPCMapping.c index f617868f..67fa1850 100644 --- a/arch/PowerPC/PPCMapping.c +++ b/arch/PowerPC/PPCMapping.c @@ -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 { diff --git a/arch/PowerPC/PPCMapping.h b/arch/PowerPC/PPCMapping.h index b8da57e5..80bdc58e 100644 --- a/arch/PowerPC/PPCMapping.h +++ b/arch/PowerPC/PPCMapping.h @@ -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); diff --git a/arch/PowerPC/PPCMappingInsn.inc b/arch/PowerPC/PPCMappingInsn.inc index 0660849d..a57bfe17 100644 --- a/arch/PowerPC/PPCMappingInsn.inc +++ b/arch/PowerPC/PPCMappingInsn.inc @@ -1474,7 +1474,7 @@ }, { - PPC_CMPD, PPC_INS_CMP, + PPC_CMPD, PPC_INS_CMPD, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif @@ -1516,7 +1516,7 @@ }, { - PPC_CMPLWI, PPC_INS_CMPLI, + PPC_CMPLWI, PPC_INS_CMPLWI, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif @@ -1537,7 +1537,7 @@ }, { - PPC_CMPWI, PPC_INS_CMPI, + PPC_CMPWI, PPC_INS_CMPWI, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif @@ -1691,7 +1691,7 @@ }, { - PPC_CROR, PPC_INS_CRMOVE, + PPC_CROR, PPC_INS_CROR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif @@ -1705,7 +1705,7 @@ }, { - PPC_CRSET, PPC_INS_CREQV, + PPC_CRSET, PPC_INS_CRSET, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif @@ -10217,7 +10217,7 @@ }, { - PPC_VOR, PPC_INS_VMR, + PPC_VOR, PPC_INS_VOR, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { PPC_GRP_ALTIVEC, 0 }, 0, 0 #endif @@ -11015,7 +11015,7 @@ }, { - PPC_XORI, PPC_INS_XNOP, + PPC_XORI, PPC_INS_XORI, #ifndef CAPSTONE_DIET { 0 }, { 0 }, { 0 }, 0, 0 #endif