Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.h
39653 views
//===-- EmulateInstructionRISCV.h -----------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_EMULATEINSTRUCTIONRISCV_H9#define LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_EMULATEINSTRUCTIONRISCV_H1011#include "RISCVInstructions.h"1213#include "lldb/Core/EmulateInstruction.h"14#include "lldb/Interpreter/OptionValue.h"15#include "lldb/Utility/Log.h"16#include "lldb/Utility/RegisterValue.h"17#include "lldb/Utility/Status.h"18#include <optional>1920namespace lldb_private {2122class EmulateInstructionRISCV : public EmulateInstruction {23public:24static llvm::StringRef GetPluginNameStatic() { return "riscv"; }2526static llvm::StringRef GetPluginDescriptionStatic() {27return "Emulate instructions for the RISC-V architecture.";28}2930static bool SupportsThisInstructionType(InstructionType inst_type) {31switch (inst_type) {32case eInstructionTypeAny:33case eInstructionTypePCModifying:34return true;35case eInstructionTypePrologueEpilogue:36case eInstructionTypeAll:37return false;38}39llvm_unreachable("Fully covered switch above!");40}4142static bool SupportsThisArch(const ArchSpec &arch);4344static lldb_private::EmulateInstruction *45CreateInstance(const lldb_private::ArchSpec &arch, InstructionType inst_type);4647static void Initialize();4849static void Terminate();5051public:52EmulateInstructionRISCV(const ArchSpec &arch) : EmulateInstruction(arch) {}5354llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }5556bool SupportsEmulatingInstructionsOfType(InstructionType inst_type) override {57return SupportsThisInstructionType(inst_type);58}5960bool SetTargetTriple(const ArchSpec &arch) override;61bool ReadInstruction() override;62std::optional<uint32_t> GetLastInstrSize() override { return m_last_size; }63bool EvaluateInstruction(uint32_t options) override;64bool TestEmulation(Stream &out_stream, ArchSpec &arch,65OptionValueDictionary *test_data) override;66std::optional<RegisterInfo> GetRegisterInfo(lldb::RegisterKind reg_kind,67uint32_t reg_num) override;6869std::optional<lldb::addr_t> ReadPC();70bool WritePC(lldb::addr_t pc);7172std::optional<DecodeResult> ReadInstructionAt(lldb::addr_t addr);73std::optional<DecodeResult> Decode(uint32_t inst);74bool Execute(DecodeResult inst, bool ignore_cond);7576template <typename T>77std::enable_if_t<std::is_integral_v<T>, std::optional<T>>78ReadMem(uint64_t addr) {79EmulateInstructionRISCV::Context ctx;80ctx.type = EmulateInstruction::eContextRegisterLoad;81ctx.SetNoArgs();82bool success = false;83T result = ReadMemoryUnsigned(ctx, addr, sizeof(T), T(), &success);84if (!success)85return {}; // aka return false86return result;87}8889template <typename T> bool WriteMem(uint64_t addr, uint64_t value) {90EmulateInstructionRISCV::Context ctx;91ctx.type = EmulateInstruction::eContextRegisterStore;92ctx.SetNoArgs();93return WriteMemoryUnsigned(ctx, addr, value, sizeof(T));94}9596llvm::RoundingMode GetRoundingMode();97bool SetAccruedExceptions(llvm::APFloatBase::opStatus);9899private:100/// Last decoded instruction from m_opcode101DecodeResult m_decoded;102/// Last decoded instruction size estimate.103std::optional<uint32_t> m_last_size;104};105106} // namespace lldb_private107108#endif // LLDB_SOURCE_PLUGINS_INSTRUCTION_RISCV_EMULATEINSTRUCTIONRISCV_H109110111