Skip to content

Commit

Permalink
Add Architecture::M68k (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
knickish authored Nov 8, 2024
1 parent 61dc7b0 commit fb4446b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum Architecture {
X86_64_X32,
Hexagon,
LoongArch64,
M68k,
Mips,
Mips64,
Msp430,
Expand Down Expand Up @@ -66,6 +67,7 @@ impl Architecture {
Architecture::X86_64_X32 => Some(AddressSize::U32),
Architecture::Hexagon => Some(AddressSize::U32),
Architecture::LoongArch64 => Some(AddressSize::U64),
Architecture::M68k => Some(AddressSize::U32),
Architecture::Mips => Some(AddressSize::U32),
Architecture::Mips64 => Some(AddressSize::U64),
Architecture::Msp430 => Some(AddressSize::U16),
Expand Down
1 change: 1 addition & 0 deletions src/read/elf/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ where
(elf::EM_X86_64, true) => Architecture::X86_64,
(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, true) => Architecture::Mips64,
(elf::EM_MSP430, _) => Architecture::Msp430,
Expand Down
15 changes: 15 additions & 0 deletions src/read/elf/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,21 @@ fn parse_relocation<Elf: FileHeader>(
elf::R_LARCH_B26 => (K::Relative, E::LoongArchBranch, 26),
_ => unknown,
},
elf::EM_68K => match r_type {
elf::R_68K_32 => (K::Absolute, g, 32),
elf::R_68K_16 => (K::Absolute, g, 16),
elf::R_68K_8 => (K::Absolute, g, 8),
elf::R_68K_PC32 => (K::Relative, g, 32),
elf::R_68K_PC16 => (K::Relative, g, 16),
elf::R_68K_PC8 => (K::Relative, g, 8),
elf::R_68K_GOT32 => (K::Got, g, 32),
elf::R_68K_GOT16 => (K::Got, g, 16),
elf::R_68K_GOT8 => (K::Got, g, 8),
elf::R_68K_PLT32 => (K::PltRelative, g, 32),
elf::R_68K_PLT16 => (K::PltRelative, g, 16),
elf::R_68K_PLT8 => (K::PltRelative, g, 8),
_ => unknown,
},
elf::EM_MIPS => match r_type {
elf::R_MIPS_16 => (K::Absolute, g, 16),
elf::R_MIPS_32 => (K::Absolute, g, 32),
Expand Down
17 changes: 17 additions & 0 deletions src/write/elf/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl<'a> Object<'a> {
Architecture::X86_64_X32 => true,
Architecture::Hexagon => true,
Architecture::LoongArch64 => true,
Architecture::M68k => false,
Architecture::Mips => false,
Architecture::Mips64 => true,
Architecture::Msp430 => true,
Expand Down Expand Up @@ -260,6 +261,21 @@ impl<'a> Object<'a> {
(K::PltRelative, E::LoongArchBranch, 26) => elf::R_LARCH_B26,
_ => return unsupported_reloc(),
},
Architecture::M68k => match (kind, encoding, size) {
(RelocationKind::Absolute, _, 8) => elf::R_68K_8,
(RelocationKind::Absolute, _, 16) => elf::R_68K_16,
(RelocationKind::Absolute, _, 32) => elf::R_68K_32,
(RelocationKind::Relative, _, 8) => elf::R_68K_PC8,
(RelocationKind::Relative, _, 16) => elf::R_68K_PC16,
(RelocationKind::Relative, _, 32) => elf::R_68K_PC32,
(RelocationKind::Got, _, 8) => elf::R_68K_GOT8,
(RelocationKind::Got, _, 16) => elf::R_68K_GOT16,
(RelocationKind::Got, _, 32) => elf::R_68K_GOT32,
(RelocationKind::PltRelative, _, 8) => elf::R_68K_PLT8,
(RelocationKind::PltRelative, _, 16) => elf::R_68K_PLT16,
(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,
Expand Down Expand Up @@ -543,6 +559,7 @@ impl<'a> Object<'a> {
(Architecture::X86_64_X32, None) => elf::EM_X86_64,
(Architecture::Hexagon, None) => elf::EM_HEXAGON,
(Architecture::LoongArch64, None) => elf::EM_LOONGARCH,
(Architecture::M68k, None) => elf::EM_68K,
(Architecture::Mips, None) => elf::EM_MIPS,
(Architecture::Mips64, None) => elf::EM_MIPS,
(Architecture::Msp430, None) => elf::EM_MSP430,
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 @@ -272,6 +272,7 @@ fn elf_any() {
(Architecture::X86_64_X32, Endianness::Little),
(Architecture::Hexagon, Endianness::Little),
(Architecture::LoongArch64, Endianness::Little),
(Architecture::M68k, Endianness::Big),
(Architecture::Mips, Endianness::Little),
(Architecture::Mips64, Endianness::Little),
(Architecture::Msp430, Endianness::Little),
Expand Down

0 comments on commit fb4446b

Please sign in to comment.