mirror of
https://github.com/capstone-engine/capstone.git
synced 2024-12-04 12:03:26 +00:00
mips: Fix j/jal target address calculation
This commit is contained in:
parent
c36e675213
commit
921a46c38f
@ -1215,8 +1215,8 @@ static DecodeStatus DecodeCOP2RegisterClass(MCInst *Inst,
|
||||
static DecodeStatus DecodeBranchTarget(MCInst *Inst,
|
||||
unsigned Offset, uint64_t Address, MCRegisterInfo *Decoder)
|
||||
{
|
||||
int32_t BranchOffset = (SignExtend32(Offset, 16) * 4) + 4;
|
||||
MCOperand_CreateImm0(Inst, BranchOffset);
|
||||
uint64_t TargetAddress = (SignExtend32(Offset, 16) * 4) + Address + 4;
|
||||
MCOperand_CreateImm0(Inst, TargetAddress);
|
||||
|
||||
return MCDisassembler_Success;
|
||||
}
|
||||
@ -1224,8 +1224,8 @@ static DecodeStatus DecodeBranchTarget(MCInst *Inst,
|
||||
static DecodeStatus DecodeJumpTarget(MCInst *Inst,
|
||||
unsigned Insn, uint64_t Address, MCRegisterInfo *Decoder)
|
||||
{
|
||||
unsigned JumpOffset = fieldFromInstruction(Insn, 0, 26) << 2;
|
||||
MCOperand_CreateImm0(Inst, JumpOffset);
|
||||
uint64_t TargetAddress = (fieldFromInstruction(Insn, 0, 26) << 2) | ((Address + 4) & ~0x0FFFFFFF);
|
||||
MCOperand_CreateImm0(Inst, TargetAddress);
|
||||
|
||||
return MCDisassembler_Success;
|
||||
}
|
||||
|
@ -180,27 +180,6 @@ void Mips_printInst(MCInst *MI, SStream *O, void *info)
|
||||
}
|
||||
}
|
||||
|
||||
// check to see if @id is opcode of a relative branch instruction
|
||||
static bool relativeBranch(unsigned int id)
|
||||
{
|
||||
static unsigned int branchIns[] = {
|
||||
Mips_BEQ, Mips_BC1F, Mips_BGEZ, Mips_BGEZAL, Mips_BGTZ,
|
||||
Mips_BLEZ, Mips_BLTZ, Mips_BLTZAL, Mips_BNE, Mips_BC1T,
|
||||
Mips_BEQL, Mips_BGEZALL, Mips_BGEZL, Mips_BGTZL, Mips_BLEZL,
|
||||
Mips_BLTZALL, Mips_BLTZL, Mips_BNEL, Mips_BC1F, Mips_BC1FL,
|
||||
Mips_BC1TL, Mips_BC0F,
|
||||
};
|
||||
int i;
|
||||
|
||||
for(i = 0; i < ARR_SIZE(branchIns); i++) {
|
||||
if (id == branchIns[i])
|
||||
return true;
|
||||
}
|
||||
|
||||
// not found
|
||||
return false;
|
||||
}
|
||||
|
||||
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
|
||||
{
|
||||
MCOperand *Op = MCInst_getOperand(MI, OpNo);
|
||||
@ -236,10 +215,6 @@ static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
|
||||
if (MI->csh->detail)
|
||||
MI->flat_insn->detail->mips.operands[MI->flat_insn->detail->mips.op_count].mem.disp = imm;
|
||||
} else {
|
||||
if (relativeBranch(MI->Opcode)) {
|
||||
imm += MI->address;
|
||||
}
|
||||
|
||||
if (imm >= 0) {
|
||||
if (imm > HEX_THRESHOLD)
|
||||
SStream_concat(O, "0x%"PRIx64, imm);
|
||||
|
Loading…
Reference in New Issue
Block a user