Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.h
39646 views
//===---EmulateInstructionLoongArch.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_LOONGARCH_EMULATEINSTRUCTIONLOONGARCH_H9#define LLDB_SOURCE_PLUGINS_INSTRUCTION_LOONGARCH_EMULATEINSTRUCTIONLOONGARCH_H1011#include "lldb/Core/EmulateInstruction.h"12#include "lldb/Interpreter/OptionValue.h"13#include "lldb/Utility/Log.h"14#include "lldb/Utility/Status.h"15#include <optional>1617namespace lldb_private {1819class EmulateInstructionLoongArch : public EmulateInstruction {20public:21static llvm::StringRef GetPluginNameStatic() { return "LoongArch"; }2223static llvm::StringRef GetPluginDescriptionStatic() {24return "Emulate instructions for the LoongArch architecture.";25}2627static bool SupportsThisInstructionType(InstructionType inst_type) {28return inst_type == eInstructionTypePCModifying;29}3031static bool SupportsThisArch(const ArchSpec &arch);3233static lldb_private::EmulateInstruction *34CreateInstance(const lldb_private::ArchSpec &arch, InstructionType inst_type);3536static void Initialize();3738static void Terminate();3940public:41EmulateInstructionLoongArch(const ArchSpec &arch) : EmulateInstruction(arch) {42m_arch_subtype = arch.GetMachine();43}4445llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }4647bool SupportsEmulatingInstructionsOfType(InstructionType inst_type) override {48return SupportsThisInstructionType(inst_type);49}5051bool SetTargetTriple(const ArchSpec &arch) override;52bool ReadInstruction() override;53bool EvaluateInstruction(uint32_t options) override;54bool TestEmulation(Stream &out_stream, ArchSpec &arch,55OptionValueDictionary *test_data) override;5657std::optional<RegisterInfo> GetRegisterInfo(lldb::RegisterKind reg_kind,58uint32_t reg_num) override;59lldb::addr_t ReadPC(bool *success);60bool WritePC(lldb::addr_t pc);61bool IsLoongArch64() { return m_arch_subtype == llvm::Triple::loongarch64; }62bool TestExecute(uint32_t inst);6364private:65struct Opcode {66uint32_t mask;67uint32_t value;68bool (EmulateInstructionLoongArch::*callback)(uint32_t opcode);69const char *name;70};7172llvm::Triple::ArchType m_arch_subtype;73Opcode *GetOpcodeForInstruction(uint32_t inst);7475bool EmulateBEQZ(uint32_t inst);76bool EmulateBNEZ(uint32_t inst);77bool EmulateBCEQZ(uint32_t inst);78bool EmulateBCNEZ(uint32_t inst);79bool EmulateJIRL(uint32_t inst);80bool EmulateB(uint32_t inst);81bool EmulateBL(uint32_t inst);82bool EmulateBEQ(uint32_t inst);83bool EmulateBNE(uint32_t inst);84bool EmulateBLT(uint32_t inst);85bool EmulateBGE(uint32_t inst);86bool EmulateBLTU(uint32_t inst);87bool EmulateBGEU(uint32_t inst);88bool EmulateNonJMP(uint32_t inst);8990bool EmulateBEQZ64(uint32_t inst);91bool EmulateBNEZ64(uint32_t inst);92bool EmulateBCEQZ64(uint32_t inst);93bool EmulateBCNEZ64(uint32_t inst);94bool EmulateJIRL64(uint32_t inst);95bool EmulateB64(uint32_t inst);96bool EmulateBL64(uint32_t inst);97bool EmulateBEQ64(uint32_t inst);98bool EmulateBNE64(uint32_t inst);99bool EmulateBLT64(uint32_t inst);100bool EmulateBGE64(uint32_t inst);101bool EmulateBLTU64(uint32_t inst);102bool EmulateBGEU64(uint32_t inst);103};104105} // namespace lldb_private106107#endif // LLDB_SOURCE_PLUGINS_INSTRUCTION_LOONGARCH_EMULATEINSTRUCTIONLOONGARCH_H108109110