EmulateInstructionARM.h revision 9b8d783409b5b80af2cf129c45cbc39c9544ccca
1//===-- lldb_EmulateInstructionARM.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 lldb_EmulateInstructionARM_h_ 11#define lldb_EmulateInstructionARM_h_ 12 13#include "lldb/Core/EmulateInstruction.h" 14#include "lldb/Core/Error.h" 15 16namespace lldb_private { 17 18class EmulateInstructionARM : public EmulateInstruction 19{ 20public: 21 typedef enum 22 { 23 eEncodingA1, 24 eEncodingA2, 25 eEncodingA3, 26 eEncodingA4, 27 eEncodingA5, 28 eEncodingT1, 29 eEncodingT2, 30 eEncodingT3, 31 eEncodingT4, 32 eEncodingT5, 33 } ARMEncoding; 34 35 36 static void 37 Initialize (); 38 39 static void 40 Terminate (); 41 42 virtual const char * 43 GetPluginName() 44 { 45 return "EmulateInstructionARM"; 46 } 47 48 virtual const char * 49 GetShortPluginName() 50 { 51 return "lldb.emulate-instruction.arm"; 52 } 53 54 virtual uint32_t 55 GetPluginVersion() 56 { 57 return 1; 58 } 59 60 virtual void 61 GetPluginCommandHelp (const char *command, Stream *strm) 62 { 63 } 64 65 virtual lldb_private::Error 66 ExecutePluginCommand (Args &command, Stream *strm) 67 { 68 Error error; 69 error.SetErrorString("no plug-in commands are supported"); 70 return error; 71 } 72 73 virtual Log * 74 EnablePluginLogging (Stream *strm, Args &command) 75 { 76 return NULL; 77 } 78 79 enum Mode 80 { 81 eModeInvalid, 82 eModeARM, 83 eModeThumb 84 }; 85 86 EmulateInstructionARM (void *baton, 87 ReadMemory read_mem_callback, 88 WriteMemory write_mem_callback, 89 ReadRegister read_reg_callback, 90 WriteRegister write_reg_callback) : 91 EmulateInstruction (lldb::eByteOrderLittle, // Byte order for ARM 92 4, // Address size in byte 93 baton, 94 read_mem_callback, 95 write_mem_callback, 96 read_reg_callback, 97 write_reg_callback), 98 m_arm_isa (0), 99 m_inst_mode (eModeInvalid), 100 m_inst_cpsr (0) 101 { 102 } 103 104 105 virtual bool 106 SetTargetTriple (const ConstString &triple); 107 108 virtual bool 109 ReadInstruction (); 110 111 virtual bool 112 EvaluateInstruction (); 113 114 bool 115 ConditionPassed (); 116 117 uint32_t 118 CurrentCond (); 119 120protected: 121 122 // Typedef for the callback function used during the emulation. 123 // Pass along (ARMEncoding)encoding as the callback data. 124 typedef enum 125 { 126 eSize16, 127 eSize32 128 } ARMInstrSize; 129 130 typedef struct 131 { 132 uint32_t mask; 133 uint32_t value; 134 uint32_t variants; 135 EmulateInstructionARM::ARMEncoding encoding; 136 ARMInstrSize size; 137 bool (EmulateInstructionARM::*callback) (EmulateInstructionARM::ARMEncoding encoding); 138 const char *name; 139 } ARMOpcode; 140 141 142 static ARMOpcode* 143 GetARMOpcodeForInstruction (const uint32_t opcode); 144 145 static ARMOpcode* 146 GetThumbOpcodeForInstruction (const uint32_t opcode); 147 148 bool 149 EmulatePush (ARMEncoding encoding); 150 151 bool 152 EmulatePop (ARMEncoding encoding); 153 154 bool 155 EmulateAddRdSPImmediate (ARMEncoding encoding); 156 157 bool 158 EmulateMovRdSP (ARMEncoding encoding); 159 160 bool 161 EmulateMovLowHigh (ARMEncoding encoding); 162 163 bool 164 EmulateLDRRdPCRelative (ARMEncoding encoding); 165 166 bool 167 EmulateAddSPImmediate (ARMEncoding encoding); 168 169 bool 170 EmulateAddSPRm (ARMEncoding encoding); 171 172 bool 173 EmulateBLXImmediate (ARMEncoding encoding); 174 175 bool 176 EmulateBLXRm (ARMEncoding encoding); 177 178 bool 179 EmulateSubR7IPImmediate (ARMEncoding encoding); 180 181 bool 182 EmulateSubIPSPImmediate (ARMEncoding encoding); 183 184 bool 185 EmulateSubSPImmdiate (ARMEncoding encoding); 186 187 bool 188 EmulateSTRRtSP (ARMEncoding encoding); 189 190 bool 191 EmulateVPUSH (ARMEncoding encoding); 192 193 bool 194 EmulateVPOP (ARMEncoding encoding); 195 196 uint32_t m_arm_isa; 197 Mode m_inst_mode; 198 uint32_t m_inst_cpsr; 199}; 200 201} // namespace lldb_private 202 203#endif // lldb_EmulateInstructionARM_h_ 204