107 lines · c
1//===---EmulateInstructionLoongArch.h--------------------------------------===//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 LLDB_SOURCE_PLUGINS_INSTRUCTION_LOONGARCH_EMULATEINSTRUCTIONLOONGARCH_H10#define LLDB_SOURCE_PLUGINS_INSTRUCTION_LOONGARCH_EMULATEINSTRUCTIONLOONGARCH_H11 12#include "lldb/Core/EmulateInstruction.h"13#include "lldb/Interpreter/OptionValue.h"14#include "lldb/Utility/Log.h"15#include "lldb/Utility/Status.h"16#include <optional>17 18namespace lldb_private {19 20class EmulateInstructionLoongArch : public EmulateInstruction {21public:22 static llvm::StringRef GetPluginNameStatic() { return "LoongArch"; }23 24 static llvm::StringRef GetPluginDescriptionStatic() {25 return "Emulate instructions for the LoongArch architecture.";26 }27 28 static bool SupportsThisInstructionType(InstructionType inst_type) {29 return inst_type == eInstructionTypePCModifying;30 }31 32 static bool SupportsThisArch(const ArchSpec &arch);33 34 static lldb_private::EmulateInstruction *35 CreateInstance(const lldb_private::ArchSpec &arch, InstructionType inst_type);36 37 static void Initialize();38 39 static void Terminate();40 41public:42 EmulateInstructionLoongArch(const ArchSpec &arch) : EmulateInstruction(arch) {43 m_arch_subtype = arch.GetMachine();44 }45 46 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }47 48 bool SupportsEmulatingInstructionsOfType(InstructionType inst_type) override {49 return SupportsThisInstructionType(inst_type);50 }51 52 bool SetTargetTriple(const ArchSpec &arch) override;53 bool ReadInstruction() override;54 bool EvaluateInstruction(uint32_t options) override;55 bool TestEmulation(Stream &out_stream, ArchSpec &arch,56 OptionValueDictionary *test_data) override;57 58 std::optional<RegisterInfo> GetRegisterInfo(lldb::RegisterKind reg_kind,59 uint32_t reg_num) override;60 bool IsLoongArch64() { return m_arch_subtype == llvm::Triple::loongarch64; }61 bool TestExecute(uint32_t inst);62 63private:64 struct Opcode {65 uint32_t mask;66 uint32_t value;67 bool (EmulateInstructionLoongArch::*callback)(uint32_t opcode);68 const char *name;69 };70 71 llvm::Triple::ArchType m_arch_subtype;72 Opcode *GetOpcodeForInstruction(uint32_t inst);73 74 bool EmulateBEQZ(uint32_t inst);75 bool EmulateBNEZ(uint32_t inst);76 bool EmulateBCEQZ(uint32_t inst);77 bool EmulateBCNEZ(uint32_t inst);78 bool EmulateJIRL(uint32_t inst);79 bool EmulateB(uint32_t inst);80 bool EmulateBL(uint32_t inst);81 bool EmulateBEQ(uint32_t inst);82 bool EmulateBNE(uint32_t inst);83 bool EmulateBLT(uint32_t inst);84 bool EmulateBGE(uint32_t inst);85 bool EmulateBLTU(uint32_t inst);86 bool EmulateBGEU(uint32_t inst);87 bool EmulateNonJMP(uint32_t inst);88 89 bool EmulateBEQZ64(uint32_t inst);90 bool EmulateBNEZ64(uint32_t inst);91 bool EmulateBCEQZ64(uint32_t inst);92 bool EmulateBCNEZ64(uint32_t inst);93 bool EmulateJIRL64(uint32_t inst);94 bool EmulateB64(uint32_t inst);95 bool EmulateBL64(uint32_t inst);96 bool EmulateBEQ64(uint32_t inst);97 bool EmulateBNE64(uint32_t inst);98 bool EmulateBLT64(uint32_t inst);99 bool EmulateBGE64(uint32_t inst);100 bool EmulateBLTU64(uint32_t inst);101 bool EmulateBGEU64(uint32_t inst);102};103 104} // namespace lldb_private105 106#endif // LLDB_SOURCE_PLUGINS_INSTRUCTION_LOONGARCH_EMULATEINSTRUCTIONLOONGARCH_H107