forked from OSchip/llvm-project
[LLDB][RISCV] Add RISC-V ArchSpec and rv32/rv64 variant detection
Adds the RISC-V ArchSpec bits contributed by @simoncook as part of D62732, plus logic to distinguish between riscv32 and riscv64 based on ELF class. The patch follows the implementation approach previously used for MIPS. It defines RISC-V architecture subtypes and inspects the ELF header, namely the ELF class, to detect the right subtype. Differential Revision: https://reviews.llvm.org/D86292
This commit is contained in:
parent
2ce16810f2
commit
15f5971150
|
@ -92,6 +92,12 @@ public:
|
|||
eARM_abi_hard_float = 0x00000400
|
||||
};
|
||||
|
||||
enum RISCVSubType {
|
||||
eRISCVSubType_unknown,
|
||||
eRISCVSubType_riscv32,
|
||||
eRISCVSubType_riscv64,
|
||||
};
|
||||
|
||||
enum Core {
|
||||
eCore_arm_generic,
|
||||
eCore_arm_armv4,
|
||||
|
@ -184,6 +190,9 @@ public:
|
|||
eCore_hexagon_hexagonv4,
|
||||
eCore_hexagon_hexagonv5,
|
||||
|
||||
eCore_riscv32,
|
||||
eCore_riscv64,
|
||||
|
||||
eCore_uknownMach32,
|
||||
eCore_uknownMach64,
|
||||
|
||||
|
|
|
@ -296,9 +296,23 @@ static uint32_t mipsVariantFromElfFlags (const elf::ELFHeader &header) {
|
|||
return arch_variant;
|
||||
}
|
||||
|
||||
static uint32_t riscvVariantFromElfFlags(const elf::ELFHeader &header) {
|
||||
uint32_t fileclass = header.e_ident[EI_CLASS];
|
||||
switch (fileclass) {
|
||||
case llvm::ELF::ELFCLASS32:
|
||||
return ArchSpec::eRISCVSubType_riscv32;
|
||||
case llvm::ELF::ELFCLASS64:
|
||||
return ArchSpec::eRISCVSubType_riscv64;
|
||||
default:
|
||||
return ArchSpec::eRISCVSubType_unknown;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) {
|
||||
if (header.e_machine == llvm::ELF::EM_MIPS)
|
||||
return mipsVariantFromElfFlags(header);
|
||||
else if (header.e_machine == llvm::ELF::EM_RISCV)
|
||||
return riscvVariantFromElfFlags(header);
|
||||
|
||||
return LLDB_INVALID_CPUTYPE;
|
||||
}
|
||||
|
|
|
@ -212,6 +212,11 @@ static const CoreDefinition g_core_definitions[] = {
|
|||
{eByteOrderLittle, 4, 4, 4, llvm::Triple::hexagon,
|
||||
ArchSpec::eCore_hexagon_hexagonv5, "hexagonv5"},
|
||||
|
||||
{eByteOrderLittle, 4, 2, 4, llvm::Triple::riscv32, ArchSpec::eCore_riscv32,
|
||||
"riscv32"},
|
||||
{eByteOrderLittle, 8, 2, 4, llvm::Triple::riscv64, ArchSpec::eCore_riscv64,
|
||||
"riscv64"},
|
||||
|
||||
{eByteOrderLittle, 4, 4, 4, llvm::Triple::UnknownArch,
|
||||
ArchSpec::eCore_uknownMach32, "unknown-mach-32"},
|
||||
{eByteOrderLittle, 8, 4, 4, llvm::Triple::UnknownArch,
|
||||
|
@ -395,6 +400,10 @@ static const ArchDefinitionEntry g_elf_arch_entries[] = {
|
|||
0xFFFFFFFFu, 0xFFFFFFFFu}, // ARC
|
||||
{ArchSpec::eCore_avr, llvm::ELF::EM_AVR, LLDB_INVALID_CPUTYPE,
|
||||
0xFFFFFFFFu, 0xFFFFFFFFu}, // AVR
|
||||
{ArchSpec::eCore_riscv32, llvm::ELF::EM_RISCV,
|
||||
ArchSpec::eRISCVSubType_riscv32, 0xFFFFFFFFu, 0xFFFFFFFFu}, // riscv32
|
||||
{ArchSpec::eCore_riscv64, llvm::ELF::EM_RISCV,
|
||||
ArchSpec::eRISCVSubType_riscv64, 0xFFFFFFFFu, 0xFFFFFFFFu}, // riscv64
|
||||
};
|
||||
|
||||
static const ArchDefinition g_elf_arch_def = {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# RUN: yaml2obj --docnum=1 %s > %t32
|
||||
# RUN: yaml2obj --docnum=2 %s > %t64
|
||||
# RUN: lldb-test object-file %t32 | FileCheck --check-prefix=CHECK-RV32 %s
|
||||
# RUN: lldb-test object-file %t64 | FileCheck --check-prefix=CHECK-RV64 %s
|
||||
|
||||
# CHECK-RV32: Architecture: riscv32--
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS32
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_EXEC
|
||||
Machine: EM_RISCV
|
||||
...
|
||||
|
||||
# CHECK-RV64: Architecture: riscv64--
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_EXEC
|
||||
Machine: EM_RISCV
|
||||
...
|
Loading…
Reference in New Issue