@@ -15,7 +15,7 @@ use crate::{
15
15
diff:: { DiffObjConfig , MipsAbi , MipsInstrCategory , display:: InstructionPart } ,
16
16
obj:: {
17
17
InstructionArg , InstructionArgValue , InstructionRef , Relocation , RelocationFlags ,
18
- ResolvedInstructionRef , ResolvedRelocation , SymbolFlag , SymbolFlagSet ,
18
+ ResolvedInstructionRef , ResolvedRelocation , Section , Symbol , SymbolFlag , SymbolFlagSet ,
19
19
} ,
20
20
} ;
21
21
@@ -140,6 +140,14 @@ impl ArchMips {
140
140
} )
141
141
}
142
142
143
+ fn default_instruction_flags ( & self ) -> rabbitizer:: InstructionFlags {
144
+ match self . isa_extension {
145
+ Some ( extension) => rabbitizer:: InstructionFlags :: new_extension ( extension) ,
146
+ None => rabbitizer:: InstructionFlags :: new ( IsaVersion :: MIPS_III ) ,
147
+ }
148
+ . with_abi ( self . abi )
149
+ }
150
+
143
151
fn instruction_flags ( & self , diff_config : & DiffObjConfig ) -> rabbitizer:: InstructionFlags {
144
152
let isa_extension = match diff_config. mips_instr_category {
145
153
MipsInstrCategory :: Auto => self . isa_extension ,
@@ -151,7 +159,7 @@ impl ArchMips {
151
159
} ;
152
160
match isa_extension {
153
161
Some ( extension) => rabbitizer:: InstructionFlags :: new_extension ( extension) ,
154
- None => rabbitizer:: InstructionFlags :: new_isa ( IsaVersion :: MIPS_III , None ) ,
162
+ None => rabbitizer:: InstructionFlags :: new ( IsaVersion :: MIPS_III ) ,
155
163
}
156
164
. with_abi ( match diff_config. mips_abi {
157
165
MipsAbi :: Auto => self . abi ,
@@ -331,6 +339,36 @@ impl Arch for ArchMips {
331
339
}
332
340
flags
333
341
}
342
+
343
+ fn infer_function_size (
344
+ & self ,
345
+ symbol : & Symbol ,
346
+ section : & Section ,
347
+ next_address : u64 ,
348
+ ) -> Result < u64 > {
349
+ // Trim any trailing 4-byte zeroes from the end (nops)
350
+ let mut new_address = next_address;
351
+ while new_address >= symbol. address + 4
352
+ && let Some ( data) = section. data_range ( new_address - 4 , 4 )
353
+ && data == [ 0u8 ; 4 ]
354
+ {
355
+ new_address -= 4 ;
356
+ }
357
+ // Check if the last instruction has a delay slot, if so, include the delay slot nop
358
+ if new_address + 4 <= next_address
359
+ && new_address >= symbol. address + 4
360
+ && let Some ( data) = section. data_range ( new_address - 4 , 4 )
361
+ && let instruction = rabbitizer:: Instruction :: new (
362
+ self . endianness . read_u32_bytes ( data. try_into ( ) . unwrap ( ) ) ,
363
+ Vram :: new ( ( new_address - 4 ) as u32 ) ,
364
+ self . default_instruction_flags ( ) ,
365
+ )
366
+ && instruction. opcode ( ) . has_delay_slot ( )
367
+ {
368
+ new_address += 4 ;
369
+ }
370
+ Ok ( new_address. saturating_sub ( symbol. address ) )
371
+ }
334
372
}
335
373
336
374
fn push_args (
0 commit comments