Skip to content

Commit

Permalink
Added Mips64 N32 architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
Tazdevil971 committed Nov 13, 2024
1 parent fb4446b commit 93b2a7d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub enum Architecture {
M68k,
Mips,
Mips64,
#[allow(non_camel_case_types)]
Mips64_N32,
Msp430,
PowerPc,
PowerPc64,
Expand Down Expand Up @@ -70,6 +72,7 @@ impl Architecture {
Architecture::M68k => Some(AddressSize::U32),
Architecture::Mips => Some(AddressSize::U32),
Architecture::Mips64 => Some(AddressSize::U64),
Architecture::Mips64_N32 => Some(AddressSize::U32),
Architecture::Msp430 => Some(AddressSize::U16),
Architecture::PowerPc => Some(AddressSize::U32),
Architecture::PowerPc64 => Some(AddressSize::U64),
Expand Down
8 changes: 7 additions & 1 deletion src/read/elf/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ where
(elf::EM_HEXAGON, _) => Architecture::Hexagon,
(elf::EM_LOONGARCH, true) => Architecture::LoongArch64,
(elf::EM_68K, false) => Architecture::M68k,
(elf::EM_MIPS, false) => Architecture::Mips,
(elf::EM_MIPS, false) => {
if (self.header.e_flags(self.endian) & elf::EF_MIPS_ABI2) != 0 {
Architecture::Mips64_N32
} else {
Architecture::Mips
}
}
(elf::EM_MIPS, true) => Architecture::Mips64,
(elf::EM_MSP430, _) => Architecture::Msp430,
(elf::EM_PPC, _) => Architecture::PowerPc,
Expand Down
25 changes: 18 additions & 7 deletions src/write/elf/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl<'a> Object<'a> {
Architecture::M68k => false,
Architecture::Mips => false,
Architecture::Mips64 => true,
Architecture::Mips64_N32 => true,
Architecture::Msp430 => true,
Architecture::PowerPc => true,
Architecture::PowerPc64 => true,
Expand Down Expand Up @@ -276,12 +277,16 @@ impl<'a> Object<'a> {
(RelocationKind::PltRelative, _, 32) => elf::R_68K_PLT32,
_ => return unsupported_reloc(),
},
Architecture::Mips | Architecture::Mips64 => match (kind, encoding, size) {
(K::Absolute, _, 16) => elf::R_MIPS_16,
(K::Absolute, _, 32) => elf::R_MIPS_32,
(K::Absolute, _, 64) => elf::R_MIPS_64,
_ => return unsupported_reloc(),
},
Architecture::Mips | Architecture::Mips64 | Architecture::Mips64_N32 => {
match (kind, encoding, size) {
(K::Absolute, _, 16) => elf::R_MIPS_16,
(K::Absolute, _, 32) => elf::R_MIPS_32,
(K::Absolute, _, 64) => elf::R_MIPS_64,
_ => {
return Err(Error(format!("unimplemented relocation {:?}", reloc)));
}
}
}
Architecture::Msp430 => match (kind, encoding, size) {
(K::Absolute, _, 32) => elf::R_MSP430_32,
(K::Absolute, _, 16) => elf::R_MSP430_16_BYTE,
Expand Down Expand Up @@ -562,6 +567,7 @@ impl<'a> Object<'a> {
(Architecture::M68k, None) => elf::EM_68K,
(Architecture::Mips, None) => elf::EM_MIPS,
(Architecture::Mips64, None) => elf::EM_MIPS,
(Architecture::Mips64_N32, None) => elf::EM_MIPS,
(Architecture::Msp430, None) => elf::EM_MSP430,
(Architecture::PowerPc, None) => elf::EM_PPC,
(Architecture::PowerPc64, None) => elf::EM_PPC64,
Expand All @@ -581,7 +587,7 @@ impl<'a> Object<'a> {
)));
}
};
let (os_abi, abi_version, e_flags) = if let FileFlags::Elf {
let (os_abi, abi_version, mut e_flags) = if let FileFlags::Elf {
os_abi,
abi_version,
e_flags,
Expand All @@ -591,6 +597,11 @@ impl<'a> Object<'a> {
} else {
(elf::ELFOSABI_NONE, 0, 0)
};

if self.architecture == Architecture::Mips64_N32 {
e_flags |= elf::EF_MIPS_ABI2;
}

writer.write_file_header(&FileHeader {
os_abi,
abi_version,
Expand Down
1 change: 1 addition & 0 deletions tests/round_trip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ fn elf_any() {
(Architecture::M68k, Endianness::Big),
(Architecture::Mips, Endianness::Little),
(Architecture::Mips64, Endianness::Little),
(Architecture::Mips64_N32, Endianness::Little),
(Architecture::Msp430, Endianness::Little),
(Architecture::PowerPc, Endianness::Big),
(Architecture::PowerPc64, Endianness::Big),
Expand Down

0 comments on commit 93b2a7d

Please sign in to comment.