Skip to content

Commit 08a1e68

Browse files
committed
arch: multiple delay slot support, suppress spurious mips warning
1 parent 56115ae commit 08a1e68

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

arch/mips/arch_mips.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class MipsArchitecture: public Architecture
301301
if (instr.operands[0].immediate != addr + 8)
302302
result.AddBranch(CallDestination, instr.operands[0].immediate, nullptr, hasBranchDelay);
303303
else
304-
result.branchDelay = 1; // We have a "get pc" mnemonic; do nothing
304+
result.delaySlots = 1; // We have a "get pc" mnemonic; do nothing
305305
break;
306306

307307
case MIPS_JAL:
@@ -311,7 +311,7 @@ class MipsArchitecture: public Architecture
311311
//Jmp to register register value is unknown
312312
case MIPS_JALR:
313313
case MIPS_JALR_HB:
314-
result.branchDelay = 1;
314+
result.delaySlots = 1;
315315
break;
316316

317317
case MIPS_BGEZAL:

arch/riscv/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ impl<D: 'static + RiscVDisassembler + Send + Sync> architecture::Architecture fo
687687
_ => return None,
688688
};
689689

690-
let mut res = InstructionInfo::new(inst_len, false);
690+
let mut res = InstructionInfo::new(inst_len, 0);
691691

692692
match op {
693693
Op::Jal(ref j) => {

architecture.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ InstructionInfo::InstructionInfo()
3434
length = 0;
3535
archTransitionByTargetAddr = false;
3636
branchCount = 0;
37-
branchDelay = false;
37+
delaySlots = 0;
3838
}
3939

4040

41-
void InstructionInfo::AddBranch(BNBranchType type, uint64_t target, Architecture* arch, bool hasDelaySlot)
41+
void InstructionInfo::AddBranch(BNBranchType type, uint64_t target, Architecture* arch, uint8_t delaySlot)
4242
{
4343
if (branchCount >= BN_MAX_INSTRUCTION_BRANCHES)
4444
return;
45-
branchDelay = hasDelaySlot;
45+
delaySlots = delaySlot;
4646
branchType[branchCount] = type;
4747
branchTarget[branchCount] = target;
4848
branchArch[branchCount++] = arch ? arch->GetObject() : nullptr;
@@ -242,6 +242,7 @@ bool Architecture::GetInstructionInfoCallback(
242242
CallbackRef<Architecture> arch(ctxt);
243243

244244
InstructionInfo info;
245+
info.delaySlots = result->delaySlots;
245246
bool ok = arch->GetInstructionInfo(data, addr, maxLen, info);
246247
*result = info;
247248
return ok;

binaryninjaapi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7569,7 +7569,7 @@ namespace BinaryNinja {
75697569
struct InstructionInfo : public BNInstructionInfo
75707570
{
75717571
InstructionInfo();
7572-
void AddBranch(BNBranchType type, uint64_t target = 0, Architecture* arch = nullptr, bool hasDelaySlot = false);
7572+
void AddBranch(BNBranchType type, uint64_t target = 0, Architecture* arch = nullptr, uint8_t delaySlots = 0);
75737573
};
75747574

75757575
struct NameAndType

binaryninjacore.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
// Current ABI version for linking to the core. This is incremented any time
3838
// there are changes to the API that affect linking, including new functions,
3939
// new types, or modifications to existing functions or types.
40-
#define BN_CURRENT_CORE_ABI_VERSION 63
40+
#define BN_CURRENT_CORE_ABI_VERSION 64
4141

4242
// Minimum ABI version that is supported for loading of plugins. Plugins that
4343
// are linked to an ABI version less than this will not be able to load and
4444
// will require rebuilding. The minimum version is increased when there are
4545
// incompatible changes that break binary compatibility, such as changes to
4646
// existing types or functions.
47-
#define BN_MINIMUM_CORE_ABI_VERSION 62
47+
#define BN_MINIMUM_CORE_ABI_VERSION 64
4848

4949
#ifdef __GNUC__
5050
#ifdef BINARYNINJACORE_LIBRARY
@@ -1685,7 +1685,7 @@ extern "C"
16851685
size_t length;
16861686
size_t branchCount;
16871687
bool archTransitionByTargetAddr;
1688-
bool branchDelay;
1688+
uint8_t delaySlots;
16891689
BNBranchType branchType[BN_MAX_INSTRUCTION_BRANCHES];
16901690
uint64_t branchTarget[BN_MAX_INSTRUCTION_BRANCHES];
16911691
BNArchitecture* branchArch[BN_MAX_INSTRUCTION_BRANCHES]; // If null, same architecture as instruction

python/architecture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def __repr__(self):
131131
class InstructionInfo:
132132
length: int = 0
133133
arch_transition_by_target_addr: bool = False
134-
branch_delay: bool = False
134+
branch_delay: int = 0
135135
branches: List[InstructionBranch] = field(default_factory=list)
136136

137137
def add_branch(self, branch_type: BranchType, target: int = 0, arch: Optional['Architecture'] = None) -> None:
@@ -648,7 +648,7 @@ def _get_instruction_info(self, ctxt, data, addr, max_len, result):
648648
return False
649649
result[0].length = info.length
650650
result[0].archTransitionByTargetAddr = info.arch_transition_by_target_addr
651-
result[0].branchDelay = info.branch_delay
651+
result[0].delaySlots = info.branch_delay
652652
result[0].branchCount = len(info.branches)
653653
for i in range(0, len(info.branches)):
654654
if isinstance(info.branches[i].type, str):
@@ -2346,7 +2346,7 @@ def get_instruction_info(self, data: bytes, addr: int) -> Optional[InstructionIn
23462346
result = InstructionInfo()
23472347
result.length = info.length
23482348
result.arch_transition_by_target_addr = info.archTransitionByTargetAddr
2349-
result.branch_delay = info.branchDelay
2349+
result.branch_delay = info.delaySlots
23502350
for i in range(0, info.branchCount):
23512351
target = info.branchTarget[i]
23522352
if info.branchArch[i]:

rust/src/architecture.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ impl<'a> Iterator for BranchIter<'a> {
9797
#[repr(C)]
9898
pub struct InstructionInfo(BNInstructionInfo);
9999
impl InstructionInfo {
100-
pub fn new(len: usize, branch_delay: bool) -> Self {
100+
pub fn new(len: usize, delay_slots: u8) -> Self {
101101
InstructionInfo(BNInstructionInfo {
102102
length: len,
103103
archTransitionByTargetAddr: false,
104-
branchDelay: branch_delay,
104+
delaySlots: delay_slots,
105105
branchCount: 0usize,
106106
branchType: [BranchType::UnresolvedBranch; 3],
107107
branchTarget: [0u64; 3],
@@ -121,8 +121,8 @@ impl InstructionInfo {
121121
self.0.branchCount
122122
}
123123

124-
pub fn branch_delay(&self) -> bool {
125-
self.0.branchDelay
124+
pub fn delay_slots(&self) -> u8 {
125+
self.0.delaySlots
126126
}
127127

128128
pub fn branches(&self) -> BranchIter {

0 commit comments

Comments
 (0)