Skip to content

Commit

Permalink
Set constant zero as mem base if base reg == r0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Jul 25, 2023
1 parent 0060839 commit e8fd99c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions arch/PowerPC/PPCMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ void PPC_init_mri(MCRegisterInfo *MRI)

const char *PPC_reg_name(csh handle, unsigned int reg)
{
return PPC_LLVM_getRegisterName(reg);
// Special case: To allow to check for (RA|0): RA > R1
if (reg == 0)
return NULL;

if (reg > PPC_REG_INVALID && reg < PPC_REG_ENDING)
return PPC_LLVM_getRegisterName(reg);
return NULL;
}

// given internal insn id, return public instruction info
Expand Down Expand Up @@ -372,7 +378,7 @@ static void add_cs_detail_general(MCInst *MI, ppc_op_group op_group,
// in PPCInstPrinter.
case PPC_OP_GROUP_MemRegImm:
case PPC_OP_GROUP_MemRegReg: {
// These cases print 0 if the register is R0.
// These cases print 0 if the base register is R0.
// So no printOperand() function is called.
// We must handle the zero case here.
unsigned OpNumReg = 0;
Expand All @@ -382,8 +388,11 @@ static void add_cs_detail_general(MCInst *MI, ppc_op_group op_group,
OpNumReg = OpNum;

MCOperand *Op = MCInst_getOperand(MI, OpNumReg);
if (MCOperand_isReg(Op) && MCOperand_getReg(Op) == PPC_R0)
PPC_set_detail_op_mem(MI, OpNum, PPC_R0, false);
if (MCOperand_isReg(Op) && MCOperand_getReg(Op) == PPC_R0) {
PPC_get_detail_op(MI, 0)->mem.base = 0;
PPC_get_detail_op(MI, 0)->type = PPC_OP_MEM;
PPC_get_detail_op(MI, 0)->access = map_get_op_access(MI, OpNum);
}
break;
}
case PPC_OP_GROUP_MemRegImmHash:
Expand Down

0 comments on commit e8fd99c

Please sign in to comment.