blob: e7b555a22feba48cb2855d38a999ce3cbc226fff [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);
Owen Andersonc36481c2011-08-09 23:25:42 +0000132static bool DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Insn,
133 uint64_t Address, const void *Decoder);
Owen Anderson26d2f0a2011-08-11 20:21:46 +0000134static bool DecodeMSRMask(llvm::MCInst &Inst, unsigned Insn,
135 uint64_t Address, const void *Decoder);
Owen Anderson3f3570a2011-08-12 17:58:32 +0000136static bool DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
Owen Andersoncbfc0442011-08-11 21:34:58 +0000137 uint64_t Address, const void *Decoder);
Owen Anderson3f3570a2011-08-12 17:58:32 +0000138static bool DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
139 uint64_t Address, const void *Decoder);
Owen Anderson7cdbf082011-08-12 18:12:39 +0000140static bool DecodeSTRPreImm(llvm::MCInst &Inst, unsigned Insn,
141 uint64_t Address, const void *Decoder);
142static bool DecodeSTRPreReg(llvm::MCInst &Inst, unsigned Insn,
143 uint64_t Address, const void *Decoder);
Owen Anderson7a2e1772011-08-15 18:44:44 +0000144static bool DecodeVLD1LN(llvm::MCInst &Inst, unsigned Insn,
145 uint64_t Address, const void *Decoder);
146static bool DecodeVLD2LN(llvm::MCInst &Inst, unsigned Insn,
147 uint64_t Address, const void *Decoder);
148static bool DecodeVLD3LN(llvm::MCInst &Inst, unsigned Insn,
149 uint64_t Address, const void *Decoder);
150static bool DecodeVLD4LN(llvm::MCInst &Inst, unsigned Insn,
151 uint64_t Address, const void *Decoder);
152static bool DecodeVST1LN(llvm::MCInst &Inst, unsigned Insn,
153 uint64_t Address, const void *Decoder);
154static bool DecodeVST2LN(llvm::MCInst &Inst, unsigned Insn,
155 uint64_t Address, const void *Decoder);
156static bool DecodeVST3LN(llvm::MCInst &Inst, unsigned Insn,
157 uint64_t Address, const void *Decoder);
158static bool DecodeVST4LN(llvm::MCInst &Inst, unsigned Insn,
159 uint64_t Address, const void *Decoder);
Owen Anderson7cdbf082011-08-12 18:12:39 +0000160
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000161
162static bool DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
163 uint64_t Address, const void *Decoder);
164static bool DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
165 uint64_t Address, const void *Decoder);
166static bool DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
167 uint64_t Address, const void *Decoder);
168static bool DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
169 uint64_t Address, const void *Decoder);
170static bool DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
171 uint64_t Address, const void *Decoder);
172static bool DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
173 uint64_t Address, const void *Decoder);
174static bool DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
175 uint64_t Address, const void *Decoder);
176static bool DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
177 uint64_t Address, const void *Decoder);
178static bool DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
179 uint64_t Address, const void *Decoder);
180static bool DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Val,
181 uint64_t Address, const void *Decoder);
182static bool DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
183 uint64_t Address, const void *Decoder);
184static bool DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
185 uint64_t Address, const void *Decoder);
186static bool DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
187 uint64_t Address, const void *Decoder);
188static bool DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
189 uint64_t Address, const void *Decoder);
190static bool DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Val,
191 uint64_t Address, const void *Decoder);
192static bool DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
193 uint64_t Address, const void *Decoder);
194static bool DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
195 uint64_t Address, const void *Decoder);
196static bool DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Insn,
197 uint64_t Address, const void *Decoder);
198static bool DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
199 uint64_t Address, const void *Decoder);
200static bool DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
201 uint64_t Address, const void *Decoder);
202static bool DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Val,
203 uint64_t Address, const void *Decoder);
204static bool DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
205 uint64_t Address, const void *Decoder);
206static bool DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
207 uint64_t Address, const void *Decoder);
208static bool DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
209 uint64_t Address, const void *Decoder);
210
211#include "ARMGenDisassemblerTables.inc"
212#include "ARMGenInstrInfo.inc"
Oscar Fuentes38e13902010-09-28 11:48:19 +0000213#include "ARMGenEDInfo.inc"
Sean Callanan9899f702010-04-13 21:21:57 +0000214
215using namespace llvm;
Johnny Chenb68a3ee2010-04-02 22:27:38 +0000216
Johnny Chenb68a3ee2010-04-02 22:27:38 +0000217static MCDisassembler *createARMDisassembler(const Target &T) {
218 return new ARMDisassembler;
219}
220
221static MCDisassembler *createThumbDisassembler(const Target &T) {
222 return new ThumbDisassembler;
223}
224
Sean Callanan9899f702010-04-13 21:21:57 +0000225EDInstInfo *ARMDisassembler::getEDInfo() const {
226 return instInfoARM;
227}
228
229EDInstInfo *ThumbDisassembler::getEDInfo() const {
230 return instInfoARM;
231}
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000232
233
234bool ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
235 const MemoryObject &Region,
236 uint64_t Address,raw_ostream &os) const {
237 uint8_t bytes[4];
238
239 // We want to read exactly 4 bytes of data.
240 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
241 return false;
242
243 // Encoded as a small-endian 32-bit word in the stream.
244 uint32_t insn = (bytes[3] << 24) |
245 (bytes[2] << 16) |
246 (bytes[1] << 8) |
247 (bytes[0] << 0);
248
249 // Calling the auto-generated decoder function.
250 bool result = decodeARMInstruction32(MI, insn, Address, this);
251 if (result) {
252 Size = 4;
253 return true;
254 }
255
256 // Instructions that are shared between ARM and Thumb modes.
257 // FIXME: This shouldn't really exist. It's an artifact of the
258 // fact that we fail to encode a few instructions properly for Thumb.
259 MI.clear();
260 result = decodeCommonInstruction32(MI, insn, Address, this);
261 if (result) {
262 Size = 4;
263 return true;
264 }
265
266 // VFP and NEON instructions, similarly, are shared between ARM
267 // and Thumb modes.
268 MI.clear();
269 result = decodeVFPInstruction32(MI, insn, Address, this);
270 if (result) {
271 Size = 4;
272 return true;
273 }
274
275 MI.clear();
Owen Anderson8533eba2011-08-10 19:01:10 +0000276 result = decodeNEONDataInstruction32(MI, insn, Address, this);
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000277 if (result) {
Owen Anderson8533eba2011-08-10 19:01:10 +0000278 Size = 4;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000279 // Add a fake predicate operand, because we share these instruction
280 // definitions with Thumb2 where these instructions are predicable.
281 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
Owen Anderson8533eba2011-08-10 19:01:10 +0000282 return true;
283 }
284
285 MI.clear();
286 result = decodeNEONLoadStoreInstruction32(MI, insn, Address, this);
287 if (result) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000288 Size = 4;
Owen Anderson8533eba2011-08-10 19:01:10 +0000289 // Add a fake predicate operand, because we share these instruction
290 // definitions with Thumb2 where these instructions are predicable.
291 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
292 return true;
293 }
294
295 MI.clear();
296 result = decodeNEONDupInstruction32(MI, insn, Address, this);
297 if (result) {
298 Size = 4;
299 // Add a fake predicate operand, because we share these instruction
300 // definitions with Thumb2 where these instructions are predicable.
301 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000302 return true;
303 }
304
305 MI.clear();
306
307 return false;
308}
309
310namespace llvm {
311extern MCInstrDesc ARMInsts[];
312}
313
314// Thumb1 instructions don't have explicit S bits. Rather, they
315// implicitly set CPSR. Since it's not represented in the encoding, the
316// auto-generated decoder won't inject the CPSR operand. We need to fix
317// that as a post-pass.
318static void AddThumb1SBit(MCInst &MI, bool InITBlock) {
319 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
320 MCInst::iterator I = MI.begin();
Owen Anderson10cbaab2011-08-10 17:36:48 +0000321 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000322 if (OpInfo[i].isOptionalDef() && OpInfo[i].RegClass == ARM::CCRRegClassID) {
323 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
324 return;
325 }
326 }
327
328 if (OpInfo[MI.size()].isOptionalDef() &&
329 OpInfo[MI.size()].RegClass == ARM::CCRRegClassID)
330 MI.insert(MI.end(), MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
331}
332
333// Most Thumb instructions don't have explicit predicates in the
334// encoding, but rather get their predicates from IT context. We need
335// to fix up the predicate operands using this context information as a
336// post-pass.
337void ThumbDisassembler::AddThumbPredicate(MCInst &MI) const {
338 // A few instructions actually have predicates encoded in them. Don't
339 // try to overwrite it if we're seeing one of those.
340 switch (MI.getOpcode()) {
341 case ARM::tBcc:
342 case ARM::t2Bcc:
343 return;
344 default:
345 break;
346 }
347
348 // If we're in an IT block, base the predicate on that. Otherwise,
349 // assume a predicate of AL.
350 unsigned CC;
Owen Anderson10cbaab2011-08-10 17:36:48 +0000351 if (!ITBlock.empty()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000352 CC = ITBlock.back();
353 ITBlock.pop_back();
354 } else
355 CC = ARMCC::AL;
356
357 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
358 MCInst::iterator I = MI.begin();
Owen Anderson10cbaab2011-08-10 17:36:48 +0000359 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000360 if (OpInfo[i].isPredicate()) {
361 I = MI.insert(I, MCOperand::CreateImm(CC));
362 ++I;
363 if (CC == ARMCC::AL)
364 MI.insert(I, MCOperand::CreateReg(0));
365 else
366 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
367 return;
368 }
369 }
370
371 MI.insert(MI.end(), MCOperand::CreateImm(CC));
372 if (CC == ARMCC::AL)
373 MI.insert(MI.end(), MCOperand::CreateReg(0));
374 else
375 MI.insert(MI.end(), MCOperand::CreateReg(ARM::CPSR));
376}
377
378// Thumb VFP instructions are a special case. Because we share their
379// encodings between ARM and Thumb modes, and they are predicable in ARM
380// mode, the auto-generated decoder will give them an (incorrect)
381// predicate operand. We need to rewrite these operands based on the IT
382// context as a post-pass.
383void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const {
384 unsigned CC;
Owen Anderson10cbaab2011-08-10 17:36:48 +0000385 if (!ITBlock.empty()) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000386 CC = ITBlock.back();
387 ITBlock.pop_back();
388 } else
389 CC = ARMCC::AL;
390
391 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
392 MCInst::iterator I = MI.begin();
Owen Anderson10cbaab2011-08-10 17:36:48 +0000393 for (unsigned i = 0, e = MI.size(); i < e; ++i, ++I) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000394 if (OpInfo[i].isPredicate() ) {
395 I->setImm(CC);
396 ++I;
397 if (CC == ARMCC::AL)
398 I->setReg(0);
399 else
400 I->setReg(ARM::CPSR);
401 return;
402 }
403 }
404}
405
406
407bool ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
408 const MemoryObject &Region,
409 uint64_t Address,raw_ostream &os) const {
410 uint8_t bytes[4];
411
412 // We want to read exactly 2 bytes of data.
413 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1)
414 return false;
415
416 uint16_t insn16 = (bytes[1] << 8) | bytes[0];
417 bool result = decodeThumbInstruction16(MI, insn16, Address, this);
418 if (result) {
419 Size = 2;
Owen Anderson10cbaab2011-08-10 17:36:48 +0000420 bool InITBlock = !ITBlock.empty();
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000421 AddThumbPredicate(MI);
422 AddThumb1SBit(MI, InITBlock);
423 return true;
424 }
425
426 MI.clear();
427 result = decodeThumb2Instruction16(MI, insn16, Address, this);
428 if (result) {
429 Size = 2;
430 AddThumbPredicate(MI);
431
432 // If we find an IT instruction, we need to parse its condition
433 // code and mask operands so that we can apply them correctly
434 // to the subsequent instructions.
435 if (MI.getOpcode() == ARM::t2IT) {
436 unsigned firstcond = MI.getOperand(0).getImm();
437 uint32_t mask = MI.getOperand(1).getImm();
438 unsigned zeros = CountTrailingZeros_32(mask);
439 mask >>= zeros+1;
440
441 for (unsigned i = 0; i < 4 - (zeros+1); ++i) {
442 if (firstcond ^ (mask & 1))
443 ITBlock.push_back(firstcond ^ 1);
444 else
445 ITBlock.push_back(firstcond);
446 mask >>= 1;
447 }
448 ITBlock.push_back(firstcond);
449 }
450
451 return true;
452 }
453
454 // We want to read exactly 4 bytes of data.
455 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
456 return false;
457
458 uint32_t insn32 = (bytes[3] << 8) |
459 (bytes[2] << 0) |
460 (bytes[1] << 24) |
461 (bytes[0] << 16);
462 MI.clear();
463 result = decodeThumbInstruction32(MI, insn32, Address, this);
464 if (result) {
465 Size = 4;
466 bool InITBlock = ITBlock.size();
467 AddThumbPredicate(MI);
468 AddThumb1SBit(MI, InITBlock);
469 return true;
470 }
471
472 MI.clear();
473 result = decodeThumb2Instruction32(MI, insn32, Address, this);
474 if (result) {
475 Size = 4;
476 AddThumbPredicate(MI);
477 return true;
478 }
479
480 MI.clear();
Owen Anderson8533eba2011-08-10 19:01:10 +0000481 result = decodeCommonInstruction32(MI, insn32, Address, this);
482 if (result) {
483 Size = 4;
484 AddThumbPredicate(MI);
485 return true;
486 }
487
488 MI.clear();
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000489 result = decodeVFPInstruction32(MI, insn32, Address, this);
490 if (result) {
491 Size = 4;
492 UpdateThumbVFPPredicate(MI);
493 return true;
494 }
495
496 MI.clear();
Owen Anderson8533eba2011-08-10 19:01:10 +0000497 if (fieldFromInstruction32(insn32, 24, 4) == 0xF) {
498 uint32_t NEONDataInsn = insn32;
499 NEONDataInsn &= 0xF0FFFFFF; // Clear bits 27-24
500 NEONDataInsn |= (NEONDataInsn & 0x10000000) >> 4; // Move bit 28 to bit 24
501 NEONDataInsn |= 0x12000000; // Set bits 28 and 25
502 result = decodeNEONDataInstruction32(MI, NEONDataInsn, Address, this);
503 if (result) {
504 Size = 4;
505 AddThumbPredicate(MI);
506 return true;
507 }
508 }
509
510 MI.clear();
511 result = decodeNEONLoadStoreInstruction32(MI, insn32, Address, this);
512 if (result) {
513 Size = 4;
514 AddThumbPredicate(MI);
515 return true;
516 }
517
518 MI.clear();
519 result = decodeNEONDupInstruction32(MI, insn32, Address, this);
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000520 if (result) {
521 Size = 4;
522 AddThumbPredicate(MI);
523 return true;
524 }
525
526 return false;
527}
528
529
530extern "C" void LLVMInitializeARMDisassembler() {
531 TargetRegistry::RegisterMCDisassembler(TheARMTarget,
532 createARMDisassembler);
533 TargetRegistry::RegisterMCDisassembler(TheThumbTarget,
534 createThumbDisassembler);
535}
536
537static const unsigned GPRDecoderTable[] = {
538 ARM::R0, ARM::R1, ARM::R2, ARM::R3,
539 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
540 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
541 ARM::R12, ARM::SP, ARM::LR, ARM::PC
542};
543
544static bool DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
545 uint64_t Address, const void *Decoder) {
546 if (RegNo > 15)
547 return false;
548
549 unsigned Register = GPRDecoderTable[RegNo];
550 Inst.addOperand(MCOperand::CreateReg(Register));
551 return true;
552}
553
Owen Anderson51c98052011-08-09 22:48:45 +0000554static bool DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
555 uint64_t Address, const void *Decoder) {
556 if (RegNo == 15) return false;
557 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
558}
559
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000560static bool DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
561 uint64_t Address, const void *Decoder) {
562 if (RegNo > 7)
563 return false;
564 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
565}
566
567static bool DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
568 uint64_t Address, const void *Decoder) {
569 unsigned Register = 0;
570 switch (RegNo) {
571 case 0:
572 Register = ARM::R0;
573 break;
574 case 1:
575 Register = ARM::R1;
576 break;
577 case 2:
578 Register = ARM::R2;
579 break;
580 case 3:
581 Register = ARM::R3;
582 break;
583 case 9:
584 Register = ARM::R9;
585 break;
586 case 12:
587 Register = ARM::R12;
588 break;
589 default:
590 return false;
591 }
592
593 Inst.addOperand(MCOperand::CreateReg(Register));
594 return true;
595}
596
597static bool DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
598 uint64_t Address, const void *Decoder) {
599 if (RegNo == 13 || RegNo == 15) return false;
600 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
601}
602
603static const unsigned SPRDecoderTable[] = {
604 ARM::S0, ARM::S1, ARM::S2, ARM::S3,
605 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
606 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
607 ARM::S12, ARM::S13, ARM::S14, ARM::S15,
608 ARM::S16, ARM::S17, ARM::S18, ARM::S19,
609 ARM::S20, ARM::S21, ARM::S22, ARM::S23,
610 ARM::S24, ARM::S25, ARM::S26, ARM::S27,
611 ARM::S28, ARM::S29, ARM::S30, ARM::S31
612};
613
614static bool DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
615 uint64_t Address, const void *Decoder) {
616 if (RegNo > 31)
617 return false;
618
619 unsigned Register = SPRDecoderTable[RegNo];
620 Inst.addOperand(MCOperand::CreateReg(Register));
621 return true;
622}
623
624static const unsigned DPRDecoderTable[] = {
625 ARM::D0, ARM::D1, ARM::D2, ARM::D3,
626 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
627 ARM::D8, ARM::D9, ARM::D10, ARM::D11,
628 ARM::D12, ARM::D13, ARM::D14, ARM::D15,
629 ARM::D16, ARM::D17, ARM::D18, ARM::D19,
630 ARM::D20, ARM::D21, ARM::D22, ARM::D23,
631 ARM::D24, ARM::D25, ARM::D26, ARM::D27,
632 ARM::D28, ARM::D29, ARM::D30, ARM::D31
633};
634
635static bool DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
636 uint64_t Address, const void *Decoder) {
637 if (RegNo > 31)
638 return false;
639
640 unsigned Register = DPRDecoderTable[RegNo];
641 Inst.addOperand(MCOperand::CreateReg(Register));
642 return true;
643}
644
645static bool DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
646 uint64_t Address, const void *Decoder) {
647 if (RegNo > 7)
648 return false;
649 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
650}
651
652static bool DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
653 uint64_t Address, const void *Decoder) {
654 if (RegNo > 15)
655 return false;
656 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
657}
658
659static const unsigned QPRDecoderTable[] = {
660 ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
661 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7,
662 ARM::Q8, ARM::Q9, ARM::Q10, ARM::Q11,
663 ARM::Q12, ARM::Q13, ARM::Q14, ARM::Q15
664};
665
666
667static bool DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
668 uint64_t Address, const void *Decoder) {
669 if (RegNo > 31)
670 return false;
671 RegNo >>= 1;
672
673 unsigned Register = QPRDecoderTable[RegNo];
674 Inst.addOperand(MCOperand::CreateReg(Register));
675 return true;
676}
677
678static bool DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
679 uint64_t Address, const void *Decoder) {
680 if (Val == 0xF) return false;
Owen Andersonbd9091c2011-08-09 21:07:45 +0000681 // AL predicate is not allowed on Thumb1 branches.
682 if (Inst.getOpcode() == ARM::tBcc && Val == 0xE)
683 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000684 Inst.addOperand(MCOperand::CreateImm(Val));
685 if (Val == ARMCC::AL) {
686 Inst.addOperand(MCOperand::CreateReg(0));
687 } else
688 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
689 return true;
690}
691
692static bool DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
693 uint64_t Address, const void *Decoder) {
694 if (Val)
695 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
696 else
697 Inst.addOperand(MCOperand::CreateReg(0));
698 return true;
699}
700
701static bool DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
702 uint64_t Address, const void *Decoder) {
703 uint32_t imm = Val & 0xFF;
704 uint32_t rot = (Val & 0xF00) >> 7;
705 uint32_t rot_imm = (imm >> rot) | (imm << (32-rot));
706 Inst.addOperand(MCOperand::CreateImm(rot_imm));
707 return true;
708}
709
710static bool DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
711 uint64_t Address, const void *Decoder) {
712 Val <<= 2;
713 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(Val)));
714 return true;
715}
716
717static bool DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Val,
718 uint64_t Address, const void *Decoder) {
719
720 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
721 unsigned type = fieldFromInstruction32(Val, 5, 2);
722 unsigned imm = fieldFromInstruction32(Val, 7, 5);
723
724 // Register-immediate
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000725 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000726
727 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
728 switch (type) {
729 case 0:
730 Shift = ARM_AM::lsl;
731 break;
732 case 1:
733 Shift = ARM_AM::lsr;
734 break;
735 case 2:
736 Shift = ARM_AM::asr;
737 break;
738 case 3:
739 Shift = ARM_AM::ror;
740 break;
741 }
742
743 if (Shift == ARM_AM::ror && imm == 0)
744 Shift = ARM_AM::rrx;
745
746 unsigned Op = Shift | (imm << 3);
747 Inst.addOperand(MCOperand::CreateImm(Op));
748
749 return true;
750}
751
752static bool DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Val,
753 uint64_t Address, const void *Decoder) {
754
755 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
756 unsigned type = fieldFromInstruction32(Val, 5, 2);
757 unsigned Rs = fieldFromInstruction32(Val, 8, 4);
758
759 // Register-register
Owen Andersonde317f42011-08-09 23:33:27 +0000760 if (!DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)) return false;
761 if (!DecodeGPRnopcRegisterClass(Inst, Rs, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000762
763 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
764 switch (type) {
765 case 0:
766 Shift = ARM_AM::lsl;
767 break;
768 case 1:
769 Shift = ARM_AM::lsr;
770 break;
771 case 2:
772 Shift = ARM_AM::asr;
773 break;
774 case 3:
775 Shift = ARM_AM::ror;
776 break;
777 }
778
779 Inst.addOperand(MCOperand::CreateImm(Shift));
780
781 return true;
782}
783
784static bool DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
785 uint64_t Address, const void *Decoder) {
Owen Anderson26d2f0a2011-08-11 20:21:46 +0000786 // Empty register lists are not allowed.
787 if (CountPopulation_32(Val) == 0) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000788 for (unsigned i = 0; i < 16; ++i) {
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000789 if (Val & (1 << i)) {
790 if (!DecodeGPRRegisterClass(Inst, i, Address, Decoder)) return false;
791 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000792 }
793
794 return true;
795}
796
797static bool DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
798 uint64_t Address, const void *Decoder) {
799 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
800 unsigned regs = Val & 0xFF;
801
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000802 if (!DecodeSPRRegisterClass(Inst, Vd, Address, Decoder)) return false;
803 for (unsigned i = 0; i < (regs - 1); ++i) {
804 if (!DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder)) return false;
805 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000806
807 return true;
808}
809
810static bool DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
811 uint64_t Address, const void *Decoder) {
812 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
813 unsigned regs = (Val & 0xFF) / 2;
814
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000815 if (!DecodeDPRRegisterClass(Inst, Vd, Address, Decoder)) return false;
816 for (unsigned i = 0; i < (regs - 1); ++i) {
817 if (!DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder)) return false;
818 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000819
820 return true;
821}
822
823static bool DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Val,
824 uint64_t Address, const void *Decoder) {
Owen Anderson10cbaab2011-08-10 17:36:48 +0000825 // This operand encodes a mask of contiguous zeros between a specified MSB
826 // and LSB. To decode it, we create the mask of all bits MSB-and-lower,
827 // the mask of all bits LSB-and-lower, and then xor them to create
828 // the mask of that's all ones on [msb, lsb]. Finally we not it to
829 // create the final mask.
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000830 unsigned msb = fieldFromInstruction32(Val, 5, 5);
831 unsigned lsb = fieldFromInstruction32(Val, 0, 5);
832 uint32_t msb_mask = (1 << (msb+1)) - 1;
833 uint32_t lsb_mask = (1 << lsb) - 1;
834 Inst.addOperand(MCOperand::CreateImm(~(msb_mask ^ lsb_mask)));
835 return true;
836}
837
838static bool DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
839 uint64_t Address, const void *Decoder) {
840 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
841 unsigned CRd = fieldFromInstruction32(Insn, 12, 4);
842 unsigned coproc = fieldFromInstruction32(Insn, 8, 4);
843 unsigned imm = fieldFromInstruction32(Insn, 0, 8);
844 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
845 unsigned U = fieldFromInstruction32(Insn, 23, 1);
846
847 switch (Inst.getOpcode()) {
848 case ARM::LDC_OFFSET:
849 case ARM::LDC_PRE:
850 case ARM::LDC_POST:
851 case ARM::LDC_OPTION:
852 case ARM::LDCL_OFFSET:
853 case ARM::LDCL_PRE:
854 case ARM::LDCL_POST:
855 case ARM::LDCL_OPTION:
856 case ARM::STC_OFFSET:
857 case ARM::STC_PRE:
858 case ARM::STC_POST:
859 case ARM::STC_OPTION:
860 case ARM::STCL_OFFSET:
861 case ARM::STCL_PRE:
862 case ARM::STCL_POST:
863 case ARM::STCL_OPTION:
864 if (coproc == 0xA || coproc == 0xB)
865 return false;
866 break;
867 default:
868 break;
869 }
870
871 Inst.addOperand(MCOperand::CreateImm(coproc));
872 Inst.addOperand(MCOperand::CreateImm(CRd));
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000873 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000874 switch (Inst.getOpcode()) {
875 case ARM::LDC_OPTION:
876 case ARM::LDCL_OPTION:
877 case ARM::LDC2_OPTION:
878 case ARM::LDC2L_OPTION:
879 case ARM::STC_OPTION:
880 case ARM::STCL_OPTION:
881 case ARM::STC2_OPTION:
882 case ARM::STC2L_OPTION:
883 case ARM::LDCL_POST:
884 case ARM::STCL_POST:
885 break;
886 default:
887 Inst.addOperand(MCOperand::CreateReg(0));
888 break;
889 }
890
891 unsigned P = fieldFromInstruction32(Insn, 24, 1);
892 unsigned W = fieldFromInstruction32(Insn, 21, 1);
893
894 bool writeback = (P == 0) || (W == 1);
895 unsigned idx_mode = 0;
896 if (P && writeback)
897 idx_mode = ARMII::IndexModePre;
898 else if (!P && writeback)
899 idx_mode = ARMII::IndexModePost;
900
901 switch (Inst.getOpcode()) {
902 case ARM::LDCL_POST:
903 case ARM::STCL_POST:
904 imm |= U << 8;
905 case ARM::LDC_OPTION:
906 case ARM::LDCL_OPTION:
907 case ARM::LDC2_OPTION:
908 case ARM::LDC2L_OPTION:
909 case ARM::STC_OPTION:
910 case ARM::STCL_OPTION:
911 case ARM::STC2_OPTION:
912 case ARM::STC2L_OPTION:
913 Inst.addOperand(MCOperand::CreateImm(imm));
914 break;
915 default:
916 if (U)
917 Inst.addOperand(MCOperand::CreateImm(
918 ARM_AM::getAM2Opc(ARM_AM::add, imm, ARM_AM::lsl, idx_mode)));
919 else
920 Inst.addOperand(MCOperand::CreateImm(
921 ARM_AM::getAM2Opc(ARM_AM::sub, imm, ARM_AM::lsl, idx_mode)));
922 break;
923 }
924
925 switch (Inst.getOpcode()) {
926 case ARM::LDC_OFFSET:
927 case ARM::LDC_PRE:
928 case ARM::LDC_POST:
929 case ARM::LDC_OPTION:
930 case ARM::LDCL_OFFSET:
931 case ARM::LDCL_PRE:
932 case ARM::LDCL_POST:
933 case ARM::LDCL_OPTION:
934 case ARM::STC_OFFSET:
935 case ARM::STC_PRE:
936 case ARM::STC_POST:
937 case ARM::STC_OPTION:
938 case ARM::STCL_OFFSET:
939 case ARM::STCL_PRE:
940 case ARM::STCL_POST:
941 case ARM::STCL_OPTION:
942 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
943 break;
944 default:
945 break;
946 }
947
948 return true;
949}
950
951static bool DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
952 uint64_t Address, const void *Decoder) {
953 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
954 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
955 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
956 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
957 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
958 unsigned reg = fieldFromInstruction32(Insn, 25, 1);
959 unsigned P = fieldFromInstruction32(Insn, 24, 1);
960 unsigned W = fieldFromInstruction32(Insn, 21, 1);
961
962 // On stores, the writeback operand precedes Rt.
963 switch (Inst.getOpcode()) {
964 case ARM::STR_POST_IMM:
965 case ARM::STR_POST_REG:
Owen Anderson508e1d32011-08-11 20:47:56 +0000966 case ARM::STRB_POST_IMM:
967 case ARM::STRB_POST_REG:
Jim Grosbach342ebd52011-08-11 22:18:00 +0000968 case ARM::STRT_POST_REG:
969 case ARM::STRT_POST_IMM:
Jim Grosbach10348e72011-08-11 20:04:56 +0000970 case ARM::STRBT_POST_REG:
971 case ARM::STRBT_POST_IMM:
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000972 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000973 break;
974 default:
975 break;
976 }
977
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000978 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000979
980 // On loads, the writeback operand comes after Rt.
981 switch (Inst.getOpcode()) {
982 case ARM::LDR_POST_IMM:
983 case ARM::LDR_POST_REG:
Owen Anderson508e1d32011-08-11 20:47:56 +0000984 case ARM::LDRB_POST_IMM:
985 case ARM::LDRB_POST_REG:
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000986 case ARM::LDR_PRE:
Owen Anderson0d094992011-08-12 20:36:11 +0000987 case ARM::LDRB_PRE:
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000988 case ARM::LDRBT_POST_REG:
989 case ARM::LDRBT_POST_IMM:
Jim Grosbach59999262011-08-10 23:43:54 +0000990 case ARM::LDRT_POST_REG:
991 case ARM::LDRT_POST_IMM:
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000992 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
993 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000994 break;
995 default:
996 break;
997 }
998
Owen Andersonae0bc5d2011-08-11 18:24:51 +0000999 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001000
1001 ARM_AM::AddrOpc Op = ARM_AM::add;
1002 if (!fieldFromInstruction32(Insn, 23, 1))
1003 Op = ARM_AM::sub;
1004
1005 bool writeback = (P == 0) || (W == 1);
1006 unsigned idx_mode = 0;
1007 if (P && writeback)
1008 idx_mode = ARMII::IndexModePre;
1009 else if (!P && writeback)
1010 idx_mode = ARMII::IndexModePost;
1011
Owen Anderson71156a62011-08-11 19:00:18 +00001012 if (writeback && (Rn == 15 || Rn == Rt)) return false; // UNPREDICTABLE
1013
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001014 if (reg) {
Owen Anderson2b7b2382011-08-11 18:55:42 +00001015 if (!DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001016 ARM_AM::ShiftOpc Opc = ARM_AM::lsl;
1017 switch( fieldFromInstruction32(Insn, 5, 2)) {
1018 case 0:
1019 Opc = ARM_AM::lsl;
1020 break;
1021 case 1:
1022 Opc = ARM_AM::lsr;
1023 break;
1024 case 2:
1025 Opc = ARM_AM::asr;
1026 break;
1027 case 3:
1028 Opc = ARM_AM::ror;
1029 break;
1030 default:
1031 return false;
1032 }
1033 unsigned amt = fieldFromInstruction32(Insn, 7, 5);
1034 unsigned imm = ARM_AM::getAM2Opc(Op, amt, Opc, idx_mode);
1035
1036 Inst.addOperand(MCOperand::CreateImm(imm));
1037 } else {
1038 Inst.addOperand(MCOperand::CreateReg(0));
1039 unsigned tmp = ARM_AM::getAM2Opc(Op, imm, ARM_AM::lsl, idx_mode);
1040 Inst.addOperand(MCOperand::CreateImm(tmp));
1041 }
1042
1043 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1044
1045 return true;
1046}
1047
1048static bool DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Val,
1049 uint64_t Address, const void *Decoder) {
1050 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1051 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1052 unsigned type = fieldFromInstruction32(Val, 5, 2);
1053 unsigned imm = fieldFromInstruction32(Val, 7, 5);
1054 unsigned U = fieldFromInstruction32(Val, 12, 1);
1055
Owen Anderson51157d22011-08-09 21:38:14 +00001056 ARM_AM::ShiftOpc ShOp = ARM_AM::lsl;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001057 switch (type) {
1058 case 0:
1059 ShOp = ARM_AM::lsl;
1060 break;
1061 case 1:
1062 ShOp = ARM_AM::lsr;
1063 break;
1064 case 2:
1065 ShOp = ARM_AM::asr;
1066 break;
1067 case 3:
1068 ShOp = ARM_AM::ror;
1069 break;
1070 }
1071
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001072 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1073 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001074 unsigned shift;
1075 if (U)
1076 shift = ARM_AM::getAM2Opc(ARM_AM::add, imm, ShOp);
1077 else
1078 shift = ARM_AM::getAM2Opc(ARM_AM::sub, imm, ShOp);
1079 Inst.addOperand(MCOperand::CreateImm(shift));
1080
1081 return true;
1082}
1083
1084static bool DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
1085 uint64_t Address, const void *Decoder) {
1086 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1087 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1088 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1089 unsigned type = fieldFromInstruction32(Insn, 22, 1);
1090 unsigned imm = fieldFromInstruction32(Insn, 8, 4);
1091 unsigned U = ((~fieldFromInstruction32(Insn, 23, 1)) & 1) << 8;
1092 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1093 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1094 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1095
1096 bool writeback = (W == 1) | (P == 0);
1097 if (writeback) { // Writeback
1098 if (P)
1099 U |= ARMII::IndexModePre << 9;
1100 else
1101 U |= ARMII::IndexModePost << 9;
1102
1103 // On stores, the writeback operand precedes Rt.
1104 switch (Inst.getOpcode()) {
1105 case ARM::STRD:
1106 case ARM::STRD_PRE:
1107 case ARM::STRD_POST:
Owen Anderson79628e92011-08-12 20:02:50 +00001108 case ARM::STRH:
1109 case ARM::STRH_PRE:
1110 case ARM::STRH_POST:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001111 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1112 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001113 break;
1114 default:
1115 break;
1116 }
1117 }
1118
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001119 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder))
1120 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001121 switch (Inst.getOpcode()) {
1122 case ARM::STRD:
1123 case ARM::STRD_PRE:
1124 case ARM::STRD_POST:
1125 case ARM::LDRD:
1126 case ARM::LDRD_PRE:
1127 case ARM::LDRD_POST:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001128 if (!DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder))
1129 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001130 break;
1131 default:
1132 break;
1133 }
1134
1135 if (writeback) {
1136 // On loads, the writeback operand comes after Rt.
1137 switch (Inst.getOpcode()) {
1138 case ARM::LDRD:
1139 case ARM::LDRD_PRE:
1140 case ARM::LDRD_POST:
Owen Anderson0d094992011-08-12 20:36:11 +00001141 case ARM::LDRH:
1142 case ARM::LDRH_PRE:
1143 case ARM::LDRH_POST:
1144 case ARM::LDRSH:
1145 case ARM::LDRSH_PRE:
1146 case ARM::LDRSH_POST:
1147 case ARM::LDRSB:
1148 case ARM::LDRSB_PRE:
1149 case ARM::LDRSB_POST:
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001150 case ARM::LDRHTr:
1151 case ARM::LDRSBTr:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001152 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1153 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001154 break;
1155 default:
1156 break;
1157 }
1158 }
1159
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001160 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1161 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001162
1163 if (type) {
1164 Inst.addOperand(MCOperand::CreateReg(0));
1165 Inst.addOperand(MCOperand::CreateImm(U | (imm << 4) | Rm));
1166 } else {
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001167 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1168 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001169 Inst.addOperand(MCOperand::CreateImm(U));
1170 }
1171
1172 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1173
1174 return true;
1175}
1176
1177static bool DecodeRFEInstruction(llvm::MCInst &Inst, unsigned Insn,
1178 uint64_t Address, const void *Decoder) {
1179 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1180 unsigned mode = fieldFromInstruction32(Insn, 23, 2);
1181
1182 switch (mode) {
1183 case 0:
1184 mode = ARM_AM::da;
1185 break;
1186 case 1:
1187 mode = ARM_AM::ia;
1188 break;
1189 case 2:
1190 mode = ARM_AM::db;
1191 break;
1192 case 3:
1193 mode = ARM_AM::ib;
1194 break;
1195 }
1196
1197 Inst.addOperand(MCOperand::CreateImm(mode));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001198 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001199
1200 return true;
1201}
1202
1203static bool DecodeMemMultipleWritebackInstruction(llvm::MCInst &Inst,
1204 unsigned Insn,
1205 uint64_t Address, const void *Decoder) {
1206 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1207 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1208 unsigned reglist = fieldFromInstruction32(Insn, 0, 16);
1209
1210 if (pred == 0xF) {
1211 switch (Inst.getOpcode()) {
1212 case ARM::STMDA:
1213 Inst.setOpcode(ARM::RFEDA);
1214 break;
1215 case ARM::STMDA_UPD:
1216 Inst.setOpcode(ARM::RFEDA_UPD);
1217 break;
1218 case ARM::STMDB:
1219 Inst.setOpcode(ARM::RFEDB);
1220 break;
1221 case ARM::STMDB_UPD:
1222 Inst.setOpcode(ARM::RFEDB_UPD);
1223 break;
1224 case ARM::STMIA:
1225 Inst.setOpcode(ARM::RFEIA);
1226 break;
1227 case ARM::STMIA_UPD:
1228 Inst.setOpcode(ARM::RFEIA_UPD);
1229 break;
1230 case ARM::STMIB:
1231 Inst.setOpcode(ARM::RFEIB);
1232 break;
1233 case ARM::STMIB_UPD:
1234 Inst.setOpcode(ARM::RFEIB_UPD);
1235 break;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001236 }
1237 return DecodeRFEInstruction(Inst, Insn, Address, Decoder);
1238 }
1239
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001240 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
1241 !DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) || // Tied
1242 !DecodePredicateOperand(Inst, pred, Address, Decoder) ||
1243 !DecodeRegListOperand(Inst, reglist, Address, Decoder))
1244 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001245
1246 return true;
1247}
1248
1249static bool DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
1250 uint64_t Address, const void *Decoder) {
1251 unsigned imod = fieldFromInstruction32(Insn, 18, 2);
1252 unsigned M = fieldFromInstruction32(Insn, 17, 1);
1253 unsigned iflags = fieldFromInstruction32(Insn, 6, 3);
1254 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1255
Owen Anderson35008c22011-08-09 23:05:39 +00001256 // imod == '01' --> UNPREDICTABLE
1257 if (imod == 1) return false;
1258
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001259 if (M && mode && imod && iflags) {
1260 Inst.setOpcode(ARM::CPS3p);
1261 Inst.addOperand(MCOperand::CreateImm(imod));
1262 Inst.addOperand(MCOperand::CreateImm(iflags));
1263 Inst.addOperand(MCOperand::CreateImm(mode));
1264 return true;
1265 } else if (!mode && !M) {
1266 Inst.setOpcode(ARM::CPS2p);
1267 Inst.addOperand(MCOperand::CreateImm(imod));
1268 Inst.addOperand(MCOperand::CreateImm(iflags));
1269 return true;
1270 } else if (!imod && !iflags && M) {
1271 Inst.setOpcode(ARM::CPS1p);
1272 Inst.addOperand(MCOperand::CreateImm(mode));
1273 return true;
1274 }
1275
1276 return false;
1277}
1278
1279static bool DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
1280 uint64_t Address, const void *Decoder) {
1281 unsigned Rd = fieldFromInstruction32(Insn, 16, 4);
1282 unsigned Rn = fieldFromInstruction32(Insn, 0, 4);
1283 unsigned Rm = fieldFromInstruction32(Insn, 8, 4);
1284 unsigned Ra = fieldFromInstruction32(Insn, 12, 4);
1285 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1286
1287 if (pred == 0xF)
1288 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
1289
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001290 if (!DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder) ||
1291 !DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder) ||
1292 !DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder) ||
1293 !DecodeGPRnopcRegisterClass(Inst, Ra, Address, Decoder))
1294 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001295
Owen Anderson1fb66732011-08-11 22:05:38 +00001296 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1297
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001298 return true;
1299}
1300
1301static bool DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
1302 uint64_t Address, const void *Decoder) {
1303 unsigned add = fieldFromInstruction32(Val, 12, 1);
1304 unsigned imm = fieldFromInstruction32(Val, 0, 12);
1305 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1306
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001307 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1308 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001309
1310 if (!add) imm *= -1;
1311 if (imm == 0 && !add) imm = INT32_MIN;
1312 Inst.addOperand(MCOperand::CreateImm(imm));
1313
1314 return true;
1315}
1316
1317static bool DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
1318 uint64_t Address, const void *Decoder) {
1319 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
1320 unsigned U = fieldFromInstruction32(Val, 8, 1);
1321 unsigned imm = fieldFromInstruction32(Val, 0, 8);
1322
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001323 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
1324 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001325
1326 if (U)
1327 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add, imm)));
1328 else
1329 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub, imm)));
1330
1331 return true;
1332}
1333
1334static bool DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
1335 uint64_t Address, const void *Decoder) {
1336 return DecodeGPRRegisterClass(Inst, Val, Address, Decoder);
1337}
1338
1339static bool DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1340 uint64_t Address, const void *Decoder) {
1341 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1342 unsigned imm = fieldFromInstruction32(Insn, 0, 24) << 2;
1343
1344 if (pred == 0xF) {
1345 Inst.setOpcode(ARM::BLXi);
1346 imm |= fieldFromInstruction32(Insn, 24, 1) << 1;
Benjamin Kramer793b8112011-08-09 22:02:50 +00001347 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001348 return true;
1349 }
1350
Benjamin Kramer793b8112011-08-09 22:02:50 +00001351 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001352 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1353
1354 return true;
1355}
1356
1357
1358static bool DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
1359 uint64_t Address, const void *Decoder) {
1360 Inst.addOperand(MCOperand::CreateImm(64 - Val));
1361 return true;
1362}
1363
1364static bool DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
1365 uint64_t Address, const void *Decoder) {
1366 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1367 unsigned align = fieldFromInstruction32(Val, 4, 2);
1368
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001369 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1370 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001371 if (!align)
1372 Inst.addOperand(MCOperand::CreateImm(0));
1373 else
1374 Inst.addOperand(MCOperand::CreateImm(4 << align));
1375
1376 return true;
1377}
1378
1379static bool DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Insn,
1380 uint64_t Address, const void *Decoder) {
1381 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1382 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1383 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1384 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1385 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1386 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1387
1388 // First output register
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001389 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001390
1391 // Second output register
1392 switch (Inst.getOpcode()) {
1393 case ARM::VLD1q8:
1394 case ARM::VLD1q16:
1395 case ARM::VLD1q32:
1396 case ARM::VLD1q64:
1397 case ARM::VLD1q8_UPD:
1398 case ARM::VLD1q16_UPD:
1399 case ARM::VLD1q32_UPD:
1400 case ARM::VLD1q64_UPD:
1401 case ARM::VLD1d8T:
1402 case ARM::VLD1d16T:
1403 case ARM::VLD1d32T:
1404 case ARM::VLD1d64T:
1405 case ARM::VLD1d8T_UPD:
1406 case ARM::VLD1d16T_UPD:
1407 case ARM::VLD1d32T_UPD:
1408 case ARM::VLD1d64T_UPD:
1409 case ARM::VLD1d8Q:
1410 case ARM::VLD1d16Q:
1411 case ARM::VLD1d32Q:
1412 case ARM::VLD1d64Q:
1413 case ARM::VLD1d8Q_UPD:
1414 case ARM::VLD1d16Q_UPD:
1415 case ARM::VLD1d32Q_UPD:
1416 case ARM::VLD1d64Q_UPD:
1417 case ARM::VLD2d8:
1418 case ARM::VLD2d16:
1419 case ARM::VLD2d32:
1420 case ARM::VLD2d8_UPD:
1421 case ARM::VLD2d16_UPD:
1422 case ARM::VLD2d32_UPD:
1423 case ARM::VLD2q8:
1424 case ARM::VLD2q16:
1425 case ARM::VLD2q32:
1426 case ARM::VLD2q8_UPD:
1427 case ARM::VLD2q16_UPD:
1428 case ARM::VLD2q32_UPD:
1429 case ARM::VLD3d8:
1430 case ARM::VLD3d16:
1431 case ARM::VLD3d32:
1432 case ARM::VLD3d8_UPD:
1433 case ARM::VLD3d16_UPD:
1434 case ARM::VLD3d32_UPD:
1435 case ARM::VLD4d8:
1436 case ARM::VLD4d16:
1437 case ARM::VLD4d32:
1438 case ARM::VLD4d8_UPD:
1439 case ARM::VLD4d16_UPD:
1440 case ARM::VLD4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001441 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001442 break;
1443 case ARM::VLD2b8:
1444 case ARM::VLD2b16:
1445 case ARM::VLD2b32:
1446 case ARM::VLD2b8_UPD:
1447 case ARM::VLD2b16_UPD:
1448 case ARM::VLD2b32_UPD:
1449 case ARM::VLD3q8:
1450 case ARM::VLD3q16:
1451 case ARM::VLD3q32:
1452 case ARM::VLD3q8_UPD:
1453 case ARM::VLD3q16_UPD:
1454 case ARM::VLD3q32_UPD:
1455 case ARM::VLD4q8:
1456 case ARM::VLD4q16:
1457 case ARM::VLD4q32:
1458 case ARM::VLD4q8_UPD:
1459 case ARM::VLD4q16_UPD:
1460 case ARM::VLD4q32_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 default:
1463 break;
1464 }
1465
1466 // Third output register
1467 switch(Inst.getOpcode()) {
1468 case ARM::VLD1d8T:
1469 case ARM::VLD1d16T:
1470 case ARM::VLD1d32T:
1471 case ARM::VLD1d64T:
1472 case ARM::VLD1d8T_UPD:
1473 case ARM::VLD1d16T_UPD:
1474 case ARM::VLD1d32T_UPD:
1475 case ARM::VLD1d64T_UPD:
1476 case ARM::VLD1d8Q:
1477 case ARM::VLD1d16Q:
1478 case ARM::VLD1d32Q:
1479 case ARM::VLD1d64Q:
1480 case ARM::VLD1d8Q_UPD:
1481 case ARM::VLD1d16Q_UPD:
1482 case ARM::VLD1d32Q_UPD:
1483 case ARM::VLD1d64Q_UPD:
1484 case ARM::VLD2q8:
1485 case ARM::VLD2q16:
1486 case ARM::VLD2q32:
1487 case ARM::VLD2q8_UPD:
1488 case ARM::VLD2q16_UPD:
1489 case ARM::VLD2q32_UPD:
1490 case ARM::VLD3d8:
1491 case ARM::VLD3d16:
1492 case ARM::VLD3d32:
1493 case ARM::VLD3d8_UPD:
1494 case ARM::VLD3d16_UPD:
1495 case ARM::VLD3d32_UPD:
1496 case ARM::VLD4d8:
1497 case ARM::VLD4d16:
1498 case ARM::VLD4d32:
1499 case ARM::VLD4d8_UPD:
1500 case ARM::VLD4d16_UPD:
1501 case ARM::VLD4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001502 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001503 break;
1504 case ARM::VLD3q8:
1505 case ARM::VLD3q16:
1506 case ARM::VLD3q32:
1507 case ARM::VLD3q8_UPD:
1508 case ARM::VLD3q16_UPD:
1509 case ARM::VLD3q32_UPD:
1510 case ARM::VLD4q8:
1511 case ARM::VLD4q16:
1512 case ARM::VLD4q32:
1513 case ARM::VLD4q8_UPD:
1514 case ARM::VLD4q16_UPD:
1515 case ARM::VLD4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001516 if (!DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001517 break;
1518 default:
1519 break;
1520 }
1521
1522 // Fourth output register
1523 switch (Inst.getOpcode()) {
1524 case ARM::VLD1d8Q:
1525 case ARM::VLD1d16Q:
1526 case ARM::VLD1d32Q:
1527 case ARM::VLD1d64Q:
1528 case ARM::VLD1d8Q_UPD:
1529 case ARM::VLD1d16Q_UPD:
1530 case ARM::VLD1d32Q_UPD:
1531 case ARM::VLD1d64Q_UPD:
1532 case ARM::VLD2q8:
1533 case ARM::VLD2q16:
1534 case ARM::VLD2q32:
1535 case ARM::VLD2q8_UPD:
1536 case ARM::VLD2q16_UPD:
1537 case ARM::VLD2q32_UPD:
1538 case ARM::VLD4d8:
1539 case ARM::VLD4d16:
1540 case ARM::VLD4d32:
1541 case ARM::VLD4d8_UPD:
1542 case ARM::VLD4d16_UPD:
1543 case ARM::VLD4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001544 if (!DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001545 break;
1546 case ARM::VLD4q8:
1547 case ARM::VLD4q16:
1548 case ARM::VLD4q32:
1549 case ARM::VLD4q8_UPD:
1550 case ARM::VLD4q16_UPD:
1551 case ARM::VLD4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001552 if (!DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001553 break;
1554 default:
1555 break;
1556 }
1557
1558 // Writeback operand
1559 switch (Inst.getOpcode()) {
1560 case ARM::VLD1d8_UPD:
1561 case ARM::VLD1d16_UPD:
1562 case ARM::VLD1d32_UPD:
1563 case ARM::VLD1d64_UPD:
1564 case ARM::VLD1q8_UPD:
1565 case ARM::VLD1q16_UPD:
1566 case ARM::VLD1q32_UPD:
1567 case ARM::VLD1q64_UPD:
1568 case ARM::VLD1d8T_UPD:
1569 case ARM::VLD1d16T_UPD:
1570 case ARM::VLD1d32T_UPD:
1571 case ARM::VLD1d64T_UPD:
1572 case ARM::VLD1d8Q_UPD:
1573 case ARM::VLD1d16Q_UPD:
1574 case ARM::VLD1d32Q_UPD:
1575 case ARM::VLD1d64Q_UPD:
1576 case ARM::VLD2d8_UPD:
1577 case ARM::VLD2d16_UPD:
1578 case ARM::VLD2d32_UPD:
1579 case ARM::VLD2q8_UPD:
1580 case ARM::VLD2q16_UPD:
1581 case ARM::VLD2q32_UPD:
1582 case ARM::VLD2b8_UPD:
1583 case ARM::VLD2b16_UPD:
1584 case ARM::VLD2b32_UPD:
1585 case ARM::VLD3d8_UPD:
1586 case ARM::VLD3d16_UPD:
1587 case ARM::VLD3d32_UPD:
1588 case ARM::VLD3q8_UPD:
1589 case ARM::VLD3q16_UPD:
1590 case ARM::VLD3q32_UPD:
1591 case ARM::VLD4d8_UPD:
1592 case ARM::VLD4d16_UPD:
1593 case ARM::VLD4d32_UPD:
1594 case ARM::VLD4q8_UPD:
1595 case ARM::VLD4q16_UPD:
1596 case ARM::VLD4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001597 if (!DecodeGPRRegisterClass(Inst, wb, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001598 break;
1599 default:
1600 break;
1601 }
1602
1603 // AddrMode6 Base (register+alignment)
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001604 if (!DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001605
1606 // AddrMode6 Offset (register)
1607 if (Rm == 0xD)
1608 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001609 else if (Rm != 0xF) {
1610 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
1611 return false;
1612 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001613
1614 return true;
1615}
1616
1617static bool DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Insn,
1618 uint64_t Address, const void *Decoder) {
1619 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1620 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1621 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1622 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1623 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1624 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1625
1626 // Writeback Operand
1627 switch (Inst.getOpcode()) {
1628 case ARM::VST1d8_UPD:
1629 case ARM::VST1d16_UPD:
1630 case ARM::VST1d32_UPD:
1631 case ARM::VST1d64_UPD:
1632 case ARM::VST1q8_UPD:
1633 case ARM::VST1q16_UPD:
1634 case ARM::VST1q32_UPD:
1635 case ARM::VST1q64_UPD:
1636 case ARM::VST1d8T_UPD:
1637 case ARM::VST1d16T_UPD:
1638 case ARM::VST1d32T_UPD:
1639 case ARM::VST1d64T_UPD:
1640 case ARM::VST1d8Q_UPD:
1641 case ARM::VST1d16Q_UPD:
1642 case ARM::VST1d32Q_UPD:
1643 case ARM::VST1d64Q_UPD:
1644 case ARM::VST2d8_UPD:
1645 case ARM::VST2d16_UPD:
1646 case ARM::VST2d32_UPD:
1647 case ARM::VST2q8_UPD:
1648 case ARM::VST2q16_UPD:
1649 case ARM::VST2q32_UPD:
1650 case ARM::VST2b8_UPD:
1651 case ARM::VST2b16_UPD:
1652 case ARM::VST2b32_UPD:
1653 case ARM::VST3d8_UPD:
1654 case ARM::VST3d16_UPD:
1655 case ARM::VST3d32_UPD:
1656 case ARM::VST3q8_UPD:
1657 case ARM::VST3q16_UPD:
1658 case ARM::VST3q32_UPD:
1659 case ARM::VST4d8_UPD:
1660 case ARM::VST4d16_UPD:
1661 case ARM::VST4d32_UPD:
1662 case ARM::VST4q8_UPD:
1663 case ARM::VST4q16_UPD:
1664 case ARM::VST4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001665 if (!DecodeGPRRegisterClass(Inst, wb, Address, Decoder))
1666 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001667 break;
1668 default:
1669 break;
1670 }
1671
1672 // AddrMode6 Base (register+alignment)
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001673 if (!DecodeAddrMode6Operand(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001674
1675 // AddrMode6 Offset (register)
1676 if (Rm == 0xD)
1677 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001678 else if (Rm != 0xF) {
1679 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1680 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001681
1682 // First input register
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001683 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001684
1685 // Second input register
1686 switch (Inst.getOpcode()) {
1687 case ARM::VST1q8:
1688 case ARM::VST1q16:
1689 case ARM::VST1q32:
1690 case ARM::VST1q64:
1691 case ARM::VST1q8_UPD:
1692 case ARM::VST1q16_UPD:
1693 case ARM::VST1q32_UPD:
1694 case ARM::VST1q64_UPD:
1695 case ARM::VST1d8T:
1696 case ARM::VST1d16T:
1697 case ARM::VST1d32T:
1698 case ARM::VST1d64T:
1699 case ARM::VST1d8T_UPD:
1700 case ARM::VST1d16T_UPD:
1701 case ARM::VST1d32T_UPD:
1702 case ARM::VST1d64T_UPD:
1703 case ARM::VST1d8Q:
1704 case ARM::VST1d16Q:
1705 case ARM::VST1d32Q:
1706 case ARM::VST1d64Q:
1707 case ARM::VST1d8Q_UPD:
1708 case ARM::VST1d16Q_UPD:
1709 case ARM::VST1d32Q_UPD:
1710 case ARM::VST1d64Q_UPD:
1711 case ARM::VST2d8:
1712 case ARM::VST2d16:
1713 case ARM::VST2d32:
1714 case ARM::VST2d8_UPD:
1715 case ARM::VST2d16_UPD:
1716 case ARM::VST2d32_UPD:
1717 case ARM::VST2q8:
1718 case ARM::VST2q16:
1719 case ARM::VST2q32:
1720 case ARM::VST2q8_UPD:
1721 case ARM::VST2q16_UPD:
1722 case ARM::VST2q32_UPD:
1723 case ARM::VST3d8:
1724 case ARM::VST3d16:
1725 case ARM::VST3d32:
1726 case ARM::VST3d8_UPD:
1727 case ARM::VST3d16_UPD:
1728 case ARM::VST3d32_UPD:
1729 case ARM::VST4d8:
1730 case ARM::VST4d16:
1731 case ARM::VST4d32:
1732 case ARM::VST4d8_UPD:
1733 case ARM::VST4d16_UPD:
1734 case ARM::VST4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001735 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001736 break;
1737 case ARM::VST2b8:
1738 case ARM::VST2b16:
1739 case ARM::VST2b32:
1740 case ARM::VST2b8_UPD:
1741 case ARM::VST2b16_UPD:
1742 case ARM::VST2b32_UPD:
1743 case ARM::VST3q8:
1744 case ARM::VST3q16:
1745 case ARM::VST3q32:
1746 case ARM::VST3q8_UPD:
1747 case ARM::VST3q16_UPD:
1748 case ARM::VST3q32_UPD:
1749 case ARM::VST4q8:
1750 case ARM::VST4q16:
1751 case ARM::VST4q32:
1752 case ARM::VST4q8_UPD:
1753 case ARM::VST4q16_UPD:
1754 case ARM::VST4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001755 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001756 break;
1757 default:
1758 break;
1759 }
1760
1761 // Third input register
1762 switch (Inst.getOpcode()) {
1763 case ARM::VST1d8T:
1764 case ARM::VST1d16T:
1765 case ARM::VST1d32T:
1766 case ARM::VST1d64T:
1767 case ARM::VST1d8T_UPD:
1768 case ARM::VST1d16T_UPD:
1769 case ARM::VST1d32T_UPD:
1770 case ARM::VST1d64T_UPD:
1771 case ARM::VST1d8Q:
1772 case ARM::VST1d16Q:
1773 case ARM::VST1d32Q:
1774 case ARM::VST1d64Q:
1775 case ARM::VST1d8Q_UPD:
1776 case ARM::VST1d16Q_UPD:
1777 case ARM::VST1d32Q_UPD:
1778 case ARM::VST1d64Q_UPD:
1779 case ARM::VST2q8:
1780 case ARM::VST2q16:
1781 case ARM::VST2q32:
1782 case ARM::VST2q8_UPD:
1783 case ARM::VST2q16_UPD:
1784 case ARM::VST2q32_UPD:
1785 case ARM::VST3d8:
1786 case ARM::VST3d16:
1787 case ARM::VST3d32:
1788 case ARM::VST3d8_UPD:
1789 case ARM::VST3d16_UPD:
1790 case ARM::VST3d32_UPD:
1791 case ARM::VST4d8:
1792 case ARM::VST4d16:
1793 case ARM::VST4d32:
1794 case ARM::VST4d8_UPD:
1795 case ARM::VST4d16_UPD:
1796 case ARM::VST4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001797 if (!DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001798 break;
1799 case ARM::VST3q8:
1800 case ARM::VST3q16:
1801 case ARM::VST3q32:
1802 case ARM::VST3q8_UPD:
1803 case ARM::VST3q16_UPD:
1804 case ARM::VST3q32_UPD:
1805 case ARM::VST4q8:
1806 case ARM::VST4q16:
1807 case ARM::VST4q32:
1808 case ARM::VST4q8_UPD:
1809 case ARM::VST4q16_UPD:
1810 case ARM::VST4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001811 if (!DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001812 break;
1813 default:
1814 break;
1815 }
1816
1817 // Fourth input register
1818 switch (Inst.getOpcode()) {
1819 case ARM::VST1d8Q:
1820 case ARM::VST1d16Q:
1821 case ARM::VST1d32Q:
1822 case ARM::VST1d64Q:
1823 case ARM::VST1d8Q_UPD:
1824 case ARM::VST1d16Q_UPD:
1825 case ARM::VST1d32Q_UPD:
1826 case ARM::VST1d64Q_UPD:
1827 case ARM::VST2q8:
1828 case ARM::VST2q16:
1829 case ARM::VST2q32:
1830 case ARM::VST2q8_UPD:
1831 case ARM::VST2q16_UPD:
1832 case ARM::VST2q32_UPD:
1833 case ARM::VST4d8:
1834 case ARM::VST4d16:
1835 case ARM::VST4d32:
1836 case ARM::VST4d8_UPD:
1837 case ARM::VST4d16_UPD:
1838 case ARM::VST4d32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001839 if (!DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001840 break;
1841 case ARM::VST4q8:
1842 case ARM::VST4q16:
1843 case ARM::VST4q32:
1844 case ARM::VST4q8_UPD:
1845 case ARM::VST4q16_UPD:
1846 case ARM::VST4q32_UPD:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001847 if (!DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001848 break;
1849 default:
1850 break;
1851 }
1852
1853 return true;
1854}
1855
1856static bool DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1857 uint64_t Address, const void *Decoder) {
1858 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1859 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1860 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1861 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1862 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1863 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1864 unsigned regs = fieldFromInstruction32(Insn, 5, 1) + 1;
1865
1866 align *= (1 << size);
1867
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001868 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1869 if (regs == 2) {
1870 if (!DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder)) return false;
1871 }
1872 if (Rm == 0xD) {
1873 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1874 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001875
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001876 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001877 Inst.addOperand(MCOperand::CreateImm(align));
1878
1879 if (Rm == 0xD)
1880 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001881 else if (Rm != 0xF) {
1882 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1883 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001884
1885 return true;
1886}
1887
1888static bool DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1889 uint64_t Address, const void *Decoder) {
1890 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1891 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1892 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1893 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1894 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1895 unsigned size = 1 << fieldFromInstruction32(Insn, 6, 2);
1896 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1897 align *= 2*size;
1898
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001899 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
1900 if (!DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder)) return false;
1901 if (Rm == 0xD) {
1902 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1903 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001904
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001905 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001906 Inst.addOperand(MCOperand::CreateImm(align));
1907
1908 if (Rm == 0xD)
1909 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001910 else if (Rm != 0xF) {
1911 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1912 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001913
1914 return true;
1915}
1916
1917static bool DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1918 uint64_t Address, const void *Decoder) {
1919 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1920 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1921 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1922 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1923 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1924
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001925 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder) ||
1926 !DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder) ||
1927 !DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder))
1928 return false;
1929 if (Rm == 0xD) {
1930 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1931 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001932
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001933 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001934 Inst.addOperand(MCOperand::CreateImm(0));
1935
1936 if (Rm == 0xD)
1937 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001938 else if (Rm != 0xF) {
1939 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1940 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001941
1942 return true;
1943}
1944
1945static bool DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1946 uint64_t Address, const void *Decoder) {
1947 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1948 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1949 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1950 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1951 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1952 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1953 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1954
1955 if (size == 0x3) {
1956 size = 4;
1957 align = 16;
1958 } else {
1959 if (size == 2) {
1960 size = 1 << size;
1961 align *= 8;
1962 } else {
1963 size = 1 << size;
1964 align *= 4*size;
1965 }
1966 }
1967
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001968 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder) ||
1969 !DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder) ||
1970 !DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder) ||
1971 !DecodeDPRRegisterClass(Inst, (Rd+3*inc)%32, Address, Decoder))
1972 return false;
1973 if (Rm == 0xD) {
1974 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
1975 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001976
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001977 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001978 Inst.addOperand(MCOperand::CreateImm(align));
1979
1980 if (Rm == 0xD)
1981 Inst.addOperand(MCOperand::CreateReg(0));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00001982 else if (Rm != 0xF) {
1983 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
1984 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001985
1986 return true;
1987}
1988
1989static bool DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1990 uint64_t Address, const void *Decoder) {
1991 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1992 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1993 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
1994 imm |= fieldFromInstruction32(Insn, 16, 3) << 4;
1995 imm |= fieldFromInstruction32(Insn, 24, 1) << 7;
1996 imm |= fieldFromInstruction32(Insn, 8, 4) << 8;
1997 imm |= fieldFromInstruction32(Insn, 5, 1) << 12;
1998 unsigned Q = fieldFromInstruction32(Insn, 6, 1);
1999
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002000 if (Q) {
2001 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2002 } else {
2003 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2004 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002005
2006 Inst.addOperand(MCOperand::CreateImm(imm));
2007
2008 switch (Inst.getOpcode()) {
2009 case ARM::VORRiv4i16:
2010 case ARM::VORRiv2i32:
2011 case ARM::VBICiv4i16:
2012 case ARM::VBICiv2i32:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002013 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002014 break;
2015 case ARM::VORRiv8i16:
2016 case ARM::VORRiv4i32:
2017 case ARM::VBICiv8i16:
2018 case ARM::VBICiv4i32:
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002019 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002020 break;
2021 default:
2022 break;
2023 }
2024
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002025 return true;
2026}
2027
2028static bool DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Insn,
2029 uint64_t Address, const void *Decoder) {
2030 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2031 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2032 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2033 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2034 unsigned size = fieldFromInstruction32(Insn, 18, 2);
2035
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002036 if (!DecodeQPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2037 if (!DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002038 Inst.addOperand(MCOperand::CreateImm(8 << size));
2039
2040 return true;
2041}
2042
2043static bool DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
2044 uint64_t Address, const void *Decoder) {
2045 Inst.addOperand(MCOperand::CreateImm(8 - Val));
2046 return true;
2047}
2048
2049static bool DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
2050 uint64_t Address, const void *Decoder) {
2051 Inst.addOperand(MCOperand::CreateImm(16 - Val));
2052 return true;
2053}
2054
2055static bool DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
2056 uint64_t Address, const void *Decoder) {
2057 Inst.addOperand(MCOperand::CreateImm(32 - Val));
2058 return true;
2059}
2060
2061static bool DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
2062 uint64_t Address, const void *Decoder) {
2063 Inst.addOperand(MCOperand::CreateImm(64 - Val));
2064 return true;
2065}
2066
2067static bool DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
2068 uint64_t Address, const void *Decoder) {
2069 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2070 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2071 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2072 Rn |= fieldFromInstruction32(Insn, 7, 1) << 4;
2073 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2074 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2075 unsigned op = fieldFromInstruction32(Insn, 6, 1);
2076 unsigned length = fieldFromInstruction32(Insn, 8, 2) + 1;
2077
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002078 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2079 if (op) {
2080 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false; // Writeback
2081 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002082
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002083 for (unsigned i = 0; i < length; ++i) {
2084 if (!DecodeDPRRegisterClass(Inst, (Rn+i)%32, Address, Decoder)) return false;
2085 }
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002086
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002087 if (!DecodeDPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002088
2089 return true;
2090}
2091
2092static bool DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
2093 uint64_t Address, const void *Decoder) {
2094 // The immediate needs to be a fully instantiated float. However, the
2095 // auto-generated decoder is only able to fill in some of the bits
2096 // necessary. For instance, the 'b' bit is replicated multiple times,
2097 // and is even present in inverted form in one bit. We do a little
2098 // binary parsing here to fill in those missing bits, and then
2099 // reinterpret it all as a float.
2100 union {
2101 uint32_t integer;
2102 float fp;
2103 } fp_conv;
2104
2105 fp_conv.integer = Val;
2106 uint32_t b = fieldFromInstruction32(Val, 25, 1);
2107 fp_conv.integer |= b << 26;
2108 fp_conv.integer |= b << 27;
2109 fp_conv.integer |= b << 28;
2110 fp_conv.integer |= b << 29;
2111 fp_conv.integer |= (~b & 0x1) << 30;
2112
2113 Inst.addOperand(MCOperand::CreateFPImm(fp_conv.fp));
2114 return true;
2115}
2116
2117static bool DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
2118 uint64_t Address, const void *Decoder) {
2119 unsigned dst = fieldFromInstruction16(Insn, 8, 3);
2120 unsigned imm = fieldFromInstruction16(Insn, 0, 8);
2121
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002122 if (!DecodetGPRRegisterClass(Inst, dst, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002123
2124 if (Inst.getOpcode() == ARM::tADR)
2125 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2126 else if (Inst.getOpcode() == ARM::tADDrSPi)
2127 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2128 else
2129 return false;
2130
2131 Inst.addOperand(MCOperand::CreateImm(imm));
2132 return true;
2133}
2134
2135static bool DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
2136 uint64_t Address, const void *Decoder) {
2137 Inst.addOperand(MCOperand::CreateImm(SignExtend32<12>(Val << 1)));
2138 return true;
2139}
2140
2141static bool DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
2142 uint64_t Address, const void *Decoder) {
2143 Inst.addOperand(MCOperand::CreateImm(SignExtend32<21>(Val)));
2144 return true;
2145}
2146
2147static bool DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
2148 uint64_t Address, const void *Decoder) {
2149 Inst.addOperand(MCOperand::CreateImm(SignExtend32<7>(Val << 1)));
2150 return true;
2151}
2152
2153static bool DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
2154 uint64_t Address, const void *Decoder) {
2155 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2156 unsigned Rm = fieldFromInstruction32(Val, 3, 3);
2157
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002158 if (!DecodetGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2159 !DecodetGPRRegisterClass(Inst, Rm, Address, Decoder))
2160 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002161
2162 return true;
2163}
2164
2165static bool DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
2166 uint64_t Address, const void *Decoder) {
2167 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2168 unsigned imm = fieldFromInstruction32(Val, 3, 5);
2169
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002170 if (!DecodetGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002171 Inst.addOperand(MCOperand::CreateImm(imm));
2172
2173 return true;
2174}
2175
2176static bool DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
2177 uint64_t Address, const void *Decoder) {
2178 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2179
2180 return true;
2181}
2182
2183static bool DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
2184 uint64_t Address, const void *Decoder) {
2185 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2186 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2187
2188 return true;
2189}
2190
2191static bool DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
2192 uint64_t Address, const void *Decoder) {
2193 unsigned Rn = fieldFromInstruction32(Val, 6, 4);
2194 unsigned Rm = fieldFromInstruction32(Val, 2, 4);
2195 unsigned imm = fieldFromInstruction32(Val, 0, 2);
2196
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002197 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2198 !DecoderGPRRegisterClass(Inst, Rm, Address, Decoder))
2199 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002200 Inst.addOperand(MCOperand::CreateImm(imm));
2201
2202 return true;
2203}
2204
2205static bool DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Insn,
2206 uint64_t Address, const void *Decoder) {
2207 if (Inst.getOpcode() != ARM::t2PLDs) {
2208 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002209 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002210 }
2211
2212 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2213 if (Rn == 0xF) {
2214 switch (Inst.getOpcode()) {
2215 case ARM::t2LDRBs:
2216 Inst.setOpcode(ARM::t2LDRBpci);
2217 break;
2218 case ARM::t2LDRHs:
2219 Inst.setOpcode(ARM::t2LDRHpci);
2220 break;
2221 case ARM::t2LDRSHs:
2222 Inst.setOpcode(ARM::t2LDRSHpci);
2223 break;
2224 case ARM::t2LDRSBs:
2225 Inst.setOpcode(ARM::t2LDRSBpci);
2226 break;
2227 case ARM::t2PLDs:
2228 Inst.setOpcode(ARM::t2PLDi12);
2229 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2230 break;
2231 default:
2232 return false;
2233 }
2234
2235 int imm = fieldFromInstruction32(Insn, 0, 12);
2236 if (!fieldFromInstruction32(Insn, 23, 1)) imm *= -1;
2237 Inst.addOperand(MCOperand::CreateImm(imm));
2238
2239 return true;
2240 }
2241
2242 unsigned addrmode = fieldFromInstruction32(Insn, 4, 2);
2243 addrmode |= fieldFromInstruction32(Insn, 0, 4) << 2;
2244 addrmode |= fieldFromInstruction32(Insn, 16, 4) << 6;
2245 DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder);
2246
2247 return true;
2248}
2249
2250static bool DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002251 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002252 int imm = Val & 0xFF;
2253 if (!(Val & 0x100)) imm *= -1;
2254 Inst.addOperand(MCOperand::CreateImm(imm << 2));
2255
2256 return true;
2257}
2258
2259static bool DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
2260 uint64_t Address, const void *Decoder) {
2261 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2262 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2263
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002264 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2265 !DecodeT2Imm8S4(Inst, imm, Address, Decoder))
2266 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002267
2268 return true;
2269}
2270
2271static bool DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002272 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002273 int imm = Val & 0xFF;
2274 if (!(Val & 0x100)) imm *= -1;
2275 Inst.addOperand(MCOperand::CreateImm(imm));
2276
2277 return true;
2278}
2279
2280
2281static bool DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002282 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002283 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2284 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2285
2286 // Some instructions always use an additive offset.
2287 switch (Inst.getOpcode()) {
2288 case ARM::t2LDRT:
2289 case ARM::t2LDRBT:
2290 case ARM::t2LDRHT:
2291 case ARM::t2LDRSBT:
2292 case ARM::t2LDRSHT:
2293 imm |= 0x100;
2294 break;
2295 default:
2296 break;
2297 }
2298
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002299 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder) ||
2300 !DecodeT2Imm8(Inst, imm, Address, Decoder))
2301 return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002302
2303 return true;
2304}
2305
2306
2307static bool DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002308 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002309 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
2310 unsigned imm = fieldFromInstruction32(Val, 0, 12);
2311
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002312 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002313 Inst.addOperand(MCOperand::CreateImm(imm));
2314
2315 return true;
2316}
2317
2318
2319static bool DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002320 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002321 unsigned imm = fieldFromInstruction16(Insn, 0, 7);
2322
2323 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2324 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2325 Inst.addOperand(MCOperand::CreateImm(imm));
2326
2327 return true;
2328}
2329
2330static bool DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002331 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002332 if (Inst.getOpcode() == ARM::tADDrSP) {
2333 unsigned Rdm = fieldFromInstruction16(Insn, 0, 3);
2334 Rdm |= fieldFromInstruction16(Insn, 7, 1) << 3;
2335
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002336 if (!DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002337 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002338 if (!DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002339 } else if (Inst.getOpcode() == ARM::tADDspr) {
2340 unsigned Rm = fieldFromInstruction16(Insn, 3, 4);
2341
2342 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2343 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002344 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002345 }
2346
2347 return true;
2348}
2349
2350static bool DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002351 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002352 unsigned imod = fieldFromInstruction16(Insn, 4, 1) | 0x2;
2353 unsigned flags = fieldFromInstruction16(Insn, 0, 3);
2354
2355 Inst.addOperand(MCOperand::CreateImm(imod));
2356 Inst.addOperand(MCOperand::CreateImm(flags));
2357
2358 return true;
2359}
2360
2361static bool DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002362 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002363 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2364 unsigned add = fieldFromInstruction32(Insn, 4, 1);
2365
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002366 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) return false;
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002367 Inst.addOperand(MCOperand::CreateImm(add));
2368
2369 return true;
2370}
2371
2372static bool DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002373 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002374 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2375 return true;
2376}
2377
2378static bool DecodeCoprocessor(llvm::MCInst &Inst, unsigned Val,
2379 uint64_t Address, const void *Decoder) {
2380 if (Val == 0xA || Val == 0xB)
2381 return false;
2382
2383 Inst.addOperand(MCOperand::CreateImm(Val));
2384 return true;
2385}
2386
2387static bool DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002388 uint64_t Address, const void *Decoder) {
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002389 if (Val == 0)
2390 Inst.addOperand(MCOperand::CreateImm(32));
2391 else
2392 Inst.addOperand(MCOperand::CreateImm(Val));
2393 return true;
2394}
2395
2396static bool DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Insn,
2397 uint64_t Address, const void *Decoder) {
2398 unsigned pred = fieldFromInstruction32(Insn, 22, 4);
2399 if (pred == 0xE || pred == 0xF) {
2400 unsigned opc = fieldFromInstruction32(Insn, 4, 2);
2401 switch (opc) {
2402 default:
2403 return false;
2404 case 0:
2405 Inst.setOpcode(ARM::t2DSB);
2406 break;
2407 case 1:
2408 Inst.setOpcode(ARM::t2DMB);
2409 break;
2410 case 2:
2411 Inst.setOpcode(ARM::t2ISB);
2412 return true;
2413 }
2414
2415 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
Owen Andersonc36481c2011-08-09 23:25:42 +00002416 return DecodeMemBarrierOption(Inst, imm, Address, Decoder);
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002417 }
2418
2419 unsigned brtarget = fieldFromInstruction32(Insn, 0, 11) << 1;
2420 brtarget |= fieldFromInstruction32(Insn, 11, 1) << 19;
2421 brtarget |= fieldFromInstruction32(Insn, 13, 1) << 18;
2422 brtarget |= fieldFromInstruction32(Insn, 16, 6) << 12;
2423 brtarget |= fieldFromInstruction32(Insn, 26, 1) << 20;
2424
Owen Andersonae0bc5d2011-08-11 18:24:51 +00002425 if (!DecodeT2BROperand(Inst, brtarget, Address, Decoder) ||
2426 !DecodePredicateOperand(Inst, pred, Address, Decoder))
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002427 return false;
2428
2429 return true;
2430}
2431
2432// Decode a shifted immediate operand. These basically consist
2433// of an 8-bit value, and a 4-bit directive that specifies either
2434// a splat operation or a rotation.
2435static bool DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
2436 uint64_t Address, const void *Decoder) {
2437 unsigned ctrl = fieldFromInstruction32(Val, 10, 2);
2438 if (ctrl == 0) {
2439 unsigned byte = fieldFromInstruction32(Val, 8, 2);
2440 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2441 switch (byte) {
2442 case 0:
2443 Inst.addOperand(MCOperand::CreateImm(imm));
2444 break;
2445 case 1:
2446 Inst.addOperand(MCOperand::CreateImm((imm << 16) | imm));
2447 break;
2448 case 2:
2449 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 8)));
2450 break;
2451 case 3:
2452 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 16) |
2453 (imm << 8) | imm));
2454 break;
2455 }
2456 } else {
2457 unsigned unrot = fieldFromInstruction32(Val, 0, 7) | 0x80;
2458 unsigned rot = fieldFromInstruction32(Val, 7, 5);
2459 unsigned imm = (unrot >> rot) | (unrot << ((32-rot)&31));
2460 Inst.addOperand(MCOperand::CreateImm(imm));
2461 }
2462
2463 return true;
2464}
2465
2466static bool DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
2467 uint64_t Address, const void *Decoder){
2468 Inst.addOperand(MCOperand::CreateImm(Val << 1));
2469 return true;
2470}
2471
2472static bool DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
Owen Anderson10cbaab2011-08-10 17:36:48 +00002473 uint64_t Address, const void *Decoder){
Owen Anderson8d7d2e12011-08-09 20:55:18 +00002474 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2475 return true;
2476}
2477
Owen Andersonc36481c2011-08-09 23:25:42 +00002478static bool DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Val,
2479 uint64_t Address, const void *Decoder) {
2480 switch (Val) {
2481 default:
2482 return false;
2483 case 0xF: // SY
2484 case 0xE: // ST
2485 case 0xB: // ISH
2486 case 0xA: // ISHST
2487 case 0x7: // NSH
2488 case 0x6: // NSHST
2489 case 0x3: // OSH
2490 case 0x2: // OSHST
2491 break;
2492 }
2493
2494 Inst.addOperand(MCOperand::CreateImm(Val));
2495 return true;
2496}
2497
Owen Anderson26d2f0a2011-08-11 20:21:46 +00002498static bool DecodeMSRMask(llvm::MCInst &Inst, unsigned Val,
2499 uint64_t Address, const void *Decoder) {
2500 if (!Val) return false;
2501 Inst.addOperand(MCOperand::CreateImm(Val));
2502 return true;
2503}
Owen Andersoncbfc0442011-08-11 21:34:58 +00002504
Owen Anderson3f3570a2011-08-12 17:58:32 +00002505static bool DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
2506 uint64_t Address, const void *Decoder) {
2507 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2508 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2509 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2510
2511 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return false;
2512
2513 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2514 if (!DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)) return false;
2515 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2516 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
2517
2518 return true;
2519}
2520
2521
2522static bool DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
Owen Andersoncbfc0442011-08-11 21:34:58 +00002523 uint64_t Address, const void *Decoder) {
2524 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2525 unsigned Rt = fieldFromInstruction32(Insn, 0, 4);
2526 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
Owen Andersonadf2b092011-08-11 22:08:38 +00002527 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
Owen Andersoncbfc0442011-08-11 21:34:58 +00002528
Owen Anderson3f3570a2011-08-12 17:58:32 +00002529 if (!DecoderGPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
Owen Andersoncbfc0442011-08-11 21:34:58 +00002530
2531 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return false;
2532 if (Rd == Rn || Rd == Rt || Rd == Rt+1) return false;
2533
2534 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2535 if (!DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder)) return false;
2536 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
Owen Andersonadf2b092011-08-11 22:08:38 +00002537 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
Owen Andersoncbfc0442011-08-11 21:34:58 +00002538
2539 return true;
2540}
2541
Owen Anderson7cdbf082011-08-12 18:12:39 +00002542static bool DecodeSTRPreImm(llvm::MCInst &Inst, unsigned Insn,
2543 uint64_t Address, const void *Decoder) {
2544 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2545 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2546 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
2547 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
2548 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
2549 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
Owen Andersoncbfc0442011-08-11 21:34:58 +00002550
Owen Anderson7cdbf082011-08-12 18:12:39 +00002551 if (Rn == 0xF || Rn == Rt) return false; // UNPREDICTABLE
2552
2553 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2554 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2555 if (!DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder)) return false;
2556 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
2557
2558 return true;
2559}
2560
2561static bool DecodeSTRPreReg(llvm::MCInst &Inst, unsigned Insn,
2562 uint64_t Address, const void *Decoder) {
2563 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2564 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2565 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
2566 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
2567 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
2568 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2569
2570 if (Rn == 0xF || Rn == Rt) return false; // UNPREDICTABLE
2571
2572 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2573 if (!DecodeGPRRegisterClass(Inst, Rt, Address, Decoder)) return false;
2574 if (!DecodeSORegMemOperand(Inst, imm, Address, Decoder)) return false;
2575 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
2576
2577 return true;
2578}
Owen Anderson7a2e1772011-08-15 18:44:44 +00002579
2580static bool DecodeVLD1LN(llvm::MCInst &Inst, unsigned Insn,
2581 uint64_t Address, const void *Decoder) {
2582 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2583 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2584 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2585 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2586 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2587
2588 unsigned align = 0;
2589 unsigned index = 0;
2590 switch (size) {
2591 default:
2592 return false;
2593 case 0:
2594 if (fieldFromInstruction32(Insn, 4, 1))
2595 return false; // UNDEFINED
2596 index = fieldFromInstruction32(Insn, 5, 3);
2597 break;
2598 case 1:
2599 if (fieldFromInstruction32(Insn, 5, 1))
2600 return false; // UNDEFINED
2601 index = fieldFromInstruction32(Insn, 6, 2);
2602 if (fieldFromInstruction32(Insn, 4, 1))
2603 align = 2;
2604 break;
2605 case 2:
2606 if (fieldFromInstruction32(Insn, 6, 1))
2607 return false; // UNDEFINED
2608 index = fieldFromInstruction32(Insn, 7, 1);
2609 if (fieldFromInstruction32(Insn, 4, 2) != 0)
2610 align = 4;
2611 }
2612
2613 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2614 if (Rm != 0xF) { // Writeback
2615 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2616 return false;
2617 }
2618 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2619 Inst.addOperand(MCOperand::CreateImm(align));
2620 if (Rm != 0xF && Rm != 0xD) {
2621 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2622 return false;
2623 }
2624
2625 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2626 Inst.addOperand(MCOperand::CreateImm(index));
2627
2628 return true;
2629}
2630
2631static bool DecodeVST1LN(llvm::MCInst &Inst, unsigned Insn,
2632 uint64_t Address, const void *Decoder) {
2633 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2634 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2635 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2636 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2637 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2638
2639 unsigned align = 0;
2640 unsigned index = 0;
2641 switch (size) {
2642 default:
2643 return false;
2644 case 0:
2645 if (fieldFromInstruction32(Insn, 4, 1))
2646 return false; // UNDEFINED
2647 index = fieldFromInstruction32(Insn, 5, 3);
2648 break;
2649 case 1:
2650 if (fieldFromInstruction32(Insn, 5, 1))
2651 return false; // UNDEFINED
2652 index = fieldFromInstruction32(Insn, 6, 2);
2653 if (fieldFromInstruction32(Insn, 4, 1))
2654 align = 2;
2655 break;
2656 case 2:
2657 if (fieldFromInstruction32(Insn, 6, 1))
2658 return false; // UNDEFINED
2659 index = fieldFromInstruction32(Insn, 7, 1);
2660 if (fieldFromInstruction32(Insn, 4, 2) != 0)
2661 align = 4;
2662 }
2663
2664 if (Rm != 0xF) { // Writeback
2665 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2666 return false;
2667 }
2668 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2669 Inst.addOperand(MCOperand::CreateImm(align));
2670 if (Rm != 0xF && Rm != 0xD) {
2671 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2672 return false;
2673 }
2674
2675 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2676 Inst.addOperand(MCOperand::CreateImm(index));
2677
2678 return true;
2679}
2680
2681
2682static bool DecodeVLD2LN(llvm::MCInst &Inst, unsigned Insn,
2683 uint64_t Address, const void *Decoder) {
2684 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2685 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2686 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2687 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2688 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2689
2690 unsigned align = 0;
2691 unsigned index = 0;
2692 unsigned inc = 1;
2693 switch (size) {
2694 default:
2695 return false;
2696 case 0:
2697 index = fieldFromInstruction32(Insn, 5, 3);
2698 if (fieldFromInstruction32(Insn, 4, 1))
2699 align = 2;
2700 break;
2701 case 1:
2702 index = fieldFromInstruction32(Insn, 6, 2);
2703 if (fieldFromInstruction32(Insn, 4, 1))
2704 align = 4;
2705 if (fieldFromInstruction32(Insn, 5, 1))
2706 inc = 2;
2707 break;
2708 case 2:
2709 if (fieldFromInstruction32(Insn, 5, 1))
2710 return false; // UNDEFINED
2711 index = fieldFromInstruction32(Insn, 7, 1);
2712 if (fieldFromInstruction32(Insn, 4, 1) != 0)
2713 align = 8;
2714 if (fieldFromInstruction32(Insn, 6, 1))
2715 inc = 2;
2716 break;
2717 }
2718
2719 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2720 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2721 if (Rm != 0xF) { // Writeback
2722 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2723 return false;
2724 }
2725 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2726 Inst.addOperand(MCOperand::CreateImm(align));
2727 if (Rm != 0xF && Rm != 0xD) {
2728 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2729 return false;
2730 }
2731
2732 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2733 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2734 Inst.addOperand(MCOperand::CreateImm(index));
2735
2736 return true;
2737}
2738
2739static bool DecodeVST2LN(llvm::MCInst &Inst, unsigned Insn,
2740 uint64_t Address, const void *Decoder) {
2741 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2742 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2743 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2744 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2745 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2746
2747 unsigned align = 0;
2748 unsigned index = 0;
2749 unsigned inc = 1;
2750 switch (size) {
2751 default:
2752 return false;
2753 case 0:
2754 index = fieldFromInstruction32(Insn, 5, 3);
2755 if (fieldFromInstruction32(Insn, 4, 1))
2756 align = 2;
2757 break;
2758 case 1:
2759 index = fieldFromInstruction32(Insn, 6, 2);
2760 if (fieldFromInstruction32(Insn, 4, 1))
2761 align = 4;
2762 if (fieldFromInstruction32(Insn, 5, 1))
2763 inc = 2;
2764 break;
2765 case 2:
2766 if (fieldFromInstruction32(Insn, 5, 1))
2767 return false; // UNDEFINED
2768 index = fieldFromInstruction32(Insn, 7, 1);
2769 if (fieldFromInstruction32(Insn, 4, 1) != 0)
2770 align = 8;
2771 if (fieldFromInstruction32(Insn, 6, 1))
2772 inc = 2;
2773 break;
2774 }
2775
2776 if (Rm != 0xF) { // Writeback
2777 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2778 return false;
2779 }
2780 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2781 Inst.addOperand(MCOperand::CreateImm(align));
2782 if (Rm != 0xF && Rm != 0xD) {
2783 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2784 return false;
2785 }
2786
2787 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2788 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2789 Inst.addOperand(MCOperand::CreateImm(index));
2790
2791 return true;
2792}
2793
2794
2795static bool DecodeVLD3LN(llvm::MCInst &Inst, unsigned Insn,
2796 uint64_t Address, const void *Decoder) {
2797 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2798 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2799 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2800 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2801 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2802
2803 unsigned align = 0;
2804 unsigned index = 0;
2805 unsigned inc = 1;
2806 switch (size) {
2807 default:
2808 return false;
2809 case 0:
2810 if (fieldFromInstruction32(Insn, 4, 1))
2811 return false; // UNDEFINED
2812 index = fieldFromInstruction32(Insn, 5, 3);
2813 break;
2814 case 1:
2815 if (fieldFromInstruction32(Insn, 4, 1))
2816 return false; // UNDEFINED
2817 index = fieldFromInstruction32(Insn, 6, 2);
2818 if (fieldFromInstruction32(Insn, 5, 1))
2819 inc = 2;
2820 break;
2821 case 2:
2822 if (fieldFromInstruction32(Insn, 4, 2))
2823 return false; // UNDEFINED
2824 index = fieldFromInstruction32(Insn, 7, 1);
2825 if (fieldFromInstruction32(Insn, 6, 1))
2826 inc = 2;
2827 break;
2828 }
2829
2830 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2831 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2832 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
2833
2834 if (Rm != 0xF) { // Writeback
2835 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2836 return false;
2837 }
2838 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2839 Inst.addOperand(MCOperand::CreateImm(align));
2840 if (Rm != 0xF && Rm != 0xD) {
2841 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2842 return false;
2843 }
2844
2845 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2846 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2847 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
2848 Inst.addOperand(MCOperand::CreateImm(index));
2849
2850 return true;
2851}
2852
2853static bool DecodeVST3LN(llvm::MCInst &Inst, unsigned Insn,
2854 uint64_t Address, const void *Decoder) {
2855 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2856 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2857 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2858 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2859 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2860
2861 unsigned align = 0;
2862 unsigned index = 0;
2863 unsigned inc = 1;
2864 switch (size) {
2865 default:
2866 return false;
2867 case 0:
2868 if (fieldFromInstruction32(Insn, 4, 1))
2869 return false; // UNDEFINED
2870 index = fieldFromInstruction32(Insn, 5, 3);
2871 break;
2872 case 1:
2873 if (fieldFromInstruction32(Insn, 4, 1))
2874 return false; // UNDEFINED
2875 index = fieldFromInstruction32(Insn, 6, 2);
2876 if (fieldFromInstruction32(Insn, 5, 1))
2877 inc = 2;
2878 break;
2879 case 2:
2880 if (fieldFromInstruction32(Insn, 4, 2))
2881 return false; // UNDEFINED
2882 index = fieldFromInstruction32(Insn, 7, 1);
2883 if (fieldFromInstruction32(Insn, 6, 1))
2884 inc = 2;
2885 break;
2886 }
2887
2888 if (Rm != 0xF) { // Writeback
2889 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2890 return false;
2891 }
2892 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2893 Inst.addOperand(MCOperand::CreateImm(align));
2894 if (Rm != 0xF && Rm != 0xD) {
2895 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2896 return false;
2897 }
2898
2899 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2900 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2901 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
2902 Inst.addOperand(MCOperand::CreateImm(index));
2903
2904 return true;
2905}
2906
2907
2908static bool DecodeVLD4LN(llvm::MCInst &Inst, unsigned Insn,
2909 uint64_t Address, const void *Decoder) {
2910 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2911 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2912 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2913 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2914 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2915
2916 unsigned align = 0;
2917 unsigned index = 0;
2918 unsigned inc = 1;
2919 switch (size) {
2920 default:
2921 return false;
2922 case 0:
2923 if (fieldFromInstruction32(Insn, 4, 1))
2924 align = 4;
2925 index = fieldFromInstruction32(Insn, 5, 3);
2926 break;
2927 case 1:
2928 if (fieldFromInstruction32(Insn, 4, 1))
2929 align = 8;
2930 index = fieldFromInstruction32(Insn, 6, 2);
2931 if (fieldFromInstruction32(Insn, 5, 1))
2932 inc = 2;
2933 break;
2934 case 2:
2935 if (fieldFromInstruction32(Insn, 4, 2))
2936 align = 4 << fieldFromInstruction32(Insn, 4, 2);
2937 index = fieldFromInstruction32(Insn, 7, 1);
2938 if (fieldFromInstruction32(Insn, 6, 1))
2939 inc = 2;
2940 break;
2941 }
2942
2943 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2944 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2945 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
2946 if (!DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)) return false;
2947
2948 if (Rm != 0xF) { // Writeback
2949 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
2950 return false;
2951 }
2952 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
2953 Inst.addOperand(MCOperand::CreateImm(align));
2954 if (Rm != 0xF && Rm != 0xD) {
2955 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
2956 return false;
2957 }
2958
2959 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
2960 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
2961 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
2962 if (!DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)) return false;
2963 Inst.addOperand(MCOperand::CreateImm(index));
2964
2965 return true;
2966}
2967
2968static bool DecodeVST4LN(llvm::MCInst &Inst, unsigned Insn,
2969 uint64_t Address, const void *Decoder) {
2970 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2971 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2972 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2973 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2974 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2975
2976 unsigned align = 0;
2977 unsigned index = 0;
2978 unsigned inc = 1;
2979 switch (size) {
2980 default:
2981 return false;
2982 case 0:
2983 if (fieldFromInstruction32(Insn, 4, 1))
2984 align = 4;
2985 index = fieldFromInstruction32(Insn, 5, 3);
2986 break;
2987 case 1:
2988 if (fieldFromInstruction32(Insn, 4, 1))
2989 align = 8;
2990 index = fieldFromInstruction32(Insn, 6, 2);
2991 if (fieldFromInstruction32(Insn, 5, 1))
2992 inc = 2;
2993 break;
2994 case 2:
2995 if (fieldFromInstruction32(Insn, 4, 2))
2996 align = 4 << fieldFromInstruction32(Insn, 4, 2);
2997 index = fieldFromInstruction32(Insn, 7, 1);
2998 if (fieldFromInstruction32(Insn, 6, 1))
2999 inc = 2;
3000 break;
3001 }
3002
3003 if (Rm != 0xF) { // Writeback
3004 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder))
3005 return false;
3006 }
3007 if (!DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)) return false;
3008 Inst.addOperand(MCOperand::CreateImm(align));
3009 if (Rm != 0xF && Rm != 0xD) {
3010 if (!DecodeGPRRegisterClass(Inst, Rm, Address, Decoder))
3011 return false;
3012 }
3013
3014 if (!DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)) return false;
3015 if (!DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder)) return false;
3016 if (!DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder)) return false;
3017 if (!DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder)) return false;
3018 Inst.addOperand(MCOperand::CreateImm(index));
3019
3020 return true;
3021}
3022