blob: f65b9a2b9609096e9862e55fa43137e3e487d9b2 [file] [log] [blame]
Greg Clayton64c84432011-01-21 22:02:52 +00001//===-- 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 Clayton8482ded2011-02-01 00:04:43 +000013#include "lldb/Core/EmulateInstruction.h"
Greg Clayton31e2a382011-01-30 20:03:56 +000014#include "lldb/Core/Error.h"
15
Greg Clayton64c84432011-01-21 22:02:52 +000016namespace lldb_private {
17
Johnny Chen93070472011-02-04 23:02:47 +000018// ITSession - Keep track of the IT Block progression.
19class ITSession
20{
21public:
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 Chenc315f862011-02-05 00:46:10 +000034 // LastInITBlock - Returns true if we're the last instruction inside an IT Block.
35 bool LastInITBlock();
36
Johnny Chen93070472011-02-04 23:02:47 +000037 // GetCond - Gets condition bits for the current thumb instruction.
38 uint32_t GetCond();
39
40private:
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 Clayton64c84432011-01-21 22:02:52 +000045class EmulateInstructionARM : public EmulateInstruction
46{
47public:
Greg Clayton2b8e8b02011-02-01 00:49:32 +000048 typedef enum
49 {
50 eEncodingA1,
51 eEncodingA2,
52 eEncodingA3,
53 eEncodingA4,
54 eEncodingA5,
55 eEncodingT1,
56 eEncodingT2,
57 eEncodingT3,
58 eEncodingT4,
Greg Clayton17f5afe2011-02-05 02:56:16 +000059 eEncodingT5
Greg Clayton2b8e8b02011-02-01 00:49:32 +000060 } ARMEncoding;
61
62
63 static void
64 Initialize ();
65
66 static void
67 Terminate ();
Greg Clayton31e2a382011-01-30 20:03:56 +000068
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 Clayton64c84432011-01-21 22:02:52 +0000106 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 Clayton31e2a382011-01-30 20:03:56 +0000125 m_arm_isa (0),
126 m_inst_mode (eModeInvalid),
Johnny Chenc315f862011-02-05 00:46:10 +0000127 m_inst_cpsr (0),
128 m_it_session ()
Greg Clayton64c84432011-01-21 22:02:52 +0000129 {
130 }
Greg Clayton31e2a382011-01-30 20:03:56 +0000131
132
133 virtual bool
134 SetTargetTriple (const ConstString &triple);
Greg Clayton64c84432011-01-21 22:02:52 +0000135
136 virtual bool
137 ReadInstruction ();
138
139 virtual bool
140 EvaluateInstruction ();
141
142 bool
143 ConditionPassed ();
144
145 uint32_t
146 CurrentCond ();
147
148protected:
Greg Clayton2b8e8b02011-02-01 00:49:32 +0000149
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 Chen9b8d7832011-02-02 01:13:56 +0000201 EmulateBLXImmediate (ARMEncoding encoding);
202
203 bool
204 EmulateBLXRm (ARMEncoding encoding);
205
206 bool
Greg Clayton2b8e8b02011-02-01 00:49:32 +0000207 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 Chen587a0a42011-02-01 18:35:28 +0000221 bool
222 EmulateVPOP (ARMEncoding encoding);
223
Johnny Chenb77be412011-02-04 00:40:18 +0000224 bool
225 EmulateSVC (ARMEncoding encoding);
226
Johnny Chenc315f862011-02-05 00:46:10 +0000227 bool
228 EmulateIT (ARMEncoding encoding);
229
Johnny Chen3b620b32011-02-07 20:11:47 +0000230 bool
231 EmulateB (ARMEncoding encoding);
232
Greg Clayton31e2a382011-01-30 20:03:56 +0000233 uint32_t m_arm_isa;
Greg Clayton64c84432011-01-21 22:02:52 +0000234 Mode m_inst_mode;
235 uint32_t m_inst_cpsr;
Johnny Chenc315f862011-02-05 00:46:10 +0000236 ITSession m_it_session;
Greg Clayton64c84432011-01-21 22:02:52 +0000237};
238
239} // namespace lldb_private
240
241#endif // lldb_EmulateInstructionARM_h_