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 
18 public:
21  m_ignore_conditions(false) {}
22 
23  static void Initialize();
24 
25  static void Terminate();
26 
28 
29  static const char *GetPluginDescriptionStatic();
30 
34 
37  switch (inst_type) {
40  return true;
41 
44  return false;
45  }
46  return false;
47  }
48 
50 
51  uint32_t GetPluginVersion() override { return 1; }
52 
53  bool SetTargetTriple(const lldb_private::ArchSpec &arch) override;
54 
56  lldb_private::InstructionType inst_type) override {
58  }
59 
60  bool ReadInstruction() override;
61 
62  bool EvaluateInstruction(uint32_t evaluate_options) override;
63 
66  lldb_private::OptionValueDictionary *test_data) override {
67  return false;
68  }
69 
70  bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num,
71  lldb_private::RegisterInfo &reg_info) override;
72 
73  bool
75 
77 
78  enum BranchType {
84  };
85 
87 
89 
91 
92  enum ExceptionLevel { EL0 = 0, EL1 = 1, EL2 = 2, EL3 = 3 };
93 
94  enum ExtendType {
103  };
104 
106 
108 
110 
112 
114 
115  enum StackPointerSelection { SP0 = 0, SPx = 1 };
116 
118 
124  };
125 
126  enum AccType {
132  };
133 
134  typedef struct {
135  uint32_t N : 1, V : 1, C : 1,
136  Z : 1, // condition code flags – can also be accessed as
137  // PSTATE.[N,Z,C,V]
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
144  D : 1, A : 1, I : 1,
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)
152  } ProcState;
153 
154 protected:
155  static uint64_t AddWithCarry(uint32_t N, uint64_t x, uint64_t y, bool carry_in,
157 
158  typedef struct {
162  bool (EmulateInstructionARM64::*callback)(const uint32_t opcode);
163  const char *name;
164  } Opcode;
165 
166  static Opcode *GetOpcodeForInstruction(const uint32_t opcode);
167 
169 
170  bool BranchTo(const Context &context, uint32_t N, lldb::addr_t target);
171 
172  bool ConditionHolds(const uint32_t cond);
173 
174  bool UsingAArch32();
175 
176  bool EmulateADDSUBImm(const uint32_t opcode);
177 
178  template <AddrMode a_mode> bool EmulateLDPSTP(const uint32_t opcode);
179 
180  template <AddrMode a_mode> bool EmulateLDRSTRImm(const uint32_t opcode);
181 
182  bool EmulateB(const uint32_t opcode);
183 
184  bool EmulateBcond(const uint32_t opcode);
185 
186  bool EmulateCBZ(const uint32_t opcode);
187 
188  bool EmulateTBZ(const uint32_t opcode);
189 
191  ProcState m_emulated_pstate; // This can get updated by the opcode.
193 };
194 
195 #endif // LLDB_SOURCE_PLUGINS_INSTRUCTION_ARM64_EMULATEINSTRUCTIONARM64_H
EmulateInstructionARM64::ProcState::F
uint32_t F
Definition: EmulateInstructionARM64.h:145
EmulateInstructionARM64::ProcState::Z
uint32_t Z
Definition: EmulateInstructionARM64.h:136
lldb_private::eInstructionTypePCModifying
@ eInstructionTypePCModifying
Definition: lldb-private-enumerations.h:123
EmulateInstructionARM64::BranchType
BranchType
Definition: EmulateInstructionARM64.h:78
EmulateInstructionARM64::ProcState::IT
uint32_t IT
Definition: EmulateInstructionARM64.h:139
lldb_private::ArchSpec
Definition: ArchSpec.h:33
EmulateInstructionARM64::ProcState
Definition: EmulateInstructionARM64.h:134
EmulateInstructionARM64::Unpredictable_WBOVERLAP
@ Unpredictable_WBOVERLAP
Definition: EmulateInstructionARM64.h:117
EmulateInstructionARM64::ExtractType_LEFT
@ ExtractType_LEFT
Definition: EmulateInstructionARM64.h:105
EmulateInstructionARM64::GetPluginDescriptionStatic
static const char * GetPluginDescriptionStatic()
Definition: EmulateInstructionARM64.cpp:130
EmulateInstructionARM64::ExtendType
ExtendType
Definition: EmulateInstructionARM64.h:94
EmulateInstructionARM64::SPx
@ SPx
Definition: EmulateInstructionARM64.h:115
EmulateInstructionARM64::AddWithCarry
static uint64_t AddWithCarry(uint32_t N, uint64_t x, uint64_t y, bool carry_in, EmulateInstructionARM64::ProcState &proc_state)
Definition: EmulateInstructionARM64.cpp:571
EmulateInstructionARM64::BitwiseOp_NOT
@ BitwiseOp_NOT
Definition: EmulateInstructionARM64.h:90
EmulateInstructionARM64::Opcode
Definition: EmulateInstructionARM64.h:158
EmulateInstructionARM64::GetPluginNameStatic
static lldb_private::ConstString GetPluginNameStatic()
Definition: EmulateInstructionARM64.cpp:120
EmulateInstructionARM64::SupportsEmulatingInstructionsOfTypeStatic
static bool SupportsEmulatingInstructionsOfTypeStatic(lldb_private::InstructionType inst_type)
Definition: EmulateInstructionARM64.h:35
EmulateInstructionARM64::BranchType_ERET
@ BranchType_ERET
Definition: EmulateInstructionARM64.h:80
EmulateInstructionARM64::Constraint_SUPPRESSWB
@ Constraint_SUPPRESSWB
Definition: EmulateInstructionARM64.h:122
EmulateInstructionARM64::ProcState::Q
uint32_t Q
Definition: EmulateInstructionARM64.h:138
EmulateInstructionARM64::m_ignore_conditions
bool m_ignore_conditions
Definition: EmulateInstructionARM64.h:192
EmulateInstructionARM64::CountOp_CLS
@ CountOp_CLS
Definition: EmulateInstructionARM64.h:86
EmulateInstructionARM64::Terminate
static void Terminate()
Definition: EmulateInstructionARM64.cpp:116
EmulateInstructionARM64::EmulateLDRSTRImm
bool EmulateLDRSTRImm(const uint32_t opcode)
Definition: EmulateInstructionARM64.cpp:926
EmulateInstructionARM64::RevOp
RevOp
Definition: EmulateInstructionARM64.h:88
lldb_private::EmulateInstruction::Context
Definition: EmulateInstruction.h:184
EmulateInstructionARM64::ExtendType_UXTB
@ ExtendType_UXTB
Definition: EmulateInstructionARM64.h:99
EmulateInstructionARM64::GetOpcodeForInstruction
static Opcode * GetOpcodeForInstruction(const uint32_t opcode)
Definition: EmulateInstructionARM64.cpp:194
EmulateInstructionARM64::AddrMode_OFF
@ AddrMode_OFF
Definition: EmulateInstructionARM64.h:76
EmulateInstructionARM64
Definition: EmulateInstructionARM64.h:17
EmulateInstructionARM64::ExtractType_RIGHT
@ ExtractType_RIGHT
Definition: EmulateInstructionARM64.h:105
EmulateInstructionARM64::GetFramePointerRegisterNumber
uint32_t GetFramePointerRegisterNumber() const
Definition: EmulateInstructionARM64.cpp:467
EmulateInstructionARM64::ProcState::IL
uint32_t IL
Definition: EmulateInstructionARM64.h:143
EmulateInstructionARM64::Unpredictable_LDPOVERLAP
@ Unpredictable_LDPOVERLAP
Definition: EmulateInstructionARM64.h:117
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
EmulateInstructionARM64::ProcState::E
uint32_t E
Definition: EmulateInstructionARM64.h:146
EmulateInstructionARM64::Constraint_NOP
@ Constraint_NOP
Definition: EmulateInstructionARM64.h:123
EmulateInstructionARM64::MoveWideOp_N
@ MoveWideOp_N
Definition: EmulateInstructionARM64.h:111
EmulateInstructionARM64::TestEmulation
bool TestEmulation(lldb_private::Stream *out_stream, lldb_private::ArchSpec &arch, lldb_private::OptionValueDictionary *test_data) override
Definition: EmulateInstructionARM64.h:64
EmulateInstructionARM64::ProcState::EL
uint32_t EL
Definition: EmulateInstructionARM64.h:149
EmulateInstructionARM64::CreateFunctionEntryUnwind
bool CreateFunctionEntryUnwind(lldb_private::UnwindPlan &unwind_plan) override
Definition: EmulateInstructionARM64.cpp:448
EmulateInstructionARM64::BranchType_RET
@ BranchType_RET
Definition: EmulateInstructionARM64.h:82
EmulateInstructionARM64::CountOp_CNT
@ CountOp_CNT
Definition: EmulateInstructionARM64.h:86
EmulateInstructionARM64::ProcState::SS
uint32_t SS
Definition: EmulateInstructionARM64.h:142
lldb_private::eInstructionTypeAll
@ eInstructionTypeAll
Definition: lldb-private-enumerations.h:125
EmulateInstructionARM64::ShiftType_LSL
@ ShiftType_LSL
Definition: EmulateInstructionARM64.h:113
EmulateInstructionARM64::GetPluginVersion
uint32_t GetPluginVersion() override
Definition: EmulateInstructionARM64.h:51
EmulateInstructionARM64::MemOp_LOAD
@ MemOp_LOAD
Definition: EmulateInstructionARM64.h:109
EmulateInstructionARM64::ProcState::M
uint32_t M
Definition: EmulateInstructionARM64.h:147
OptionValue.h
EmulateInstructionARM64::ExtractType
ExtractType
Definition: EmulateInstructionARM64.h:105
EmulateInstructionARM64::Opcode::name
const char * name
Definition: EmulateInstructionARM64.h:163
EmulateInstructionARM64::EmulateADDSUBImm
bool EmulateADDSUBImm(const uint32_t opcode)
Definition: EmulateInstructionARM64.cpp:588
EmulateInstructionARM64::AccType_ORDERED
@ AccType_ORDERED
Definition: EmulateInstructionARM64.h:131
EmulateInstructionARM64::LogicalOp
LogicalOp
Definition: EmulateInstructionARM64.h:107
EmulateInstructionARM64::ShiftType_ASR
@ ShiftType_ASR
Definition: EmulateInstructionARM64.h:113
EmulateInstruction.h
EmulateInstructionARM64::ConditionHolds
bool ConditionHolds(const uint32_t cond)
Definition: EmulateInstructionARM64.cpp:529
EmulateInstructionARM64::ProcState::T
uint32_t T
Definition: EmulateInstructionARM64.h:141
EmulateInstructionARM64::MemOp_PREFETCH
@ MemOp_PREFETCH
Definition: EmulateInstructionARM64.h:109
EmulateInstructionARM64::ExceptionLevel
ExceptionLevel
Definition: EmulateInstructionARM64.h:92
EmulateInstructionARM64::StackPointerSelection
StackPointerSelection
Definition: EmulateInstructionARM64.h:115
EmulateInstructionARM64::LogicalOp_ORR
@ LogicalOp_ORR
Definition: EmulateInstructionARM64.h:107
EmulateInstructionARM64::SP0
@ SP0
Definition: EmulateInstructionARM64.h:115
EmulateInstructionARM64::ConstraintType
ConstraintType
Definition: EmulateInstructionARM64.h:119
lldb_private::ConstString
Definition: ConstString.h:40
EmulateInstructionARM64::MoveWideOp_Z
@ MoveWideOp_Z
Definition: EmulateInstructionARM64.h:111
EmulateInstructionARM64::ProcState::SP
uint32_t SP
Definition: EmulateInstructionARM64.h:150
EmulateInstructionARM64::ExtendType_SXTW
@ ExtendType_SXTW
Definition: EmulateInstructionARM64.h:97
EmulateInstructionARM64::AccType_STREAM
@ AccType_STREAM
Definition: EmulateInstructionARM64.h:129
ARMDefines.h
EmulateInstructionARM64::MemOp
MemOp
Definition: EmulateInstructionARM64.h:109
EmulateInstructionARM64::ProcState::J
uint32_t J
Definition: EmulateInstructionARM64.h:140
EmulateInstructionARM64::RevOp_RBIT
@ RevOp_RBIT
Definition: EmulateInstructionARM64.h:88
EmulateInstructionARM64::CountOp
CountOp
Definition: EmulateInstructionARM64.h:86
EmulateInstructionARM64::AddrMode
AddrMode
Definition: EmulateInstructionARM64.h:76
EmulateInstructionARM64::EmulateLDPSTP
bool EmulateLDPSTP(const uint32_t opcode)
Definition: EmulateInstructionARM64.cpp:703
EmulateInstructionARM64::LogicalOp_AND
@ LogicalOp_AND
Definition: EmulateInstructionARM64.h:107
EmulateInstructionARM64::CreateInstance
static lldb_private::EmulateInstruction * CreateInstance(const lldb_private::ArchSpec &arch, lldb_private::InstructionType inst_type)
Definition: EmulateInstructionARM64.cpp:135
EmulateInstructionARM64::ReadInstruction
bool ReadInstruction() override
Definition: EmulateInstructionARM64.cpp:382
EmulateInstructionARM64::Constraint_NONE
@ Constraint_NONE
Definition: EmulateInstructionARM64.h:120
lldb::RegisterKind
RegisterKind
Register numbering types.
Definition: lldb-enumerations.h:227
EmulateInstructionARM64::AccType_ALIGNED
@ AccType_ALIGNED
Definition: EmulateInstructionARM64.h:130
EmulateInstructionARM64::m_opcode_pstate
ProcState m_opcode_pstate
Definition: EmulateInstructionARM64.h:190
EmulateInstructionARM64::ProcState::RW
uint32_t RW
Definition: EmulateInstructionARM64.h:148
EmulateInstructionARM64::Opcode::mask
uint32_t mask
Definition: EmulateInstructionARM64.h:159
EmulateInstructionARM64::EmulateBcond
bool EmulateBcond(const uint32_t opcode)
Definition: EmulateInstructionARM64.cpp:1089
EmulateInstructionARM64::BranchType_DRET
@ BranchType_DRET
Definition: EmulateInstructionARM64.h:81
EmulateInstructionARM64::BitwiseOp
BitwiseOp
Definition: EmulateInstructionARM64.h:90
EmulateInstructionARM64::MoveWideOp_K
@ MoveWideOp_K
Definition: EmulateInstructionARM64.h:111
uint32_t
lldb_private::EmulateInstruction
Definition: EmulateInstruction.h:93
EmulateInstructionARM64::EL3
@ EL3
Definition: EmulateInstructionARM64.h:92
EmulateInstructionARM64::ProcState::I
uint32_t I
Definition: EmulateInstructionARM64.h:144
EmulateInstructionARM64::ExtendType_UXTH
@ ExtendType_UXTH
Definition: EmulateInstructionARM64.h:100
EmulateInstructionARM64::ProcState::V
uint32_t V
Definition: EmulateInstructionARM64.h:135
EmulateInstructionARM64::Opcode::value
uint32_t value
Definition: EmulateInstructionARM64.h:160
EmulateInstructionARM64::GetPluginName
lldb_private::ConstString GetPluginName() override
Definition: EmulateInstructionARM64.cpp:125
EmulateInstructionARM64::SupportsEmulatingInstructionsOfType
bool SupportsEmulatingInstructionsOfType(lldb_private::InstructionType inst_type) override
Definition: EmulateInstructionARM64.h:55
EmulateInstructionARM64::MemOp_NOP
@ MemOp_NOP
Definition: EmulateInstructionARM64.h:109
EmulateInstructionARM64::ShiftType_LSR
@ ShiftType_LSR
Definition: EmulateInstructionARM64.h:113
EmulateInstructionARM64::AddrMode_PRE
@ AddrMode_PRE
Definition: EmulateInstructionARM64.h:76
EmulateInstructionARM64::Opcode::vfp_variants
uint32_t vfp_variants
Definition: EmulateInstructionARM64.h:161
EmulateInstructionARM64::EmulateCBZ
bool EmulateCBZ(const uint32_t opcode)
Definition: EmulateInstructionARM64.cpp:1118
EmulateInstructionARM64::Initialize
static void Initialize()
Definition: EmulateInstructionARM64.cpp:111
EmulateInstructionARM64::AccType
AccType
Definition: EmulateInstructionARM64.h:126
EmulateInstructionARM64::RevOp_REV64
@ RevOp_REV64
Definition: EmulateInstructionARM64.h:88
EmulateInstructionARM64::ShiftType_ROR
@ ShiftType_ROR
Definition: EmulateInstructionARM64.h:113
EmulateInstructionARM64::MemOp_STORE
@ MemOp_STORE
Definition: EmulateInstructionARM64.h:109
lldb_private::eInstructionTypePrologueEpilogue
@ eInstructionTypePrologueEpilogue
Definition: lldb-private-enumerations.h:120
EmulateInstructionARM64::BranchType_JMP
@ BranchType_JMP
Definition: EmulateInstructionARM64.h:83
EmulateInstructionARM64::AccType_UNPRIV
@ AccType_UNPRIV
Definition: EmulateInstructionARM64.h:128
EmulateInstructionARM64::EL2
@ EL2
Definition: EmulateInstructionARM64.h:92
EmulateInstructionARM64::EvaluateInstruction
bool EvaluateInstruction(uint32_t evaluate_options) override
Definition: EmulateInstructionARM64.cpp:399
lldb_private::InstructionType
InstructionType
Instruction types.
Definition: lldb-private-enumerations.h:118
EmulateInstructionARM64::GetRegisterInfo
bool GetRegisterInfo(lldb::RegisterKind reg_kind, uint32_t reg_num, lldb_private::RegisterInfo &reg_info) override
Definition: EmulateInstructionARM64.cpp:157
EmulateInstructionARM64::Unpredictable
Unpredictable
Definition: EmulateInstructionARM64.h:117
Status.h
EmulateInstructionARM64::EmulateInstructionARM64
EmulateInstructionARM64(const lldb_private::ArchSpec &arch)
Definition: EmulateInstructionARM64.h:19
EmulateInstructionARM64::Constraint_UNKNOWN
@ Constraint_UNKNOWN
Definition: EmulateInstructionARM64.h:121
EmulateInstructionARM64::BranchTo
bool BranchTo(const Context &context, uint32_t N, lldb::addr_t target)
Definition: EmulateInstructionARM64.cpp:481
EmulateInstructionARM64::LogicalOp_EOR
@ LogicalOp_EOR
Definition: EmulateInstructionARM64.h:107
EmulateInstructionARM64::MoveWideOp
MoveWideOp
Definition: EmulateInstructionARM64.h:111
EmulateInstructionARM64::ExtendType_SXTB
@ ExtendType_SXTB
Definition: EmulateInstructionARM64.h:95
EmulateInstructionARM64::CountOp_CLZ
@ CountOp_CLZ
Definition: EmulateInstructionARM64.h:86
EmulateInstructionARM64::ExtendType_UXTW
@ ExtendType_UXTW
Definition: EmulateInstructionARM64.h:101
lldb_private::OptionValueDictionary
Definition: OptionValueDictionary.h:18
EmulateInstructionARM64::BranchType_CALL
@ BranchType_CALL
Definition: EmulateInstructionARM64.h:79
lldb_private::EmulateInstruction::EmulateInstruction
EmulateInstruction(const ArchSpec &arch)
Definition: EmulateInstruction.cpp:74
EmulateInstructionARM64::ExtendType_SXTH
@ ExtendType_SXTH
Definition: EmulateInstructionARM64.h:96
EmulateInstructionARM64::UsingAArch32
bool UsingAArch32()
Definition: EmulateInstructionARM64.cpp:474
EmulateInstructionARM64::m_emulated_pstate
ProcState m_emulated_pstate
Definition: EmulateInstructionARM64.h:191
EmulateInstructionARM64::AccType_NORMAL
@ AccType_NORMAL
Definition: EmulateInstructionARM64.h:127
EmulateInstructionARM64::ExtendType_UXTX
@ ExtendType_UXTX
Definition: EmulateInstructionARM64.h:102
EmulateInstructionARM64::SetTargetTriple
bool SetTargetTriple(const lldb_private::ArchSpec &arch) override
Definition: EmulateInstructionARM64.cpp:148
EmulateInstructionARM64::ShiftType
ShiftType
Definition: EmulateInstructionARM64.h:113
EmulateInstructionARM64::EmulateB
bool EmulateB(const uint32_t opcode)
Definition: EmulateInstructionARM64.cpp:1053
EmulateInstructionARM64::AddrMode_POST
@ AddrMode_POST
Definition: EmulateInstructionARM64.h:76
EmulateInstructionARM64::ExtendType_SXTX
@ ExtendType_SXTX
Definition: EmulateInstructionARM64.h:98
EmulateInstructionARM64::RevOp_REV16
@ RevOp_REV16
Definition: EmulateInstructionARM64.h:88
lldb_private::UnwindPlan
Definition: UnwindPlan.h:53
lldb_private::eInstructionTypeAny
@ eInstructionTypeAny
Definition: lldb-private-enumerations.h:119
EmulateInstructionARM64::EL1
@ EL1
Definition: EmulateInstructionARM64.h:92
EmulateInstructionARM64::BitwiseOp_RBIT
@ BitwiseOp_RBIT
Definition: EmulateInstructionARM64.h:90
EmulateInstructionARM64::EmulateTBZ
bool EmulateTBZ(const uint32_t opcode)
Definition: EmulateInstructionARM64.cpp:1156
EmulateInstructionARM64::EL0
@ EL0
Definition: EmulateInstructionARM64.h:92
EmulateInstructionARM64::RevOp_REV32
@ RevOp_REV32
Definition: EmulateInstructionARM64.h:88