1 //===-- EmulateInstructionARM64.h -------------------------------*- C++ -*-===//
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-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef EmulateInstructionARM64_h_
10 #define EmulateInstructionARM64_h_
12 #include "Plugins/Process/Utility/ARMDefines.h"
13 #include "lldb/Core/EmulateInstruction.h"
14 #include "lldb/Interpreter/OptionValue.h"
15 #include "lldb/Utility/Status.h"
17 class EmulateInstructionARM64 : public lldb_private::EmulateInstruction {
19 EmulateInstructionARM64(const lldb_private::ArchSpec &arch)
20 : EmulateInstruction(arch), m_opcode_pstate(), m_emulated_pstate(),
21 m_ignore_conditions(false) {}
23 static void Initialize();
25 static void Terminate();
27 static lldb_private::ConstString GetPluginNameStatic();
29 static const char *GetPluginDescriptionStatic();
31 static lldb_private::EmulateInstruction *
32 CreateInstance(const lldb_private::ArchSpec &arch,
33 lldb_private::InstructionType inst_type);
35 static bool SupportsEmulatingInstructionsOfTypeStatic(
36 lldb_private::InstructionType inst_type) {
38 case lldb_private::eInstructionTypeAny:
39 case lldb_private::eInstructionTypePrologueEpilogue:
42 case lldb_private::eInstructionTypePCModifying:
43 case lldb_private::eInstructionTypeAll:
49 lldb_private::ConstString GetPluginName() override;
51 uint32_t GetPluginVersion() override { return 1; }
53 bool SetTargetTriple(const lldb_private::ArchSpec &arch) override;
55 bool SupportsEmulatingInstructionsOfType(
56 lldb_private::InstructionType inst_type) override {
57 return SupportsEmulatingInstructionsOfTypeStatic(inst_type);
60 bool ReadInstruction() override;
62 bool EvaluateInstruction(uint32_t evaluate_options) override;
64 bool TestEmulation(lldb_private::Stream *out_stream,
65 lldb_private::ArchSpec &arch,
66 lldb_private::OptionValueDictionary *test_data) override {
70 bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num,
71 lldb_private::RegisterInfo ®_info) override;
74 CreateFunctionEntryUnwind(lldb_private::UnwindPlan &unwind_plan) override;
76 enum AddrMode { AddrMode_OFF, AddrMode_PRE, AddrMode_POST };
86 enum CountOp { CountOp_CLZ, CountOp_CLS, CountOp_CNT };
88 enum RevOp { RevOp_RBIT, RevOp_REV16, RevOp_REV32, RevOp_REV64 };
90 enum BitwiseOp { BitwiseOp_NOT, BitwiseOp_RBIT };
92 enum ExceptionLevel { EL0 = 0, EL1 = 1, EL2 = 2, EL3 = 3 };
105 enum ExtractType { ExtractType_LEFT, ExtractType_RIGHT };
107 enum LogicalOp { LogicalOp_AND, LogicalOp_EOR, LogicalOp_ORR };
109 enum MemOp { MemOp_LOAD, MemOp_STORE, MemOp_PREFETCH, MemOp_NOP };
111 enum MoveWideOp { MoveWideOp_N, MoveWideOp_Z, MoveWideOp_K };
113 enum ShiftType { ShiftType_LSL, ShiftType_LSR, ShiftType_ASR, ShiftType_ROR };
115 enum StackPointerSelection { SP0 = 0, SPx = 1 };
117 enum Unpredictable { Unpredictable_WBOVERLAP, Unpredictable_LDPOVERLAP };
119 enum ConstraintType {
122 Constraint_SUPPRESSWB,
135 uint32_t N : 1, V : 1, C : 1,
136 Z : 1, // condition code flags – can also be accessed as
138 Q : 1, // AArch32 only – CSPR.Q bit
139 IT : 8, // AArch32 only – CPSR.IT bits
140 J : 1, // AArch32 only – CSPR.J bit
141 T : 1, // AArch32 only – CPSR.T bit
142 SS : 1, // Single step process state bit
143 IL : 1, // Illegal state bit
145 F : 1, // Interrupt masks – can also be accessed as PSTATE.[D,A,I,F]
146 E : 1, // AArch32 only – CSPR.E bit
147 M : 5, // AArch32 only – mode encodings
148 RW : 1, // Current register width – 0 is AArch64, 1 is AArch32
149 EL : 2, // Current exception level (see ExceptionLevel enum)
150 SP : 1; // AArch64 only - Stack Pointer selection (see
151 // StackPointerSelection enum)
158 uint32_t vfp_variants;
159 bool (EmulateInstructionARM64::*callback)(const uint32_t opcode);
163 static Opcode *GetOpcodeForInstruction(const uint32_t opcode);
165 uint32_t GetFramePointerRegisterNumber() const;
167 bool BranchTo(const Context &context, uint32_t N, lldb::addr_t target);
169 bool ConditionHolds(const uint32_t cond);
173 bool EmulateADDSUBImm(const uint32_t opcode);
175 template <AddrMode a_mode> bool EmulateLDPSTP(const uint32_t opcode);
177 template <AddrMode a_mode> bool EmulateLDRSTRImm(const uint32_t opcode);
179 bool EmulateB(const uint32_t opcode);
181 bool EmulateBcond(const uint32_t opcode);
183 bool EmulateCBZ(const uint32_t opcode);
185 bool EmulateTBZ(const uint32_t opcode);
187 ProcState m_opcode_pstate;
188 ProcState m_emulated_pstate; // This can get updated by the opcode.
189 bool m_ignore_conditions;
192 #endif // EmulateInstructionARM64_h_