1 //===-- EmulateInstructionARM64.h -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef EmulateInstructionARM64_h_
11 #define EmulateInstructionARM64_h_
13 #include "Plugins/Process/Utility/ARMDefines.h"
14 #include "lldb/Core/EmulateInstruction.h"
15 #include "lldb/Interpreter/OptionValue.h"
16 #include "lldb/Utility/Status.h"
18 class EmulateInstructionARM64 : public lldb_private::EmulateInstruction {
20 EmulateInstructionARM64(const lldb_private::ArchSpec &arch)
21 : EmulateInstruction(arch), m_opcode_pstate(), m_emulated_pstate(),
22 m_ignore_conditions(false) {}
24 static void Initialize();
26 static void Terminate();
28 static lldb_private::ConstString GetPluginNameStatic();
30 static const char *GetPluginDescriptionStatic();
32 static lldb_private::EmulateInstruction *
33 CreateInstance(const lldb_private::ArchSpec &arch,
34 lldb_private::InstructionType inst_type);
36 static bool SupportsEmulatingInstructionsOfTypeStatic(
37 lldb_private::InstructionType inst_type) {
39 case lldb_private::eInstructionTypeAny:
40 case lldb_private::eInstructionTypePrologueEpilogue:
43 case lldb_private::eInstructionTypePCModifying:
44 case lldb_private::eInstructionTypeAll:
50 lldb_private::ConstString GetPluginName() override;
52 uint32_t GetPluginVersion() override { return 1; }
54 bool SetTargetTriple(const lldb_private::ArchSpec &arch) override;
56 bool SupportsEmulatingInstructionsOfType(
57 lldb_private::InstructionType inst_type) override {
58 return SupportsEmulatingInstructionsOfTypeStatic(inst_type);
61 bool ReadInstruction() override;
63 bool EvaluateInstruction(uint32_t evaluate_options) override;
65 bool TestEmulation(lldb_private::Stream *out_stream,
66 lldb_private::ArchSpec &arch,
67 lldb_private::OptionValueDictionary *test_data) override {
71 bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num,
72 lldb_private::RegisterInfo ®_info) override;
75 CreateFunctionEntryUnwind(lldb_private::UnwindPlan &unwind_plan) override;
77 typedef enum { AddrMode_OFF, AddrMode_PRE, AddrMode_POST } AddrMode;
87 typedef enum { CountOp_CLZ, CountOp_CLS, CountOp_CNT } CountOp;
89 typedef enum { RevOp_RBIT, RevOp_REV16, RevOp_REV32, RevOp_REV64 } RevOp;
91 typedef enum { BitwiseOp_NOT, BitwiseOp_RBIT } BitwiseOp;
93 typedef enum { EL0 = 0, EL1 = 1, EL2 = 2, EL3 = 3 } ExceptionLevel;
106 typedef enum { ExtractType_LEFT, ExtractType_RIGHT } ExtractType;
108 typedef enum { LogicalOp_AND, LogicalOp_EOR, LogicalOp_ORR } LogicalOp;
110 typedef enum { MemOp_LOAD, MemOp_STORE, MemOp_PREFETCH, MemOp_NOP } MemOp;
112 typedef enum { MoveWideOp_N, MoveWideOp_Z, MoveWideOp_K } MoveWideOp;
121 typedef enum { SP0 = 0, SPx = 1 } StackPointerSelection;
124 Unpredictable_WBOVERLAP,
125 Unpredictable_LDPOVERLAP
131 Constraint_SUPPRESSWB,
144 uint32_t N : 1, V : 1, C : 1,
145 Z : 1, // condition code flags – can also be accessed as
147 Q : 1, // AArch32 only – CSPR.Q bit
148 IT : 8, // AArch32 only – CPSR.IT bits
149 J : 1, // AArch32 only – CSPR.J bit
150 T : 1, // AArch32 only – CPSR.T bit
151 SS : 1, // Single step process state bit
152 IL : 1, // Illegal state bit
154 F : 1, // Interrupt masks – can also be accessed as PSTATE.[D,A,I,F]
155 E : 1, // AArch32 only – CSPR.E bit
156 M : 5, // AArch32 only – mode encodings
157 RW : 1, // Current register width – 0 is AArch64, 1 is AArch32
158 EL : 2, // Current exception level (see ExceptionLevel enum)
159 SP : 1; // AArch64 only - Stack Pointer selection (see
160 // StackPointerSelection enum)
167 uint32_t vfp_variants;
168 bool (EmulateInstructionARM64::*callback)(const uint32_t opcode);
172 static Opcode *GetOpcodeForInstruction(const uint32_t opcode);
174 uint32_t GetFramePointerRegisterNumber() const;
176 bool BranchTo(const Context &context, uint32_t N, lldb::addr_t target);
178 bool ConditionHolds(const uint32_t cond);
182 bool EmulateADDSUBImm(const uint32_t opcode);
184 template <AddrMode a_mode> bool EmulateLDPSTP(const uint32_t opcode);
186 template <AddrMode a_mode> bool EmulateLDRSTRImm(const uint32_t opcode);
188 bool EmulateB(const uint32_t opcode);
190 bool EmulateBcond(const uint32_t opcode);
192 bool EmulateCBZ(const uint32_t opcode);
194 bool EmulateTBZ(const uint32_t opcode);
196 ProcState m_opcode_pstate;
197 ProcState m_emulated_pstate; // This can get updated by the opcode.
198 bool m_ignore_conditions;
201 #endif // EmulateInstructionARM64_h_