x64 disasm: properly symbolize rip-relative addresses

This commit is contained in:
Henrik Rydgard 2015-10-24 10:37:01 +02:00
parent 27a124dcff
commit b7db15225f
4 changed files with 28 additions and 5 deletions

View File

@ -161,10 +161,25 @@ const char *ppsspp_resolver(struct ud*,
if (addr >= (uint64_t)(&currentMIPS->r[0]) && addr < (uint64_t)&currentMIPS->r[32]) {
*offset = addr - (uint64_t)(&currentMIPS->r[0]);
return "mips.r";
}
if (addr >= (uint64_t)(&currentMIPS->v[0]) && addr < (uint64_t)&currentMIPS->v[128]) {
} else if (addr >= (uint64_t)(&currentMIPS->v[0]) && addr < (uint64_t)&currentMIPS->v[128]) {
*offset = addr - (uint64_t)(&currentMIPS->v[0]);
return "mips.v";
} else if (addr == (uint64_t)(&currentMIPS->downcount)) {
return "mips.downcount";
} else if (addr == (uint64_t)(&currentMIPS->fpcond)) {
return "mips.fpcond";
} else if (addr == (uint64_t)(&currentMIPS->temp)) {
return "mips.temp";
} else if (addr == (uint64_t)(&currentMIPS->pc)) {
return "mips.pc";
} else if (addr == (uint64_t)(&currentMIPS->hi)) {
return "mips.hi";
} else if (addr == (uint64_t)(&currentMIPS->lo)) {
return "mips.lo";
} else if (addr == (uint64_t)(&currentMIPS->fcr31)) {
return "mips.fcr31";
} else if (addr >= (uint64_t)(&currentMIPS->vfpuCtrl[0]) && addr < (uint64_t)(&currentMIPS->vfpuCtrl[16])) {
return "mips.vfpuCtrl";
}
// But these do.

View File

@ -442,6 +442,8 @@ void Jit::AddContinuedBlock(u32 dest)
}
bool Jit::DescribeCodePtr(const u8 *ptr, std::string &name) {
if (ptr == (const u8 *)&saved_flags)
name = "saved_flags";
if (ptr == applyRoundingMode)
name = "applyRoundingMode";
else if (ptr == updateRoundingMode)

View File

@ -71,7 +71,7 @@ static void gen_operand(struct ud* u, struct ud_operand* op, int syn_cast)
if (u->pfx_seg) {
ud_asmprintf(u, "%s:", ud_reg_tab[u->pfx_seg - UD_R_AL]);
}
if (op->base) {
if (op->base && op->base != UD_R_RIP) {
ud_asmprintf(u, "%s", ud_reg_tab[op->base - UD_R_AL]);
}
if (op->index) {

View File

@ -174,12 +174,16 @@ ud_syn_print_imm(struct ud* u, const struct ud_operand *op)
ud_asmprintf(u, "0x%" FMT64 "x", v);
}
uint64_t
ud_syn_rip_target(struct ud *u, struct ud_operand *opr) {
return (u->pc + opr->lval.sdword);
}
void
ud_syn_print_mem_disp(struct ud* u, const struct ud_operand *op, int sign)
{
UD_ASSERT(op->offset != 0);
if (op->base == UD_NONE && op->index == UD_NONE) {
if (op->base == UD_NONE && op->index == UD_NONE) {
uint64_t v;
UD_ASSERT(op->scale == UD_NONE && op->offset != 8);
/* unsigned mem-offset */
@ -199,7 +203,9 @@ ud_syn_print_mem_disp(struct ud* u, const struct ud_operand *op, int sign)
case 32: v = op->lval.sdword; break;
default: UD_ASSERT(!"invalid offset"); v = 0; /* keep cc happy */
}
if (v < 0) {
if (op->base == UD_R_RIP) {
ud_syn_print_addr(u, ud_syn_rip_target(u, op));
} else if (v < 0) {
ud_asmprintf(u, "-0x%" FMT64 "x", -v);
} else if (v > 0) {
ud_asmprintf(u, "%s0x%" FMT64 "x", sign? "+" : "", v);