Skip to content

Commit

Permalink
Fix Z80 ELF defines.
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobly0 committed Jun 4, 2022
1 parent ba4e437 commit 142c6ae
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 9 deletions.
14 changes: 13 additions & 1 deletion llvm/include/llvm/BinaryFormat/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,19 @@ enum {

// Z80 specific e_flags
enum : unsigned {
EF_Z80_EZ80 = 0x1,
EF_Z80_MACH_Z80 = 0x01,
EF_Z80_MACH_Z180 = 0x02,
EF_Z80_MACH_R800 = 0x03,
EF_Z80_MACH_EZ80_Z80 = 0x04,
EF_Z80_MACH_EZ80_ADL = 0x84,
EF_Z80_MACH_GBZ80 = 0x05,
EF_Z80_MACH_Z80N = 0x06,
EF_Z80_MACH_MSK = 0xff,
};

// Z80 relocations.
enum {
#include "ELFRelocs/z80.def"
};

#undef ELF_RELOC
Expand Down
19 changes: 19 additions & 0 deletions llvm/include/llvm/BinaryFormat/ELFRelocs/z80.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#ifndef ELF_RELOC
#error "ELF_RELOC must be defined"
#endif

ELF_RELOC(R_Z80_NONE, 0)
ELF_RELOC(R_Z80_8, 1)
ELF_RELOC(R_Z80_8_DIS, 2)
ELF_RELOC(R_Z80_8_PCREL, 3)
ELF_RELOC(R_Z80_16, 4)
ELF_RELOC(R_Z80_24, 5)
ELF_RELOC(R_Z80_32, 6)
ELF_RELOC(R_Z80_BYTE0, 7)
ELF_RELOC(R_Z80_BYTE1, 8)
ELF_RELOC(R_Z80_BYTE2, 9)
ELF_RELOC(R_Z80_BYTE3, 10)
ELF_RELOC(R_Z80_WORD0, 11)
ELF_RELOC(R_Z80_WORD1, 12)
ELF_RELOC(R_Z80_16_BE, 13)
33 changes: 26 additions & 7 deletions llvm/include/llvm/Object/ELFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -1212,8 +1212,24 @@ StringRef ELFObjectFile<ELFT>::getFileFormatName() const {
case ELF::EM_LOONGARCH:
return "elf32-loongarch";
case ELF::EM_Z80:
return (EF.getHeader().e_flags & ELF::EF_Z80_EZ80 ? "elf32-ez80"
: "elf32-z80");
switch (EF.getHeader().e_flags & ELF::EF_Z80_MACH_MSK) {
default:
return "elf32-z80-unknown";
case ELF::EF_Z80_MACH_Z80:
return "elf32-z80";
case ELF::EF_Z80_MACH_Z180:
return "elf32-z180";
case ELF::EF_Z80_MACH_R800:
return "elf32-r800";
case ELF::EF_Z80_MACH_EZ80_Z80:
return "elf32-ez80-code16";
case ELF::EF_Z80_MACH_EZ80_ADL:
return "elf32-ez80";
case ELF::EF_Z80_MACH_GBZ80:
return "elf32-gbz80";
case ELF::EF_Z80_MACH_Z80N:
return "elf32-z80n";
}
default:
return "elf32-unknown";
}
Expand Down Expand Up @@ -1339,13 +1355,16 @@ template <class ELFT> Triple::ArchType ELFObjectFile<ELFT>::getArch() const {
}

case ELF::EM_Z80:
if (!IsLittleEndian)
if (!IsLittleEndian ||
EF.getHeader().e_ident[ELF::EI_CLASS] != ELF::ELFCLASS32)
return Triple::UnknownArch;

if (EF.getHeader().e_flags & ELF::EF_Z80_EZ80)
switch (EF.getHeader().e_flags & ELF::EF_Z80_MACH_MSK) {
default:
return Triple::z80;
case ELF::EF_Z80_MACH_EZ80_Z80:
case ELF::EF_Z80_MACH_EZ80_ADL:
return Triple::ez80;

return Triple::z80;
}

default:
return Triple::UnknownArch;
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ module LLVM_BinaryFormat {
textual header "BinaryFormat/ELFRelocs/SystemZ.def"
textual header "BinaryFormat/ELFRelocs/VE.def"
textual header "BinaryFormat/ELFRelocs/x86_64.def"
textual header "BinaryFormat/ELFRelocs/Z80.def"
textual header "BinaryFormat/WasmRelocs.def"
textual header "BinaryFormat/MsgPack.def"
}
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Object/ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ StringRef llvm::object::getELFRelocationTypeName(uint32_t Machine,
break;
}
break;
case ELF::EM_Z80:
switch (Type) {
#include "llvm/BinaryFormat/ELFRelocs/z80.def"
default:
break;
}
break;
default:
break;
}
Expand Down Expand Up @@ -223,6 +230,8 @@ uint32_t llvm::object::getELFRelativeRelocationType(uint32_t Machine) {
break;
case ELF::EM_BPF:
break;
case ELF::EM_Z80:
break;
default:
break;
}
Expand Down
8 changes: 7 additions & 1 deletion llvm/tools/llvm-readobj/ELFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,13 @@ const EnumEntry<unsigned> ElfHeaderAVRFlags[] = {
};

static const EnumEntry<unsigned> ElfHeaderZ80Flags[] = {
ENUM_ENT(EF_Z80_EZ80, "eZ80")
ENUM_ENT(EF_Z80_MACH_Z80, "Z80"),
ENUM_ENT(EF_Z80_MACH_Z180, "Z180"),
ENUM_ENT(EF_Z80_MACH_R800, "R800"),
ENUM_ENT(EF_Z80_MACH_EZ80_Z80, "eZ80-Z80"),
ENUM_ENT(EF_Z80_MACH_EZ80_ADL, "eZ80-ADL"),
ENUM_ENT(EF_Z80_MACH_GBZ80, "gbZ80"),
ENUM_ENT(EF_Z80_MACH_Z80N, "Z80N"),
};


Expand Down

0 comments on commit 142c6ae

Please sign in to comment.