Skip to content

Commit 95615c2

Browse files
committed
Improve MIPS ABI auto-detection
1 parent 9798116 commit 95615c2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

objdiff-core/src/arch/mips.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ pub struct ObjArchMips {
2727
const EF_MIPS_ABI: u32 = 0x0000F000;
2828
const EF_MIPS_MACH: u32 = 0x00FF0000;
2929

30-
const E_MIPS_MACH_ALLEGREX: u32 = 0x00840000;
31-
const E_MIPS_MACH_5900: u32 = 0x00920000;
30+
const EF_MIPS_MACH_ALLEGREX: u32 = 0x00840000;
31+
const EF_MIPS_MACH_5900: u32 = 0x00920000;
3232

3333
impl ObjArchMips {
3434
pub fn new(object: &File) -> Result<Self> {
@@ -38,13 +38,19 @@ impl ObjArchMips {
3838
FileFlags::None => {}
3939
FileFlags::Elf { e_flags, .. } => {
4040
abi = match e_flags & EF_MIPS_ABI {
41-
elf::EF_MIPS_ABI_O32 => Abi::O32,
41+
elf::EF_MIPS_ABI_O32 | elf::EF_MIPS_ABI_O64 => Abi::O32,
4242
elf::EF_MIPS_ABI_EABI32 | elf::EF_MIPS_ABI_EABI64 => Abi::N32,
43-
_ => Abi::NUMERIC,
43+
_ => {
44+
if e_flags & elf::EF_MIPS_ABI2 != 0 {
45+
Abi::N32
46+
} else {
47+
Abi::NUMERIC
48+
}
49+
}
4450
};
4551
instr_category = match e_flags & EF_MIPS_MACH {
46-
E_MIPS_MACH_ALLEGREX => InstrCategory::R4000ALLEGREX,
47-
E_MIPS_MACH_5900 => InstrCategory::R5900,
52+
EF_MIPS_MACH_ALLEGREX => InstrCategory::R4000ALLEGREX,
53+
EF_MIPS_MACH_5900 => InstrCategory::R5900,
4854
_ => InstrCategory::CPU,
4955
};
5056
}

0 commit comments

Comments
 (0)