From 8d193e8332c125cd00522af93175b39b4ee59b7f Mon Sep 17 00:00:00 2001 From: kirk Date: Thu, 7 Nov 2024 22:59:03 +0000 Subject: [PATCH] add m68k arch support --- src/common.rs | 2 ++ src/read/elf/file.rs | 1 + src/write/elf/object.rs | 12 ++++++++++++ 3 files changed, 15 insertions(+) diff --git a/src/common.rs b/src/common.rs index 9ed0f443..9f2bcc14 100644 --- a/src/common.rs +++ b/src/common.rs @@ -19,6 +19,7 @@ pub enum Architecture { X86_64_X32, Hexagon, LoongArch64, + M68k, Mips, Mips64, Msp430, @@ -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), diff --git a/src/read/elf/file.rs b/src/read/elf/file.rs index 6de69ee5..ad5d9add 100644 --- a/src/read/elf/file.rs +++ b/src/read/elf/file.rs @@ -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, diff --git a/src/write/elf/object.rs b/src/write/elf/object.rs index cd6b8ead..daa98fb7 100644 --- a/src/write/elf/object.rs +++ b/src/write/elf/object.rs @@ -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, @@ -260,6 +261,16 @@ impl<'a> Object<'a> { (K::PltRelative, E::LoongArchBranch, 26) => elf::R_LARCH_B26, _ => return unsupported_reloc(), }, + Architecture::M68k => match (dbg!(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, _, 16) => elf::R_68K_PC16, + (RelocationKind::Relative, _, 32) => elf::R_68K_PC32, + _ => { + return Err(Error(format!("unimplemented relocation {:?}", reloc))); + } + }, Architecture::Mips | Architecture::Mips64 => match (kind, encoding, size) { (K::Absolute, _, 16) => elf::R_MIPS_16, (K::Absolute, _, 32) => elf::R_MIPS_32, @@ -543,6 +554,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,