Skip to content

Commit 238f6ec

Browse files
committed
Start using rabbitizer crate
1 parent e2fde3d commit 238f6ec

File tree

3 files changed

+25
-178
lines changed

3 files changed

+25
-178
lines changed

Cargo.lock

Lines changed: 6 additions & 165 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ notify = "5.0.0"
3232
object = { version = "0.30.0", features = ["read_core", "std", "elf"], default-features = false }
3333
png = "0.17.7"
3434
ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "aa631a33de7882c679afca89350898b87cb3ba3f" }
35-
rabbitizer = { git = "https://github.com/encounter/rabbitizer-rs", rev = "10c279b2ef251c62885b1dcdcfe740b0db8e9956" }
35+
rabbitizer = "1.5.6"
3636
reqwest = "0.11.13"
3737
rfd = { version = "0.10.0" } # , default-features = false, features = ['xdg-portal']
3838
self_update = "0.32.0"

src/obj/mips.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
use anyhow::Result;
2-
use rabbitizer::{config_set_register_fpr_abi_names, Abi, Instruction, SimpleOperandType};
2+
use rabbitizer::{config, Abi, Instruction, InstrCategory, OperandType};
33

44
use crate::obj::{ObjIns, ObjInsArg, ObjReloc};
55

6+
fn configure_rabbitizer() {
7+
unsafe {
8+
config::RabbitizerConfig_Cfg.reg_names.fpr_abi_names = Abi::O32;
9+
}
10+
}
11+
612
pub fn process_code(
713
data: &[u8],
814
start_address: u64,
915
end_address: u64,
1016
relocs: &[ObjReloc],
1117
) -> Result<(Vec<u8>, Vec<ObjIns>)> {
12-
config_set_register_fpr_abi_names(Abi::RABBITIZER_ABI_O32);
18+
configure_rabbitizer();
1319

1420
let ins_count = data.len() / 4;
1521
let mut ops = Vec::<u8>::with_capacity(ins_count);
@@ -18,21 +24,21 @@ pub fn process_code(
1824
for chunk in data.chunks_exact(4) {
1925
let reloc = relocs.iter().find(|r| (r.address as u32 & !3) == cur_addr);
2026
let code = u32::from_be_bytes(chunk.try_into()?);
21-
let mut instruction = Instruction::new(code, cur_addr);
27+
let mut instruction = Instruction::new(code, cur_addr, InstrCategory::CPU);
2228

23-
let op = instruction.instr_id() as u8;
29+
let op = instruction.unique_id as u8;
2430
ops.push(op);
2531

26-
let mnemonic = instruction.instr_id().get_opcode_name().unwrap_or_default().to_string();
32+
let mnemonic = instruction.opcode_name().to_string();
2733
let is_branch = instruction.is_branch();
2834
let branch_offset = instruction.branch_offset();
2935
let branch_dest =
3036
if is_branch { Some((cur_addr as i32 + branch_offset) as u32) } else { None };
3137
let args = instruction
32-
.simple_operands()
38+
.get_operands_slice()
3339
.iter()
34-
.map(|op| match op.kind {
35-
SimpleOperandType::Imm | SimpleOperandType::Label => {
40+
.map(|op| match op {
41+
OperandType::cpu_immediate | OperandType::cpu_label => {
3642
if is_branch {
3743
ObjInsArg::BranchOffset(branch_offset)
3844
} else if let Some(reloc) = reloc {
@@ -46,17 +52,17 @@ pub fn process_code(
4652
ObjInsArg::Reloc
4753
}
4854
} else {
49-
ObjInsArg::MipsArg(op.disassembled.clone())
55+
ObjInsArg::MipsArg(op.disassemble(instruction, None))
5056
}
5157
}
52-
SimpleOperandType::ImmBase => {
58+
OperandType::cpu_immediate_base => {
5359
if reloc.is_some() {
5460
ObjInsArg::RelocWithBase
5561
} else {
56-
ObjInsArg::MipsArg(op.disassembled.clone())
62+
ObjInsArg::MipsArg(op.disassemble(instruction, None))
5763
}
5864
}
59-
_ => ObjInsArg::MipsArg(op.disassembled.clone()),
65+
_ => ObjInsArg::MipsArg(op.disassemble(instruction, None)),
6066
})
6167
.collect();
6268
insts.push(ObjIns {

0 commit comments

Comments
 (0)