Greg Clayton | 64c8443 | 2011-01-21 22:02:52 +0000 | [diff] [blame] | 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 | |
Greg Clayton | 8482ded | 2011-02-01 00:04:43 +0000 | [diff] [blame] | 13 | #include "lldb/Core/EmulateInstruction.h" |
Greg Clayton | 31e2a38 | 2011-01-30 20:03:56 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Error.h" |
| 15 | |
Greg Clayton | 64c8443 | 2011-01-21 22:02:52 +0000 | [diff] [blame] | 16 | namespace lldb_private { |
| 17 | |
Johnny Chen | 9307047 | 2011-02-04 23:02:47 +0000 | [diff] [blame] | 18 | // ITSession - Keep track of the IT Block progression. |
| 19 | class ITSession |
| 20 | { |
| 21 | public: |
| 22 | ITSession() : ITCounter(0), ITState(0) {} |
| 23 | ~ITSession() {} |
| 24 | |
| 25 | // InitIT - Initializes ITCounter/ITState. |
| 26 | bool InitIT(unsigned short bits7_0); |
| 27 | |
| 28 | // ITAdvance - Updates ITCounter/ITState as IT Block progresses. |
| 29 | void ITAdvance(); |
| 30 | |
| 31 | // InITBlock - Returns true if we're inside an IT Block. |
| 32 | bool InITBlock(); |
| 33 | |
Johnny Chen | c315f86 | 2011-02-05 00:46:10 +0000 | [diff] [blame] | 34 | // LastInITBlock - Returns true if we're the last instruction inside an IT Block. |
| 35 | bool LastInITBlock(); |
| 36 | |
Johnny Chen | 9307047 | 2011-02-04 23:02:47 +0000 | [diff] [blame] | 37 | // GetCond - Gets condition bits for the current thumb instruction. |
| 38 | uint32_t GetCond(); |
| 39 | |
| 40 | private: |
| 41 | uint32_t ITCounter; // Possible values: 0, 1, 2, 3, 4. |
| 42 | uint32_t ITState; // A2.5.2 Consists of IT[7:5] and IT[4:0] initially. |
| 43 | }; |
| 44 | |
Greg Clayton | 64c8443 | 2011-01-21 22:02:52 +0000 | [diff] [blame] | 45 | class EmulateInstructionARM : public EmulateInstruction |
| 46 | { |
| 47 | public: |
Greg Clayton | 2b8e8b0 | 2011-02-01 00:49:32 +0000 | [diff] [blame] | 48 | typedef enum |
| 49 | { |
| 50 | eEncodingA1, |
| 51 | eEncodingA2, |
| 52 | eEncodingA3, |
| 53 | eEncodingA4, |
| 54 | eEncodingA5, |
| 55 | eEncodingT1, |
| 56 | eEncodingT2, |
| 57 | eEncodingT3, |
| 58 | eEncodingT4, |
Greg Clayton | 17f5afe | 2011-02-05 02:56:16 +0000 | [diff] [blame] | 59 | eEncodingT5 |
Greg Clayton | 2b8e8b0 | 2011-02-01 00:49:32 +0000 | [diff] [blame] | 60 | } ARMEncoding; |
| 61 | |
| 62 | |
| 63 | static void |
| 64 | Initialize (); |
| 65 | |
| 66 | static void |
| 67 | Terminate (); |
Greg Clayton | 31e2a38 | 2011-01-30 20:03:56 +0000 | [diff] [blame] | 68 | |
| 69 | virtual const char * |
| 70 | GetPluginName() |
| 71 | { |
| 72 | return "EmulateInstructionARM"; |
| 73 | } |
| 74 | |
| 75 | virtual const char * |
| 76 | GetShortPluginName() |
| 77 | { |
| 78 | return "lldb.emulate-instruction.arm"; |
| 79 | } |
| 80 | |
| 81 | virtual uint32_t |
| 82 | GetPluginVersion() |
| 83 | { |
| 84 | return 1; |
| 85 | } |
| 86 | |
| 87 | virtual void |
| 88 | GetPluginCommandHelp (const char *command, Stream *strm) |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | virtual lldb_private::Error |
| 93 | ExecutePluginCommand (Args &command, Stream *strm) |
| 94 | { |
| 95 | Error error; |
| 96 | error.SetErrorString("no plug-in commands are supported"); |
| 97 | return error; |
| 98 | } |
| 99 | |
| 100 | virtual Log * |
| 101 | EnablePluginLogging (Stream *strm, Args &command) |
| 102 | { |
| 103 | return NULL; |
| 104 | } |
| 105 | |
Greg Clayton | 64c8443 | 2011-01-21 22:02:52 +0000 | [diff] [blame] | 106 | enum Mode |
| 107 | { |
| 108 | eModeInvalid, |
| 109 | eModeARM, |
| 110 | eModeThumb |
| 111 | }; |
| 112 | |
| 113 | EmulateInstructionARM (void *baton, |
| 114 | ReadMemory read_mem_callback, |
| 115 | WriteMemory write_mem_callback, |
| 116 | ReadRegister read_reg_callback, |
| 117 | WriteRegister write_reg_callback) : |
| 118 | EmulateInstruction (lldb::eByteOrderLittle, // Byte order for ARM |
| 119 | 4, // Address size in byte |
| 120 | baton, |
| 121 | read_mem_callback, |
| 122 | write_mem_callback, |
| 123 | read_reg_callback, |
| 124 | write_reg_callback), |
Greg Clayton | 31e2a38 | 2011-01-30 20:03:56 +0000 | [diff] [blame] | 125 | m_arm_isa (0), |
| 126 | m_inst_mode (eModeInvalid), |
Johnny Chen | c315f86 | 2011-02-05 00:46:10 +0000 | [diff] [blame] | 127 | m_inst_cpsr (0), |
| 128 | m_it_session () |
Greg Clayton | 64c8443 | 2011-01-21 22:02:52 +0000 | [diff] [blame] | 129 | { |
| 130 | } |
Greg Clayton | 31e2a38 | 2011-01-30 20:03:56 +0000 | [diff] [blame] | 131 | |
| 132 | |
| 133 | virtual bool |
| 134 | SetTargetTriple (const ConstString &triple); |
Greg Clayton | 64c8443 | 2011-01-21 22:02:52 +0000 | [diff] [blame] | 135 | |
| 136 | virtual bool |
| 137 | ReadInstruction (); |
| 138 | |
| 139 | virtual bool |
| 140 | EvaluateInstruction (); |
| 141 | |
| 142 | bool |
| 143 | ConditionPassed (); |
| 144 | |
| 145 | uint32_t |
| 146 | CurrentCond (); |
| 147 | |
| 148 | protected: |
Greg Clayton | 2b8e8b0 | 2011-02-01 00:49:32 +0000 | [diff] [blame] | 149 | |
| 150 | // Typedef for the callback function used during the emulation. |
| 151 | // Pass along (ARMEncoding)encoding as the callback data. |
| 152 | typedef enum |
| 153 | { |
| 154 | eSize16, |
| 155 | eSize32 |
| 156 | } ARMInstrSize; |
| 157 | |
| 158 | typedef struct |
| 159 | { |
| 160 | uint32_t mask; |
| 161 | uint32_t value; |
| 162 | uint32_t variants; |
| 163 | EmulateInstructionARM::ARMEncoding encoding; |
| 164 | ARMInstrSize size; |
| 165 | bool (EmulateInstructionARM::*callback) (EmulateInstructionARM::ARMEncoding encoding); |
| 166 | const char *name; |
| 167 | } ARMOpcode; |
| 168 | |
| 169 | |
| 170 | static ARMOpcode* |
| 171 | GetARMOpcodeForInstruction (const uint32_t opcode); |
| 172 | |
| 173 | static ARMOpcode* |
| 174 | GetThumbOpcodeForInstruction (const uint32_t opcode); |
| 175 | |
| 176 | bool |
| 177 | EmulatePush (ARMEncoding encoding); |
| 178 | |
| 179 | bool |
| 180 | EmulatePop (ARMEncoding encoding); |
| 181 | |
| 182 | bool |
| 183 | EmulateAddRdSPImmediate (ARMEncoding encoding); |
| 184 | |
| 185 | bool |
| 186 | EmulateMovRdSP (ARMEncoding encoding); |
| 187 | |
| 188 | bool |
| 189 | EmulateMovLowHigh (ARMEncoding encoding); |
| 190 | |
| 191 | bool |
| 192 | EmulateLDRRdPCRelative (ARMEncoding encoding); |
| 193 | |
| 194 | bool |
| 195 | EmulateAddSPImmediate (ARMEncoding encoding); |
| 196 | |
| 197 | bool |
| 198 | EmulateAddSPRm (ARMEncoding encoding); |
| 199 | |
| 200 | bool |
Johnny Chen | 9b8d783 | 2011-02-02 01:13:56 +0000 | [diff] [blame] | 201 | EmulateBLXImmediate (ARMEncoding encoding); |
| 202 | |
| 203 | bool |
| 204 | EmulateBLXRm (ARMEncoding encoding); |
| 205 | |
| 206 | bool |
Greg Clayton | 2b8e8b0 | 2011-02-01 00:49:32 +0000 | [diff] [blame] | 207 | EmulateSubR7IPImmediate (ARMEncoding encoding); |
| 208 | |
| 209 | bool |
| 210 | EmulateSubIPSPImmediate (ARMEncoding encoding); |
| 211 | |
| 212 | bool |
| 213 | EmulateSubSPImmdiate (ARMEncoding encoding); |
| 214 | |
| 215 | bool |
| 216 | EmulateSTRRtSP (ARMEncoding encoding); |
| 217 | |
| 218 | bool |
| 219 | EmulateVPUSH (ARMEncoding encoding); |
| 220 | |
Johnny Chen | 587a0a4 | 2011-02-01 18:35:28 +0000 | [diff] [blame] | 221 | bool |
| 222 | EmulateVPOP (ARMEncoding encoding); |
| 223 | |
Johnny Chen | b77be41 | 2011-02-04 00:40:18 +0000 | [diff] [blame] | 224 | bool |
| 225 | EmulateSVC (ARMEncoding encoding); |
| 226 | |
Johnny Chen | c315f86 | 2011-02-05 00:46:10 +0000 | [diff] [blame] | 227 | bool |
| 228 | EmulateIT (ARMEncoding encoding); |
| 229 | |
Johnny Chen | 3b620b3 | 2011-02-07 20:11:47 +0000 | [diff] [blame^] | 230 | bool |
| 231 | EmulateB (ARMEncoding encoding); |
| 232 | |
Greg Clayton | 31e2a38 | 2011-01-30 20:03:56 +0000 | [diff] [blame] | 233 | uint32_t m_arm_isa; |
Greg Clayton | 64c8443 | 2011-01-21 22:02:52 +0000 | [diff] [blame] | 234 | Mode m_inst_mode; |
| 235 | uint32_t m_inst_cpsr; |
Johnny Chen | c315f86 | 2011-02-05 00:46:10 +0000 | [diff] [blame] | 236 | ITSession m_it_session; |
Greg Clayton | 64c8443 | 2011-01-21 22:02:52 +0000 | [diff] [blame] | 237 | }; |
| 238 | |
| 239 | } // namespace lldb_private |
| 240 | |
| 241 | #endif // lldb_EmulateInstructionARM_h_ |