Skip to content

Commit

Permalink
Experimental v810 support in lldb
Browse files Browse the repository at this point in the history
  • Loading branch information
SupernaviX committed Sep 23, 2024
1 parent 1a25910 commit eeecf70
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 2 deletions.
4 changes: 3 additions & 1 deletion configure-rs.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
cmake -S llvm -B build -G Ninja \
-DLLVM_DEFAULT_TARGET_TRIPLE="v810-unknown-vb" \
-DLLVM_ENABLE_DUMP=ON \
-DLLVM_ENABLE_PROJECTS="clang;lld" \
-DLLVM_ENABLE_PROJECTS="clang;lld;lldb" \
-DLLVM_ENABLE_RUNTIMES="compiler-rt" \
-DLLVM_RUNTIME_TARGETS="v810-unknown-vb" \
-DLLVM_BUILTIN_TARGETS="v810-unknown-vb" \
-DLLDB_ENABLE_PYTHON=ON \
-DLLDB_INCLUDE_TESTS=OFF \
-DBUILTINS_v810-unknown-vb_COMPILER_RT_BAREMETAL_BUILD=ON \
-DBUILTINS_v810-unknown-vb_COMPILER_RT_BUILD_BUILTINS=ON \
-DBUILTINS_v810-unknown-vb_COMPILER_RT_BUILD_CRT=OFF \
Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/Utility/ArchSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class ArchSpec {

eCore_sparc9_generic,

eCore_v810_generic,

eCore_x86_32_i386,
eCore_x86_32_i486,
eCore_x86_32_i486sx,
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/ABI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
foreach(target AArch64 ARM ARC Hexagon Mips MSP430 PowerPC RISCV SystemZ X86)
foreach(target AArch64 ARM ARC Hexagon Mips MSP430 PowerPC RISCV SystemZ V810 X86)
if (${target} IN_LIST LLVM_TARGETS_TO_BUILD)
add_subdirectory(${target})
endif()
Expand Down
156 changes: 156 additions & 0 deletions lldb/source/Plugins/ABI/V810/ABIV810.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#include "ABIV810.h"

#include "llvm/TargetParser/Triple.h"

#include "lldb/Core/PluginManager.h"
#include "lldb/Target/Target.h"

using namespace lldb;
using namespace lldb_private;

LLDB_PLUGIN_DEFINE(ABIV810)

enum dwarf_regnums {
dwarf_r0 = 0,
dwarf_r1,
dwarf_r2,
dwarf_r3,
dwarf_r4,
dwarf_r5,
dwarf_r6,
dwarf_r7,
dwarf_r8,
dwarf_r9,
dwarf_r10,
dwarf_r11,
dwarf_r12,
dwarf_r13,
dwarf_r14,
dwarf_r15,
dwarf_r16,
dwarf_r17,
dwarf_r18,
dwarf_r19,
dwarf_r20,
dwarf_r21,
dwarf_r22,
dwarf_r23,
dwarf_r24,
dwarf_r25,
dwarf_r26,
dwarf_r27,
dwarf_r28,
dwarf_r29,
dwarf_r30,
dwarf_r31,
dwarf_pc
};

static const RegisterInfo g_register_infos[] = {
{"r0", nullptr, 4, 0, eEncodingUint, eFormatHex, {dwarf_r0, dwarf_r0, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r1", nullptr, 4, 4, eEncodingUint, eFormatHex, {dwarf_r1, dwarf_r1, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"fp", "r2", 4, 8, eEncodingUint, eFormatHex, {dwarf_r2, dwarf_r2, LLDB_REGNUM_GENERIC_FP, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"sp", "r3", 4, 12, eEncodingUint, eFormatHex, {dwarf_r3, dwarf_r3, LLDB_REGNUM_GENERIC_SP, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"gp", "r4", 4, 16, eEncodingUint, eFormatHex, {dwarf_r4, dwarf_r4, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"tp", "r5", 4, 20, eEncodingUint, eFormatHex, {dwarf_r5, dwarf_r5, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r6", nullptr, 4, 24, eEncodingUint, eFormatHex, {dwarf_r6, dwarf_r6, LLDB_REGNUM_GENERIC_ARG1, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r7", nullptr, 4, 28, eEncodingUint, eFormatHex, {dwarf_r7, dwarf_r7, LLDB_REGNUM_GENERIC_ARG2, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r8", nullptr, 4, 32, eEncodingUint, eFormatHex, {dwarf_r8, dwarf_r8, LLDB_REGNUM_GENERIC_ARG3, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r9", nullptr, 4, 36, eEncodingUint, eFormatHex, {dwarf_r9, dwarf_r9, LLDB_REGNUM_GENERIC_ARG4, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r10", nullptr, 4, 40, eEncodingUint, eFormatHex, {dwarf_r10, dwarf_r10, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r11", nullptr, 4, 44, eEncodingUint, eFormatHex, {dwarf_r11, dwarf_r11, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r12", nullptr, 4, 48, eEncodingUint, eFormatHex, {dwarf_r12, dwarf_r12, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r13", nullptr, 4, 52, eEncodingUint, eFormatHex, {dwarf_r13, dwarf_r13, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r14", nullptr, 4, 56, eEncodingUint, eFormatHex, {dwarf_r14, dwarf_r14, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r15", nullptr, 4, 60, eEncodingUint, eFormatHex, {dwarf_r15, dwarf_r15, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r16", nullptr, 4, 64, eEncodingUint, eFormatHex, {dwarf_r16, dwarf_r16, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r17", nullptr, 4, 68, eEncodingUint, eFormatHex, {dwarf_r17, dwarf_r17, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r18", nullptr, 4, 72, eEncodingUint, eFormatHex, {dwarf_r18, dwarf_r18, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r19", nullptr, 4, 76, eEncodingUint, eFormatHex, {dwarf_r19, dwarf_r19, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r20", nullptr, 4, 80, eEncodingUint, eFormatHex, {dwarf_r20, dwarf_r20, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r21", nullptr, 4, 84, eEncodingUint, eFormatHex, {dwarf_r21, dwarf_r21, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r22", nullptr, 4, 88, eEncodingUint, eFormatHex, {dwarf_r22, dwarf_r22, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r23", nullptr, 4, 92, eEncodingUint, eFormatHex, {dwarf_r23, dwarf_r23, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r24", nullptr, 4, 96, eEncodingUint, eFormatHex, {dwarf_r24, dwarf_r24, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r25", nullptr, 4, 100, eEncodingUint, eFormatHex, {dwarf_r25, dwarf_r25, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r26", nullptr, 4, 104, eEncodingUint, eFormatHex, {dwarf_r26, dwarf_r26, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r27", nullptr, 4, 108, eEncodingUint, eFormatHex, {dwarf_r27, dwarf_r27, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r28", nullptr, 4, 112, eEncodingUint, eFormatHex, {dwarf_r28, dwarf_r28, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r29", nullptr, 4, 116, eEncodingUint, eFormatHex, {dwarf_r29, dwarf_r29, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r30", nullptr, 4, 120, eEncodingUint, eFormatHex, {dwarf_r30, dwarf_r30, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"r31", nullptr, 4, 124, eEncodingUint, eFormatHex, {dwarf_r31, dwarf_r31, LLDB_REGNUM_GENERIC_RA, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
{"pc", nullptr, 4, 128, eEncodingUint, eFormatHex, {dwarf_pc, dwarf_pc, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_REGNUM}, nullptr, nullptr, nullptr},
};

static const uint32_t k_num_register_infos = std::size(g_register_infos);

const lldb_private::RegisterInfo *
ABIV810::GetRegisterInfoArray(uint32_t &count) {
count = k_num_register_infos;
return g_register_infos;
}

bool ABIV810::PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
lldb::addr_t functionAddress,
lldb::addr_t returnAddress,
llvm::ArrayRef<lldb::addr_t> args) const {
llvm_unreachable("PrepareTrivialCall not implemented");
}

bool ABIV810::GetArgumentValues(lldb_private::Thread &thread,
lldb_private::ValueList &values) const {
llvm_unreachable("GetArgumentValues not implemented");
}

lldb_private::Status
ABIV810::SetReturnValueObject(lldb::StackFrameSP &frame_sp,
lldb::ValueObjectSP &new_value) {
llvm_unreachable("SetReturnValueObject not implemented");
}

lldb::ValueObjectSP
ABIV810::GetReturnValueObjectImpl(lldb_private::Thread &thread,
lldb_private::CompilerType &type) const {
llvm_unreachable("GetReturnValueObjectImpl not implemented");
}

bool
ABIV810::CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) {
return false;
}

bool
ABIV810::CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) {
unwind_plan.Clear();
unwind_plan.SetRegisterKind(eRegisterKindDWARF);

UnwindPlan::RowSP row(new UnwindPlan::Row);

row->GetCFAValue().SetIsRegisterDereferenced(dwarf_r2);
row->SetRegisterLocationToAtCFAPlusOffset(dwarf_r31, 0, true);

unwind_plan.AppendRow(row);
unwind_plan.SetSourceName("v810 default unwind plan");
unwind_plan.SetSourcedFromCompiler(eLazyBoolNo);
unwind_plan.SetUnwindPlanValidAtAllInstructions(eLazyBoolNo);
unwind_plan.SetUnwindPlanForSignalTrap(eLazyBoolNo);
return true;
}

ABISP
ABIV810::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) {
const llvm::Triple::ArchType arch_type = arch.GetTriple().getArch();
if (arch_type == llvm::Triple::v810) {
return ABISP(new ABIV810(std::move(process_sp), MakeMCRegisterInfo(arch)));
}
return ABISP();
}

void ABIV810::Initialize() {
PluginManager::RegisterPlugin(
GetPluginNameStatic(), "ABI for v810 targets", CreateInstance);
}

void ABIV810::Terminate() {
PluginManager::UnregisterPlugin(CreateInstance);
}
59 changes: 59 additions & 0 deletions lldb/source/Plugins/ABI/V810/ABIV810.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef LLDB_SOURCE_PLUGINS_ABI_V810_ABIV810_H
#define LLDB_SOURCE_PLUGINS_ABI_V810_ABIV810_H

#include "lldb/Target/ABI.h"
#include "lldb/lldb-private.h"

class ABIV810 : public lldb_private::RegInfoBasedABI {
public:
~ABIV810() override = default;

size_t GetRedZoneSize() const override { return 0; }

bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,
lldb::addr_t functionAddress,
lldb::addr_t returnAddress,
llvm::ArrayRef<lldb::addr_t> args) const override;

bool GetArgumentValues(lldb_private::Thread &thread,
lldb_private::ValueList &values) const override;

lldb_private::Status
SetReturnValueObject(lldb::StackFrameSP &frame_sp,
lldb::ValueObjectSP &new_value) override;

lldb::ValueObjectSP
GetReturnValueObjectImpl(lldb_private::Thread &thread,
lldb_private::CompilerType &type) const override;

bool
CreateFunctionEntryUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;

bool CreateDefaultUnwindPlan(lldb_private::UnwindPlan &unwind_plan) override;

bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override {
return false;
}

bool CallFrameAddressIsValid(lldb::addr_t cfa) override {
return true;
}

bool CodeAddressIsValid(lldb::addr_t pc) override {
return !(pc & 0xffffffff00000000);
}

const lldb_private::RegisterInfo *
GetRegisterInfoArray(uint32_t &count) override;

static void Initialize();
static void Terminate();
static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp, const lldb_private::ArchSpec &arch);

static llvm::StringRef GetPluginNameStatic() { return "v810"; }
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
private:
using lldb_private::RegInfoBasedABI::RegInfoBasedABI;
};

#endif
11 changes: 11 additions & 0 deletions lldb/source/Plugins/ABI/V810/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_lldb_library(lldbPluginABIV810 PLUGIN
ABIV810.cpp

LINK_LIBS
lldbCore
lldbSymbol
lldbTarget
LINK_COMPONENTS
Support
TargetParser
)
5 changes: 5 additions & 0 deletions lldb/source/Utility/ArchSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ static const CoreDefinition g_core_definitions[] = {
{eByteOrderLittle, 8, 4, 4, llvm::Triple::sparcv9,
ArchSpec::eCore_sparc9_generic, "sparcv9"},

{eByteOrderLittle, 4, 2, 4, llvm::Triple::v810,
ArchSpec::eCore_v810_generic, "v810"},

{eByteOrderLittle, 4, 1, 15, llvm::Triple::x86, ArchSpec::eCore_x86_32_i386,
"i386"},
{eByteOrderLittle, 4, 1, 15, llvm::Triple::x86, ArchSpec::eCore_x86_32_i486,
Expand Down Expand Up @@ -367,6 +370,8 @@ static const ArchDefinition g_macho_arch_def = {eArchTypeMachO,
static const ArchDefinitionEntry g_elf_arch_entries[] = {
{ArchSpec::eCore_sparc_generic, llvm::ELF::EM_SPARC, LLDB_INVALID_CPUTYPE,
0xFFFFFFFFu, 0xFFFFFFFFu}, // Sparc
{ArchSpec::eCore_v810_generic, llvm::ELF::EM_V810, LLDB_INVALID_CPUTYPE,
0xFFFFFFFFu, 0xFFFFFFFFu}, // V810
{ArchSpec::eCore_x86_32_i386, llvm::ELF::EM_386, LLDB_INVALID_CPUTYPE,
0xFFFFFFFFu, 0xFFFFFFFFu}, // Intel 80386
{ArchSpec::eCore_x86_32_i486, llvm::ELF::EM_IAMCU, LLDB_INVALID_CPUTYPE,
Expand Down

0 comments on commit eeecf70

Please sign in to comment.