11use std:: collections:: BTreeMap ;
22
33use anyhow:: Result ;
4- use rabbitizer:: { config_set_register_fpr_abi_names , Abi , Instruction , SimpleOperandType } ;
4+ use rabbitizer:: { config , Abi , Instruction , InstrCategory , OperandType } ;
55
66use crate :: obj:: { ObjIns , ObjInsArg , ObjReloc } ;
77
8+ fn configure_rabbitizer ( ) {
9+ unsafe {
10+ config:: RabbitizerConfig_Cfg . reg_names . fpr_abi_names = Abi :: O32 ;
11+ }
12+ }
13+
814pub fn process_code (
915 data : & [ u8 ] ,
1016 start_address : u64 ,
1117 end_address : u64 ,
1218 relocs : & [ ObjReloc ] ,
1319 line_info : & Option < BTreeMap < u32 , u32 > > ,
1420) -> Result < ( Vec < u8 > , Vec < ObjIns > ) > {
15- config_set_register_fpr_abi_names ( Abi :: RABBITIZER_ABI_O32 ) ;
21+ configure_rabbitizer ( ) ;
1622
1723 let ins_count = data. len ( ) / 4 ;
1824 let mut ops = Vec :: < u8 > :: with_capacity ( ins_count) ;
@@ -21,21 +27,21 @@ pub fn process_code(
2127 for chunk in data. chunks_exact ( 4 ) {
2228 let reloc = relocs. iter ( ) . find ( |r| ( r. address as u32 & !3 ) == cur_addr) ;
2329 let code = u32:: from_be_bytes ( chunk. try_into ( ) ?) ;
24- let mut instruction = Instruction :: new ( code, cur_addr) ;
30+ let instruction = Instruction :: new ( code, cur_addr, InstrCategory :: CPU ) ;
2531
26- let op = instruction. instr_id ( ) as u8 ;
32+ let op = instruction. unique_id as u8 ;
2733 ops. push ( op) ;
2834
29- let mnemonic = instruction. instr_id ( ) . get_opcode_name ( ) . unwrap_or_default ( ) . to_string ( ) ;
35+ let mnemonic = instruction. opcode_name ( ) . to_string ( ) ;
3036 let is_branch = instruction. is_branch ( ) ;
3137 let branch_offset = instruction. branch_offset ( ) ;
3238 let branch_dest =
3339 if is_branch { Some ( ( cur_addr as i32 + branch_offset) as u32 ) } else { None } ;
3440 let args = instruction
35- . simple_operands ( )
41+ . get_operands_slice ( )
3642 . iter ( )
37- . map ( |op| match op. kind {
38- SimpleOperandType :: Imm | SimpleOperandType :: Label => {
43+ . map ( |op| match op {
44+ OperandType :: cpu_immediate | OperandType :: cpu_label | OperandType :: cpu_branch_target_label => {
3945 if is_branch {
4046 ObjInsArg :: BranchOffset ( branch_offset)
4147 } else if let Some ( reloc) = reloc {
@@ -49,17 +55,17 @@ pub fn process_code(
4955 ObjInsArg :: Reloc
5056 }
5157 } else {
52- ObjInsArg :: MipsArg ( op. disassembled . clone ( ) )
58+ ObjInsArg :: MipsArg ( op. disassemble ( & instruction , None ) )
5359 }
5460 }
55- SimpleOperandType :: ImmBase => {
61+ OperandType :: cpu_immediate_base => {
5662 if reloc. is_some ( ) {
5763 ObjInsArg :: RelocWithBase
5864 } else {
59- ObjInsArg :: MipsArg ( op. disassembled . clone ( ) )
65+ ObjInsArg :: MipsArg ( op. disassemble ( & instruction , None ) )
6066 }
6167 }
62- _ => ObjInsArg :: MipsArg ( op. disassembled . clone ( ) ) ,
68+ _ => ObjInsArg :: MipsArg ( op. disassemble ( & instruction , None ) ) ,
6369 } )
6470 . collect ( ) ;
6571 let line =
0 commit comments