LLDB mainline
EmulateInstructionARM64.h
Go to the documentation of this file.
1//===-- EmulateInstructionARM64.h -------------------------------*- C++ -*-===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_SOURCE_PLUGINS_INSTRUCTION_ARM64_EMULATEINSTRUCTIONARM64_H
10#define LLDB_SOURCE_PLUGINS_INSTRUCTION_ARM64_EMULATEINSTRUCTIONARM64_H
11
15#include "lldb/Utility/Status.h"
16#include <optional>
17
19public:
22 m_ignore_conditions(false) {}
23
24 static void Initialize();
25
26 static void Terminate();
27
28 static llvm::StringRef GetPluginNameStatic() { return "arm64"; }
29
30 static llvm::StringRef GetPluginDescriptionStatic();
31
35
38 switch (inst_type) {
41 return true;
42
45 return false;
46 }
47 return false;
48 }
49
50 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
51
52 bool SetTargetTriple(const lldb_private::ArchSpec &arch) override;
53
55 lldb_private::InstructionType inst_type) override {
57 }
58
59 bool ReadInstruction() override;
60
61 bool EvaluateInstruction(uint32_t evaluate_options) override;
62
65 lldb_private::OptionValueDictionary *test_data) override {
66 return false;
67 }
68
69 std::optional<lldb_private::RegisterInfo>
70 GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) override;
71
72 bool
74
76
83 };
84
86
88
90
91 enum ExceptionLevel { EL0 = 0, EL1 = 1, EL2 = 2, EL3 = 3 };
92
102 };
103
105
107
109
111
113
114 enum StackPointerSelection { SP0 = 0, SPx = 1 };
115
117
123 };
124
125 enum AccType {
131 };
132
133 typedef struct {
134 uint32_t N : 1, V : 1, C : 1,
135 Z : 1, // condition code flags – can also be accessed as
136 // PSTATE.[N,Z,C,V]
137 Q : 1, // AArch32 only – CSPR.Q bit
138 IT : 8, // AArch32 only – CPSR.IT bits
139 J : 1, // AArch32 only – CSPR.J bit
140 T : 1, // AArch32 only – CPSR.T bit
141 SS : 1, // Single step process state bit
142 IL : 1, // Illegal state bit
143 D : 1, A : 1, I : 1,
144 F : 1, // Interrupt masks – can also be accessed as PSTATE.[D,A,I,F]
145 E : 1, // AArch32 only – CSPR.E bit
146 M : 5, // AArch32 only – mode encodings
147 RW : 1, // Current register width – 0 is AArch64, 1 is AArch32
148 EL : 2, // Current exception level (see ExceptionLevel enum)
149 SP : 1; // AArch64 only - Stack Pointer selection (see
150 // StackPointerSelection enum)
151 } ProcState;
152
153protected:
154 static uint64_t AddWithCarry(uint32_t N, uint64_t x, uint64_t y, bool carry_in,
156
157 typedef struct {
158 uint32_t mask;
159 uint32_t value;
160 uint32_t vfp_variants;
161 bool (EmulateInstructionARM64::*callback)(const uint32_t opcode);
162 const char *name;
163 } Opcode;
164
165 static Opcode *GetOpcodeForInstruction(const uint32_t opcode);
166
167 uint32_t GetFramePointerRegisterNumber() const;
168
169 bool BranchTo(const Context &context, uint32_t N, lldb::addr_t target);
170
171 bool ConditionHolds(const uint32_t cond);
172
173 bool UsingAArch32();
174
175 bool EmulateADDSUBImm(const uint32_t opcode);
176
177 template <AddrMode a_mode> bool EmulateLDPSTP(const uint32_t opcode);
178
179 template <AddrMode a_mode> bool EmulateLDRSTRImm(const uint32_t opcode);
180
181 bool EmulateB(const uint32_t opcode);
182
183 bool EmulateBcond(const uint32_t opcode);
184
185 bool EmulateCBZ(const uint32_t opcode);
186
187 bool EmulateTBZ(const uint32_t opcode);
188
190 ProcState m_emulated_pstate; // This can get updated by the opcode.
192};
193
194#endif // LLDB_SOURCE_PLUGINS_INSTRUCTION_ARM64_EMULATEINSTRUCTIONARM64_H
bool EmulateLDRSTRImm(const uint32_t opcode)
std::optional< lldb_private::RegisterInfo > GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num) override
static bool SupportsEmulatingInstructionsOfTypeStatic(lldb_private::InstructionType inst_type)
static llvm::StringRef GetPluginNameStatic()
llvm::StringRef GetPluginName() override
bool EmulateLDPSTP(const uint32_t opcode)
bool EmulateTBZ(const uint32_t opcode)
bool EmulateBcond(const uint32_t opcode)
static Opcode * GetOpcodeForInstruction(const uint32_t opcode)
EmulateInstructionARM64(const lldb_private::ArchSpec &arch)
bool TestEmulation(lldb_private::Stream &out_stream, lldb_private::ArchSpec &arch, lldb_private::OptionValueDictionary *test_data) override
bool BranchTo(const Context &context, uint32_t N, lldb::addr_t target)
bool EmulateCBZ(const uint32_t opcode)
bool SetTargetTriple(const lldb_private::ArchSpec &arch) override
bool CreateFunctionEntryUnwind(lldb_private::UnwindPlan &unwind_plan) override
bool EvaluateInstruction(uint32_t evaluate_options) override
static llvm::StringRef GetPluginDescriptionStatic()
bool EmulateADDSUBImm(const uint32_t opcode)
bool ConditionHolds(const uint32_t cond)
bool EmulateB(const uint32_t opcode)
uint32_t GetFramePointerRegisterNumber() const
static lldb_private::EmulateInstruction * CreateInstance(const lldb_private::ArchSpec &arch, lldb_private::InstructionType inst_type)
bool SupportsEmulatingInstructionsOfType(lldb_private::InstructionType inst_type) override
static uint64_t AddWithCarry(uint32_t N, uint64_t x, uint64_t y, bool carry_in, EmulateInstructionARM64::ProcState &proc_state)
An architecture specification class.
Definition: ArchSpec.h:31
"lldb/Core/EmulateInstruction.h" A class that allows emulation of CPU opcodes.
EmulateInstruction(const ArchSpec &arch)
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
InstructionType
Instruction types.
uint64_t addr_t
Definition: lldb-types.h:79
RegisterKind
Register numbering types.