@@ -11,16 +11,16 @@ use core::{
11
11
} ;
12
12
13
13
use itertools:: Itertools ;
14
- use ppc750cl :: Simm ;
14
+ use powerpc :: { Extensions , Simm } ;
15
15
16
16
use crate :: {
17
17
arch:: DataType ,
18
18
obj:: { FlowAnalysisResult , FlowAnalysisValue , Object , Relocation , Symbol } ,
19
19
util:: { RawDouble , RawFloat } ,
20
20
} ;
21
21
22
- fn is_store_instruction ( op : ppc750cl :: Opcode ) -> bool {
23
- use ppc750cl :: Opcode ;
22
+ fn is_store_instruction ( op : powerpc :: Opcode ) -> bool {
23
+ use powerpc :: Opcode ;
24
24
matches ! (
25
25
op,
26
26
Opcode :: Stbux
@@ -52,8 +52,8 @@ fn is_store_instruction(op: ppc750cl::Opcode) -> bool {
52
52
)
53
53
}
54
54
55
- pub fn guess_data_type_from_load_store_inst_op ( inst_op : ppc750cl :: Opcode ) -> Option < DataType > {
56
- use ppc750cl :: Opcode ;
55
+ pub fn guess_data_type_from_load_store_inst_op ( inst_op : powerpc :: Opcode ) -> Option < DataType > {
56
+ use powerpc :: Opcode ;
57
57
match inst_op {
58
58
Opcode :: Lbz | Opcode :: Lbzu | Opcode :: Lbzux | Opcode :: Lbzx => Some ( DataType :: Int8 ) ,
59
59
Opcode :: Lhz | Opcode :: Lhzu | Opcode :: Lhzux | Opcode :: Lhzx => Some ( DataType :: Int16 ) ,
@@ -118,12 +118,12 @@ impl RegisterState {
118
118
119
119
// During a function call, these registers must be assumed trashed.
120
120
fn clear_volatile ( & mut self ) {
121
- self [ ppc750cl :: GPR ( 0 ) ] = RegisterContent :: Unknown ;
121
+ self [ powerpc :: GPR ( 0 ) ] = RegisterContent :: Unknown ;
122
122
for i in 0 ..=13 {
123
- self [ ppc750cl :: GPR ( i) ] = RegisterContent :: Unknown ;
123
+ self [ powerpc :: GPR ( i) ] = RegisterContent :: Unknown ;
124
124
}
125
125
for i in 0 ..=13 {
126
- self [ ppc750cl :: FPR ( i) ] = RegisterContent :: Unknown ;
126
+ self [ powerpc :: FPR ( i) ] = RegisterContent :: Unknown ;
127
127
}
128
128
}
129
129
@@ -132,10 +132,10 @@ impl RegisterState {
132
132
// they get overwritten with another value before getting read.
133
133
fn set_potential_inputs ( & mut self ) {
134
134
for g_reg in 3 ..=13 {
135
- self [ ppc750cl :: GPR ( g_reg) ] = RegisterContent :: InputRegister ( g_reg) ;
135
+ self [ powerpc :: GPR ( g_reg) ] = RegisterContent :: InputRegister ( g_reg) ;
136
136
}
137
137
for f_reg in 1 ..=13 {
138
- self [ ppc750cl :: FPR ( f_reg) ] = RegisterContent :: InputRegister ( f_reg) ;
138
+ self [ powerpc :: FPR ( f_reg) ] = RegisterContent :: InputRegister ( f_reg) ;
139
139
}
140
140
}
141
141
@@ -172,34 +172,34 @@ impl RegisterState {
172
172
}
173
173
}
174
174
175
- impl Index < ppc750cl :: GPR > for RegisterState {
175
+ impl Index < powerpc :: GPR > for RegisterState {
176
176
type Output = RegisterContent ;
177
177
178
- fn index ( & self , gpr : ppc750cl :: GPR ) -> & Self :: Output { & self . gpr [ gpr. 0 as usize ] }
178
+ fn index ( & self , gpr : powerpc :: GPR ) -> & Self :: Output { & self . gpr [ gpr. 0 as usize ] }
179
179
}
180
- impl IndexMut < ppc750cl :: GPR > for RegisterState {
181
- fn index_mut ( & mut self , gpr : ppc750cl :: GPR ) -> & mut Self :: Output {
180
+ impl IndexMut < powerpc :: GPR > for RegisterState {
181
+ fn index_mut ( & mut self , gpr : powerpc :: GPR ) -> & mut Self :: Output {
182
182
& mut self . gpr [ gpr. 0 as usize ]
183
183
}
184
184
}
185
185
186
- impl Index < ppc750cl :: FPR > for RegisterState {
186
+ impl Index < powerpc :: FPR > for RegisterState {
187
187
type Output = RegisterContent ;
188
188
189
- fn index ( & self , fpr : ppc750cl :: FPR ) -> & Self :: Output { & self . fpr [ fpr. 0 as usize ] }
189
+ fn index ( & self , fpr : powerpc :: FPR ) -> & Self :: Output { & self . fpr [ fpr. 0 as usize ] }
190
190
}
191
- impl IndexMut < ppc750cl :: FPR > for RegisterState {
192
- fn index_mut ( & mut self , fpr : ppc750cl :: FPR ) -> & mut Self :: Output {
191
+ impl IndexMut < powerpc :: FPR > for RegisterState {
192
+ fn index_mut ( & mut self , fpr : powerpc :: FPR ) -> & mut Self :: Output {
193
193
& mut self . fpr [ fpr. 0 as usize ]
194
194
}
195
195
}
196
196
197
197
fn execute_instruction (
198
198
registers : & mut RegisterState ,
199
- op : & ppc750cl :: Opcode ,
200
- args : & ppc750cl :: Arguments ,
199
+ op : & powerpc :: Opcode ,
200
+ args : & powerpc :: Arguments ,
201
201
) {
202
- use ppc750cl :: { Argument , GPR , Opcode } ;
202
+ use powerpc :: { Argument , GPR , Opcode } ;
203
203
match ( op, args[ 0 ] , args[ 1 ] , args[ 2 ] ) {
204
204
( Opcode :: Or , Argument :: GPR ( a) , Argument :: GPR ( b) , Argument :: GPR ( c) ) => {
205
205
// Move is implemented as or with self for ints
@@ -270,11 +270,11 @@ fn execute_instruction(
270
270
}
271
271
}
272
272
273
- fn get_branch_offset ( args : & ppc750cl :: Arguments ) -> i32 {
273
+ fn get_branch_offset ( args : & powerpc :: Arguments ) -> i32 {
274
274
for arg in args. iter ( ) {
275
275
match arg {
276
- ppc750cl :: Argument :: BranchDest ( dest) => return dest. 0 / 4 ,
277
- ppc750cl :: Argument :: None => break ,
276
+ powerpc :: Argument :: BranchDest ( dest) => return dest. 0 / 4 ,
277
+ powerpc :: Argument :: None => break ,
278
278
_ => { }
279
279
}
280
280
}
@@ -316,7 +316,7 @@ fn clamp_text_length(s: String, max: usize) -> String {
316
316
fn get_register_content_from_reloc (
317
317
reloc : & Relocation ,
318
318
obj : & Object ,
319
- op : ppc750cl :: Opcode ,
319
+ op : powerpc :: Opcode ,
320
320
) -> RegisterContent {
321
321
if let Some ( bytes) = obj. symbol_data ( reloc. target_symbol ) {
322
322
match guess_data_type_from_load_store_inst_op ( op) {
@@ -354,18 +354,18 @@ fn fill_registers_from_relocation(
354
354
reloc : & Relocation ,
355
355
current_state : & mut RegisterState ,
356
356
obj : & Object ,
357
- op : ppc750cl :: Opcode ,
358
- args : & ppc750cl :: Arguments ,
357
+ op : powerpc :: Opcode ,
358
+ args : & powerpc :: Arguments ,
359
359
) {
360
360
// Only update the register state for loads. We may store to a reloc
361
361
// address but that doesn't update register contents.
362
362
if !is_store_instruction ( op) {
363
363
match ( op, args[ 0 ] ) {
364
364
// Everything else is a load of some sort
365
- ( _, ppc750cl :: Argument :: GPR ( gpr) ) => {
365
+ ( _, powerpc :: Argument :: GPR ( gpr) ) => {
366
366
current_state[ gpr] = get_register_content_from_reloc ( reloc, obj, op) ;
367
367
}
368
- ( _, ppc750cl :: Argument :: FPR ( fpr) ) => {
368
+ ( _, powerpc :: Argument :: FPR ( fpr) ) => {
369
369
current_state[ fpr] = get_register_content_from_reloc ( reloc, obj, op) ;
370
370
}
371
371
_ => { }
@@ -384,11 +384,12 @@ pub fn ppc_data_flow_analysis(
384
384
func_symbol : & Symbol ,
385
385
code : & [ u8 ] ,
386
386
relocations : & [ Relocation ] ,
387
+ extensions : Extensions ,
387
388
) -> Box < dyn FlowAnalysisResult > {
388
389
use alloc:: collections:: VecDeque ;
389
390
390
- use ppc750cl :: InsIter ;
391
- let instructions = InsIter :: new ( code, func_symbol. address as u32 )
391
+ use powerpc :: InsIter ;
392
+ let instructions = InsIter :: new ( code, func_symbol. address as u32 , extensions )
392
393
. map ( |( _addr, ins) | ( ins. op , ins. basic ( ) . args ) )
393
394
. collect_vec ( ) ;
394
395
@@ -449,7 +450,7 @@ pub fn ppc_data_flow_analysis(
449
450
// Only take a given (address, register state) combination once. If
450
451
// the known register state is different we have to take the branch
451
452
// again to stabilize the known values for backwards branches.
452
- if op == & ppc750cl :: Opcode :: Bc {
453
+ if op == & powerpc :: Opcode :: Bc {
453
454
let branch_state = ( index, current_state. clone ( ) ) ;
454
455
if !taken_branches. contains ( & branch_state) {
455
456
let offset = get_branch_offset ( args) ;
@@ -468,7 +469,7 @@ pub fn ppc_data_flow_analysis(
468
469
}
469
470
470
471
// Update index
471
- if op == & ppc750cl :: Opcode :: B {
472
+ if op == & powerpc :: Opcode :: B {
472
473
// Unconditional branch
473
474
let offset = get_branch_offset ( args) ;
474
475
if offset > 0 {
@@ -502,7 +503,14 @@ pub fn ppc_data_flow_analysis(
502
503
}
503
504
504
505
// Store the relevant data flow values for simplified instructions
505
- generate_flow_analysis_result ( obj, func_address, code, register_state_at, relocations)
506
+ generate_flow_analysis_result (
507
+ obj,
508
+ func_address,
509
+ code,
510
+ register_state_at,
511
+ relocations,
512
+ extensions,
513
+ )
506
514
}
507
515
508
516
fn get_string_data ( obj : & Object , symbol_index : usize , offset : Simm ) -> Option < & str > {
@@ -530,14 +538,15 @@ fn generate_flow_analysis_result(
530
538
code : & [ u8 ] ,
531
539
register_state_at : Vec < RegisterState > ,
532
540
relocations : & [ Relocation ] ,
541
+ extensions : Extensions ,
533
542
) -> Box < PPCFlowAnalysisResult > {
534
- use ppc750cl :: { Argument , InsIter } ;
543
+ use powerpc :: { Argument , InsIter } ;
535
544
let mut analysis_result = PPCFlowAnalysisResult :: new ( ) ;
536
545
let default_register_state = RegisterState :: new ( ) ;
537
- for ( addr, ins) in InsIter :: new ( code, 0 ) {
546
+ for ( addr, ins) in InsIter :: new ( code, 0 , extensions ) {
538
547
let ins_address = base_address + ( addr as u64 ) ;
539
548
let index = addr / 4 ;
540
- let ppc750cl :: ParsedIns { mnemonic : _, args } = ins. simplified ( ) ;
549
+ let powerpc :: ParsedIns { mnemonic : _, args } = ins. simplified ( ) ;
541
550
542
551
// If we're already showing relocations on a line don't also show data flow
543
552
let reloc = relocations. iter ( ) . find ( |r| ( r. address & !3 ) == ins_address) ;
@@ -546,7 +555,7 @@ fn generate_flow_analysis_result(
546
555
// they are being loaded.
547
556
// We need to do this before we break out on showing relocations in the
548
557
// subsequent if statement.
549
- if let ( ppc750cl :: Opcode :: Lfs | ppc750cl :: Opcode :: Lfd , Some ( reloc) ) = ( ins. op , reloc) {
558
+ if let ( powerpc :: Opcode :: Lfs | powerpc :: Opcode :: Lfd , Some ( reloc) ) = ( ins. op , reloc) {
550
559
let content = get_register_content_from_reloc ( reloc, obj, ins. op ) ;
551
560
if matches ! (
552
561
content,
@@ -566,7 +575,7 @@ fn generate_flow_analysis_result(
566
575
// Special case to show string constants on the line where they are
567
576
// being indexed to. This will typically be "addi t, stringbase, offset"
568
577
let registers = register_state_at. get ( index as usize ) . unwrap_or ( & default_register_state) ;
569
- if let ( ppc750cl :: Opcode :: Addi , Argument :: GPR ( rel) , Argument :: Simm ( offset) ) =
578
+ if let ( powerpc :: Opcode :: Addi , Argument :: GPR ( rel) , Argument :: Simm ( offset) ) =
570
579
( ins. op , args[ 1 ] , args[ 2 ] )
571
580
{
572
581
if let RegisterContent :: Symbol ( sym_index) = registers[ rel] {
0 commit comments