@@ -15,7 +15,7 @@ use crate::{
1515 diff:: { DiffObjConfig , MipsAbi , MipsInstrCategory , display:: InstructionPart } ,
1616 obj:: {
1717 InstructionArg , InstructionArgValue , InstructionRef , Relocation , RelocationFlags ,
18- ResolvedInstructionRef , ResolvedRelocation , SymbolFlag , SymbolFlagSet ,
18+ ResolvedInstructionRef , ResolvedRelocation , Section , Symbol , SymbolFlag , SymbolFlagSet ,
1919 } ,
2020} ;
2121
@@ -140,6 +140,14 @@ impl ArchMips {
140140 } )
141141 }
142142
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+
143151 fn instruction_flags ( & self , diff_config : & DiffObjConfig ) -> rabbitizer:: InstructionFlags {
144152 let isa_extension = match diff_config. mips_instr_category {
145153 MipsInstrCategory :: Auto => self . isa_extension ,
@@ -151,7 +159,7 @@ impl ArchMips {
151159 } ;
152160 match isa_extension {
153161 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 ) ,
155163 }
156164 . with_abi ( match diff_config. mips_abi {
157165 MipsAbi :: Auto => self . abi ,
@@ -331,6 +339,36 @@ impl Arch for ArchMips {
331339 }
332340 flags
333341 }
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+ }
334372}
335373
336374fn push_args (
0 commit comments