11use anyhow:: Result ;
2- use rabbitizer:: { config_set_register_fpr_abi_names , Abi , Instruction , SimpleOperandType } ;
2+ use rabbitizer:: { config , Abi , Instruction , InstrCategory , OperandType } ;
33
44use 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+
612pub 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