1
1
use anyhow:: Result ;
2
- use rabbitizer:: { config_set_register_fpr_abi_names , Abi , Instruction , SimpleOperandType } ;
2
+ use rabbitizer:: { config , Abi , Instruction , InstrCategory , OperandType } ;
3
3
4
4
use crate :: obj:: { ObjIns , ObjInsArg , ObjReloc } ;
5
5
6
+ fn configure_rabbitizer ( ) {
7
+ unsafe {
8
+ config:: RabbitizerConfig_Cfg . reg_names . fpr_abi_names = Abi :: O32 ;
9
+ }
10
+ }
11
+
6
12
pub fn process_code (
7
13
data : & [ u8 ] ,
8
14
start_address : u64 ,
9
15
end_address : u64 ,
10
16
relocs : & [ ObjReloc ] ,
11
17
) -> Result < ( Vec < u8 > , Vec < ObjIns > ) > {
12
- config_set_register_fpr_abi_names ( Abi :: RABBITIZER_ABI_O32 ) ;
18
+ configure_rabbitizer ( ) ;
13
19
14
20
let ins_count = data. len ( ) / 4 ;
15
21
let mut ops = Vec :: < u8 > :: with_capacity ( ins_count) ;
@@ -18,21 +24,21 @@ pub fn process_code(
18
24
for chunk in data. chunks_exact ( 4 ) {
19
25
let reloc = relocs. iter ( ) . find ( |r| ( r. address as u32 & !3 ) == cur_addr) ;
20
26
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 ) ;
22
28
23
- let op = instruction. instr_id ( ) as u8 ;
29
+ let op = instruction. unique_id as u8 ;
24
30
ops. push ( op) ;
25
31
26
- let mnemonic = instruction. instr_id ( ) . get_opcode_name ( ) . unwrap_or_default ( ) . to_string ( ) ;
32
+ let mnemonic = instruction. opcode_name ( ) . to_string ( ) ;
27
33
let is_branch = instruction. is_branch ( ) ;
28
34
let branch_offset = instruction. branch_offset ( ) ;
29
35
let branch_dest =
30
36
if is_branch { Some ( ( cur_addr as i32 + branch_offset) as u32 ) } else { None } ;
31
37
let args = instruction
32
- . simple_operands ( )
38
+ . get_operands_slice ( )
33
39
. iter ( )
34
- . map ( |op| match op. kind {
35
- SimpleOperandType :: Imm | SimpleOperandType :: Label => {
40
+ . map ( |op| match op {
41
+ OperandType :: cpu_immediate | OperandType :: cpu_label => {
36
42
if is_branch {
37
43
ObjInsArg :: BranchOffset ( branch_offset)
38
44
} else if let Some ( reloc) = reloc {
@@ -46,17 +52,17 @@ pub fn process_code(
46
52
ObjInsArg :: Reloc
47
53
}
48
54
} else {
49
- ObjInsArg :: MipsArg ( op. disassembled . clone ( ) )
55
+ ObjInsArg :: MipsArg ( op. disassemble ( instruction , None ) )
50
56
}
51
57
}
52
- SimpleOperandType :: ImmBase => {
58
+ OperandType :: cpu_immediate_base => {
53
59
if reloc. is_some ( ) {
54
60
ObjInsArg :: RelocWithBase
55
61
} else {
56
- ObjInsArg :: MipsArg ( op. disassembled . clone ( ) )
62
+ ObjInsArg :: MipsArg ( op. disassemble ( instruction , None ) )
57
63
}
58
64
}
59
- _ => ObjInsArg :: MipsArg ( op. disassembled . clone ( ) ) ,
65
+ _ => ObjInsArg :: MipsArg ( op. disassemble ( instruction , None ) ) ,
60
66
} )
61
67
. collect ( ) ;
62
68
insts. push ( ObjIns {
0 commit comments