blob: 8cfb21793e9664209eb10308b495c2ef44c012e5 [file] [log] [blame]
Johnny Chenb68a3ee2010-04-02 22:27:38 +00001//===- ARMDisassembler.cpp - Disassembler for ARM/Thumb ISA -----*- 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//===----------------------------------------------------------------------===//
Johnny Chenb68a3ee2010-04-02 22:27:38 +00009
10#define DEBUG_TYPE "arm-disassembler"
11
12#include "ARMDisassembler.h"
Owen Anderson8d7d2e12011-08-09 20:55:18 +000013#include "ARM.h"
14#include "ARMRegisterInfo.h"
15#include "MCTargetDesc/ARMAddressingModes.h"
16#include "MCTargetDesc/ARMBaseInfo.h"
Sean Callanan9899f702010-04-13 21:21:57 +000017#include "llvm/MC/EDInstInfo.h"
Johnny Chenb68a3ee2010-04-02 22:27:38 +000018#include "llvm/MC/MCInst.h"
Owen Anderson8d7d2e12011-08-09 20:55:18 +000019#include "llvm/MC/MCExpr.h"
20#include "llvm/MC/MCContext.h"
Johnny Chenb68a3ee2010-04-02 22:27:38 +000021#include "llvm/Target/TargetRegistry.h"
22#include "llvm/Support/Debug.h"
23#include "llvm/Support/MemoryObject.h"
24#include "llvm/Support/ErrorHandling.h"
25#include "llvm/Support/raw_ostream.h"
26
Owen Anderson8d7d2e12011-08-09 20:55:18 +000027// Forward declare these because the autogenerated code will reference them.
28// Definitions are further down.
29static bool DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
30 uint64_t Address, const void *Decoder);
Owen Anderson51c98052011-08-09 22:48:45 +000031static bool DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
32 uint64_t Address, const void *Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +000033static bool DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
34 uint64_t Address, const void *Decoder);
35static bool DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
36 uint64_t Address, const void *Decoder);
37static bool DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
38 uint64_t Address, const void *Decoder);
39static bool DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
40 uint64_t Address, const void *Decoder);
41static bool DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
42 uint64_t Address, const void *Decoder);
43static bool DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
44 uint64_t Address, const void *Decoder);
45static bool DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
46 uint64_t Address, const void *Decoder);
47static bool DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
48 uint64_t Address, const void *Decoder);
Johnny Chen270159f2010-08-12 01:40:54 +000049
Owen Anderson8d7d2e12011-08-09 20:55:18 +000050static bool DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
51 uint64_t Address, const void *Decoder);
52static bool DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
53 uint64_t Address, const void *Decoder);
54static bool DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
55 uint64_t Address, const void *Decoder);
56static bool DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
57 uint64_t Address, const void *Decoder);
58static bool DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
59 uint64_t Address, const void *Decoder);
60static bool DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
61 uint64_t Address, const void *Decoder);
62static bool DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
63 uint64_t Address, const void *Decoder);
Johnny Chenb68a3ee2010-04-02 22:27:38 +000064
Owen Anderson8d7d2e12011-08-09 20:55:18 +000065static bool DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Insn,
66 uint64_t Address, const void *Decoder);
67static bool DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
68 uint64_t Address, const void *Decoder);
69static bool DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
70 uint64_t Address, const void *Decoder);
71static bool DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Insn,
72 uint64_t Address, const void *Decoder);
73static bool DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
74 uint64_t Address, const void *Decoder);
75static bool DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Insn,
76 uint64_t Address, const void *Decoder);
77static bool DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Insn,
78 uint64_t Address, const void *Decoder);
79
80static bool DecodeMemMultipleWritebackInstruction(llvm::MCInst & Inst,
81 unsigned Insn,
82 uint64_t Adddress,
83 const void *Decoder);
84static bool DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
85 uint64_t Address, const void *Decoder);
Owen Anderson35008c22011-08-09 23:05:39 +000086static bool DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
87 uint64_t Address, const void *Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +000088static bool DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
89 uint64_t Address, const void *Decoder);
90static bool DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
91 uint64_t Address, const void *Decoder);
92static bool DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
93 uint64_t Address, const void *Decoder);
94static bool DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
95 uint64_t Address, const void *Decoder);
96static bool DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
97 uint64_t Address, const void *Decoder);
98static bool DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
99 uint64_t Address, const void *Decoder);
100static bool DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Val,
101 uint64_t Address, const void *Decoder);
102static bool DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Val,
103 uint64_t Address, const void *Decoder);
104static bool DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Val,
105 uint64_t Address, const void *Decoder);
106static bool DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Val,
107 uint64_t Address, const void *Decoder);
108static bool DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Val,
109 uint64_t Address, const void *Decoder);
110static bool DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Val,
111 uint64_t Address, const void *Decoder);
112static bool DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Val,
113 uint64_t Address, const void *Decoder);
114static bool DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Val,
115 uint64_t Address, const void *Decoder);
116static bool DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
117 uint64_t Address, const void *Decoder);
118static bool DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
119 uint64_t Address, const void *Decoder);
120static bool DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
121 uint64_t Address, const void *Decoder);
122static bool DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
123 uint64_t Address, const void *Decoder);
124static bool DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
125 uint64_t Address, const void *Decoder);
126static bool DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
127 uint64_t Address, const void *Decoder);
128static bool DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
129 uint64_t Address, const void *Decoder);
130static bool DecodeCoprocessor(llvm::MCInst &Inst, unsigned Insn,
131 uint64_t Address, const void *Decoder);
132static bool DecodeAddrMode3Offset(llvm::MCInst &Inst, unsigned Insn,
133 uint64_t Address, const void *Decoder);
Owen Andersonc36481c2011-08-09 23:25:42 +0000134static bool DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Insn,
135 uint64_t Address, const void *Decoder);
Owen Anderson26d2f0a2011-08-11 20:21:46 +0000136static bool DecodeMSRMask(llvm::MCInst &Inst, unsigned Insn,
137 uint64_t Address, const void *Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000138
139
140static bool DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
141 uint64_t Address, const void *Decoder);
142static bool DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
143 uint64_t Address, const void *Decoder);
144static bool DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
145 uint64_t Address, const void *Decoder);
146static bool DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
147 uint64_t Address, const void *Decoder);
148static bool DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
149 uint64_t Address, const void *Decoder);
150static bool DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
151 uint64_t Address, const void *Decoder);
152static bool DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
153 uint64_t Address, const void *Decoder);
154static bool DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
155 uint64_t Address, const void *Decoder);
156static bool DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
157 uint64_t Address, const void *Decoder);
158static bool DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Val,
159 uint64_t Address, const void *Decoder);
160static bool DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
161 uint64_t Address, const void *Decoder);
162static bool DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
163 uint64_t Address, const void *Decoder);
164static bool DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
165 uint64_t Address, const void *Decoder);
166static bool DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
167 uint64_t Address, const void *Decoder);
168static bool DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Val,
169 uint64_t Address, const void *Decoder);
170static bool DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
171 uint64_t Address, const void *Decoder);
172static bool DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
173 uint64_t Address, const void *Decoder);
174static bool DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Insn,
175 uint64_t Address, const void *Decoder);
176static bool DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
177 uint64_t Address, const void *Decoder);
178static bool DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
179 uint64_t Address, const void *Decoder);
180static bool DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Val,
181 uint64_t Address, const void *Decoder);
182static bool DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
183 uint64_t Address, const void *Decoder);
184static bool DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
185 uint64_t Address, const void *Decoder);
186static bool DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
187 uint64_t Address, const void *Decoder);
188
189#include "ARMGenDisassemblerTables.inc"
190#include "ARMGenInstrInfo.inc"
Oscar Fuentes38e13902010-09-28 11:48:19 +0000191#include "ARMGenEDInfo.inc"
Sean Callanan9899f702010-04-13 21:21:57 +0000192
193using namespace llvm;
Johnny Chenb68a3ee2010-04-02 22:27:38 +0000194
Johnny Chenb68a3ee2010-04-02 22:27:38 +0000195static MCDisassembler *createARMDisassembler(const Target &T) {
196 return new ARMDisassembler;
197}
198
199static MCDisassembler *createThumbDisassembler(const Target &T) {
200 return new ThumbDisassembler;
201}
202
Sean Callanan9899f702010-04-13 21:21:57 +0000203EDInstInfo *ARMDisassembler::getEDInfo() const {
204 return instInfoARM;
205}
206
207EDInstInfo *ThumbDisassembler::getEDInfo() const {
208 return instInfoARM;
209}
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000210
211
212bool ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
213 const MemoryObject &Region,
214 uint64_t Address,raw_ostream &os) const {
215 uint8_t bytes[4];
216
217 // We want to read exactly 4 bytes of data.
218 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
219 return false;
220
221 // Encoded as a small-endian 32-bit word in the stream.
222 uint32_t insn = (bytes[3] << 24) |
223 (bytes[2] << 16) |
224 (bytes[1] << 8) |
225 (bytes[0] << 0);
226
227 // Calling the auto-generated decoder function.
228 bool result = decodeARMInstruction32(MI, insn, Address, this);
229 if (result) {
230 Size = 4;
231 return true;
232 }
233
234 // Instructions that are shared between ARM and Thumb modes.
235 // FIXME: This shouldn't really exist. It's an artifact of the
236 // fact that we fail to encode a few instructions properly for Thumb.
237 MI.clear();
238 result = decodeCommonInstruction32(MI, insn, Address, this);
239 if (result) {
240 Size = 4;
241 return true;
242 }
243
244 // VFP and NEON instructions, similarly, are shared between ARM
245 // and Thumb modes.
246 MI.clear();
247 result = decodeVFPInstruction32(MI, insn, Address, this);
248 if (result) {
249 Size = 4;
250 return true;
251 }
252
253 MI.clear();
Owen Anderson8533eba2011-08-10 19:01:10 +0000254 result = decodeNEONDataInstruction32(MI, insn, Address, this);
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000255 if (result) {
Owen Anderson8533eba2011-08-10 19:01:10 +0000256 Size = 4;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000257 // Add a fake predicate operand, because we share these instruction
258 // definitions with Thumb2 where these instructions are predicable.
259 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
Owen Anderson8533eba2011-08-10 19:01:10 +0000260 return true;
261 }
262
263 MI.clear();
264 result = decodeNEONLoadStoreInstruction32(MI, insn, Address, this);
265 if (result) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000266 Size = 4;
Owen Anderson8533eba2011-08-10 19:01:10 +0000267 // Add a fake predicate operand, because we share these instruction
268 // definitions with Thumb2 where these instructions are predicable.
269 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
270 return true;
271 }
272
273 MI.clear();
274 result = decodeNEONDupInstruction32(MI, insn, Address, this);
275 if (result) {
276 Size = 4;
277 // Add a fake predicate operand, because we share these instruction
278 // definitions with Thumb2 where these instructions are predicable.
279 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000280 return true;
281 }
282
283 MI.clear();
284
285 return false;
286}
287
288namespace llvm {
289extern MCInstrDesc ARMInsts[];
290}
291
292// Thumb1 instructions don't have explicit S bits. Rather, they
293// implicitly set CPSR. Since it's not represented in the encoding, the
294// auto-generated decoder won't inject the CPSR operand. We need to fix
295// that as a post-pass.
296static void AddThumb1SBit(MCInst &MI, bool InITBlock) {
297 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
298 MCInst::iterator I = MI.begin();
Owen Anderson10cbaab2011-08-10 17:36:48 +0000299 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000300 if (OpInfo[i].isOptionalDef() && OpInfo[i].RegClass == ARM::CCRRegClassID) {
301 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
302 return;
303 }
304 }
305
306 if (OpInfo[MI.size()].isOptionalDef() &&
307 OpInfo[MI.size()].RegClass == ARM::CCRRegClassID)
308 MI.insert(MI.end(), MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
309}
310
311// Most Thumb instructions don't have explicit predicates in the
312// encoding, but rather get their predicates from IT context. We need
313// to fix up the predicate operands using this context information as a
314// post-pass.
315void ThumbDisassembler::AddThumbPredicate(MCInst &MI) const {
316 // A few instructions actually have predicates encoded in them. Don't
317 // try to overwrite it if we're seeing one of those.
318 switch (MI.getOpcode()) {
319 case ARM::tBcc:
320 case ARM::t2Bcc:
321 return;
322 default:
323 break;
324 }
325
326 // If we're in an IT block, base the predicate on that. Otherwise,
327 // assume a predicate of AL.
328 unsigned CC;
Owen Anderson10cbaab2011-08-10 17:36:48 +0000329 if (!ITBlock.empty()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000330 CC = ITBlock.back();
331 ITBlock.pop_back();
332 } else
333 CC = ARMCC::AL;
334
335 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
336 MCInst::iterator I = MI.begin();
Owen Anderson10cbaab2011-08-10 17:36:48 +0000337 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000338 if (OpInfo[i].isPredicate()) {
339 I = MI.insert(I, MCOperand::CreateImm(CC));
340 ++I;
341 if (CC == ARMCC::AL)
342 MI.insert(I, MCOperand::CreateReg(0));
343 else
344 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
345 return;
346 }
347 }
348
349 MI.insert(MI.end(), MCOperand::CreateImm(CC));
350 if (CC == ARMCC::AL)
351 MI.insert(MI.end(), MCOperand::CreateReg(0));
352 else
353 MI.insert(MI.end(), MCOperand::CreateReg(ARM::CPSR));
354}
355
356// Thumb VFP instructions are a special case. Because we share their
357// encodings between ARM and Thumb modes, and they are predicable in ARM
358// mode, the auto-generated decoder will give them an (incorrect)
359// predicate operand. We need to rewrite these operands based on the IT
360// context as a post-pass.
361void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const {
362 unsigned CC;
Owen Anderson10cbaab2011-08-10 17:36:48 +0000363 if (!ITBlock.empty()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000364 CC = ITBlock.back();
365 ITBlock.pop_back();
366 } else
367 CC = ARMCC::AL;
368
369 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
370 MCInst::iterator I = MI.begin();
Owen Anderson10cbaab2011-08-10 17:36:48 +0000371 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000372 if (OpInfo[i].isPredicate() ) {
373 I->setImm(CC);
374 ++I;
375 if (CC == ARMCC::AL)
376 I->setReg(0);
377 else
378 I->setReg(ARM::CPSR);
379 return;
380 }
381 }
382}
383
384
385bool ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
386 const MemoryObject &Region,
387 uint64_t Address,raw_ostream &os) const {
388 uint8_t bytes[4];
389
390 // We want to read exactly 2 bytes of data.
391 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1)
392 return false;
393
394 uint16_t insn16 = (bytes[1] << 8) | bytes[0];
395 bool result = decodeThumbInstruction16(MI, insn16, Address, this);
396 if (result) {
397 Size = 2;
Owen Anderson10cbaab2011-08-10 17:36:48 +0000398 bool InITBlock = !ITBlock.empty();
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000399 AddThumbPredicate(MI);
400 AddThumb1SBit(MI, InITBlock);
401 return true;
402 }
403
404 MI.clear();
405 result = decodeThumb2Instruction16(MI, insn16, Address, this);
406 if (result) {
407 Size = 2;
408 AddThumbPredicate(MI);
409
410 // If we find an IT instruction, we need to parse its condition
411 // code and mask operands so that we can apply them correctly
412 // to the subsequent instructions.
413 if (MI.getOpcode() == ARM::t2IT) {
414 unsigned firstcond = MI.getOperand(0).getImm();
415 uint32_t mask = MI.getOperand(1).getImm();
416 unsigned zeros = CountTrailingZeros_32(mask);
417 mask >>= zeros+1;
418
419 for (unsigned i = 0; i < 4 - (zeros+1); ++i) {
420 if (firstcond ^ (mask & 1))
421 ITBlock.push_back(firstcond ^ 1);
422 else
423 ITBlock.push_back(firstcond);
424 mask >>= 1;
425 }
426 ITBlock.push_back(firstcond);
427 }
428
429 return true;
430 }
431
432 // We want to read exactly 4 bytes of data.
433 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
434 return false;
435
436 uint32_t insn32 = (bytes[3] << 8) |
437 (bytes[2] << 0) |
438 (bytes[1] << 24) |
439 (bytes[0] << 16);
440 MI.clear();
441 result = decodeThumbInstruction32(MI, insn32, Address, this);
442 if (result) {
443 Size = 4;
444 bool InITBlock = ITBlock.size();
445 AddThumbPredicate(MI);
446 AddThumb1SBit(MI, InITBlock);
447 return true;
448 }
449
450 MI.clear();
451 result = decodeThumb2Instruction32(MI, insn32, Address, this);
452 if (result) {
453 Size = 4;
454 AddThumbPredicate(MI);
455 return true;
456 }
457
458 MI.clear();
Owen Anderson8533eba2011-08-10 19:01:10 +0000459 result = decodeCommonInstruction32(MI, insn32, Address, this);
460 if (result) {
461 Size = 4;
462 AddThumbPredicate(MI);
463 return true;
464 }
465
466 MI.clear();
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000467 result = decodeVFPInstruction32(MI, insn32, Address, this);
468 if (result) {
469 Size = 4;
470 UpdateThumbVFPPredicate(MI);
471 return true;
472 }
473
474 MI.clear();
Owen Anderson8533eba2011-08-10 19:01:10 +0000475 if (fieldFromInstruction32(insn32, 24, 4) == 0xF) {
476 uint32_t NEONDataInsn = insn32;
477 NEONDataInsn &= 0xF0FFFFFF; // Clear bits 27-24
478 NEONDataInsn |= (NEONDataInsn & 0x10000000) >> 4; // Move bit 28 to bit 24
479 NEONDataInsn |= 0x12000000; // Set bits 28 and 25
480 result = decodeNEONDataInstruction32(MI, NEONDataInsn, Address, this);
481 if (result) {
482 Size = 4;
483 AddThumbPredicate(MI);
484 return true;
485 }
486 }
487
488 MI.clear();
489 result = decodeNEONLoadStoreInstruction32(MI, insn32, Address, this);
490 if (result) {
491 Size = 4;
492 AddThumbPredicate(MI);
493 return true;
494 }
495
496 MI.clear();
497 result = decodeNEONDupInstruction32(MI, insn32, Address, this);
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000498 if (result) {
499 Size = 4;
500 AddThumbPredicate(MI);
501 return true;
502 }
503
504 return false;
505}
506
507
508extern "C" void LLVMInitializeARMDisassembler() {
509 TargetRegistry::RegisterMCDisassembler(TheARMTarget,
510 createARMDisassembler);
511 TargetRegistry::RegisterMCDisassembler(TheThumbTarget,
512 createThumbDisassembler);
513}
514
515static const unsigned GPRDecoderTable[] = {
516 ARM::R0, ARM::R1, ARM::R2, ARM::R3,
517 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
518 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
519 ARM::R12, ARM::SP, ARM::LR, ARM::PC
520};
521
522static bool DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
523 uint64_t Address, const void *Decoder) {
524 if (RegNo > 15)
525 return false;
526
527 unsigned Register = GPRDecoderTable[RegNo];
528 Inst.addOperand(MCOperand::CreateReg(Register));
529 return true;
530}
531
Owen Anderson51c98052011-08-09 22:48:45 +0000532static bool DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
533 uint64_t Address, const void *Decoder) {
534 if (RegNo == 15) return false;
535 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
536}
537
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000538static bool DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
539 uint64_t Address, const void *Decoder) {
540 if (RegNo > 7)
541 return false;
542 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
543}
544
545static bool DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
546 uint64_t Address, const void *Decoder) {
547 unsigned Register = 0;
548 switch (RegNo) {
549 case 0:
550 Register = ARM::R0;
551 break;
552 case 1:
553 Register = ARM::R1;
554 break;
555 case 2:
556 Register = ARM::R2;
557 break;
558 case 3:
559 Register = ARM::R3;
560 break;
561 case 9:
562 Register = ARM::R9;
563 break;
564 case 12:
565 Register = ARM::R12;
566 break;
567 default:
568 return false;
569 }
570
571 Inst.addOperand(MCOperand::CreateReg(Register));
572 return true;
573}
574
575static bool DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
576 uint64_t Address, const void *Decoder) {
577 if (RegNo == 13 || RegNo == 15) return false;
578 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
579}
580
581static const unsigned SPRDecoderTable[] = {
582 ARM::S0, ARM::S1, ARM::S2, ARM::S3,
583 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
584 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
585 ARM::S12, ARM::S13, ARM::S14, ARM::S15,
586 ARM::S16, ARM::S17, ARM::S18, ARM::S19,
587 ARM::S20, ARM::S21, ARM::S22, ARM::S23,
588 ARM::S24, ARM::S25, ARM::S26, ARM::S27,
589 ARM::S28, ARM::S29, ARM::S30, ARM::S31
590};
591
592static bool DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
593 uint64_t Address, const void *Decoder) {
594 if (RegNo > 31)
595 return false;
596
597 unsigned Register = SPRDecoderTable[RegNo];
598 Inst.addOperand(MCOperand::CreateReg(Register));
599 return true;
600}
601
602static const unsigned DPRDecoderTable[] = {
603 ARM::D0, ARM::D1, ARM::D2, ARM::D3,
604 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
605 ARM::D8, ARM::D9, ARM::D10, ARM::D11,
606 ARM::D12, ARM::D13, ARM::D14, ARM::D15,
607 ARM::D16, ARM::D17, ARM::D18, ARM::D19,
608 ARM::D20, ARM::D21, ARM::D22, ARM::D23,
609 ARM::D24, ARM::D25, ARM::D26, ARM::D27,
610 ARM::D28, ARM::D29, ARM::D30, ARM::D31
611};
612
613static bool DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
614 uint64_t Address, const void *Decoder) {
615 if (RegNo > 31)
616 return false;
617
618 unsigned Register = DPRDecoderTable[RegNo];
619 Inst.addOperand(MCOperand::CreateReg(Register));
620 return true;
621}
622
623static bool DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
624 uint64_t Address, const void *Decoder) {
625 if (RegNo > 7)
626 return false;
627 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
628}
629
630static bool DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
631 uint64_t Address, const void *Decoder) {
632 if (RegNo > 15)
633 return false;
634 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
635}
636
637static const unsigned QPRDecoderTable[] = {
638 ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
639 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7,
640 ARM::Q8, ARM::Q9, ARM::Q10, ARM::Q11,
641 ARM::Q12, ARM::Q13, ARM::Q14, ARM::Q15
642};
643
644
645static bool DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
646 uint64_t Address, const void *Decoder) {
647 if (RegNo > 31)
648 return false;
649 RegNo >>= 1;
650
651 unsigned Register = QPRDecoderTable[RegNo];
652 Inst.addOperand(MCOperand::CreateReg(Register));
653 return true;
654}
655
656static bool DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
657 uint64_t Address, const void *Decoder) {
658 if (Val == 0xF) return false;
Owen Andersonbd9091c2011-08-09 21:07:45 +0000659 // AL predicate is not allowed on Thumb1 branches.
660 if (Inst.getOpcode() == ARM::tBcc && Val == 0xE)
661 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000662 Inst.addOperand(MCOperand::CreateImm(Val));
663 if (Val == ARMCC::AL) {
664 Inst.addOperand(MCOperand::CreateReg(0));
665 } else
666 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
667 return true;
668}
669
670static bool DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
671 uint64_t Address, const void *Decoder) {
672 if (Val)
673 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
674 else
675 Inst.addOperand(MCOperand::CreateReg(0));
676 return true;
677}
678
679static bool DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
680 uint64_t Address, const void *Decoder) {
681 uint32_t imm = Val & 0xFF;
682 uint32_t rot = (Val & 0xF00) >> 7;
683 uint32_t rot_imm = (imm >> rot) | (imm << (32-rot));
684 Inst.addOperand(MCOperand::CreateImm(rot_imm));
685 return true;
686}
687
688static bool DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
689 uint64_t Address, const void *Decoder) {
690 Val <<= 2;
691 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(Val)));
692 return true;
693}
694
695static bool DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Val,
696 uint64_t Address, const void *Decoder) {
697
698 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
699 unsigned type = fieldFromInstruction32(Val, 5, 2);
700 unsigned imm = fieldFromInstruction32(Val, 7, 5);
701
702 // Register-immediate
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000703 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000704
705 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
706 switch (type) {
707 case 0:
708 Shift = ARM_AM::lsl;
709 break;
710 case 1:
711 Shift = ARM_AM::lsr;
712 break;
713 case 2:
714 Shift = ARM_AM::asr;
715 break;
716 case 3:
717 Shift = ARM_AM::ror;
718 break;
719 }
720
721 if (Shift == ARM_AM::ror && imm == 0)
722 Shift = ARM_AM::rrx;
723
724 unsigned Op = Shift | (imm << 3);
725 Inst.addOperand(MCOperand::CreateImm(Op));
726
727 return true;
728}
729
730static bool DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Val,
731 uint64_t Address, const void *Decoder) {
732
733 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
734 unsigned type = fieldFromInstruction32(Val, 5, 2);
735 unsigned Rs = fieldFromInstruction32(Val, 8, 4);
736
737 // Register-register
Owen Andersonde317f42011-08-09 23:33:27 +0000738 if (!DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)) return false;
739 if (!DecodeGPRnopcRegisterClass(Inst, Rs, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000740
741 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
742 switch (type) {
743 case 0:
744 Shift = ARM_AM::lsl;
745 break;
746 case 1:
747 Shift = ARM_AM::lsr;
748 break;
749 case 2:
750 Shift = ARM_AM::asr;
751 break;
752 case 3:
753 Shift = ARM_AM::ror;
754 break;
755 }
756
757 Inst.addOperand(MCOperand::CreateImm(Shift));
758
759 return true;
760}
761
762static bool DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
763 uint64_t Address, const void *Decoder) {
Owen Anderson26d2f0a2011-08-11 20:21:46 +0000764 // Empty register lists are not allowed.
765 if (CountPopulation_32(Val) == 0) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000766 for (unsigned i = 0; i < 16; ++i) {
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000767 if (Val & (1 << i)) {
768 if (!DecodeGPRRegisterClass(Inst, i, Address, Decoder)) return false;
769 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000770 }
771
772 return true;
773}
774
775static bool DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
776 uint64_t Address, const void *Decoder) {
777 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
778 unsigned regs = Val & 0xFF;
779
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000780 if (!DecodeSPRRegisterClass(Inst, Vd, Address, Decoder)) return false;
781 for (unsigned i = 0; i < (regs - 1); ++i) {
782 if (!DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder)) return false;
783 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000784
785 return true;
786}
787
788static bool DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
789 uint64_t Address, const void *Decoder) {
790 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
791 unsigned regs = (Val & 0xFF) / 2;
792
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000793 if (!DecodeDPRRegisterClass(Inst, Vd, Address, Decoder)) return false;
794 for (unsigned i = 0; i < (regs - 1); ++i) {
795 if (!DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder)) return false;
796 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000797
798 return true;
799}
800
801static bool DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Val,
802 uint64_t Address, const void *Decoder) {
Owen Anderson10cbaab2011-08-10 17:36:48 +0000803 // This operand encodes a mask of contiguous zeros between a specified MSB
804 // and LSB. To decode it, we create the mask of all bits MSB-and-lower,
805 // the mask of all bits LSB-and-lower, and then xor them to create
806 // the mask of that's all ones on [msb, lsb]. Finally we not it to
807 // create the final mask.
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000808 unsigned msb = fieldFromInstruction32(Val, 5, 5);
809 unsigned lsb = fieldFromInstruction32(Val, 0, 5);
810 uint32_t msb_mask = (1 << (msb+1)) - 1;
811 uint32_t lsb_mask = (1 << lsb) - 1;
812 Inst.addOperand(MCOperand::CreateImm(~(msb_mask ^ lsb_mask)));
813 return true;
814}
815
816static bool DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
817 uint64_t Address, const void *Decoder) {
818 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
819 unsigned CRd = fieldFromInstruction32(Insn, 12, 4);
820 unsigned coproc = fieldFromInstruction32(Insn, 8, 4);
821 unsigned imm = fieldFromInstruction32(Insn, 0, 8);
822 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
823 unsigned U = fieldFromInstruction32(Insn, 23, 1);
824
825 switch (Inst.getOpcode()) {
826 case ARM::LDC_OFFSET:
827 case ARM::LDC_PRE:
828 case ARM::LDC_POST:
829 case ARM::LDC_OPTION:
830 case ARM::LDCL_OFFSET:
831 case ARM::LDCL_PRE:
832 case ARM::LDCL_POST:
833 case ARM::LDCL_OPTION:
834 case ARM::STC_OFFSET:
835 case ARM::STC_PRE:
836 case ARM::STC_POST:
837 case ARM::STC_OPTION:
838 case ARM::STCL_OFFSET:
839 case ARM::STCL_PRE:
840 case ARM::STCL_POST:
841 case ARM::STCL_OPTION:
842 if (coproc == 0xA || coproc == 0xB)
843 return false;
844 break;
845 default:
846 break;
847 }
848
849 Inst.addOperand(MCOperand::CreateImm(coproc));
850 Inst.addOperand(MCOperand::CreateImm(CRd));
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000851 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000852 switch (Inst.getOpcode()) {
853 case ARM::LDC_OPTION:
854 case ARM::LDCL_OPTION:
855 case ARM::LDC2_OPTION:
856 case ARM::LDC2L_OPTION:
857 case ARM::STC_OPTION:
858 case ARM::STCL_OPTION:
859 case ARM::STC2_OPTION:
860 case ARM::STC2L_OPTION:
861 case ARM::LDCL_POST:
862 case ARM::STCL_POST:
863 break;
864 default:
865 Inst.addOperand(MCOperand::CreateReg(0));
866 break;
867 }
868
869 unsigned P = fieldFromInstruction32(Insn, 24, 1);
870 unsigned W = fieldFromInstruction32(Insn, 21, 1);
871
872 bool writeback = (P == 0) || (W == 1);
873 unsigned idx_mode = 0;
874 if (P && writeback)
875 idx_mode = ARMII::IndexModePre;
876 else if (!P && writeback)
877 idx_mode = ARMII::IndexModePost;
878
879 switch (Inst.getOpcode()) {
880 case ARM::LDCL_POST:
881 case ARM::STCL_POST:
882 imm |= U << 8;
883 case ARM::LDC_OPTION:
884 case ARM::LDCL_OPTION:
885 case ARM::LDC2_OPTION:
886 case ARM::LDC2L_OPTION:
887 case ARM::STC_OPTION:
888 case ARM::STCL_OPTION:
889 case ARM::STC2_OPTION:
890 case ARM::STC2L_OPTION:
891 Inst.addOperand(MCOperand::CreateImm(imm));
892 break;
893 default:
894 if (U)
895 Inst.addOperand(MCOperand::CreateImm(
896 ARM_AM::getAM2Opc(ARM_AM::add, imm, ARM_AM::lsl, idx_mode)));
897 else
898 Inst.addOperand(MCOperand::CreateImm(
899 ARM_AM::getAM2Opc(ARM_AM::sub, imm, ARM_AM::lsl, idx_mode)));
900 break;
901 }
902
903 switch (Inst.getOpcode()) {
904 case ARM::LDC_OFFSET:
905 case ARM::LDC_PRE:
906 case ARM::LDC_POST:
907 case ARM::LDC_OPTION:
908 case ARM::LDCL_OFFSET:
909 case ARM::LDCL_PRE:
910 case ARM::LDCL_POST:
911 case ARM::LDCL_OPTION:
912 case ARM::STC_OFFSET:
913 case ARM::STC_PRE:
914 case ARM::STC_POST:
915 case ARM::STC_OPTION:
916 case ARM::STCL_OFFSET:
917 case ARM::STCL_PRE:
918 case ARM::STCL_POST:
919 case ARM::STCL_OPTION:
920 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
921 break;
922 default:
923 break;
924 }
925
926 return true;
927}
928
929static bool DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
930 uint64_t Address, const void *Decoder) {
931 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
932 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
933 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
934 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
935 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
936 unsigned reg = fieldFromInstruction32(Insn, 25, 1);
937 unsigned P = fieldFromInstruction32(Insn, 24, 1);
938 unsigned W = fieldFromInstruction32(Insn, 21, 1);
939
940 // On stores, the writeback operand precedes Rt.
941 switch (Inst.getOpcode()) {
942 case ARM::STR_POST_IMM:
943 case ARM::STR_POST_REG:
944 case ARM::STRTr:
945 case ARM::STRTi:
Jim Grosbach10348e72011-08-11 20:04:56 +0000946 case ARM::STRBT_POST_REG:
947 case ARM::STRBT_POST_IMM:
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000948 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000949 break;
950 default:
951 break;
952 }
953
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000954 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000955
956 // On loads, the writeback operand comes after Rt.
957 switch (Inst.getOpcode()) {
958 case ARM::LDR_POST_IMM:
959 case ARM::LDR_POST_REG:
960 case ARM::LDR_PRE:
961 case ARM::LDRBT_POST_REG:
962 case ARM::LDRBT_POST_IMM:
Jim Grosbach59999262011-08-10 23:43:54 +0000963 case ARM::LDRT_POST_REG:
964 case ARM::LDRT_POST_IMM:
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000965 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
966 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000967 break;
968 default:
969 break;
970 }
971
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000972 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000973
974 ARM_AM::AddrOpc Op = ARM_AM::add;
975 if (!fieldFromInstruction32(Insn, 23, 1))
976 Op = ARM_AM::sub;
977
978 bool writeback = (P == 0) || (W == 1);
979 unsigned idx_mode = 0;
980 if (P && writeback)
981 idx_mode = ARMII::IndexModePre;
982 else if (!P && writeback)
983 idx_mode = ARMII::IndexModePost;
984
Owen Anderson71156a62011-08-11 19:00:18 +0000985 if (writeback && (Rn == 15 || Rn == Rt)) return false; // UNPREDICTABLE
986
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000987 if (reg) {
Owen Anderson2b7b2382011-08-11 18:55:42 +0000988 if (!DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000989 ARM_AM::ShiftOpc Opc = ARM_AM::lsl;
990 switch( fieldFromInstruction32(Insn, 5, 2)) {
991 case 0:
992 Opc = ARM_AM::lsl;
993 break;
994 case 1:
995 Opc = ARM_AM::lsr;
996 break;
997 case 2:
998 Opc = ARM_AM::asr;
999 break;
1000 case 3:
1001 Opc = ARM_AM::ror;
1002 break;
1003 default:
1004 return false;
1005 }
1006 unsigned amt = fieldFromInstruction32(Insn, 7, 5);
1007 unsigned imm = ARM_AM::getAM2Opc(Op, amt, Opc, idx_mode);
1008
1009 Inst.addOperand(MCOperand::CreateImm(imm));
1010 } else {
1011 Inst.addOperand(MCOperand::CreateReg(0));
1012 unsigned tmp = ARM_AM::getAM2Opc(Op, imm, ARM_AM::lsl, idx_mode);
1013 Inst.addOperand(MCOperand::CreateImm(tmp));
1014 }
1015
1016 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1017
1018 return true;
1019}
1020
1021static bool DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Val,
1022 uint64_t Address, const void *Decoder) {
1023 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1024 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1025 unsigned type = fieldFromInstruction32(Val, 5, 2);
1026 unsigned imm = fieldFromInstruction32(Val, 7, 5);
1027 unsigned U = fieldFromInstruction32(Val, 12, 1);
1028
Owen Anderson51157d22011-08-09 21:38:14 +00001029 ARM_AM::ShiftOpc ShOp = ARM_AM::lsl;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001030 switch (type) {
1031 case 0:
1032 ShOp = ARM_AM::lsl;
1033 break;
1034 case 1:
1035 ShOp = ARM_AM::lsr;
1036 break;
1037 case 2:
1038 ShOp = ARM_AM::asr;
1039 break;
1040 case 3:
1041 ShOp = ARM_AM::ror;
1042 break;
1043 }
1044
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001045 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1046 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001047 unsigned shift;
1048 if (U)
1049 shift = ARM_AM::getAM2Opc(ARM_AM::add, imm, ShOp);
1050 else
1051 shift = ARM_AM::getAM2Opc(ARM_AM::sub, imm, ShOp);
1052 Inst.addOperand(MCOperand::CreateImm(shift));
1053
1054 return true;
1055}
1056
1057static bool DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
1058 uint64_t Address, const void *Decoder) {
1059 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1060 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1061 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1062 unsigned type = fieldFromInstruction32(Insn, 22, 1);
1063 unsigned imm = fieldFromInstruction32(Insn, 8, 4);
1064 unsigned U = ((~fieldFromInstruction32(Insn, 23, 1)) & 1) << 8;
1065 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1066 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1067 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1068
1069 bool writeback = (W == 1) | (P == 0);
1070 if (writeback) { // Writeback
1071 if (P)
1072 U |= ARMII::IndexModePre << 9;
1073 else
1074 U |= ARMII::IndexModePost << 9;
1075
1076 // On stores, the writeback operand precedes Rt.
1077 switch (Inst.getOpcode()) {
1078 case ARM::STRD:
1079 case ARM::STRD_PRE:
1080 case ARM::STRD_POST:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001081 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1082 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001083 break;
1084 default:
1085 break;
1086 }
1087 }
1088
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001089 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))
1090 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001091 switch (Inst.getOpcode()) {
1092 case ARM::STRD:
1093 case ARM::STRD_PRE:
1094 case ARM::STRD_POST:
1095 case ARM::LDRD:
1096 case ARM::LDRD_PRE:
1097 case ARM::LDRD_POST:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001098 if (!DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder))
1099 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001100 break;
1101 default:
1102 break;
1103 }
1104
1105 if (writeback) {
1106 // On loads, the writeback operand comes after Rt.
1107 switch (Inst.getOpcode()) {
1108 case ARM::LDRD:
1109 case ARM::LDRD_PRE:
1110 case ARM::LDRD_POST:
1111 case ARM::LDRHTr:
1112 case ARM::LDRSBTr:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001113 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1114 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001115 break;
1116 default:
1117 break;
1118 }
1119 }
1120
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001121 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1122 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001123
1124 if (type) {
1125 Inst.addOperand(MCOperand::CreateReg(0));
1126 Inst.addOperand(MCOperand::CreateImm(U | (imm << 4) | Rm));
1127 } else {
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001128 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1129 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001130 Inst.addOperand(MCOperand::CreateImm(U));
1131 }
1132
1133 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1134
1135 return true;
1136}
1137
1138static bool DecodeRFEInstruction(llvm::MCInst &Inst, unsigned Insn,
1139 uint64_t Address, const void *Decoder) {
1140 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1141 unsigned mode = fieldFromInstruction32(Insn, 23, 2);
1142
1143 switch (mode) {
1144 case 0:
1145 mode = ARM_AM::da;
1146 break;
1147 case 1:
1148 mode = ARM_AM::ia;
1149 break;
1150 case 2:
1151 mode = ARM_AM::db;
1152 break;
1153 case 3:
1154 mode = ARM_AM::ib;
1155 break;
1156 }
1157
1158 Inst.addOperand(MCOperand::CreateImm(mode));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001159 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001160
1161 return true;
1162}
1163
1164static bool DecodeMemMultipleWritebackInstruction(llvm::MCInst &Inst,
1165 unsigned Insn,
1166 uint64_t Address, const void *Decoder) {
1167 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1168 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1169 unsigned reglist = fieldFromInstruction32(Insn, 0, 16);
1170
1171 if (pred == 0xF) {
1172 switch (Inst.getOpcode()) {
1173 case ARM::STMDA:
1174 Inst.setOpcode(ARM::RFEDA);
1175 break;
1176 case ARM::STMDA_UPD:
1177 Inst.setOpcode(ARM::RFEDA_UPD);
1178 break;
1179 case ARM::STMDB:
1180 Inst.setOpcode(ARM::RFEDB);
1181 break;
1182 case ARM::STMDB_UPD:
1183 Inst.setOpcode(ARM::RFEDB_UPD);
1184 break;
1185 case ARM::STMIA:
1186 Inst.setOpcode(ARM::RFEIA);
1187 break;
1188 case ARM::STMIA_UPD:
1189 Inst.setOpcode(ARM::RFEIA_UPD);
1190 break;
1191 case ARM::STMIB:
1192 Inst.setOpcode(ARM::RFEIB);
1193 break;
1194 case ARM::STMIB_UPD:
1195 Inst.setOpcode(ARM::RFEIB_UPD);
1196 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001197 }
1198 return DecodeRFEInstruction(Inst, Insn, Address, Decoder);
1199 }
1200
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001201 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
1202 !DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) || // Tied
1203 !DecodePredicateOperand(Inst, pred, Address, Decoder) ||
1204 !DecodeRegListOperand(Inst, reglist, Address, Decoder))
1205 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001206
1207 return true;
1208}
1209
1210static bool DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
1211 uint64_t Address, const void *Decoder) {
1212 unsigned imod = fieldFromInstruction32(Insn, 18, 2);
1213 unsigned M = fieldFromInstruction32(Insn, 17, 1);
1214 unsigned iflags = fieldFromInstruction32(Insn, 6, 3);
1215 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1216
Owen Anderson35008c22011-08-09 23:05:39 +00001217 // imod == '01' --> UNPREDICTABLE
1218 if (imod == 1) return false;
1219
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001220 if (M && mode && imod && iflags) {
1221 Inst.setOpcode(ARM::CPS3p);
1222 Inst.addOperand(MCOperand::CreateImm(imod));
1223 Inst.addOperand(MCOperand::CreateImm(iflags));
1224 Inst.addOperand(MCOperand::CreateImm(mode));
1225 return true;
1226 } else if (!mode && !M) {
1227 Inst.setOpcode(ARM::CPS2p);
1228 Inst.addOperand(MCOperand::CreateImm(imod));
1229 Inst.addOperand(MCOperand::CreateImm(iflags));
1230 return true;
1231 } else if (!imod && !iflags && M) {
1232 Inst.setOpcode(ARM::CPS1p);
1233 Inst.addOperand(MCOperand::CreateImm(mode));
1234 return true;
1235 }
1236
1237 return false;
1238}
1239
1240static bool DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
1241 uint64_t Address, const void *Decoder) {
1242 unsigned Rd = fieldFromInstruction32(Insn, 16, 4);
1243 unsigned Rn = fieldFromInstruction32(Insn, 0, 4);
1244 unsigned Rm = fieldFromInstruction32(Insn, 8, 4);
1245 unsigned Ra = fieldFromInstruction32(Insn, 12, 4);
1246 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1247
1248 if (pred == 0xF)
1249 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
1250
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001251 if (!DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder) ||
1252 !DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder) ||
1253 !DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder) ||
1254 !DecodeGPRnopcRegisterClass(Inst, Ra, Address, Decoder))
1255 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001256
1257 return true;
1258}
1259
1260static bool DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
1261 uint64_t Address, const void *Decoder) {
1262 unsigned add = fieldFromInstruction32(Val, 12, 1);
1263 unsigned imm = fieldFromInstruction32(Val, 0, 12);
1264 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1265
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001266 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1267 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001268
1269 if (!add) imm *= -1;
1270 if (imm == 0 && !add) imm = INT32_MIN;
1271 Inst.addOperand(MCOperand::CreateImm(imm));
1272
1273 return true;
1274}
1275
1276static bool DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
1277 uint64_t Address, const void *Decoder) {
1278 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
1279 unsigned U = fieldFromInstruction32(Val, 8, 1);
1280 unsigned imm = fieldFromInstruction32(Val, 0, 8);
1281
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001282 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1283 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001284
1285 if (U)
1286 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add, imm)));
1287 else
1288 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub, imm)));
1289
1290 return true;
1291}
1292
1293static bool DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
1294 uint64_t Address, const void *Decoder) {
1295 return DecodeGPRRegisterClass(Inst, Val, Address, Decoder);
1296}
1297
1298static bool DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1299 uint64_t Address, const void *Decoder) {
1300 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1301 unsigned imm = fieldFromInstruction32(Insn, 0, 24) << 2;
1302
1303 if (pred == 0xF) {
1304 Inst.setOpcode(ARM::BLXi);
1305 imm |= fieldFromInstruction32(Insn, 24, 1) << 1;
Benjamin Kramer793b8112011-08-09 22:02:50 +00001306 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001307 return true;
1308 }
1309
Benjamin Kramer793b8112011-08-09 22:02:50 +00001310 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001311 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1312
1313 return true;
1314}
1315
1316
1317static bool DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
1318 uint64_t Address, const void *Decoder) {
1319 Inst.addOperand(MCOperand::CreateImm(64 - Val));
1320 return true;
1321}
1322
1323static bool DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
1324 uint64_t Address, const void *Decoder) {
1325 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1326 unsigned align = fieldFromInstruction32(Val, 4, 2);
1327
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001328 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1329 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001330 if (!align)
1331 Inst.addOperand(MCOperand::CreateImm(0));
1332 else
1333 Inst.addOperand(MCOperand::CreateImm(4 << align));
1334
1335 return true;
1336}
1337
1338static bool DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Insn,
1339 uint64_t Address, const void *Decoder) {
1340 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1341 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1342 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1343 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1344 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1345 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1346
1347 // First output register
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001348 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001349
1350 // Second output register
1351 switch (Inst.getOpcode()) {
1352 case ARM::VLD1q8:
1353 case ARM::VLD1q16:
1354 case ARM::VLD1q32:
1355 case ARM::VLD1q64:
1356 case ARM::VLD1q8_UPD:
1357 case ARM::VLD1q16_UPD:
1358 case ARM::VLD1q32_UPD:
1359 case ARM::VLD1q64_UPD:
1360 case ARM::VLD1d8T:
1361 case ARM::VLD1d16T:
1362 case ARM::VLD1d32T:
1363 case ARM::VLD1d64T:
1364 case ARM::VLD1d8T_UPD:
1365 case ARM::VLD1d16T_UPD:
1366 case ARM::VLD1d32T_UPD:
1367 case ARM::VLD1d64T_UPD:
1368 case ARM::VLD1d8Q:
1369 case ARM::VLD1d16Q:
1370 case ARM::VLD1d32Q:
1371 case ARM::VLD1d64Q:
1372 case ARM::VLD1d8Q_UPD:
1373 case ARM::VLD1d16Q_UPD:
1374 case ARM::VLD1d32Q_UPD:
1375 case ARM::VLD1d64Q_UPD:
1376 case ARM::VLD2d8:
1377 case ARM::VLD2d16:
1378 case ARM::VLD2d32:
1379 case ARM::VLD2d8_UPD:
1380 case ARM::VLD2d16_UPD:
1381 case ARM::VLD2d32_UPD:
1382 case ARM::VLD2q8:
1383 case ARM::VLD2q16:
1384 case ARM::VLD2q32:
1385 case ARM::VLD2q8_UPD:
1386 case ARM::VLD2q16_UPD:
1387 case ARM::VLD2q32_UPD:
1388 case ARM::VLD3d8:
1389 case ARM::VLD3d16:
1390 case ARM::VLD3d32:
1391 case ARM::VLD3d8_UPD:
1392 case ARM::VLD3d16_UPD:
1393 case ARM::VLD3d32_UPD:
1394 case ARM::VLD4d8:
1395 case ARM::VLD4d16:
1396 case ARM::VLD4d32:
1397 case ARM::VLD4d8_UPD:
1398 case ARM::VLD4d16_UPD:
1399 case ARM::VLD4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001400 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001401 break;
1402 case ARM::VLD2b8:
1403 case ARM::VLD2b16:
1404 case ARM::VLD2b32:
1405 case ARM::VLD2b8_UPD:
1406 case ARM::VLD2b16_UPD:
1407 case ARM::VLD2b32_UPD:
1408 case ARM::VLD3q8:
1409 case ARM::VLD3q16:
1410 case ARM::VLD3q32:
1411 case ARM::VLD3q8_UPD:
1412 case ARM::VLD3q16_UPD:
1413 case ARM::VLD3q32_UPD:
1414 case ARM::VLD4q8:
1415 case ARM::VLD4q16:
1416 case ARM::VLD4q32:
1417 case ARM::VLD4q8_UPD:
1418 case ARM::VLD4q16_UPD:
1419 case ARM::VLD4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001420 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001421 default:
1422 break;
1423 }
1424
1425 // Third output register
1426 switch(Inst.getOpcode()) {
1427 case ARM::VLD1d8T:
1428 case ARM::VLD1d16T:
1429 case ARM::VLD1d32T:
1430 case ARM::VLD1d64T:
1431 case ARM::VLD1d8T_UPD:
1432 case ARM::VLD1d16T_UPD:
1433 case ARM::VLD1d32T_UPD:
1434 case ARM::VLD1d64T_UPD:
1435 case ARM::VLD1d8Q:
1436 case ARM::VLD1d16Q:
1437 case ARM::VLD1d32Q:
1438 case ARM::VLD1d64Q:
1439 case ARM::VLD1d8Q_UPD:
1440 case ARM::VLD1d16Q_UPD:
1441 case ARM::VLD1d32Q_UPD:
1442 case ARM::VLD1d64Q_UPD:
1443 case ARM::VLD2q8:
1444 case ARM::VLD2q16:
1445 case ARM::VLD2q32:
1446 case ARM::VLD2q8_UPD:
1447 case ARM::VLD2q16_UPD:
1448 case ARM::VLD2q32_UPD:
1449 case ARM::VLD3d8:
1450 case ARM::VLD3d16:
1451 case ARM::VLD3d32:
1452 case ARM::VLD3d8_UPD:
1453 case ARM::VLD3d16_UPD:
1454 case ARM::VLD3d32_UPD:
1455 case ARM::VLD4d8:
1456 case ARM::VLD4d16:
1457 case ARM::VLD4d32:
1458 case ARM::VLD4d8_UPD:
1459 case ARM::VLD4d16_UPD:
1460 case ARM::VLD4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001461 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001462 break;
1463 case ARM::VLD3q8:
1464 case ARM::VLD3q16:
1465 case ARM::VLD3q32:
1466 case ARM::VLD3q8_UPD:
1467 case ARM::VLD3q16_UPD:
1468 case ARM::VLD3q32_UPD:
1469 case ARM::VLD4q8:
1470 case ARM::VLD4q16:
1471 case ARM::VLD4q32:
1472 case ARM::VLD4q8_UPD:
1473 case ARM::VLD4q16_UPD:
1474 case ARM::VLD4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001475 if (!DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001476 break;
1477 default:
1478 break;
1479 }
1480
1481 // Fourth output register
1482 switch (Inst.getOpcode()) {
1483 case ARM::VLD1d8Q:
1484 case ARM::VLD1d16Q:
1485 case ARM::VLD1d32Q:
1486 case ARM::VLD1d64Q:
1487 case ARM::VLD1d8Q_UPD:
1488 case ARM::VLD1d16Q_UPD:
1489 case ARM::VLD1d32Q_UPD:
1490 case ARM::VLD1d64Q_UPD:
1491 case ARM::VLD2q8:
1492 case ARM::VLD2q16:
1493 case ARM::VLD2q32:
1494 case ARM::VLD2q8_UPD:
1495 case ARM::VLD2q16_UPD:
1496 case ARM::VLD2q32_UPD:
1497 case ARM::VLD4d8:
1498 case ARM::VLD4d16:
1499 case ARM::VLD4d32:
1500 case ARM::VLD4d8_UPD:
1501 case ARM::VLD4d16_UPD:
1502 case ARM::VLD4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001503 if (!DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001504 break;
1505 case ARM::VLD4q8:
1506 case ARM::VLD4q16:
1507 case ARM::VLD4q32:
1508 case ARM::VLD4q8_UPD:
1509 case ARM::VLD4q16_UPD:
1510 case ARM::VLD4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001511 if (!DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001512 break;
1513 default:
1514 break;
1515 }
1516
1517 // Writeback operand
1518 switch (Inst.getOpcode()) {
1519 case ARM::VLD1d8_UPD:
1520 case ARM::VLD1d16_UPD:
1521 case ARM::VLD1d32_UPD:
1522 case ARM::VLD1d64_UPD:
1523 case ARM::VLD1q8_UPD:
1524 case ARM::VLD1q16_UPD:
1525 case ARM::VLD1q32_UPD:
1526 case ARM::VLD1q64_UPD:
1527 case ARM::VLD1d8T_UPD:
1528 case ARM::VLD1d16T_UPD:
1529 case ARM::VLD1d32T_UPD:
1530 case ARM::VLD1d64T_UPD:
1531 case ARM::VLD1d8Q_UPD:
1532 case ARM::VLD1d16Q_UPD:
1533 case ARM::VLD1d32Q_UPD:
1534 case ARM::VLD1d64Q_UPD:
1535 case ARM::VLD2d8_UPD:
1536 case ARM::VLD2d16_UPD:
1537 case ARM::VLD2d32_UPD:
1538 case ARM::VLD2q8_UPD:
1539 case ARM::VLD2q16_UPD:
1540 case ARM::VLD2q32_UPD:
1541 case ARM::VLD2b8_UPD:
1542 case ARM::VLD2b16_UPD:
1543 case ARM::VLD2b32_UPD:
1544 case ARM::VLD3d8_UPD:
1545 case ARM::VLD3d16_UPD:
1546 case ARM::VLD3d32_UPD:
1547 case ARM::VLD3q8_UPD:
1548 case ARM::VLD3q16_UPD:
1549 case ARM::VLD3q32_UPD:
1550 case ARM::VLD4d8_UPD:
1551 case ARM::VLD4d16_UPD:
1552 case ARM::VLD4d32_UPD:
1553 case ARM::VLD4q8_UPD:
1554 case ARM::VLD4q16_UPD:
1555 case ARM::VLD4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001556 if (!DecodeGPRRegisterClass(Inst, wb, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001557 break;
1558 default:
1559 break;
1560 }
1561
1562 // AddrMode6 Base (register+alignment)
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001563 if (!DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001564
1565 // AddrMode6 Offset (register)
1566 if (Rm == 0xD)
1567 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001568 else if (Rm != 0xF) {
1569 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1570 return false;
1571 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001572
1573 return true;
1574}
1575
1576static bool DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Insn,
1577 uint64_t Address, const void *Decoder) {
1578 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1579 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1580 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1581 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1582 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1583 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1584
1585 // Writeback Operand
1586 switch (Inst.getOpcode()) {
1587 case ARM::VST1d8_UPD:
1588 case ARM::VST1d16_UPD:
1589 case ARM::VST1d32_UPD:
1590 case ARM::VST1d64_UPD:
1591 case ARM::VST1q8_UPD:
1592 case ARM::VST1q16_UPD:
1593 case ARM::VST1q32_UPD:
1594 case ARM::VST1q64_UPD:
1595 case ARM::VST1d8T_UPD:
1596 case ARM::VST1d16T_UPD:
1597 case ARM::VST1d32T_UPD:
1598 case ARM::VST1d64T_UPD:
1599 case ARM::VST1d8Q_UPD:
1600 case ARM::VST1d16Q_UPD:
1601 case ARM::VST1d32Q_UPD:
1602 case ARM::VST1d64Q_UPD:
1603 case ARM::VST2d8_UPD:
1604 case ARM::VST2d16_UPD:
1605 case ARM::VST2d32_UPD:
1606 case ARM::VST2q8_UPD:
1607 case ARM::VST2q16_UPD:
1608 case ARM::VST2q32_UPD:
1609 case ARM::VST2b8_UPD:
1610 case ARM::VST2b16_UPD:
1611 case ARM::VST2b32_UPD:
1612 case ARM::VST3d8_UPD:
1613 case ARM::VST3d16_UPD:
1614 case ARM::VST3d32_UPD:
1615 case ARM::VST3q8_UPD:
1616 case ARM::VST3q16_UPD:
1617 case ARM::VST3q32_UPD:
1618 case ARM::VST4d8_UPD:
1619 case ARM::VST4d16_UPD:
1620 case ARM::VST4d32_UPD:
1621 case ARM::VST4q8_UPD:
1622 case ARM::VST4q16_UPD:
1623 case ARM::VST4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001624 if (!DecodeGPRRegisterClass(Inst, wb, Address, Decoder))
1625 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001626 break;
1627 default:
1628 break;
1629 }
1630
1631 // AddrMode6 Base (register+alignment)
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001632 if (!DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001633
1634 // AddrMode6 Offset (register)
1635 if (Rm == 0xD)
1636 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001637 else if (Rm != 0xF) {
1638 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1639 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001640
1641 // First input register
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001642 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001643
1644 // Second input register
1645 switch (Inst.getOpcode()) {
1646 case ARM::VST1q8:
1647 case ARM::VST1q16:
1648 case ARM::VST1q32:
1649 case ARM::VST1q64:
1650 case ARM::VST1q8_UPD:
1651 case ARM::VST1q16_UPD:
1652 case ARM::VST1q32_UPD:
1653 case ARM::VST1q64_UPD:
1654 case ARM::VST1d8T:
1655 case ARM::VST1d16T:
1656 case ARM::VST1d32T:
1657 case ARM::VST1d64T:
1658 case ARM::VST1d8T_UPD:
1659 case ARM::VST1d16T_UPD:
1660 case ARM::VST1d32T_UPD:
1661 case ARM::VST1d64T_UPD:
1662 case ARM::VST1d8Q:
1663 case ARM::VST1d16Q:
1664 case ARM::VST1d32Q:
1665 case ARM::VST1d64Q:
1666 case ARM::VST1d8Q_UPD:
1667 case ARM::VST1d16Q_UPD:
1668 case ARM::VST1d32Q_UPD:
1669 case ARM::VST1d64Q_UPD:
1670 case ARM::VST2d8:
1671 case ARM::VST2d16:
1672 case ARM::VST2d32:
1673 case ARM::VST2d8_UPD:
1674 case ARM::VST2d16_UPD:
1675 case ARM::VST2d32_UPD:
1676 case ARM::VST2q8:
1677 case ARM::VST2q16:
1678 case ARM::VST2q32:
1679 case ARM::VST2q8_UPD:
1680 case ARM::VST2q16_UPD:
1681 case ARM::VST2q32_UPD:
1682 case ARM::VST3d8:
1683 case ARM::VST3d16:
1684 case ARM::VST3d32:
1685 case ARM::VST3d8_UPD:
1686 case ARM::VST3d16_UPD:
1687 case ARM::VST3d32_UPD:
1688 case ARM::VST4d8:
1689 case ARM::VST4d16:
1690 case ARM::VST4d32:
1691 case ARM::VST4d8_UPD:
1692 case ARM::VST4d16_UPD:
1693 case ARM::VST4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001694 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001695 break;
1696 case ARM::VST2b8:
1697 case ARM::VST2b16:
1698 case ARM::VST2b32:
1699 case ARM::VST2b8_UPD:
1700 case ARM::VST2b16_UPD:
1701 case ARM::VST2b32_UPD:
1702 case ARM::VST3q8:
1703 case ARM::VST3q16:
1704 case ARM::VST3q32:
1705 case ARM::VST3q8_UPD:
1706 case ARM::VST3q16_UPD:
1707 case ARM::VST3q32_UPD:
1708 case ARM::VST4q8:
1709 case ARM::VST4q16:
1710 case ARM::VST4q32:
1711 case ARM::VST4q8_UPD:
1712 case ARM::VST4q16_UPD:
1713 case ARM::VST4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001714 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001715 break;
1716 default:
1717 break;
1718 }
1719
1720 // Third input register
1721 switch (Inst.getOpcode()) {
1722 case ARM::VST1d8T:
1723 case ARM::VST1d16T:
1724 case ARM::VST1d32T:
1725 case ARM::VST1d64T:
1726 case ARM::VST1d8T_UPD:
1727 case ARM::VST1d16T_UPD:
1728 case ARM::VST1d32T_UPD:
1729 case ARM::VST1d64T_UPD:
1730 case ARM::VST1d8Q:
1731 case ARM::VST1d16Q:
1732 case ARM::VST1d32Q:
1733 case ARM::VST1d64Q:
1734 case ARM::VST1d8Q_UPD:
1735 case ARM::VST1d16Q_UPD:
1736 case ARM::VST1d32Q_UPD:
1737 case ARM::VST1d64Q_UPD:
1738 case ARM::VST2q8:
1739 case ARM::VST2q16:
1740 case ARM::VST2q32:
1741 case ARM::VST2q8_UPD:
1742 case ARM::VST2q16_UPD:
1743 case ARM::VST2q32_UPD:
1744 case ARM::VST3d8:
1745 case ARM::VST3d16:
1746 case ARM::VST3d32:
1747 case ARM::VST3d8_UPD:
1748 case ARM::VST3d16_UPD:
1749 case ARM::VST3d32_UPD:
1750 case ARM::VST4d8:
1751 case ARM::VST4d16:
1752 case ARM::VST4d32:
1753 case ARM::VST4d8_UPD:
1754 case ARM::VST4d16_UPD:
1755 case ARM::VST4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001756 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001757 break;
1758 case ARM::VST3q8:
1759 case ARM::VST3q16:
1760 case ARM::VST3q32:
1761 case ARM::VST3q8_UPD:
1762 case ARM::VST3q16_UPD:
1763 case ARM::VST3q32_UPD:
1764 case ARM::VST4q8:
1765 case ARM::VST4q16:
1766 case ARM::VST4q32:
1767 case ARM::VST4q8_UPD:
1768 case ARM::VST4q16_UPD:
1769 case ARM::VST4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001770 if (!DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001771 break;
1772 default:
1773 break;
1774 }
1775
1776 // Fourth input register
1777 switch (Inst.getOpcode()) {
1778 case ARM::VST1d8Q:
1779 case ARM::VST1d16Q:
1780 case ARM::VST1d32Q:
1781 case ARM::VST1d64Q:
1782 case ARM::VST1d8Q_UPD:
1783 case ARM::VST1d16Q_UPD:
1784 case ARM::VST1d32Q_UPD:
1785 case ARM::VST1d64Q_UPD:
1786 case ARM::VST2q8:
1787 case ARM::VST2q16:
1788 case ARM::VST2q32:
1789 case ARM::VST2q8_UPD:
1790 case ARM::VST2q16_UPD:
1791 case ARM::VST2q32_UPD:
1792 case ARM::VST4d8:
1793 case ARM::VST4d16:
1794 case ARM::VST4d32:
1795 case ARM::VST4d8_UPD:
1796 case ARM::VST4d16_UPD:
1797 case ARM::VST4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001798 if (!DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001799 break;
1800 case ARM::VST4q8:
1801 case ARM::VST4q16:
1802 case ARM::VST4q32:
1803 case ARM::VST4q8_UPD:
1804 case ARM::VST4q16_UPD:
1805 case ARM::VST4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001806 if (!DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001807 break;
1808 default:
1809 break;
1810 }
1811
1812 return true;
1813}
1814
1815static bool DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1816 uint64_t Address, const void *Decoder) {
1817 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1818 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1819 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1820 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1821 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1822 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1823 unsigned regs = fieldFromInstruction32(Insn, 5, 1) + 1;
1824
1825 align *= (1 << size);
1826
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001827 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1828 if (regs == 2) {
1829 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
1830 }
1831 if (Rm == 0xD) {
1832 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1833 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001834
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001835 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001836 Inst.addOperand(MCOperand::CreateImm(align));
1837
1838 if (Rm == 0xD)
1839 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001840 else if (Rm != 0xF) {
1841 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1842 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001843
1844 return true;
1845}
1846
1847static bool DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1848 uint64_t Address, const void *Decoder) {
1849 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1850 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1851 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1852 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1853 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1854 unsigned size = 1 << fieldFromInstruction32(Insn, 6, 2);
1855 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1856 align *= 2*size;
1857
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001858 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1859 if (!DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder)) return false;
1860 if (Rm == 0xD) {
1861 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1862 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001863
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001864 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001865 Inst.addOperand(MCOperand::CreateImm(align));
1866
1867 if (Rm == 0xD)
1868 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001869 else if (Rm != 0xF) {
1870 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1871 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001872
1873 return true;
1874}
1875
1876static bool DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1877 uint64_t Address, const void *Decoder) {
1878 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1879 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1880 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1881 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1882 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1883
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001884 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder) ||
1885 !DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder) ||
1886 !DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder))
1887 return false;
1888 if (Rm == 0xD) {
1889 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1890 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001891
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001892 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001893 Inst.addOperand(MCOperand::CreateImm(0));
1894
1895 if (Rm == 0xD)
1896 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001897 else if (Rm != 0xF) {
1898 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1899 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001900
1901 return true;
1902}
1903
1904static bool DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1905 uint64_t Address, const void *Decoder) {
1906 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1907 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1908 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1909 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1910 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1911 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1912 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1913
1914 if (size == 0x3) {
1915 size = 4;
1916 align = 16;
1917 } else {
1918 if (size == 2) {
1919 size = 1 << size;
1920 align *= 8;
1921 } else {
1922 size = 1 << size;
1923 align *= 4*size;
1924 }
1925 }
1926
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001927 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder) ||
1928 !DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder) ||
1929 !DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder) ||
1930 !DecodeDPRRegisterClass(Inst, (Rd+3*inc)%32, Address, Decoder))
1931 return false;
1932 if (Rm == 0xD) {
1933 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1934 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001935
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001936 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001937 Inst.addOperand(MCOperand::CreateImm(align));
1938
1939 if (Rm == 0xD)
1940 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001941 else if (Rm != 0xF) {
1942 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1943 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001944
1945 return true;
1946}
1947
1948static bool DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1949 uint64_t Address, const void *Decoder) {
1950 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1951 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1952 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
1953 imm |= fieldFromInstruction32(Insn, 16, 3) << 4;
1954 imm |= fieldFromInstruction32(Insn, 24, 1) << 7;
1955 imm |= fieldFromInstruction32(Insn, 8, 4) << 8;
1956 imm |= fieldFromInstruction32(Insn, 5, 1) << 12;
1957 unsigned Q = fieldFromInstruction32(Insn, 6, 1);
1958
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001959 if (Q) {
1960 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1961 } else {
1962 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1963 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001964
1965 Inst.addOperand(MCOperand::CreateImm(imm));
1966
1967 switch (Inst.getOpcode()) {
1968 case ARM::VORRiv4i16:
1969 case ARM::VORRiv2i32:
1970 case ARM::VBICiv4i16:
1971 case ARM::VBICiv2i32:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001972 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001973 break;
1974 case ARM::VORRiv8i16:
1975 case ARM::VORRiv4i32:
1976 case ARM::VBICiv8i16:
1977 case ARM::VBICiv4i32:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001978 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001979 break;
1980 default:
1981 break;
1982 }
1983
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001984 return true;
1985}
1986
1987static bool DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Insn,
1988 uint64_t Address, const void *Decoder) {
1989 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1990 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1991 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1992 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
1993 unsigned size = fieldFromInstruction32(Insn, 18, 2);
1994
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001995 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1996 if (!DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001997 Inst.addOperand(MCOperand::CreateImm(8 << size));
1998
1999 return true;
2000}
2001
2002static bool DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
2003 uint64_t Address, const void *Decoder) {
2004 Inst.addOperand(MCOperand::CreateImm(8 - Val));
2005 return true;
2006}
2007
2008static bool DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
2009 uint64_t Address, const void *Decoder) {
2010 Inst.addOperand(MCOperand::CreateImm(16 - Val));
2011 return true;
2012}
2013
2014static bool DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
2015 uint64_t Address, const void *Decoder) {
2016 Inst.addOperand(MCOperand::CreateImm(32 - Val));
2017 return true;
2018}
2019
2020static bool DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
2021 uint64_t Address, const void *Decoder) {
2022 Inst.addOperand(MCOperand::CreateImm(64 - Val));
2023 return true;
2024}
2025
2026static bool DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
2027 uint64_t Address, const void *Decoder) {
2028 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2029 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2030 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2031 Rn |= fieldFromInstruction32(Insn, 7, 1) << 4;
2032 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2033 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2034 unsigned op = fieldFromInstruction32(Insn, 6, 1);
2035 unsigned length = fieldFromInstruction32(Insn, 8, 2) + 1;
2036
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002037 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2038 if (op) {
2039 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false; // Writeback
2040 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002041
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002042 for (unsigned i = 0; i < length; ++i) {
2043 if (!DecodeDPRRegisterClass(Inst, (Rn+i)%32, Address, Decoder)) return false;
2044 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002045
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002046 if (!DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002047
2048 return true;
2049}
2050
2051static bool DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
2052 uint64_t Address, const void *Decoder) {
2053 // The immediate needs to be a fully instantiated float. However, the
2054 // auto-generated decoder is only able to fill in some of the bits
2055 // necessary. For instance, the 'b' bit is replicated multiple times,
2056 // and is even present in inverted form in one bit. We do a little
2057 // binary parsing here to fill in those missing bits, and then
2058 // reinterpret it all as a float.
2059 union {
2060 uint32_t integer;
2061 float fp;
2062 } fp_conv;
2063
2064 fp_conv.integer = Val;
2065 uint32_t b = fieldFromInstruction32(Val, 25, 1);
2066 fp_conv.integer |= b << 26;
2067 fp_conv.integer |= b << 27;
2068 fp_conv.integer |= b << 28;
2069 fp_conv.integer |= b << 29;
2070 fp_conv.integer |= (~b & 0x1) << 30;
2071
2072 Inst.addOperand(MCOperand::CreateFPImm(fp_conv.fp));
2073 return true;
2074}
2075
2076static bool DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
2077 uint64_t Address, const void *Decoder) {
2078 unsigned dst = fieldFromInstruction16(Insn, 8, 3);
2079 unsigned imm = fieldFromInstruction16(Insn, 0, 8);
2080
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002081 if (!DecodetGPRRegisterClass(Inst, dst, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002082
2083 if (Inst.getOpcode() == ARM::tADR)
2084 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2085 else if (Inst.getOpcode() == ARM::tADDrSPi)
2086 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2087 else
2088 return false;
2089
2090 Inst.addOperand(MCOperand::CreateImm(imm));
2091 return true;
2092}
2093
2094static bool DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
2095 uint64_t Address, const void *Decoder) {
2096 Inst.addOperand(MCOperand::CreateImm(SignExtend32<12>(Val << 1)));
2097 return true;
2098}
2099
2100static bool DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
2101 uint64_t Address, const void *Decoder) {
2102 Inst.addOperand(MCOperand::CreateImm(SignExtend32<21>(Val)));
2103 return true;
2104}
2105
2106static bool DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
2107 uint64_t Address, const void *Decoder) {
2108 Inst.addOperand(MCOperand::CreateImm(SignExtend32<7>(Val << 1)));
2109 return true;
2110}
2111
2112static bool DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
2113 uint64_t Address, const void *Decoder) {
2114 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2115 unsigned Rm = fieldFromInstruction32(Val, 3, 3);
2116
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002117 if (!DecodetGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2118 !DecodetGPRRegisterClass(Inst, Rm, Address, Decoder))
2119 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002120
2121 return true;
2122}
2123
2124static bool DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
2125 uint64_t Address, const void *Decoder) {
2126 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2127 unsigned imm = fieldFromInstruction32(Val, 3, 5);
2128
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002129 if (!DecodetGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002130 Inst.addOperand(MCOperand::CreateImm(imm));
2131
2132 return true;
2133}
2134
2135static bool DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
2136 uint64_t Address, const void *Decoder) {
2137 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2138
2139 return true;
2140}
2141
2142static bool DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
2143 uint64_t Address, const void *Decoder) {
2144 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2145 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2146
2147 return true;
2148}
2149
2150static bool DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
2151 uint64_t Address, const void *Decoder) {
2152 unsigned Rn = fieldFromInstruction32(Val, 6, 4);
2153 unsigned Rm = fieldFromInstruction32(Val, 2, 4);
2154 unsigned imm = fieldFromInstruction32(Val, 0, 2);
2155
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002156 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2157 !DecoderGPRRegisterClass(Inst, Rm, Address, Decoder))
2158 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002159 Inst.addOperand(MCOperand::CreateImm(imm));
2160
2161 return true;
2162}
2163
2164static bool DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Insn,
2165 uint64_t Address, const void *Decoder) {
2166 if (Inst.getOpcode() != ARM::t2PLDs) {
2167 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002168 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002169 }
2170
2171 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2172 if (Rn == 0xF) {
2173 switch (Inst.getOpcode()) {
2174 case ARM::t2LDRBs:
2175 Inst.setOpcode(ARM::t2LDRBpci);
2176 break;
2177 case ARM::t2LDRHs:
2178 Inst.setOpcode(ARM::t2LDRHpci);
2179 break;
2180 case ARM::t2LDRSHs:
2181 Inst.setOpcode(ARM::t2LDRSHpci);
2182 break;
2183 case ARM::t2LDRSBs:
2184 Inst.setOpcode(ARM::t2LDRSBpci);
2185 break;
2186 case ARM::t2PLDs:
2187 Inst.setOpcode(ARM::t2PLDi12);
2188 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2189 break;
2190 default:
2191 return false;
2192 }
2193
2194 int imm = fieldFromInstruction32(Insn, 0, 12);
2195 if (!fieldFromInstruction32(Insn, 23, 1)) imm *= -1;
2196 Inst.addOperand(MCOperand::CreateImm(imm));
2197
2198 return true;
2199 }
2200
2201 unsigned addrmode = fieldFromInstruction32(Insn, 4, 2);
2202 addrmode |= fieldFromInstruction32(Insn, 0, 4) << 2;
2203 addrmode |= fieldFromInstruction32(Insn, 16, 4) << 6;
2204 DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder);
2205
2206 return true;
2207}
2208
2209static bool DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002210 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002211 int imm = Val & 0xFF;
2212 if (!(Val & 0x100)) imm *= -1;
2213 Inst.addOperand(MCOperand::CreateImm(imm << 2));
2214
2215 return true;
2216}
2217
2218static bool DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
2219 uint64_t Address, const void *Decoder) {
2220 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2221 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2222
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002223 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2224 !DecodeT2Imm8S4(Inst, imm, Address, Decoder))
2225 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002226
2227 return true;
2228}
2229
2230static bool DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002231 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002232 int imm = Val & 0xFF;
2233 if (!(Val & 0x100)) imm *= -1;
2234 Inst.addOperand(MCOperand::CreateImm(imm));
2235
2236 return true;
2237}
2238
2239
2240static bool DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002241 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002242 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2243 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2244
2245 // Some instructions always use an additive offset.
2246 switch (Inst.getOpcode()) {
2247 case ARM::t2LDRT:
2248 case ARM::t2LDRBT:
2249 case ARM::t2LDRHT:
2250 case ARM::t2LDRSBT:
2251 case ARM::t2LDRSHT:
2252 imm |= 0x100;
2253 break;
2254 default:
2255 break;
2256 }
2257
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002258 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2259 !DecodeT2Imm8(Inst, imm, Address, Decoder))
2260 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002261
2262 return true;
2263}
2264
2265
2266static bool DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002267 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002268 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
2269 unsigned imm = fieldFromInstruction32(Val, 0, 12);
2270
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002271 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002272 Inst.addOperand(MCOperand::CreateImm(imm));
2273
2274 return true;
2275}
2276
2277
2278static bool DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002279 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002280 unsigned imm = fieldFromInstruction16(Insn, 0, 7);
2281
2282 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2283 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2284 Inst.addOperand(MCOperand::CreateImm(imm));
2285
2286 return true;
2287}
2288
2289static bool DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002290 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002291 if (Inst.getOpcode() == ARM::tADDrSP) {
2292 unsigned Rdm = fieldFromInstruction16(Insn, 0, 3);
2293 Rdm |= fieldFromInstruction16(Insn, 7, 1) << 3;
2294
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002295 if (!DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002296 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002297 if (!DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002298 } else if (Inst.getOpcode() == ARM::tADDspr) {
2299 unsigned Rm = fieldFromInstruction16(Insn, 3, 4);
2300
2301 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2302 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002303 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002304 }
2305
2306 return true;
2307}
2308
2309static bool DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002310 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002311 unsigned imod = fieldFromInstruction16(Insn, 4, 1) | 0x2;
2312 unsigned flags = fieldFromInstruction16(Insn, 0, 3);
2313
2314 Inst.addOperand(MCOperand::CreateImm(imod));
2315 Inst.addOperand(MCOperand::CreateImm(flags));
2316
2317 return true;
2318}
2319
2320static bool DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002321 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002322 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2323 unsigned add = fieldFromInstruction32(Insn, 4, 1);
2324
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002325 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002326 Inst.addOperand(MCOperand::CreateImm(add));
2327
2328 return true;
2329}
2330
2331static bool DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002332 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002333 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2334 return true;
2335}
2336
2337static bool DecodeCoprocessor(llvm::MCInst &Inst, unsigned Val,
2338 uint64_t Address, const void *Decoder) {
2339 if (Val == 0xA || Val == 0xB)
2340 return false;
2341
2342 Inst.addOperand(MCOperand::CreateImm(Val));
2343 return true;
2344}
2345
2346static bool DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002347 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002348 if (Val == 0)
2349 Inst.addOperand(MCOperand::CreateImm(32));
2350 else
2351 Inst.addOperand(MCOperand::CreateImm(Val));
2352 return true;
2353}
2354
2355static bool DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Insn,
2356 uint64_t Address, const void *Decoder) {
2357 unsigned pred = fieldFromInstruction32(Insn, 22, 4);
2358 if (pred == 0xE || pred == 0xF) {
2359 unsigned opc = fieldFromInstruction32(Insn, 4, 2);
2360 switch (opc) {
2361 default:
2362 return false;
2363 case 0:
2364 Inst.setOpcode(ARM::t2DSB);
2365 break;
2366 case 1:
2367 Inst.setOpcode(ARM::t2DMB);
2368 break;
2369 case 2:
2370 Inst.setOpcode(ARM::t2ISB);
2371 return true;
2372 }
2373
2374 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
Owen Andersonc36481c2011-08-09 23:25:42 +00002375 return DecodeMemBarrierOption(Inst, imm, Address, Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002376 }
2377
2378 unsigned brtarget = fieldFromInstruction32(Insn, 0, 11) << 1;
2379 brtarget |= fieldFromInstruction32(Insn, 11, 1) << 19;
2380 brtarget |= fieldFromInstruction32(Insn, 13, 1) << 18;
2381 brtarget |= fieldFromInstruction32(Insn, 16, 6) << 12;
2382 brtarget |= fieldFromInstruction32(Insn, 26, 1) << 20;
2383
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002384 if (!DecodeT2BROperand(Inst, brtarget, Address, Decoder) ||
2385 !DecodePredicateOperand(Inst, pred, Address, Decoder))
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002386 return false;
2387
2388 return true;
2389}
2390
2391// Decode a shifted immediate operand. These basically consist
2392// of an 8-bit value, and a 4-bit directive that specifies either
2393// a splat operation or a rotation.
2394static bool DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
2395 uint64_t Address, const void *Decoder) {
2396 unsigned ctrl = fieldFromInstruction32(Val, 10, 2);
2397 if (ctrl == 0) {
2398 unsigned byte = fieldFromInstruction32(Val, 8, 2);
2399 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2400 switch (byte) {
2401 case 0:
2402 Inst.addOperand(MCOperand::CreateImm(imm));
2403 break;
2404 case 1:
2405 Inst.addOperand(MCOperand::CreateImm((imm << 16) | imm));
2406 break;
2407 case 2:
2408 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 8)));
2409 break;
2410 case 3:
2411 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 16) |
2412 (imm << 8) | imm));
2413 break;
2414 }
2415 } else {
2416 unsigned unrot = fieldFromInstruction32(Val, 0, 7) | 0x80;
2417 unsigned rot = fieldFromInstruction32(Val, 7, 5);
2418 unsigned imm = (unrot >> rot) | (unrot << ((32-rot)&31));
2419 Inst.addOperand(MCOperand::CreateImm(imm));
2420 }
2421
2422 return true;
2423}
2424
2425static bool DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
2426 uint64_t Address, const void *Decoder){
2427 Inst.addOperand(MCOperand::CreateImm(Val << 1));
2428 return true;
2429}
2430
2431static bool DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002432 uint64_t Address, const void *Decoder){
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002433 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2434 return true;
2435}
2436
2437static bool DecodeAddrMode3Offset(llvm::MCInst &Inst, unsigned Val,
2438 uint64_t Address, const void *Decoder) {
2439 bool isImm = fieldFromInstruction32(Val, 9, 1);
2440 bool isAdd = fieldFromInstruction32(Val, 8, 1);
2441 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2442
2443 if (!isImm) {
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002444 if (!DecodeGPRRegisterClass(Inst, imm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002445 Inst.addOperand(MCOperand::CreateImm(!isAdd << 8));
2446 } else {
2447 Inst.addOperand(MCOperand::CreateReg(0));
2448 Inst.addOperand(MCOperand::CreateImm(imm | (!isAdd << 8)));
2449 }
2450
2451 return true;
2452}
Owen Andersonc36481c2011-08-09 23:25:42 +00002453
2454static bool DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Val,
2455 uint64_t Address, const void *Decoder) {
2456 switch (Val) {
2457 default:
2458 return false;
2459 case 0xF: // SY
2460 case 0xE: // ST
2461 case 0xB: // ISH
2462 case 0xA: // ISHST
2463 case 0x7: // NSH
2464 case 0x6: // NSHST
2465 case 0x3: // OSH
2466 case 0x2: // OSHST
2467 break;
2468 }
2469
2470 Inst.addOperand(MCOperand::CreateImm(Val));
2471 return true;
2472}
2473
Owen Anderson26d2f0a2011-08-11 20:21:46 +00002474static bool DecodeMSRMask(llvm::MCInst &Inst, unsigned Val,
2475 uint64_t Address, const void *Decoder) {
2476 if (!Val) return false;
2477 Inst.addOperand(MCOperand::CreateImm(Val));
2478 return true;
2479}