129 lines · c
1//===-- ABISysV_riscv.h -----------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef liblldb_ABISysV_riscv_h_10#define liblldb_ABISysV_riscv_h_11 12// Other libraries and framework includes13#include "llvm/TargetParser/Triple.h"14 15// Project includes16#include "lldb/Target/ABI.h"17#include "lldb/Target/Process.h"18#include "lldb/Utility/Flags.h"19#include "lldb/lldb-private.h"20 21class ABISysV_riscv : public lldb_private::RegInfoBasedABI {22public:23 ~ABISysV_riscv() override = default;24 25 size_t GetRedZoneSize() const override { return 0; }26 27 bool PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,28 lldb::addr_t functionAddress,29 lldb::addr_t returnAddress,30 llvm::ArrayRef<lldb::addr_t> args) const override;31 32 // Special thread plan for GDB style non-jit function calls.33 bool34 PrepareTrivialCall(lldb_private::Thread &thread, lldb::addr_t sp,35 lldb::addr_t functionAddress, lldb::addr_t returnAddress,36 llvm::Type &prototype,37 llvm::ArrayRef<ABI::CallArgument> args) const override;38 39 bool GetArgumentValues(lldb_private::Thread &thread,40 lldb_private::ValueList &values) const override;41 42 lldb_private::Status43 SetReturnValueObject(lldb::StackFrameSP &frame_sp,44 lldb::ValueObjectSP &new_value) override;45 46 lldb::ValueObjectSP47 GetReturnValueObjectImpl(lldb_private::Thread &thread,48 lldb_private::CompilerType &type) const override;49 50 // Specialized to work with llvm IR types.51 lldb::ValueObjectSP GetReturnValueObjectImpl(lldb_private::Thread &thread,52 llvm::Type &type) const override;53 54 lldb::UnwindPlanSP CreateFunctionEntryUnwindPlan() override;55 56 lldb::UnwindPlanSP CreateDefaultUnwindPlan() override;57 58 bool RegisterIsVolatile(const lldb_private::RegisterInfo *reg_info) override;59 60 bool CallFrameAddressIsValid(lldb::addr_t cfa) override {61 // The CFA must be 128 bit aligned, unless the E ABI is used62 lldb_private::ArchSpec arch = GetProcessSP()->GetTarget().GetArchitecture();63 lldb_private::Flags arch_flags = arch.GetFlags();64 if (arch_flags.Test(lldb_private::ArchSpec::eRISCV_rve))65 return (cfa & 0x3ull) == 0;66 return (cfa & 0xfull) == 0;67 }68 69 void SetIsRV64(bool is_rv64) { m_is_rv64 = is_rv64; }70 71 bool CodeAddressIsValid(lldb::addr_t pc) override {72 // Calls can use the least significant bit to store auxiliary information,73 // so no strict check is done for alignment.74 75 lldb_private::ArchSpec arch = GetProcessSP()->GetTarget().GetArchitecture();76 77 // <addr> & 2 set is a fault if C extension is not used.78 lldb_private::Flags arch_flags(arch.GetFlags());79 if (!arch_flags.Test(lldb_private::ArchSpec::eRISCV_rvc) && (pc & 2))80 return false;81 82 // Make sure 64 bit addr_t only has lower 32 bits set on riscv3283 llvm::Triple::ArchType machine = arch.GetMachine();84 if (llvm::Triple::riscv32 == machine)85 return (pc <= UINT32_MAX);86 87 return true;88 }89 90 const lldb_private::RegisterInfo *91 GetRegisterInfoArray(uint32_t &count) override;92 93 //------------------------------------------------------------------94 // Static Functions95 //------------------------------------------------------------------96 97 static void Initialize();98 99 static void Terminate();100 101 static lldb::ABISP CreateInstance(lldb::ProcessSP process_sp,102 const lldb_private::ArchSpec &arch);103 104 static llvm::StringRef GetPluginNameStatic() { return "sysv-riscv"; }105 106 //------------------------------------------------------------------107 // PluginInterface protocol108 //------------------------------------------------------------------109 110 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }111 112protected:113 void AugmentRegisterInfo(114 std::vector<lldb_private::DynamicRegisterInfo::Register> ®s) override;115 116 bool RegisterIsCalleeSaved(const lldb_private::RegisterInfo *reg_info);117 118private:119 lldb::ValueObjectSP120 GetReturnValueObjectSimple(lldb_private::Thread &thread,121 lldb_private::CompilerType &ast_type) const;122 123 using lldb_private::RegInfoBasedABI::RegInfoBasedABI; // Call CreateInstance124 // instead.125 bool m_is_rv64; // true if target is riscv64; false if target is riscv32126};127 128#endif // liblldb_ABISysV_riscv_h_129