1 //===-- EmulateInstructionARM64.h ------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef EmulateInstructionARM64_h_ 11 #define EmulateInstructionARM64_h_ 12 13 #include "lldb/Core/EmulateInstruction.h" 14 #include "lldb/Core/Error.h" 15 #include "lldb/Interpreter/OptionValue.h" 16 #include "Plugins/Process/Utility/ARMDefines.h" 17 18 class EmulateInstructionARM64 : public lldb_private::EmulateInstruction 19 { 20 public: 21 static void 22 Initialize (); 23 24 static void 25 Terminate (); 26 27 static lldb_private::ConstString 28 GetPluginNameStatic (); 29 30 static const char * 31 GetPluginDescriptionStatic (); 32 33 static lldb_private::EmulateInstruction * 34 CreateInstance (const lldb_private::ArchSpec &arch, 35 lldb_private::InstructionType inst_type); 36 37 static bool SupportsEmulatingInstructionsOfTypeStatic(lldb_private::InstructionType inst_type)38 SupportsEmulatingInstructionsOfTypeStatic (lldb_private::InstructionType inst_type) 39 { 40 switch (inst_type) 41 { 42 case lldb_private::eInstructionTypeAny: 43 case lldb_private::eInstructionTypePrologueEpilogue: 44 return true; 45 46 case lldb_private::eInstructionTypePCModifying: 47 case lldb_private::eInstructionTypeAll: 48 return false; 49 } 50 return false; 51 } 52 53 virtual lldb_private::ConstString 54 GetPluginName(); 55 56 virtual lldb_private::ConstString GetShortPluginName()57 GetShortPluginName() 58 { 59 return GetPluginNameStatic(); 60 } 61 62 virtual uint32_t GetPluginVersion()63 GetPluginVersion() 64 { 65 return 1; 66 } 67 68 bool 69 SetTargetTriple (const lldb_private::ArchSpec &arch); 70 EmulateInstructionARM64(const lldb_private::ArchSpec & arch)71 EmulateInstructionARM64 (const lldb_private::ArchSpec &arch) : 72 EmulateInstruction (arch), 73 m_opcode_pstate (), 74 m_emulated_pstate (), 75 m_ignore_conditions (false) 76 { 77 } 78 79 virtual bool SupportsEmulatingInstructionsOfType(lldb_private::InstructionType inst_type)80 SupportsEmulatingInstructionsOfType (lldb_private::InstructionType inst_type) 81 { 82 return SupportsEmulatingInstructionsOfTypeStatic (inst_type); 83 } 84 85 virtual bool 86 ReadInstruction (); 87 88 virtual bool 89 EvaluateInstruction (uint32_t evaluate_options); 90 91 virtual bool TestEmulation(lldb_private::Stream * out_stream,lldb_private::ArchSpec & arch,lldb_private::OptionValueDictionary * test_data)92 TestEmulation (lldb_private::Stream *out_stream, 93 lldb_private::ArchSpec &arch, 94 lldb_private::OptionValueDictionary *test_data) 95 { 96 return false; 97 } 98 99 virtual bool 100 GetRegisterInfo (lldb::RegisterKind reg_kind, 101 uint32_t reg_num, 102 lldb_private::RegisterInfo ®_info); 103 104 virtual bool 105 CreateFunctionEntryUnwind (lldb_private::UnwindPlan &unwind_plan); 106 107 108 typedef enum 109 { 110 AddrMode_OFF, 111 AddrMode_PRE, 112 AddrMode_POST 113 } AddrMode; 114 115 typedef enum 116 { 117 BranchType_CALL, 118 BranchType_ERET, 119 BranchType_DRET, 120 BranchType_RET, 121 BranchType_JMP 122 } BranchType; 123 124 typedef enum 125 { 126 CountOp_CLZ, 127 CountOp_CLS, 128 CountOp_CNT 129 } CountOp; 130 131 typedef enum 132 { 133 RevOp_RBIT, 134 RevOp_REV16, 135 RevOp_REV32, 136 RevOp_REV64 137 } RevOp; 138 139 typedef enum 140 { 141 BitwiseOp_NOT, 142 BitwiseOp_RBIT 143 } BitwiseOp; 144 145 146 typedef enum 147 { 148 EL0 = 0, 149 EL1 = 1, 150 EL2 = 2, 151 EL3 = 3 152 } ExceptionLevel; 153 154 typedef enum 155 { 156 ExtendType_SXTB, 157 ExtendType_SXTH, 158 ExtendType_SXTW, 159 ExtendType_SXTX, 160 ExtendType_UXTB, 161 ExtendType_UXTH, 162 ExtendType_UXTW, 163 ExtendType_UXTX 164 } ExtendType; 165 166 typedef enum 167 { 168 ExtractType_LEFT, 169 ExtractType_RIGHT 170 } ExtractType; 171 172 typedef enum 173 { 174 LogicalOp_AND, 175 LogicalOp_EOR, 176 LogicalOp_ORR 177 } LogicalOp; 178 179 typedef enum 180 { 181 MemOp_LOAD, 182 MemOp_STORE, 183 MemOp_PREFETCH, 184 MemOp_NOP 185 } MemOp; 186 187 typedef enum 188 { 189 MoveWideOp_N, 190 MoveWideOp_Z, 191 MoveWideOp_K 192 } MoveWideOp; 193 194 typedef enum { 195 ShiftType_LSL, 196 ShiftType_LSR, 197 ShiftType_ASR, 198 ShiftType_ROR 199 } ShiftType; 200 201 typedef enum 202 { 203 SP0 = 0, 204 SPx = 1 205 } StackPointerSelection; 206 207 typedef enum 208 { 209 Unpredictable_WBOVERLAP, 210 Unpredictable_LDPOVERLAP 211 } Unpredictable; 212 213 typedef enum 214 { 215 Constraint_NONE, 216 Constraint_UNKNOWN, 217 Constraint_SUPPRESSWB, 218 Constraint_NOP 219 } ConstraintType; 220 221 typedef enum 222 { 223 AccType_NORMAL, 224 AccType_UNPRIV, 225 AccType_STREAM, 226 AccType_ALIGNED, 227 AccType_ORDERED 228 } AccType; 229 230 typedef struct 231 { 232 uint32_t 233 N:1, 234 V:1, 235 C:1, 236 Z:1, // condition code flags – can also be accessed as PSTATE.[N,Z,C,V] 237 Q:1, // AArch32 only – CSPR.Q bit 238 IT:8, // AArch32 only – CPSR.IT bits 239 J:1, // AArch32 only – CSPR.J bit 240 T:1, // AArch32 only – CPSR.T bit 241 SS:1, // Single step process state bit 242 IL:1, // Illegal state bit 243 D:1, 244 A:1, 245 I:1, 246 F:1, // Interrupt masks – can also be accessed as PSTATE.[D,A,I,F] 247 E:1, // AArch32 only – CSPR.E bit 248 M:5, // AArch32 only – mode encodings 249 RW:1, // Current register width – 0 is AArch64, 1 is AArch32 250 EL:2, // Current exception level (see ExceptionLevel enum) 251 SP:1; // AArch64 only - Stack Pointer selection (see StackPointerSelection enum) 252 } ProcState; 253 254 protected: 255 256 typedef struct 257 { 258 uint32_t mask; 259 uint32_t value; 260 uint32_t vfp_variants; 261 bool (EmulateInstructionARM64::*callback) (const uint32_t opcode); 262 const char *name; 263 } Opcode; 264 265 static Opcode* 266 GetOpcodeForInstruction (const uint32_t opcode); 267 268 uint32_t 269 GetFramePointerRegisterNumber() const; 270 271 bool 272 BranchTo (const Context &context, uint32_t N, lldb::addr_t target); 273 274 bool 275 ConditionHolds (const uint32_t cond, bool *is_conditional = nullptr); 276 277 bool 278 UsingAArch32 (); 279 280 bool 281 Emulate_addsub_imm (const uint32_t opcode); 282 283 bool 284 Emulate_ldstpair_off (const uint32_t opcode); 285 286 bool 287 Emulate_ldstpair_pre (const uint32_t opcode); 288 289 bool 290 Emulate_ldstpair_post (const uint32_t opcode); 291 292 bool 293 Emulate_ldstpair (const uint32_t opcode, AddrMode a_mode); 294 295 bool 296 EmulateB (const uint32_t opcode); 297 298 bool 299 EmulateBcond (const uint32_t opcode); 300 301 bool 302 EmulateCBZ (const uint32_t opcode); 303 304 bool 305 EmulateTBZ (const uint32_t opcode); 306 307 ProcState m_opcode_pstate; 308 ProcState m_emulated_pstate; // This can get updated by the opcode. 309 bool m_ignore_conditions; 310 }; 311 312 #endif // EmulateInstructionARM64_h_ 313