blob: b09f83109043afb0c05a16c0fef96186d946ff22 [file] [log] [blame]
Greg Clayton64c84432011-01-21 22:02:52 +00001//===-- EmulateInstructionARM.cpp -------------------------------*- 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#include "EmulateInstructionARM.h"
Johnny Chen8584c922011-01-26 01:18:52 +000011#include "ARMDefines.h"
Johnny Chen4baf2e32011-01-24 18:24:53 +000012#include "ARMUtils.h"
Greg Clayton31e2a382011-01-30 20:03:56 +000013#include "lldb/Core/ConstString.h"
Greg Clayton64c84432011-01-21 22:02:52 +000014
15using namespace lldb;
16using namespace lldb_private;
17
18// ARM constants used during decoding
19#define REG_RD 0
20#define LDM_REGLIST 1
21#define PC_REG 15
22#define PC_REGLIST_BIT 0x8000
23
Johnny Chen251af6a2011-01-21 22:47:25 +000024#define ARMv4 (1u << 0)
Greg Clayton64c84432011-01-21 22:02:52 +000025#define ARMv4T (1u << 1)
26#define ARMv5T (1u << 2)
27#define ARMv5TE (1u << 3)
28#define ARMv5TEJ (1u << 4)
Johnny Chen251af6a2011-01-21 22:47:25 +000029#define ARMv6 (1u << 5)
Greg Clayton64c84432011-01-21 22:02:52 +000030#define ARMv6K (1u << 6)
31#define ARMv6T2 (1u << 7)
Johnny Chen251af6a2011-01-21 22:47:25 +000032#define ARMv7 (1u << 8)
Johnny Chen60c0d622011-01-25 23:49:39 +000033#define ARMv8 (1u << 9)
Greg Clayton64c84432011-01-21 22:02:52 +000034#define ARMvAll (0xffffffffu)
35
Johnny Chen7dc60e12011-01-24 19:46:32 +000036typedef enum
Greg Clayton64c84432011-01-21 22:02:52 +000037{
38 eEncodingA1,
39 eEncodingA2,
40 eEncodingA3,
41 eEncodingA4,
42 eEncodingA5,
43 eEncodingT1,
44 eEncodingT2,
45 eEncodingT3,
46 eEncodingT4,
47 eEncodingT5,
48} ARMEncoding;
49
Johnny Chen7dc60e12011-01-24 19:46:32 +000050typedef enum
51{
52 eSize16,
53 eSize32
54} ARMInstrSize;
55
Johnny Chen4baf2e32011-01-24 18:24:53 +000056// Typedef for the callback function used during the emulation.
Johnny Chen3c75c762011-01-22 00:47:08 +000057// Pass along (ARMEncoding)encoding as the callback data.
58typedef bool (*EmulateCallback) (EmulateInstructionARM *emulator, ARMEncoding encoding);
59
Johnny Chen7dc60e12011-01-24 19:46:32 +000060typedef struct
Greg Clayton64c84432011-01-21 22:02:52 +000061{
62 uint32_t mask;
63 uint32_t value;
64 uint32_t variants;
65 ARMEncoding encoding;
Johnny Chen7dc60e12011-01-24 19:46:32 +000066 ARMInstrSize size;
Greg Clayton64c84432011-01-21 22:02:52 +000067 EmulateCallback callback;
Johnny Chen4bee8ce2011-01-22 00:59:07 +000068 const char *name;
Johnny Chen7dc60e12011-01-24 19:46:32 +000069} ARMOpcode;
Greg Clayton64c84432011-01-21 22:02:52 +000070
Johnny Chen08c25e82011-01-31 18:02:28 +000071// Push Multiple Registers stores multiple registers to the stack, storing to
72// consecutive memory locations ending just below the address in SP, and updates
73// SP to point to the start of the stored data.
Greg Clayton64c84432011-01-21 22:02:52 +000074static bool
Johnny Chence1ca772011-01-25 01:13:00 +000075emulate_push (EmulateInstructionARM *emulator, ARMEncoding encoding)
Greg Clayton64c84432011-01-21 22:02:52 +000076{
77#if 0
78 // ARM pseudo code...
79 if (ConditionPassed())
80 {
81 EncodingSpecificOperations();
82 NullCheckIfThumbEE(13);
83 address = SP - 4*BitCount(registers);
84
85 for (i = 0 to 14)
86 {
87 if (registers<i> == 1’)
88 {
89 if i == 13 && i != LowestSetBit(registers) // Only possible for encoding A1
90 MemA[address,4] = bits(32) UNKNOWN;
91 else
92 MemA[address,4] = R[i];
93 address = address + 4;
94 }
95 }
96
97 if (registers<15> == 1’) // Only possible for encoding A1 or A2
98 MemA[address,4] = PCStoreValue();
99
100 SP = SP - 4*BitCount(registers);
101 }
102#endif
103
104 bool success = false;
105 const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
106 if (!success)
107 return false;
108
109 if (emulator->ConditionPassed())
110 {
111 const uint32_t addr_byte_size = emulator->GetAddressByteSize();
112 const addr_t sp = emulator->ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, 0, &success);
113 if (!success)
114 return false;
Johnny Chen3c75c762011-01-22 00:47:08 +0000115 uint32_t registers = 0;
Johnny Chen91d99862011-01-25 19:07:04 +0000116 uint32_t Rt; // the source register
Johnny Chen3c75c762011-01-22 00:47:08 +0000117 switch (encoding) {
Johnny Chenaedde1c2011-01-24 20:38:45 +0000118 case eEncodingT1:
Johnny Chen108d5aa2011-01-26 01:00:55 +0000119 registers = Bits32(opcode, 7, 0);
Johnny Chenaedde1c2011-01-24 20:38:45 +0000120 // The M bit represents LR.
Johnny Chen108d5aa2011-01-26 01:00:55 +0000121 if (Bits32(opcode, 8, 8))
Johnny Chenaedde1c2011-01-24 20:38:45 +0000122 registers |= 0x000eu;
123 // if BitCount(registers) < 1 then UNPREDICTABLE;
124 if (BitCount(registers) < 1)
125 return false;
126 break;
Johnny Chen7dc60e12011-01-24 19:46:32 +0000127 case eEncodingT2:
128 // Ignore bits 15 & 13.
Johnny Chen108d5aa2011-01-26 01:00:55 +0000129 registers = Bits32(opcode, 15, 0) & ~0xa000;
Johnny Chen7dc60e12011-01-24 19:46:32 +0000130 // if BitCount(registers) < 2 then UNPREDICTABLE;
131 if (BitCount(registers) < 2)
132 return false;
133 break;
134 case eEncodingT3:
Johnny Chen108d5aa2011-01-26 01:00:55 +0000135 Rt = Bits32(opcode, 15, 12);
Johnny Chen7dc60e12011-01-24 19:46:32 +0000136 // if BadReg(t) then UNPREDICTABLE;
Johnny Chen91d99862011-01-25 19:07:04 +0000137 if (BadReg(Rt))
Johnny Chen7dc60e12011-01-24 19:46:32 +0000138 return false;
Johnny Chen91d99862011-01-25 19:07:04 +0000139 registers = (1u << Rt);
Johnny Chen7dc60e12011-01-24 19:46:32 +0000140 break;
Johnny Chen3c75c762011-01-22 00:47:08 +0000141 case eEncodingA1:
Johnny Chen108d5aa2011-01-26 01:00:55 +0000142 registers = Bits32(opcode, 15, 0);
Johnny Chena33d4842011-01-24 22:25:48 +0000143 // Instead of return false, let's handle the following case as well,
144 // which amounts to pushing one reg onto the full descending stacks.
145 // if BitCount(register_list) < 2 then SEE STMDB / STMFD;
Johnny Chen3c75c762011-01-22 00:47:08 +0000146 break;
147 case eEncodingA2:
Johnny Chen108d5aa2011-01-26 01:00:55 +0000148 Rt = Bits32(opcode, 15, 12);
Johnny Chen7dc60e12011-01-24 19:46:32 +0000149 // if t == 13 then UNPREDICTABLE;
Johnny Chen91d99862011-01-25 19:07:04 +0000150 if (Rt == dwarf_sp)
Johnny Chen3c75c762011-01-22 00:47:08 +0000151 return false;
Johnny Chen91d99862011-01-25 19:07:04 +0000152 registers = (1u << Rt);
Johnny Chen3c75c762011-01-22 00:47:08 +0000153 break;
Johnny Chence1ca772011-01-25 01:13:00 +0000154 default:
155 return false;
Johnny Chen3c75c762011-01-22 00:47:08 +0000156 }
Johnny Chence1ca772011-01-25 01:13:00 +0000157 addr_t sp_offset = addr_byte_size * BitCount (registers);
Greg Clayton64c84432011-01-21 22:02:52 +0000158 addr_t addr = sp - sp_offset;
159 uint32_t i;
160
161 EmulateInstruction::Context context = { EmulateInstruction::eContextPushRegisterOnStack, eRegisterKindDWARF, 0, 0 };
162 for (i=0; i<15; ++i)
163 {
Johnny Chen108d5aa2011-01-26 01:00:55 +0000164 if (BitIsSet (registers, 1u << i))
Greg Clayton64c84432011-01-21 22:02:52 +0000165 {
166 context.arg1 = dwarf_r0 + i; // arg1 in the context is the DWARF register number
167 context.arg2 = addr - sp; // arg2 in the context is the stack pointer offset
168 uint32_t reg_value = emulator->ReadRegisterUnsigned(eRegisterKindDWARF, context.arg1, 0, &success);
169 if (!success)
170 return false;
171 if (!emulator->WriteMemoryUnsigned (context, addr, reg_value, addr_byte_size))
172 return false;
173 addr += addr_byte_size;
174 }
175 }
176
Johnny Chen108d5aa2011-01-26 01:00:55 +0000177 if (BitIsSet (registers, 1u << 15))
Greg Clayton64c84432011-01-21 22:02:52 +0000178 {
179 context.arg1 = dwarf_pc; // arg1 in the context is the DWARF register number
Johnny Chen3c75c762011-01-22 00:47:08 +0000180 context.arg2 = addr - sp; // arg2 in the context is the stack pointer offset
Greg Clayton64c84432011-01-21 22:02:52 +0000181 const uint32_t pc = emulator->ReadRegisterUnsigned(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, 0, &success);
182 if (!success)
183 return false;
184 if (!emulator->WriteMemoryUnsigned (context, addr, pc + 8, addr_byte_size))
185 return false;
186 }
187
188 context.type = EmulateInstruction::eContextAdjustStackPointer;
189 context.arg0 = eRegisterKindGeneric;
190 context.arg1 = LLDB_REGNUM_GENERIC_SP;
Johnny Chen5b442b72011-01-27 19:34:30 +0000191 context.arg2 = -sp_offset;
Greg Clayton64c84432011-01-21 22:02:52 +0000192
193 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, sp - sp_offset))
194 return false;
195 }
196 return true;
197}
198
Johnny Chen5b442b72011-01-27 19:34:30 +0000199// Set r7 or ip to point to saved value residing within the stack.
Johnny Chenbcec3af2011-01-27 01:26:19 +0000200// ADD (SP plus immediate)
201static bool
202emulate_add_rd_sp_imm (EmulateInstructionARM *emulator, ARMEncoding encoding)
203{
204#if 0
205 // ARM pseudo code...
206 if (ConditionPassed())
207 {
208 EncodingSpecificOperations();
209 (result, carry, overflow) = AddWithCarry(SP, imm32, 0’);
210 if d == 15 then
211 ALUWritePC(result); // setflags is always FALSE here
212 else
213 R[d] = result;
214 if setflags then
215 APSR.N = result<31>;
216 APSR.Z = IsZeroBit(result);
217 APSR.C = carry;
218 APSR.V = overflow;
219 }
220#endif
221
222 bool success = false;
223 const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
224 if (!success)
225 return false;
226
227 if (emulator->ConditionPassed())
228 {
229 const addr_t sp = emulator->ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, 0, &success);
230 if (!success)
231 return false;
232 uint32_t Rd; // the destination register
233 uint32_t imm32;
234 switch (encoding) {
235 case eEncodingT1:
236 Rd = 7;
237 imm32 = Bits32(opcode, 7, 0) << 2; // imm32 = ZeroExtend(imm8:'00', 32)
238 break;
239 case eEncodingA1:
240 Rd = Bits32(opcode, 15, 12);
241 imm32 = ARMExpandImm(opcode); // imm32 = ARMExpandImm(imm12)
242 break;
243 default:
244 return false;
245 }
246 addr_t sp_offset = imm32;
247 addr_t addr = sp + sp_offset; // a pointer to the stack area
248
249 EmulateInstruction::Context context = { EmulateInstruction::eContextRegisterPlusOffset,
250 eRegisterKindGeneric,
251 LLDB_REGNUM_GENERIC_SP,
252 sp_offset };
253
254 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindDWARF, dwarf_r0 + Rd, addr))
255 return false;
256 }
257 return true;
258}
259
Johnny Chen2ccad832011-01-28 19:57:25 +0000260// Set r7 or ip to the current stack pointer.
261// MOV (register)
262static bool
263emulate_mov_rd_sp (EmulateInstructionARM *emulator, ARMEncoding encoding)
264{
265#if 0
266 // ARM pseudo code...
267 if (ConditionPassed())
268 {
269 EncodingSpecificOperations();
270 result = R[m];
271 if d == 15 then
272 ALUWritePC(result); // setflags is always FALSE here
273 else
274 R[d] = result;
275 if setflags then
276 APSR.N = result<31>;
277 APSR.Z = IsZeroBit(result);
278 // APSR.C unchanged
279 // APSR.V unchanged
280 }
281#endif
282
283 bool success = false;
Johnny Chen1c13b622011-01-29 00:11:15 +0000284 //const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
285 //if (!success)
286 // return false;
Johnny Chen2ccad832011-01-28 19:57:25 +0000287
288 if (emulator->ConditionPassed())
289 {
290 const addr_t sp = emulator->ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, 0, &success);
291 if (!success)
292 return false;
293 uint32_t Rd; // the destination register
294 switch (encoding) {
295 case eEncodingT1:
296 Rd = 7;
297 break;
298 case eEncodingA1:
299 Rd = 12;
300 break;
301 default:
302 return false;
303 }
304 EmulateInstruction::Context context = { EmulateInstruction::eContextRegisterPlusOffset,
305 eRegisterKindGeneric,
306 LLDB_REGNUM_GENERIC_SP,
307 0 };
308
309 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindDWARF, dwarf_r0 + Rd, sp))
310 return false;
311 }
312 return true;
313}
314
Johnny Chen1c13b622011-01-29 00:11:15 +0000315// Move from high register (r8-r15) to low register (r0-r7).
316// MOV (register)
317static bool
318emulate_mov_low_high (EmulateInstructionARM *emulator, ARMEncoding encoding)
319{
320#if 0
321 // ARM pseudo code...
322 if (ConditionPassed())
323 {
324 EncodingSpecificOperations();
325 result = R[m];
326 if d == 15 then
327 ALUWritePC(result); // setflags is always FALSE here
328 else
329 R[d] = result;
330 if setflags then
331 APSR.N = result<31>;
332 APSR.Z = IsZeroBit(result);
333 // APSR.C unchanged
334 // APSR.V unchanged
335 }
336#endif
337
338 bool success = false;
339 const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
340 if (!success)
341 return false;
342
343 if (emulator->ConditionPassed())
344 {
345 uint32_t Rm; // the source register
346 uint32_t Rd; // the destination register
347 switch (encoding) {
348 case eEncodingT1:
349 Rm = Bits32(opcode, 6, 3);
350 Rd = Bits32(opcode, 2, 1); // bits(7) == 0
351 break;
352 default:
353 return false;
354 }
355 int32_t reg_value = emulator->ReadRegisterUnsigned(eRegisterKindDWARF, dwarf_r0 + Rm, 0, &success);
356 if (!success)
357 return false;
358
359 // The context specifies that Rm is to be moved into Rd.
360 EmulateInstruction::Context context = { EmulateInstruction::eContextRegisterPlusOffset,
361 eRegisterKindDWARF,
362 dwarf_r0 + Rm,
363 0 };
364
365 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindDWARF, dwarf_r0 + Rd, reg_value))
366 return false;
367 }
368 return true;
369}
370
Johnny Chen788e0552011-01-27 22:52:23 +0000371// PC relative immediate load into register, possibly followed by ADD (SP plus register).
372// LDR (literal)
373static bool
374emulate_ldr_rd_pc_rel (EmulateInstructionARM *emulator, ARMEncoding encoding)
375{
376#if 0
377 // ARM pseudo code...
378 if (ConditionPassed())
379 {
380 EncodingSpecificOperations(); NullCheckIfThumbEE(15);
381 base = Align(PC,4);
382 address = if add then (base + imm32) else (base - imm32);
383 data = MemU[address,4];
384 if t == 15 then
385 if address<1:0> == 00 then LoadWritePC(data); else UNPREDICTABLE;
386 elsif UnalignedSupport() || address<1:0> = 00 then
387 R[t] = data;
388 else // Can only apply before ARMv7
389 if CurrentInstrSet() == InstrSet_ARM then
390 R[t] = ROR(data, 8*UInt(address<1:0>));
391 else
392 R[t] = bits(32) UNKNOWN;
393 }
394#endif
395
396 bool success = false;
397 const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
398 if (!success)
399 return false;
400
401 if (emulator->ConditionPassed())
402 {
403 const uint32_t pc = emulator->ReadRegisterUnsigned(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, 0, &success);
404 if (!success)
405 return false;
Johnny Chen809742e2011-01-28 00:32:27 +0000406
407 // PC relative immediate load context
408 EmulateInstruction::Context context = {EmulateInstruction::eContextRegisterPlusOffset,
409 eRegisterKindGeneric,
410 LLDB_REGNUM_GENERIC_PC,
411 0};
Johnny Chen788e0552011-01-27 22:52:23 +0000412 uint32_t Rd; // the destination register
413 uint32_t imm32; // immediate offset from the PC
414 addr_t addr; // the PC relative address
415 uint32_t data; // the literal data value from the PC relative load
416 switch (encoding) {
417 case eEncodingT1:
418 Rd = Bits32(opcode, 10, 8);
419 imm32 = Bits32(opcode, 7, 0) << 2; // imm32 = ZeroExtend(imm8:'00', 32);
420 addr = pc + 4 + imm32;
Johnny Chen809742e2011-01-28 00:32:27 +0000421 context.arg2 = 4 + imm32;
Johnny Chen788e0552011-01-27 22:52:23 +0000422 break;
423 default:
424 return false;
425 }
Johnny Chen809742e2011-01-28 00:32:27 +0000426 data = emulator->ReadMemoryUnsigned(context, addr, 4, 0, &success);
Johnny Chen788e0552011-01-27 22:52:23 +0000427 if (!success)
Johnny Chen809742e2011-01-28 00:32:27 +0000428 return false;
Johnny Chen788e0552011-01-27 22:52:23 +0000429 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindDWARF, dwarf_r0 + Rd, data))
430 return false;
431 }
432 return true;
433}
434
Johnny Chen5b442b72011-01-27 19:34:30 +0000435// An add operation to adjust the SP.
436// ADD (SP plus register)
437static bool
438emulate_add_sp_rm (EmulateInstructionARM *emulator, ARMEncoding encoding)
439{
440#if 0
441 // ARM pseudo code...
442 if (ConditionPassed())
443 {
444 EncodingSpecificOperations();
445 shifted = Shift(R[m], shift_t, shift_n, APSR.C);
446 (result, carry, overflow) = AddWithCarry(SP, shifted, 0’);
447 if d == 15 then
448 ALUWritePC(result); // setflags is always FALSE here
449 else
450 R[d] = result;
451 if setflags then
452 APSR.N = result<31>;
453 APSR.Z = IsZeroBit(result);
454 APSR.C = carry;
455 APSR.V = overflow;
456 }
457#endif
458
459 bool success = false;
460 const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
461 if (!success)
462 return false;
463
464 if (emulator->ConditionPassed())
465 {
466 const addr_t sp = emulator->ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, 0, &success);
467 if (!success)
468 return false;
469 uint32_t Rm; // the second operand
470 switch (encoding) {
471 case eEncodingT2:
472 Rm = Bits32(opcode, 6, 3);
473 break;
474 default:
475 return false;
476 }
477 int32_t reg_value = emulator->ReadRegisterUnsigned(eRegisterKindDWARF, dwarf_r0 + Rm, 0, &success);
478 if (!success)
479 return false;
480
481 addr_t addr = (int32_t)sp + reg_value; // the adjusted stack pointer value
482
483 EmulateInstruction::Context context = { EmulateInstruction::eContextAdjustStackPointer,
484 eRegisterKindGeneric,
485 LLDB_REGNUM_GENERIC_SP,
486 reg_value };
487
488 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, addr))
489 return false;
490 }
491 return true;
492}
493
Johnny Chen0d0148e2011-01-28 02:26:08 +0000494// Set r7 to point to some ip offset.
495// SUB (immediate)
496static bool
497emulate_sub_r7_ip_imm (EmulateInstructionARM *emulator, ARMEncoding encoding)
498{
499#if 0
500 // ARM pseudo code...
501 if (ConditionPassed())
502 {
503 EncodingSpecificOperations();
504 (result, carry, overflow) = AddWithCarry(SP, NOT(imm32), 1’);
505 if d == 15 then // Can only occur for ARM encoding
506 ALUWritePC(result); // setflags is always FALSE here
507 else
508 R[d] = result;
509 if setflags then
510 APSR.N = result<31>;
511 APSR.Z = IsZeroBit(result);
512 APSR.C = carry;
513 APSR.V = overflow;
514 }
515#endif
516
517 bool success = false;
518 const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
519 if (!success)
520 return false;
521
522 if (emulator->ConditionPassed())
523 {
524 const addr_t ip = emulator->ReadRegisterUnsigned (eRegisterKindDWARF, dwarf_r12, 0, &success);
525 if (!success)
526 return false;
527 uint32_t imm32;
528 switch (encoding) {
529 case eEncodingA1:
530 imm32 = ARMExpandImm(opcode); // imm32 = ARMExpandImm(imm12)
531 break;
532 default:
533 return false;
534 }
535 addr_t ip_offset = imm32;
536 addr_t addr = ip - ip_offset; // the adjusted ip value
537
538 EmulateInstruction::Context context = { EmulateInstruction::eContextRegisterPlusOffset,
539 eRegisterKindDWARF,
540 dwarf_r12,
541 -ip_offset };
542
543 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindDWARF, dwarf_r7, addr))
544 return false;
545 }
546 return true;
547}
548
549// Set ip to point to some stack offset.
550// SUB (SP minus immediate)
551static bool
552emulate_sub_ip_sp_imm (EmulateInstructionARM *emulator, ARMEncoding encoding)
553{
554#if 0
555 // ARM pseudo code...
556 if (ConditionPassed())
557 {
558 EncodingSpecificOperations();
559 (result, carry, overflow) = AddWithCarry(SP, NOT(imm32), 1’);
560 if d == 15 then // Can only occur for ARM encoding
561 ALUWritePC(result); // setflags is always FALSE here
562 else
563 R[d] = result;
564 if setflags then
565 APSR.N = result<31>;
566 APSR.Z = IsZeroBit(result);
567 APSR.C = carry;
568 APSR.V = overflow;
569 }
570#endif
571
572 bool success = false;
573 const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
574 if (!success)
575 return false;
576
577 if (emulator->ConditionPassed())
578 {
579 const addr_t sp = emulator->ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, 0, &success);
580 if (!success)
581 return false;
582 uint32_t imm32;
583 switch (encoding) {
584 case eEncodingA1:
585 imm32 = ARMExpandImm(opcode); // imm32 = ARMExpandImm(imm12)
586 break;
587 default:
588 return false;
589 }
590 addr_t sp_offset = imm32;
591 addr_t addr = sp - sp_offset; // the adjusted stack pointer value
592
593 EmulateInstruction::Context context = { EmulateInstruction::eContextRegisterPlusOffset,
594 eRegisterKindGeneric,
595 LLDB_REGNUM_GENERIC_SP,
596 -sp_offset };
597
598 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindDWARF, dwarf_r12, addr))
599 return false;
600 }
601 return true;
602}
603
Johnny Chen4c0e0bc2011-01-25 22:45:28 +0000604// A sub operation to adjust the SP -- allocate space for local storage.
605static bool
606emulate_sub_sp_imm (EmulateInstructionARM *emulator, ARMEncoding encoding)
607{
608#if 0
609 // ARM pseudo code...
610 if (ConditionPassed())
611 {
612 EncodingSpecificOperations();
613 (result, carry, overflow) = AddWithCarry(SP, NOT(imm32), 1’);
614 if d == 15 then // Can only occur for ARM encoding
Johnny Chen799dfd02011-01-26 23:14:33 +0000615 ALUWritePC(result); // setflags is always FALSE here
Johnny Chen4c0e0bc2011-01-25 22:45:28 +0000616 else
617 R[d] = result;
618 if setflags then
619 APSR.N = result<31>;
620 APSR.Z = IsZeroBit(result);
621 APSR.C = carry;
622 APSR.V = overflow;
623 }
624#endif
625
626 bool success = false;
627 const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
628 if (!success)
629 return false;
630
631 if (emulator->ConditionPassed())
632 {
633 const addr_t sp = emulator->ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, 0, &success);
634 if (!success)
635 return false;
636 uint32_t imm32;
637 switch (encoding) {
Johnny Chene4455022011-01-26 00:08:59 +0000638 case eEncodingT1:
639 imm32 = ThumbImmScaled(opcode); // imm32 = ZeroExtend(imm7:'00', 32)
Johnny Chen60c0d622011-01-25 23:49:39 +0000640 case eEncodingT2:
641 imm32 = ThumbExpandImm(opcode); // imm32 = ThumbExpandImm(i:imm3:imm8)
642 break;
643 case eEncodingT3:
644 imm32 = ThumbImm12(opcode); // imm32 = ZeroExtend(i:imm3:imm8, 32)
645 break;
Johnny Chen4c0e0bc2011-01-25 22:45:28 +0000646 case eEncodingA1:
Johnny Chen60c0d622011-01-25 23:49:39 +0000647 imm32 = ARMExpandImm(opcode); // imm32 = ARMExpandImm(imm12)
Johnny Chen4c0e0bc2011-01-25 22:45:28 +0000648 break;
649 default:
650 return false;
651 }
652 addr_t sp_offset = imm32;
653 addr_t addr = sp - sp_offset; // the adjusted stack pointer value
654
655 EmulateInstruction::Context context = { EmulateInstruction::eContextAdjustStackPointer,
656 eRegisterKindGeneric,
657 LLDB_REGNUM_GENERIC_SP,
Johnny Chen5b442b72011-01-27 19:34:30 +0000658 -sp_offset };
Johnny Chen4c0e0bc2011-01-25 22:45:28 +0000659
660 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, addr))
661 return false;
662 }
663 return true;
664}
665
Johnny Chen08c25e82011-01-31 18:02:28 +0000666// A store operation to the stack that also updates the SP.
Johnny Chence1ca772011-01-25 01:13:00 +0000667static bool
668emulate_str_rt_sp (EmulateInstructionARM *emulator, ARMEncoding encoding)
669{
670#if 0
671 // ARM pseudo code...
672 if (ConditionPassed())
673 {
674 EncodingSpecificOperations();
675 offset_addr = if add then (R[n] + imm32) else (R[n] - imm32);
676 address = if index then offset_addr else R[n];
677 MemU[address,4] = if t == 15 then PCStoreValue() else R[t];
678 if wback then R[n] = offset_addr;
679 }
680#endif
681
682 bool success = false;
683 const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
684 if (!success)
685 return false;
686
687 if (emulator->ConditionPassed())
688 {
689 const uint32_t addr_byte_size = emulator->GetAddressByteSize();
690 const addr_t sp = emulator->ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, 0, &success);
691 if (!success)
692 return false;
Johnny Chen91d99862011-01-25 19:07:04 +0000693 uint32_t Rt; // the source register
Johnny Chence1ca772011-01-25 01:13:00 +0000694 uint32_t imm12;
695 switch (encoding) {
696 case eEncodingA1:
Johnny Chen108d5aa2011-01-26 01:00:55 +0000697 Rt = Bits32(opcode, 15, 12);
698 imm12 = Bits32(opcode, 11, 0);
Johnny Chence1ca772011-01-25 01:13:00 +0000699 break;
700 default:
701 return false;
702 }
703 addr_t sp_offset = imm12;
704 addr_t addr = sp - sp_offset;
705
706 EmulateInstruction::Context context = { EmulateInstruction::eContextPushRegisterOnStack, eRegisterKindDWARF, 0, 0 };
Johnny Chen91d99862011-01-25 19:07:04 +0000707 if (Rt != 15)
Johnny Chence1ca772011-01-25 01:13:00 +0000708 {
Johnny Chen91d99862011-01-25 19:07:04 +0000709 context.arg1 = dwarf_r0 + Rt; // arg1 in the context is the DWARF register number
710 context.arg2 = addr - sp; // arg2 in the context is the stack pointer offset
Johnny Chence1ca772011-01-25 01:13:00 +0000711 uint32_t reg_value = emulator->ReadRegisterUnsigned(eRegisterKindDWARF, context.arg1, 0, &success);
712 if (!success)
713 return false;
714 if (!emulator->WriteMemoryUnsigned (context, addr, reg_value, addr_byte_size))
715 return false;
716 }
717 else
718 {
719 context.arg1 = dwarf_pc; // arg1 in the context is the DWARF register number
720 context.arg2 = addr - sp; // arg2 in the context is the stack pointer offset
721 const uint32_t pc = emulator->ReadRegisterUnsigned(eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, 0, &success);
722 if (!success)
723 return false;
724 if (!emulator->WriteMemoryUnsigned (context, addr, pc + 8, addr_byte_size))
725 return false;
726 }
727
728 context.type = EmulateInstruction::eContextAdjustStackPointer;
729 context.arg0 = eRegisterKindGeneric;
730 context.arg1 = LLDB_REGNUM_GENERIC_SP;
Johnny Chen5b442b72011-01-27 19:34:30 +0000731 context.arg2 = -sp_offset;
Johnny Chence1ca772011-01-25 01:13:00 +0000732
733 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, sp - sp_offset))
734 return false;
735 }
736 return true;
737}
738
Johnny Chen08c25e82011-01-31 18:02:28 +0000739// Vector Push stores multiple extension registers to the stack.
740// It also updates SP to point to the start of the stored data.
Johnny Chen799dfd02011-01-26 23:14:33 +0000741static bool
742emulate_vpush (EmulateInstructionARM *emulator, ARMEncoding encoding)
743{
744#if 0
745 // ARM pseudo code...
746 if (ConditionPassed())
747 {
748 EncodingSpecificOperations(); CheckVFPEnabled(TRUE); NullCheckIfThumbEE(13);
749 address = SP - imm32;
750 SP = SP - imm32;
751 if single_regs then
752 for r = 0 to regs-1
753 MemA[address,4] = S[d+r]; address = address+4;
754 else
755 for r = 0 to regs-1
756 // Store as two word-aligned words in the correct order for current endianness.
757 MemA[address,4] = if BigEndian() then D[d+r]<63:32> else D[d+r]<31:0>;
758 MemA[address+4,4] = if BigEndian() then D[d+r]<31:0> else D[d+r]<63:32>;
759 address = address+8;
760 }
761#endif
762
763 bool success = false;
764 const uint32_t opcode = emulator->OpcodeAsUnsigned (&success);
765 if (!success)
766 return false;
767
768 if (emulator->ConditionPassed())
769 {
770 const uint32_t addr_byte_size = emulator->GetAddressByteSize();
771 const addr_t sp = emulator->ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, 0, &success);
772 if (!success)
773 return false;
774 bool single_regs;
775 uint32_t d; // UInt(Vd:D) starting register
776 uint32_t imm32; // stack offset
777 uint32_t regs; // number of registers
778 switch (encoding) {
779 case eEncodingT1:
780 case eEncodingA1:
781 single_regs = false;
782 d = Bits32(opcode, 15, 12) << 1 | Bits32(opcode, 22, 22);
783 imm32 = Bits32(opcode, 7, 0) * addr_byte_size;
784 // If UInt(imm8) is odd, see "FSTMX".
785 regs = Bits32(opcode, 7, 0) / 2;
786 // if regs == 0 || regs > 16 || (d+regs) > 32 then UNPREDICTABLE;
787 if (regs == 0 || regs > 16 || (d + regs) > 32)
788 return false;
789 break;
790 case eEncodingT2:
791 case eEncodingA2:
792 single_regs = true;
793 d = Bits32(opcode, 15, 12) << 1 | Bits32(opcode, 22, 22);
794 imm32 = Bits32(opcode, 7, 0) * addr_byte_size;
795 regs = Bits32(opcode, 7, 0);
796 // if regs == 0 || regs > 16 || (d+regs) > 32 then UNPREDICTABLE;
797 if (regs == 0 || regs > 16 || (d + regs) > 32)
798 return false;
799 break;
800 default:
801 return false;
802 }
803 uint32_t start_reg = single_regs ? dwarf_s0 : dwarf_d0;
804 uint32_t reg_byte_size = single_regs ? addr_byte_size : addr_byte_size * 2;
805 addr_t sp_offset = imm32;
806 addr_t addr = sp - sp_offset;
807 uint32_t i;
808
809 EmulateInstruction::Context context = { EmulateInstruction::eContextPushRegisterOnStack, eRegisterKindDWARF, 0, 0 };
810 for (i=d; i<regs; ++i)
811 {
812 context.arg1 = start_reg + i; // arg1 in the context is the DWARF register number
813 context.arg2 = addr - sp; // arg2 in the context is the stack pointer offset
814 // uint64_t to accommodate 64-bit registers.
815 uint64_t reg_value = emulator->ReadRegisterUnsigned(eRegisterKindDWARF, context.arg1, 0, &success);
816 if (!success)
817 return false;
818 if (!emulator->WriteMemoryUnsigned (context, addr, reg_value, reg_byte_size))
819 return false;
820 addr += reg_byte_size;
821 }
822
823 context.type = EmulateInstruction::eContextAdjustStackPointer;
824 context.arg0 = eRegisterKindGeneric;
825 context.arg1 = LLDB_REGNUM_GENERIC_SP;
Johnny Chen5b442b72011-01-27 19:34:30 +0000826 context.arg2 = -sp_offset;
Johnny Chen799dfd02011-01-26 23:14:33 +0000827
828 if (!emulator->WriteRegisterUnsigned (context, eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP, sp - sp_offset))
829 return false;
830 }
831 return true;
832}
833
Greg Clayton64c84432011-01-21 22:02:52 +0000834static ARMOpcode g_arm_opcodes[] =
835{
Johnny Chene4455022011-01-26 00:08:59 +0000836 // push register(s)
Johnny Chenbcec3af2011-01-27 01:26:19 +0000837 { 0x0fff0000, 0x092d0000, ARMvAll, eEncodingA1, eSize32, emulate_push, "push <registers>" },
838 { 0x0fff0fff, 0x052d0004, ARMvAll, eEncodingA2, eSize32, emulate_push, "push <register>" },
839
Johnny Chen5b442b72011-01-27 19:34:30 +0000840 // set r7 to point to a stack offset
Johnny Chenbcec3af2011-01-27 01:26:19 +0000841 { 0x0ffff000, 0x028d7000, ARMvAll, eEncodingA1, eSize32, emulate_add_rd_sp_imm, "add r7, sp, #<const>" },
Johnny Chen2ccad832011-01-28 19:57:25 +0000842 { 0x0ffff000, 0x024c7000, ARMvAll, eEncodingA1, eSize32, emulate_sub_r7_ip_imm, "sub r7, ip, #<const>"},
Johnny Chen5b442b72011-01-27 19:34:30 +0000843 // set ip to point to a stack offset
Johnny Chen2ccad832011-01-28 19:57:25 +0000844 { 0x0fffffff, 0x01a0c00d, ARMvAll, eEncodingA1, eSize32, emulate_mov_rd_sp, "mov ip, sp" },
Johnny Chenbcec3af2011-01-27 01:26:19 +0000845 { 0x0ffff000, 0x028dc000, ARMvAll, eEncodingA1, eSize32, emulate_add_rd_sp_imm, "add ip, sp, #<const>" },
Johnny Chen2ccad832011-01-28 19:57:25 +0000846 { 0x0ffff000, 0x024dc000, ARMvAll, eEncodingA1, eSize32, emulate_sub_ip_sp_imm, "sub ip, sp, #<const>"},
Johnny Chen4c0e0bc2011-01-25 22:45:28 +0000847
848 // adjust the stack pointer
Johnny Chenbcec3af2011-01-27 01:26:19 +0000849 { 0x0ffff000, 0x024dd000, ARMvAll, eEncodingA1, eSize32, emulate_sub_sp_imm, "sub sp, sp, #<const>"},
Johnny Chence1ca772011-01-25 01:13:00 +0000850
Johnny Chen2ccad832011-01-28 19:57:25 +0000851 // push one register
Johnny Chence1ca772011-01-25 01:13:00 +0000852 // if Rn == '1101' && imm12 == '000000000100' then SEE PUSH;
Johnny Chen788e0552011-01-27 22:52:23 +0000853 { 0x0fff0000, 0x052d0000, ARMvAll, eEncodingA1, eSize32, emulate_str_rt_sp, "str Rt, [sp, #-imm12]!" },
Johnny Chen799dfd02011-01-26 23:14:33 +0000854
855 // vector push consecutive extension register(s)
Johnny Chenbcec3af2011-01-27 01:26:19 +0000856 { 0x0fbf0f00, 0x0d2d0b00, ARMv6T2|ARMv7, eEncodingA1, eSize32, emulate_vpush, "vpush.64 <list>"},
857 { 0x0fbf0f00, 0x0d2d0a00, ARMv6T2|ARMv7, eEncodingA2, eSize32, emulate_vpush, "vpush.32 <list>"}
Greg Clayton64c84432011-01-21 22:02:52 +0000858};
859
Johnny Chen347320d2011-01-24 23:40:59 +0000860static ARMOpcode g_thumb_opcodes[] =
861{
Johnny Chene4455022011-01-26 00:08:59 +0000862 // push register(s)
Johnny Chenbcec3af2011-01-27 01:26:19 +0000863 { 0xfffffe00, 0x0000b400, ARMvAll, eEncodingT1, eSize16, emulate_push, "push <registers>" },
864 { 0xffff0000, 0xe92d0000, ARMv6T2|ARMv7, eEncodingT2, eSize32, emulate_push, "push.w <registers>" },
865 { 0xffff0fff, 0xf84d0d04, ARMv6T2|ARMv7, eEncodingT3, eSize32, emulate_push, "push.w <register>" },
Johnny Chen1c13b622011-01-29 00:11:15 +0000866 // move from high register to low register
867 { 0xffffffc0, 0x00004640, ARMvAll, eEncodingT1, eSize16, emulate_mov_low_high, "mov r0-r7, r8-r15" },
Johnny Chenbcec3af2011-01-27 01:26:19 +0000868
Johnny Chen5b442b72011-01-27 19:34:30 +0000869 // set r7 to point to a stack offset
Johnny Chen2ccad832011-01-28 19:57:25 +0000870 { 0xffffff00, 0x0000af00, ARMvAll, eEncodingT1, eSize16, emulate_add_rd_sp_imm, "add r7, sp, #imm" },
871 { 0xffffffff, 0x0000466f, ARMvAll, eEncodingT1, eSize16, emulate_mov_rd_sp, "mov r7, sp" },
Johnny Chen788e0552011-01-27 22:52:23 +0000872
873 // PC relative load into register (see also emulate_add_sp_rm)
874 { 0xfffff800, 0x00004800, ARMvAll, eEncodingT1, eSize16, emulate_ldr_rd_pc_rel, "ldr <Rd>, [PC, #imm]"},
Johnny Chen60c0d622011-01-25 23:49:39 +0000875
876 // adjust the stack pointer
Johnny Chen5b442b72011-01-27 19:34:30 +0000877 { 0xffffff87, 0x00004485, ARMvAll, eEncodingT2, eSize16, emulate_add_sp_rm, "add sp, <Rm>"},
Johnny Chen788e0552011-01-27 22:52:23 +0000878 { 0xffffff80, 0x0000b080, ARMvAll, eEncodingT1, eSize16, emulate_sub_sp_imm, "add sp, sp, #imm"},
Johnny Chen5b442b72011-01-27 19:34:30 +0000879 { 0xfbef8f00, 0xf1ad0d00, ARMv6T2|ARMv7, eEncodingT2, eSize32, emulate_sub_sp_imm, "sub.w sp, sp, #<const>"},
Johnny Chen788e0552011-01-27 22:52:23 +0000880 { 0xfbff8f00, 0xf2ad0d00, ARMv6T2|ARMv7, eEncodingT3, eSize32, emulate_sub_sp_imm, "subw sp, sp, #imm12"},
Johnny Chen799dfd02011-01-26 23:14:33 +0000881
882 // vector push consecutive extension register(s)
Johnny Chenbcec3af2011-01-27 01:26:19 +0000883 { 0xffbf0f00, 0xed2d0b00, ARMv6T2|ARMv7, eEncodingT1, eSize32, emulate_vpush, "vpush.64 <list>"},
884 { 0xffbf0f00, 0xed2d0a00, ARMv6T2|ARMv7, eEncodingT2, eSize32, emulate_vpush, "vpush.32 <list>"}
Johnny Chen347320d2011-01-24 23:40:59 +0000885};
886
Greg Clayton64c84432011-01-21 22:02:52 +0000887static const size_t k_num_arm_opcodes = sizeof(g_arm_opcodes)/sizeof(ARMOpcode);
Johnny Chen347320d2011-01-24 23:40:59 +0000888static const size_t k_num_thumb_opcodes = sizeof(g_thumb_opcodes)/sizeof(ARMOpcode);
Greg Clayton64c84432011-01-21 22:02:52 +0000889
Greg Clayton31e2a382011-01-30 20:03:56 +0000890bool
891EmulateInstructionARM::SetTargetTriple (const ConstString &triple)
892{
893 m_arm_isa = 0;
894 const char *triple_cstr = triple.GetCString();
895 if (triple_cstr)
896 {
897 const char *dash = ::strchr (triple_cstr, '-');
898 if (dash)
899 {
900 std::string arch (triple_cstr, dash);
901 const char *arch_cstr = arch.c_str();
902 if (strcasecmp(arch_cstr, "armv4t") == 0)
903 m_arm_isa = ARMv4T;
904 else if (strcasecmp(arch_cstr, "armv4") == 0)
905 m_arm_isa = ARMv4;
906 else if (strcasecmp(arch_cstr, "armv5tej") == 0)
907 m_arm_isa = ARMv5TEJ;
908 else if (strcasecmp(arch_cstr, "armv5te") == 0)
909 m_arm_isa = ARMv5TE;
910 else if (strcasecmp(arch_cstr, "armv5t") == 0)
911 m_arm_isa = ARMv5T;
912 else if (strcasecmp(arch_cstr, "armv6k") == 0)
913 m_arm_isa = ARMv6K;
914 else if (strcasecmp(arch_cstr, "armv6") == 0)
915 m_arm_isa = ARMv6;
916 else if (strcasecmp(arch_cstr, "armv6t2") == 0)
917 m_arm_isa = ARMv6T2;
918 else if (strcasecmp(arch_cstr, "armv7") == 0)
919 m_arm_isa = ARMv7;
920 else if (strcasecmp(arch_cstr, "armv8") == 0)
921 m_arm_isa = ARMv8;
922 }
923 }
924 return m_arm_isa != 0;
925}
926
927
Greg Clayton64c84432011-01-21 22:02:52 +0000928bool
929EmulateInstructionARM::ReadInstruction ()
930{
931 bool success = false;
932 m_inst_cpsr = ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS, 0, &success);
933 if (success)
934 {
935 addr_t pc = ReadRegisterUnsigned (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_PC, LLDB_INVALID_ADDRESS, &success);
936 if (success)
937 {
938 Context read_inst_context = {eContextReadOpcode, 0, 0};
939 if (m_inst_cpsr & MASK_CPSR_T)
940 {
941 m_inst_mode = eModeThumb;
942 uint32_t thumb_opcode = ReadMemoryUnsigned(read_inst_context, pc, 2, 0, &success);
943
944 if (success)
945 {
946 if ((m_inst.opcode.inst16 & 0xe000) != 0xe000 || ((m_inst.opcode.inst16 & 0x1800u) == 0))
947 {
948 m_inst.opcode_type = eOpcode16;
949 m_inst.opcode.inst16 = thumb_opcode;
950 }
951 else
952 {
953 m_inst.opcode_type = eOpcode32;
954 m_inst.opcode.inst32 = (thumb_opcode << 16) | ReadMemoryUnsigned(read_inst_context, pc + 2, 2, 0, &success);
955 }
956 }
957 }
958 else
959 {
960 m_inst_mode = eModeARM;
961 m_inst.opcode_type = eOpcode32;
962 m_inst.opcode.inst32 = ReadMemoryUnsigned(read_inst_context, pc, 4, 0, &success);
963 }
964 }
965 }
966 if (!success)
967 {
968 m_inst_mode = eModeInvalid;
969 m_inst_pc = LLDB_INVALID_ADDRESS;
970 }
971 return success;
972}
973
974uint32_t
975EmulateInstructionARM::CurrentCond ()
976{
977 switch (m_inst_mode)
978 {
979 default:
980 case eModeInvalid:
981 break;
982
983 case eModeARM:
984 return UnsignedBits(m_inst.opcode.inst32, 31, 28);
985
986 case eModeThumb:
987 return 0x0000000Eu; // Return always for now, we need to handl IT instructions later
988 }
989 return UINT32_MAX; // Return invalid value
990}
991bool
992EmulateInstructionARM::ConditionPassed ()
993{
994 if (m_inst_cpsr == 0)
995 return false;
996
997 const uint32_t cond = CurrentCond ();
998
999 if (cond == UINT32_MAX)
1000 return false;
1001
1002 bool result = false;
1003 switch (UnsignedBits(cond, 3, 1))
1004 {
1005 case 0: result = (m_inst_cpsr & MASK_CPSR_Z) != 0; break;
1006 case 1: result = (m_inst_cpsr & MASK_CPSR_C) != 0; break;
1007 case 2: result = (m_inst_cpsr & MASK_CPSR_N) != 0; break;
1008 case 3: result = (m_inst_cpsr & MASK_CPSR_V) != 0; break;
1009 case 4: result = ((m_inst_cpsr & MASK_CPSR_C) != 0) && ((m_inst_cpsr & MASK_CPSR_Z) == 0); break;
1010 case 5:
1011 {
1012 bool n = (m_inst_cpsr & MASK_CPSR_N);
1013 bool v = (m_inst_cpsr & MASK_CPSR_V);
1014 result = n == v;
1015 }
1016 break;
1017 case 6:
1018 {
1019 bool n = (m_inst_cpsr & MASK_CPSR_N);
1020 bool v = (m_inst_cpsr & MASK_CPSR_V);
1021 result = n == v && ((m_inst_cpsr & MASK_CPSR_Z) == 0);
1022 }
1023 break;
1024 case 7:
1025 result = true;
1026 break;
1027 }
1028
1029 if (cond & 1)
1030 result = !result;
1031 return result;
1032}
1033
1034
1035bool
1036EmulateInstructionARM::EvaluateInstruction ()
1037{
1038 return false;
1039}