1 //===- ARMDisassembler.cpp - Disassembler for ARM/Thumb ISA -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #define DEBUG_TYPE "arm-disassembler"
12 #include "ARMDisassembler.h"
14 #include "ARMRegisterInfo.h"
15 #include "MCTargetDesc/ARMAddressingModes.h"
16 #include "MCTargetDesc/ARMBaseInfo.h"
17 #include "llvm/MC/EDInstInfo.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/Support/MemoryObject.h"
23 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/TargetRegistry.h"
25 #include "llvm/Support/raw_ostream.h"
27 // Pull DecodeStatus and its enum values into the global namespace.
28 typedef llvm::MCDisassembler::DecodeStatus DecodeStatus;
29 #define Success llvm::MCDisassembler::Success
30 #define Unpredictable llvm::MCDisassembler::SoftFail
31 #define Fail llvm::MCDisassembler::Fail
33 // Helper macro to perform setwise reduction of the current running status
34 // and another status, and return if the new status is Fail.
35 #define CHECK(S,X) do { \
36 S = (DecodeStatus) ((int)S & (X)); \
37 if (S == Fail) return Fail; \
40 // Forward declare these because the autogenerated code will reference them.
41 // Definitions are further down.
42 static DecodeStatus DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
43 uint64_t Address, const void *Decoder);
44 static DecodeStatus DecodeGPRnopcRegisterClass(llvm::MCInst &Inst,
45 unsigned RegNo, uint64_t Address,
47 static DecodeStatus DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
48 uint64_t Address, const void *Decoder);
49 static DecodeStatus DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
50 uint64_t Address, const void *Decoder);
51 static DecodeStatus DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
52 uint64_t Address, const void *Decoder);
53 static DecodeStatus DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
54 uint64_t Address, const void *Decoder);
55 static DecodeStatus DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
56 uint64_t Address, const void *Decoder);
57 static DecodeStatus DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
58 uint64_t Address, const void *Decoder);
59 static DecodeStatus DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst,
63 static DecodeStatus DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
64 uint64_t Address, const void *Decoder);
66 static DecodeStatus DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
67 uint64_t Address, const void *Decoder);
68 static DecodeStatus DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
69 uint64_t Address, const void *Decoder);
70 static DecodeStatus DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
71 uint64_t Address, const void *Decoder);
72 static DecodeStatus DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
73 uint64_t Address, const void *Decoder);
74 static DecodeStatus DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
75 uint64_t Address, const void *Decoder);
76 static DecodeStatus DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
77 uint64_t Address, const void *Decoder);
78 static DecodeStatus DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
79 uint64_t Address, const void *Decoder);
81 static DecodeStatus DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Insn,
82 uint64_t Address, const void *Decoder);
83 static DecodeStatus DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
84 uint64_t Address, const void *Decoder);
85 static DecodeStatus DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst,
89 static DecodeStatus DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Insn,
90 uint64_t Address, const void *Decoder);
91 static DecodeStatus DecodeAddrMode3Instruction(llvm::MCInst &Inst,unsigned Insn,
92 uint64_t Address, const void *Decoder);
93 static DecodeStatus DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Insn,
94 uint64_t Address, const void *Decoder);
95 static DecodeStatus DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Insn,
96 uint64_t Address, const void *Decoder);
98 static DecodeStatus DecodeMemMultipleWritebackInstruction(llvm::MCInst & Inst,
101 const void *Decoder);
102 static DecodeStatus DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
103 uint64_t Address, const void *Decoder);
104 static DecodeStatus DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
105 uint64_t Address, const void *Decoder);
106 static DecodeStatus DecodeT2CPSInstruction(llvm::MCInst &Inst, unsigned Insn,
107 uint64_t Address, const void *Decoder);
108 static DecodeStatus DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
109 uint64_t Address, const void *Decoder);
110 static DecodeStatus DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
111 uint64_t Address, const void *Decoder);
112 static DecodeStatus DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
113 uint64_t Address, const void *Decoder);
114 static DecodeStatus DecodeBranchImmInstruction(llvm::MCInst &Inst,unsigned Insn,
115 uint64_t Address, const void *Decoder);
116 static DecodeStatus DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
117 uint64_t Address, const void *Decoder);
118 static DecodeStatus DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
119 uint64_t Address, const void *Decoder);
120 static DecodeStatus DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Val,
121 uint64_t Address, const void *Decoder);
122 static DecodeStatus DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Val,
123 uint64_t Address, const void *Decoder);
124 static DecodeStatus DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Val,
125 uint64_t Address, const void *Decoder);
126 static DecodeStatus DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Val,
127 uint64_t Address, const void *Decoder);
128 static DecodeStatus DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Val,
129 uint64_t Address, const void *Decoder);
130 static DecodeStatus DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Val,
131 uint64_t Address, const void *Decoder);
132 static DecodeStatus DecodeNEONModImmInstruction(llvm::MCInst &Inst,unsigned Val,
133 uint64_t Address, const void *Decoder);
134 static DecodeStatus DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Val,
135 uint64_t Address, const void *Decoder);
136 static DecodeStatus DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
137 uint64_t Address, const void *Decoder);
138 static DecodeStatus DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
139 uint64_t Address, const void *Decoder);
140 static DecodeStatus DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
141 uint64_t Address, const void *Decoder);
142 static DecodeStatus DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
143 uint64_t Address, const void *Decoder);
144 static DecodeStatus DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
145 uint64_t Address, const void *Decoder);
146 static DecodeStatus DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
147 uint64_t Address, const void *Decoder);
148 static DecodeStatus DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
149 uint64_t Address, const void *Decoder);
150 static DecodeStatus DecodeCoprocessor(llvm::MCInst &Inst, unsigned Insn,
151 uint64_t Address, const void *Decoder);
152 static DecodeStatus DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Insn,
153 uint64_t Address, const void *Decoder);
154 static DecodeStatus DecodeMSRMask(llvm::MCInst &Inst, unsigned Insn,
155 uint64_t Address, const void *Decoder);
156 static DecodeStatus DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
157 uint64_t Address, const void *Decoder);
158 static DecodeStatus DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
159 uint64_t Address, const void *Decoder);
160 static DecodeStatus DecodeSTRPreImm(llvm::MCInst &Inst, unsigned Insn,
161 uint64_t Address, const void *Decoder);
162 static DecodeStatus DecodeSTRPreReg(llvm::MCInst &Inst, unsigned Insn,
163 uint64_t Address, const void *Decoder);
164 static DecodeStatus DecodeVLD1LN(llvm::MCInst &Inst, unsigned Insn,
165 uint64_t Address, const void *Decoder);
166 static DecodeStatus DecodeVLD2LN(llvm::MCInst &Inst, unsigned Insn,
167 uint64_t Address, const void *Decoder);
168 static DecodeStatus DecodeVLD3LN(llvm::MCInst &Inst, unsigned Insn,
169 uint64_t Address, const void *Decoder);
170 static DecodeStatus DecodeVLD4LN(llvm::MCInst &Inst, unsigned Insn,
171 uint64_t Address, const void *Decoder);
172 static DecodeStatus DecodeVST1LN(llvm::MCInst &Inst, unsigned Insn,
173 uint64_t Address, const void *Decoder);
174 static DecodeStatus DecodeVST2LN(llvm::MCInst &Inst, unsigned Insn,
175 uint64_t Address, const void *Decoder);
176 static DecodeStatus DecodeVST3LN(llvm::MCInst &Inst, unsigned Insn,
177 uint64_t Address, const void *Decoder);
178 static DecodeStatus DecodeVST4LN(llvm::MCInst &Inst, unsigned Insn,
179 uint64_t Address, const void *Decoder);
180 static DecodeStatus DecodeVMOVSRR(llvm::MCInst &Inst, unsigned Insn,
181 uint64_t Address, const void *Decoder);
182 static DecodeStatus DecodeVMOVRRS(llvm::MCInst &Inst, unsigned Insn,
183 uint64_t Address, const void *Decoder);
185 static DecodeStatus DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
186 uint64_t Address, const void *Decoder);
187 static DecodeStatus DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
188 uint64_t Address, const void *Decoder);
189 static DecodeStatus DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
190 uint64_t Address, const void *Decoder);
191 static DecodeStatus DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
192 uint64_t Address, const void *Decoder);
193 static DecodeStatus DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
194 uint64_t Address, const void *Decoder);
195 static DecodeStatus DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
196 uint64_t Address, const void *Decoder);
197 static DecodeStatus DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
198 uint64_t Address, const void *Decoder);
199 static DecodeStatus DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
200 uint64_t Address, const void *Decoder);
201 static DecodeStatus DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
202 uint64_t Address, const void *Decoder);
203 static DecodeStatus DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Val,
204 uint64_t Address, const void *Decoder);
205 static DecodeStatus DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
206 uint64_t Address, const void *Decoder);
207 static DecodeStatus DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
208 uint64_t Address, const void *Decoder);
209 static DecodeStatus DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
210 uint64_t Address, const void *Decoder);
211 static DecodeStatus DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
212 uint64_t Address, const void *Decoder);
213 static DecodeStatus DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Val,
214 uint64_t Address, const void *Decoder);
215 static DecodeStatus DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
216 uint64_t Address, const void *Decoder);
217 static DecodeStatus DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
218 uint64_t Address, const void *Decoder);
219 static DecodeStatus DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Insn,
220 uint64_t Address, const void *Decoder);
221 static DecodeStatus DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
222 uint64_t Address, const void *Decoder);
223 static DecodeStatus DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Val,
224 uint64_t Address, const void *Decoder);
225 static DecodeStatus DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
226 uint64_t Address, const void *Decoder);
227 static DecodeStatus DecodeThumbBCCTargetOperand(llvm::MCInst &Inst,unsigned Val,
228 uint64_t Address, const void *Decoder);
229 static DecodeStatus DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
230 uint64_t Address, const void *Decoder);
231 static DecodeStatus DecodeITCond(llvm::MCInst &Inst, unsigned Val,
232 uint64_t Address, const void *Decoder);
233 static DecodeStatus DecodeITMask(llvm::MCInst &Inst, unsigned Val,
234 uint64_t Address, const void *Decoder);
236 #include "ARMGenDisassemblerTables.inc"
237 #include "ARMGenInstrInfo.inc"
238 #include "ARMGenEDInfo.inc"
240 using namespace llvm;
242 static MCDisassembler *createARMDisassembler(const Target &T) {
243 return new ARMDisassembler;
246 static MCDisassembler *createThumbDisassembler(const Target &T) {
247 return new ThumbDisassembler;
250 EDInstInfo *ARMDisassembler::getEDInfo() const {
254 EDInstInfo *ThumbDisassembler::getEDInfo() const {
258 DecodeStatus ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
259 const MemoryObject &Region,
261 raw_ostream &os) const {
264 // We want to read exactly 4 bytes of data.
265 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
268 // Encoded as a small-endian 32-bit word in the stream.
269 uint32_t insn = (bytes[3] << 24) |
274 // Calling the auto-generated decoder function.
275 DecodeStatus result = decodeARMInstruction32(MI, insn, Address, this);
276 if (result != Fail) {
281 // Instructions that are shared between ARM and Thumb modes.
282 // FIXME: This shouldn't really exist. It's an artifact of the
283 // fact that we fail to encode a few instructions properly for Thumb.
285 result = decodeCommonInstruction32(MI, insn, Address, this);
286 if (result != Fail) {
291 // VFP and NEON instructions, similarly, are shared between ARM
294 result = decodeVFPInstruction32(MI, insn, Address, this);
295 if (result != Fail) {
301 result = decodeNEONDataInstruction32(MI, insn, Address, this);
302 if (result != Fail) {
304 // Add a fake predicate operand, because we share these instruction
305 // definitions with Thumb2 where these instructions are predicable.
306 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return Fail;
311 result = decodeNEONLoadStoreInstruction32(MI, insn, Address, this);
312 if (result != Fail) {
314 // Add a fake predicate operand, because we share these instruction
315 // definitions with Thumb2 where these instructions are predicable.
316 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return Fail;
321 result = decodeNEONDupInstruction32(MI, insn, Address, this);
322 if (result != Fail) {
324 // Add a fake predicate operand, because we share these instruction
325 // definitions with Thumb2 where these instructions are predicable.
326 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return Fail;
336 extern MCInstrDesc ARMInsts[];
339 // Thumb1 instructions don't have explicit S bits. Rather, they
340 // implicitly set CPSR. Since it's not represented in the encoding, the
341 // auto-generated decoder won't inject the CPSR operand. We need to fix
342 // that as a post-pass.
343 static void AddThumb1SBit(MCInst &MI, bool InITBlock) {
344 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
345 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
346 MCInst::iterator I = MI.begin();
347 for (unsigned i = 0; i < NumOps; ++i, ++I) {
348 if (I == MI.end()) break;
349 if (OpInfo[i].isOptionalDef() && OpInfo[i].RegClass == ARM::CCRRegClassID) {
350 if (i > 0 && OpInfo[i-1].isPredicate()) continue;
351 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
356 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
359 // Most Thumb instructions don't have explicit predicates in the
360 // encoding, but rather get their predicates from IT context. We need
361 // to fix up the predicate operands using this context information as a
363 void ThumbDisassembler::AddThumbPredicate(MCInst &MI) const {
364 // A few instructions actually have predicates encoded in them. Don't
365 // try to overwrite it if we're seeing one of those.
366 switch (MI.getOpcode()) {
374 // If we're in an IT block, base the predicate on that. Otherwise,
375 // assume a predicate of AL.
377 if (!ITBlock.empty()) {
385 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
386 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
387 MCInst::iterator I = MI.begin();
388 for (unsigned i = 0; i < NumOps; ++i, ++I) {
389 if (I == MI.end()) break;
390 if (OpInfo[i].isPredicate()) {
391 I = MI.insert(I, MCOperand::CreateImm(CC));
394 MI.insert(I, MCOperand::CreateReg(0));
396 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
401 I = MI.insert(I, MCOperand::CreateImm(CC));
404 MI.insert(I, MCOperand::CreateReg(0));
406 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
409 // Thumb VFP instructions are a special case. Because we share their
410 // encodings between ARM and Thumb modes, and they are predicable in ARM
411 // mode, the auto-generated decoder will give them an (incorrect)
412 // predicate operand. We need to rewrite these operands based on the IT
413 // context as a post-pass.
414 void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const {
416 if (!ITBlock.empty()) {
422 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
423 MCInst::iterator I = MI.begin();
424 unsigned short NumOps = ARMInsts[MI.getOpcode()].NumOperands;
425 for (unsigned i = 0; i < NumOps; ++i, ++I) {
426 if (OpInfo[i].isPredicate() ) {
432 I->setReg(ARM::CPSR);
438 DecodeStatus ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
439 const MemoryObject &Region,
441 raw_ostream &os) const {
444 // We want to read exactly 2 bytes of data.
445 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1)
448 uint16_t insn16 = (bytes[1] << 8) | bytes[0];
449 DecodeStatus result = decodeThumbInstruction16(MI, insn16, Address, this);
450 if (result != Fail) {
452 AddThumbPredicate(MI);
457 result = decodeThumbSBitInstruction16(MI, insn16, Address, this);
460 bool InITBlock = !ITBlock.empty();
461 AddThumbPredicate(MI);
462 AddThumb1SBit(MI, InITBlock);
467 result = decodeThumb2Instruction16(MI, insn16, Address, this);
468 if (result != Fail) {
470 AddThumbPredicate(MI);
472 // If we find an IT instruction, we need to parse its condition
473 // code and mask operands so that we can apply them correctly
474 // to the subsequent instructions.
475 if (MI.getOpcode() == ARM::t2IT) {
476 unsigned firstcond = MI.getOperand(0).getImm();
477 uint32_t mask = MI.getOperand(1).getImm();
478 unsigned zeros = CountTrailingZeros_32(mask);
481 for (unsigned i = 0; i < 4 - (zeros+1); ++i) {
482 if (firstcond ^ (mask & 1))
483 ITBlock.push_back(firstcond ^ 1);
485 ITBlock.push_back(firstcond);
488 ITBlock.push_back(firstcond);
494 // We want to read exactly 4 bytes of data.
495 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
498 uint32_t insn32 = (bytes[3] << 8) |
503 result = decodeThumbInstruction32(MI, insn32, Address, this);
504 if (result != Fail) {
506 bool InITBlock = ITBlock.size();
507 AddThumbPredicate(MI);
508 AddThumb1SBit(MI, InITBlock);
513 result = decodeThumb2Instruction32(MI, insn32, Address, this);
514 if (result != Fail) {
516 AddThumbPredicate(MI);
521 result = decodeCommonInstruction32(MI, insn32, Address, this);
522 if (result != Fail) {
524 AddThumbPredicate(MI);
529 result = decodeVFPInstruction32(MI, insn32, Address, this);
530 if (result != Fail) {
532 UpdateThumbVFPPredicate(MI);
537 result = decodeNEONDupInstruction32(MI, insn32, Address, this);
538 if (result != Fail) {
540 AddThumbPredicate(MI);
544 if (fieldFromInstruction32(insn32, 24, 8) == 0xF9) {
546 uint32_t NEONLdStInsn = insn32;
547 NEONLdStInsn &= 0xF0FFFFFF;
548 NEONLdStInsn |= 0x04000000;
549 result = decodeNEONLoadStoreInstruction32(MI, NEONLdStInsn, Address, this);
550 if (result != Fail) {
552 AddThumbPredicate(MI);
557 if (fieldFromInstruction32(insn32, 24, 4) == 0xF) {
559 uint32_t NEONDataInsn = insn32;
560 NEONDataInsn &= 0xF0FFFFFF; // Clear bits 27-24
561 NEONDataInsn |= (NEONDataInsn & 0x10000000) >> 4; // Move bit 28 to bit 24
562 NEONDataInsn |= 0x12000000; // Set bits 28 and 25
563 result = decodeNEONDataInstruction32(MI, NEONDataInsn, Address, this);
564 if (result != Fail) {
566 AddThumbPredicate(MI);
575 extern "C" void LLVMInitializeARMDisassembler() {
576 TargetRegistry::RegisterMCDisassembler(TheARMTarget,
577 createARMDisassembler);
578 TargetRegistry::RegisterMCDisassembler(TheThumbTarget,
579 createThumbDisassembler);
582 static const unsigned GPRDecoderTable[] = {
583 ARM::R0, ARM::R1, ARM::R2, ARM::R3,
584 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
585 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
586 ARM::R12, ARM::SP, ARM::LR, ARM::PC
589 static DecodeStatus DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
590 uint64_t Address, const void *Decoder) {
594 unsigned Register = GPRDecoderTable[RegNo];
595 Inst.addOperand(MCOperand::CreateReg(Register));
600 DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
601 uint64_t Address, const void *Decoder) {
602 if (RegNo == 15) return Fail;
603 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
606 static DecodeStatus DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
607 uint64_t Address, const void *Decoder) {
610 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
613 static DecodeStatus DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
614 uint64_t Address, const void *Decoder) {
615 unsigned Register = 0;
639 Inst.addOperand(MCOperand::CreateReg(Register));
643 static DecodeStatus DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
644 uint64_t Address, const void *Decoder) {
645 if (RegNo == 13 || RegNo == 15) return Fail;
646 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
649 static const unsigned SPRDecoderTable[] = {
650 ARM::S0, ARM::S1, ARM::S2, ARM::S3,
651 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
652 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
653 ARM::S12, ARM::S13, ARM::S14, ARM::S15,
654 ARM::S16, ARM::S17, ARM::S18, ARM::S19,
655 ARM::S20, ARM::S21, ARM::S22, ARM::S23,
656 ARM::S24, ARM::S25, ARM::S26, ARM::S27,
657 ARM::S28, ARM::S29, ARM::S30, ARM::S31
660 static DecodeStatus DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
661 uint64_t Address, const void *Decoder) {
665 unsigned Register = SPRDecoderTable[RegNo];
666 Inst.addOperand(MCOperand::CreateReg(Register));
670 static const unsigned DPRDecoderTable[] = {
671 ARM::D0, ARM::D1, ARM::D2, ARM::D3,
672 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
673 ARM::D8, ARM::D9, ARM::D10, ARM::D11,
674 ARM::D12, ARM::D13, ARM::D14, ARM::D15,
675 ARM::D16, ARM::D17, ARM::D18, ARM::D19,
676 ARM::D20, ARM::D21, ARM::D22, ARM::D23,
677 ARM::D24, ARM::D25, ARM::D26, ARM::D27,
678 ARM::D28, ARM::D29, ARM::D30, ARM::D31
681 static DecodeStatus DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
682 uint64_t Address, const void *Decoder) {
686 unsigned Register = DPRDecoderTable[RegNo];
687 Inst.addOperand(MCOperand::CreateReg(Register));
691 static DecodeStatus DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
692 uint64_t Address, const void *Decoder) {
695 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
699 DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
700 uint64_t Address, const void *Decoder) {
703 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
706 static const unsigned QPRDecoderTable[] = {
707 ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
708 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7,
709 ARM::Q8, ARM::Q9, ARM::Q10, ARM::Q11,
710 ARM::Q12, ARM::Q13, ARM::Q14, ARM::Q15
714 static DecodeStatus DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
715 uint64_t Address, const void *Decoder) {
720 unsigned Register = QPRDecoderTable[RegNo];
721 Inst.addOperand(MCOperand::CreateReg(Register));
725 static DecodeStatus DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
726 uint64_t Address, const void *Decoder) {
727 if (Val == 0xF) return Fail;
728 // AL predicate is not allowed on Thumb1 branches.
729 if (Inst.getOpcode() == ARM::tBcc && Val == 0xE)
731 Inst.addOperand(MCOperand::CreateImm(Val));
732 if (Val == ARMCC::AL) {
733 Inst.addOperand(MCOperand::CreateReg(0));
735 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
739 static DecodeStatus DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
740 uint64_t Address, const void *Decoder) {
742 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
744 Inst.addOperand(MCOperand::CreateReg(0));
748 static DecodeStatus DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
749 uint64_t Address, const void *Decoder) {
750 uint32_t imm = Val & 0xFF;
751 uint32_t rot = (Val & 0xF00) >> 7;
752 uint32_t rot_imm = (imm >> rot) | (imm << (32-rot));
753 Inst.addOperand(MCOperand::CreateImm(rot_imm));
757 static DecodeStatus DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
758 uint64_t Address, const void *Decoder) {
760 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(Val)));
764 static DecodeStatus DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Val,
765 uint64_t Address, const void *Decoder) {
766 DecodeStatus S = Success;
768 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
769 unsigned type = fieldFromInstruction32(Val, 5, 2);
770 unsigned imm = fieldFromInstruction32(Val, 7, 5);
772 // Register-immediate
773 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
775 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
791 if (Shift == ARM_AM::ror && imm == 0)
794 unsigned Op = Shift | (imm << 3);
795 Inst.addOperand(MCOperand::CreateImm(Op));
800 static DecodeStatus DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Val,
801 uint64_t Address, const void *Decoder) {
802 DecodeStatus S = Success;
804 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
805 unsigned type = fieldFromInstruction32(Val, 5, 2);
806 unsigned Rs = fieldFromInstruction32(Val, 8, 4);
809 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder));
810 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rs, Address, Decoder));
812 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
828 Inst.addOperand(MCOperand::CreateImm(Shift));
833 static DecodeStatus DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
834 uint64_t Address, const void *Decoder) {
835 DecodeStatus S = Success;
837 // Empty register lists are not allowed.
838 if (CountPopulation_32(Val) == 0) return Fail;
839 for (unsigned i = 0; i < 16; ++i) {
840 if (Val & (1 << i)) {
841 CHECK(S, DecodeGPRRegisterClass(Inst, i, Address, Decoder));
848 static DecodeStatus DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
849 uint64_t Address, const void *Decoder) {
850 DecodeStatus S = Success;
852 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
853 unsigned regs = Val & 0xFF;
855 CHECK(S, DecodeSPRRegisterClass(Inst, Vd, Address, Decoder));
856 for (unsigned i = 0; i < (regs - 1); ++i) {
857 CHECK(S, DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder));
863 static DecodeStatus DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
864 uint64_t Address, const void *Decoder) {
865 DecodeStatus S = Success;
867 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
868 unsigned regs = (Val & 0xFF) / 2;
870 CHECK(S, DecodeDPRRegisterClass(Inst, Vd, Address, Decoder));
871 for (unsigned i = 0; i < (regs - 1); ++i) {
872 CHECK(S, DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder));
878 static DecodeStatus DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Val,
879 uint64_t Address, const void *Decoder) {
880 // This operand encodes a mask of contiguous zeros between a specified MSB
881 // and LSB. To decode it, we create the mask of all bits MSB-and-lower,
882 // the mask of all bits LSB-and-lower, and then xor them to create
883 // the mask of that's all ones on [msb, lsb]. Finally we not it to
884 // create the final mask.
885 unsigned msb = fieldFromInstruction32(Val, 5, 5);
886 unsigned lsb = fieldFromInstruction32(Val, 0, 5);
887 uint32_t msb_mask = (1 << (msb+1)) - 1;
888 uint32_t lsb_mask = (1 << lsb) - 1;
889 Inst.addOperand(MCOperand::CreateImm(~(msb_mask ^ lsb_mask)));
893 static DecodeStatus DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
894 uint64_t Address, const void *Decoder) {
895 DecodeStatus S = Success;
897 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
898 unsigned CRd = fieldFromInstruction32(Insn, 12, 4);
899 unsigned coproc = fieldFromInstruction32(Insn, 8, 4);
900 unsigned imm = fieldFromInstruction32(Insn, 0, 8);
901 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
902 unsigned U = fieldFromInstruction32(Insn, 23, 1);
904 switch (Inst.getOpcode()) {
905 case ARM::LDC_OFFSET:
908 case ARM::LDC_OPTION:
909 case ARM::LDCL_OFFSET:
912 case ARM::LDCL_OPTION:
913 case ARM::STC_OFFSET:
916 case ARM::STC_OPTION:
917 case ARM::STCL_OFFSET:
920 case ARM::STCL_OPTION:
921 if (coproc == 0xA || coproc == 0xB)
928 Inst.addOperand(MCOperand::CreateImm(coproc));
929 Inst.addOperand(MCOperand::CreateImm(CRd));
930 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
931 switch (Inst.getOpcode()) {
932 case ARM::LDC_OPTION:
933 case ARM::LDCL_OPTION:
934 case ARM::LDC2_OPTION:
935 case ARM::LDC2L_OPTION:
936 case ARM::STC_OPTION:
937 case ARM::STCL_OPTION:
938 case ARM::STC2_OPTION:
939 case ARM::STC2L_OPTION:
942 case ARM::LDC2L_POST:
943 case ARM::STC2L_POST:
946 Inst.addOperand(MCOperand::CreateReg(0));
950 unsigned P = fieldFromInstruction32(Insn, 24, 1);
951 unsigned W = fieldFromInstruction32(Insn, 21, 1);
953 bool writeback = (P == 0) || (W == 1);
954 unsigned idx_mode = 0;
956 idx_mode = ARMII::IndexModePre;
957 else if (!P && writeback)
958 idx_mode = ARMII::IndexModePost;
960 switch (Inst.getOpcode()) {
963 case ARM::LDC2L_POST:
964 case ARM::STC2L_POST:
966 case ARM::LDC_OPTION:
967 case ARM::LDCL_OPTION:
968 case ARM::LDC2_OPTION:
969 case ARM::LDC2L_OPTION:
970 case ARM::STC_OPTION:
971 case ARM::STCL_OPTION:
972 case ARM::STC2_OPTION:
973 case ARM::STC2L_OPTION:
974 Inst.addOperand(MCOperand::CreateImm(imm));
978 Inst.addOperand(MCOperand::CreateImm(
979 ARM_AM::getAM2Opc(ARM_AM::add, imm, ARM_AM::lsl, idx_mode)));
981 Inst.addOperand(MCOperand::CreateImm(
982 ARM_AM::getAM2Opc(ARM_AM::sub, imm, ARM_AM::lsl, idx_mode)));
986 switch (Inst.getOpcode()) {
987 case ARM::LDC_OFFSET:
990 case ARM::LDC_OPTION:
991 case ARM::LDCL_OFFSET:
994 case ARM::LDCL_OPTION:
995 case ARM::STC_OFFSET:
998 case ARM::STC_OPTION:
999 case ARM::STCL_OFFSET:
1001 case ARM::STCL_POST:
1002 case ARM::STCL_OPTION:
1003 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1013 DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
1014 uint64_t Address, const void *Decoder) {
1015 DecodeStatus S = Success;
1017 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1018 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1019 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1020 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
1021 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1022 unsigned reg = fieldFromInstruction32(Insn, 25, 1);
1023 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1024 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1026 // On stores, the writeback operand precedes Rt.
1027 switch (Inst.getOpcode()) {
1028 case ARM::STR_POST_IMM:
1029 case ARM::STR_POST_REG:
1030 case ARM::STRB_POST_IMM:
1031 case ARM::STRB_POST_REG:
1032 case ARM::STRT_POST_REG:
1033 case ARM::STRT_POST_IMM:
1034 case ARM::STRBT_POST_REG:
1035 case ARM::STRBT_POST_IMM:
1036 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1042 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
1044 // On loads, the writeback operand comes after Rt.
1045 switch (Inst.getOpcode()) {
1046 case ARM::LDR_POST_IMM:
1047 case ARM::LDR_POST_REG:
1048 case ARM::LDRB_POST_IMM:
1049 case ARM::LDRB_POST_REG:
1052 case ARM::LDRBT_POST_REG:
1053 case ARM::LDRBT_POST_IMM:
1054 case ARM::LDRT_POST_REG:
1055 case ARM::LDRT_POST_IMM:
1056 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1062 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1064 ARM_AM::AddrOpc Op = ARM_AM::add;
1065 if (!fieldFromInstruction32(Insn, 23, 1))
1068 bool writeback = (P == 0) || (W == 1);
1069 unsigned idx_mode = 0;
1071 idx_mode = ARMII::IndexModePre;
1072 else if (!P && writeback)
1073 idx_mode = ARMII::IndexModePost;
1075 if (writeback && (Rn == 15 || Rn == Rt)) S = Unpredictable; // UNPREDICTABLE
1078 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder));
1079 ARM_AM::ShiftOpc Opc = ARM_AM::lsl;
1080 switch( fieldFromInstruction32(Insn, 5, 2)) {
1096 unsigned amt = fieldFromInstruction32(Insn, 7, 5);
1097 unsigned imm = ARM_AM::getAM2Opc(Op, amt, Opc, idx_mode);
1099 Inst.addOperand(MCOperand::CreateImm(imm));
1101 Inst.addOperand(MCOperand::CreateReg(0));
1102 unsigned tmp = ARM_AM::getAM2Opc(Op, imm, ARM_AM::lsl, idx_mode);
1103 Inst.addOperand(MCOperand::CreateImm(tmp));
1106 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1111 static DecodeStatus DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Val,
1112 uint64_t Address, const void *Decoder) {
1113 DecodeStatus S = Success;
1115 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1116 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1117 unsigned type = fieldFromInstruction32(Val, 5, 2);
1118 unsigned imm = fieldFromInstruction32(Val, 7, 5);
1119 unsigned U = fieldFromInstruction32(Val, 12, 1);
1121 ARM_AM::ShiftOpc ShOp = ARM_AM::lsl;
1137 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1138 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1141 shift = ARM_AM::getAM2Opc(ARM_AM::add, imm, ShOp);
1143 shift = ARM_AM::getAM2Opc(ARM_AM::sub, imm, ShOp);
1144 Inst.addOperand(MCOperand::CreateImm(shift));
1150 DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
1151 uint64_t Address, const void *Decoder) {
1152 DecodeStatus S = Success;
1154 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
1155 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1156 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1157 unsigned type = fieldFromInstruction32(Insn, 22, 1);
1158 unsigned imm = fieldFromInstruction32(Insn, 8, 4);
1159 unsigned U = ((~fieldFromInstruction32(Insn, 23, 1)) & 1) << 8;
1160 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1161 unsigned W = fieldFromInstruction32(Insn, 21, 1);
1162 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1164 bool writeback = (W == 1) | (P == 0);
1166 // For {LD,ST}RD, Rt must be even, else undefined.
1167 switch (Inst.getOpcode()) {
1170 case ARM::STRD_POST:
1173 case ARM::LDRD_POST:
1174 if (Rt & 0x1) return Fail;
1180 if (writeback) { // Writeback
1182 U |= ARMII::IndexModePre << 9;
1184 U |= ARMII::IndexModePost << 9;
1186 // On stores, the writeback operand precedes Rt.
1187 switch (Inst.getOpcode()) {
1190 case ARM::STRD_POST:
1193 case ARM::STRH_POST:
1194 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1201 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
1202 switch (Inst.getOpcode()) {
1205 case ARM::STRD_POST:
1208 case ARM::LDRD_POST:
1209 CHECK(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder));
1216 // On loads, the writeback operand comes after Rt.
1217 switch (Inst.getOpcode()) {
1220 case ARM::LDRD_POST:
1223 case ARM::LDRH_POST:
1225 case ARM::LDRSH_PRE:
1226 case ARM::LDRSH_POST:
1228 case ARM::LDRSB_PRE:
1229 case ARM::LDRSB_POST:
1232 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1239 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1242 Inst.addOperand(MCOperand::CreateReg(0));
1243 Inst.addOperand(MCOperand::CreateImm(U | (imm << 4) | Rm));
1245 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1246 Inst.addOperand(MCOperand::CreateImm(U));
1249 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1254 static DecodeStatus DecodeRFEInstruction(llvm::MCInst &Inst, unsigned Insn,
1255 uint64_t Address, const void *Decoder) {
1256 DecodeStatus S = Success;
1258 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1259 unsigned mode = fieldFromInstruction32(Insn, 23, 2);
1276 Inst.addOperand(MCOperand::CreateImm(mode));
1277 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1282 static DecodeStatus DecodeMemMultipleWritebackInstruction(llvm::MCInst &Inst,
1284 uint64_t Address, const void *Decoder) {
1285 DecodeStatus S = Success;
1287 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1288 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1289 unsigned reglist = fieldFromInstruction32(Insn, 0, 16);
1292 switch (Inst.getOpcode()) {
1294 Inst.setOpcode(ARM::RFEDA);
1296 case ARM::LDMDA_UPD:
1297 Inst.setOpcode(ARM::RFEDA_UPD);
1300 Inst.setOpcode(ARM::RFEDB);
1302 case ARM::LDMDB_UPD:
1303 Inst.setOpcode(ARM::RFEDB_UPD);
1306 Inst.setOpcode(ARM::RFEIA);
1308 case ARM::LDMIA_UPD:
1309 Inst.setOpcode(ARM::RFEIA_UPD);
1312 Inst.setOpcode(ARM::RFEIB);
1314 case ARM::LDMIB_UPD:
1315 Inst.setOpcode(ARM::RFEIB_UPD);
1318 Inst.setOpcode(ARM::SRSDA);
1320 case ARM::STMDA_UPD:
1321 Inst.setOpcode(ARM::SRSDA_UPD);
1324 Inst.setOpcode(ARM::SRSDB);
1326 case ARM::STMDB_UPD:
1327 Inst.setOpcode(ARM::SRSDB_UPD);
1330 Inst.setOpcode(ARM::SRSIA);
1332 case ARM::STMIA_UPD:
1333 Inst.setOpcode(ARM::SRSIA_UPD);
1336 Inst.setOpcode(ARM::SRSIB);
1338 case ARM::STMIB_UPD:
1339 Inst.setOpcode(ARM::SRSIB_UPD);
1345 // For stores (which become SRS's, the only operand is the mode.
1346 if (fieldFromInstruction32(Insn, 20, 1) == 0) {
1348 MCOperand::CreateImm(fieldFromInstruction32(Insn, 0, 4)));
1352 return DecodeRFEInstruction(Inst, Insn, Address, Decoder);
1355 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1356 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder)); // Tied
1357 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1358 CHECK(S, DecodeRegListOperand(Inst, reglist, Address, Decoder));
1363 static DecodeStatus DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
1364 uint64_t Address, const void *Decoder) {
1365 unsigned imod = fieldFromInstruction32(Insn, 18, 2);
1366 unsigned M = fieldFromInstruction32(Insn, 17, 1);
1367 unsigned iflags = fieldFromInstruction32(Insn, 6, 3);
1368 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1370 DecodeStatus S = Success;
1372 // imod == '01' --> UNPREDICTABLE
1373 // NOTE: Even though this is technically UNPREDICTABLE, we choose to
1374 // return failure here. The '01' imod value is unprintable, so there's
1375 // nothing useful we could do even if we returned UNPREDICTABLE.
1377 if (imod == 1) CHECK(S, Fail);
1380 Inst.setOpcode(ARM::CPS3p);
1381 Inst.addOperand(MCOperand::CreateImm(imod));
1382 Inst.addOperand(MCOperand::CreateImm(iflags));
1383 Inst.addOperand(MCOperand::CreateImm(mode));
1384 } else if (imod && !M) {
1385 Inst.setOpcode(ARM::CPS2p);
1386 Inst.addOperand(MCOperand::CreateImm(imod));
1387 Inst.addOperand(MCOperand::CreateImm(iflags));
1388 if (mode) CHECK(S, Unpredictable);
1389 } else if (!imod && M) {
1390 Inst.setOpcode(ARM::CPS1p);
1391 Inst.addOperand(MCOperand::CreateImm(mode));
1392 if (iflags) CHECK(S, Unpredictable);
1394 // imod == '00' && M == '0' --> UNPREDICTABLE
1395 Inst.setOpcode(ARM::CPS1p);
1396 Inst.addOperand(MCOperand::CreateImm(mode));
1397 CHECK(S, Unpredictable);
1403 static DecodeStatus DecodeT2CPSInstruction(llvm::MCInst &Inst, unsigned Insn,
1404 uint64_t Address, const void *Decoder) {
1405 unsigned imod = fieldFromInstruction32(Insn, 9, 2);
1406 unsigned M = fieldFromInstruction32(Insn, 8, 1);
1407 unsigned iflags = fieldFromInstruction32(Insn, 5, 3);
1408 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1410 DecodeStatus S = Success;
1412 // imod == '01' --> UNPREDICTABLE
1413 // NOTE: Even though this is technically UNPREDICTABLE, we choose to
1414 // return failure here. The '01' imod value is unprintable, so there's
1415 // nothing useful we could do even if we returned UNPREDICTABLE.
1417 if (imod == 1) CHECK(S, Fail);
1420 Inst.setOpcode(ARM::t2CPS3p);
1421 Inst.addOperand(MCOperand::CreateImm(imod));
1422 Inst.addOperand(MCOperand::CreateImm(iflags));
1423 Inst.addOperand(MCOperand::CreateImm(mode));
1424 } else if (imod && !M) {
1425 Inst.setOpcode(ARM::t2CPS2p);
1426 Inst.addOperand(MCOperand::CreateImm(imod));
1427 Inst.addOperand(MCOperand::CreateImm(iflags));
1428 if (mode) CHECK(S, Unpredictable);
1429 } else if (!imod && M) {
1430 Inst.setOpcode(ARM::t2CPS1p);
1431 Inst.addOperand(MCOperand::CreateImm(mode));
1432 if (iflags) CHECK(S, Unpredictable);
1434 // imod == '00' && M == '0' --> UNPREDICTABLE
1435 Inst.setOpcode(ARM::t2CPS1p);
1436 Inst.addOperand(MCOperand::CreateImm(mode));
1437 CHECK(S, Unpredictable);
1444 static DecodeStatus DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
1445 uint64_t Address, const void *Decoder) {
1446 DecodeStatus S = Success;
1448 unsigned Rd = fieldFromInstruction32(Insn, 16, 4);
1449 unsigned Rn = fieldFromInstruction32(Insn, 0, 4);
1450 unsigned Rm = fieldFromInstruction32(Insn, 8, 4);
1451 unsigned Ra = fieldFromInstruction32(Insn, 12, 4);
1452 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1455 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
1457 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rd, Address, Decoder));
1458 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rn, Address, Decoder));
1459 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Rm, Address, Decoder));
1460 CHECK(S, DecodeGPRnopcRegisterClass(Inst, Ra, Address, Decoder));
1462 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1467 static DecodeStatus DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
1468 uint64_t Address, const void *Decoder) {
1469 DecodeStatus S = Success;
1471 unsigned add = fieldFromInstruction32(Val, 12, 1);
1472 unsigned imm = fieldFromInstruction32(Val, 0, 12);
1473 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1475 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1477 if (!add) imm *= -1;
1478 if (imm == 0 && !add) imm = INT32_MIN;
1479 Inst.addOperand(MCOperand::CreateImm(imm));
1484 static DecodeStatus DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
1485 uint64_t Address, const void *Decoder) {
1486 DecodeStatus S = Success;
1488 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
1489 unsigned U = fieldFromInstruction32(Val, 8, 1);
1490 unsigned imm = fieldFromInstruction32(Val, 0, 8);
1492 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
1495 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add, imm)));
1497 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub, imm)));
1502 static DecodeStatus DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
1503 uint64_t Address, const void *Decoder) {
1504 return DecodeGPRRegisterClass(Inst, Val, Address, Decoder);
1508 DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1509 uint64_t Address, const void *Decoder) {
1510 DecodeStatus S = Success;
1512 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1513 unsigned imm = fieldFromInstruction32(Insn, 0, 24) << 2;
1516 Inst.setOpcode(ARM::BLXi);
1517 imm |= fieldFromInstruction32(Insn, 24, 1) << 1;
1518 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1522 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1523 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
1529 static DecodeStatus DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
1530 uint64_t Address, const void *Decoder) {
1531 Inst.addOperand(MCOperand::CreateImm(64 - Val));
1535 static DecodeStatus DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
1536 uint64_t Address, const void *Decoder) {
1537 DecodeStatus S = Success;
1539 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1540 unsigned align = fieldFromInstruction32(Val, 4, 2);
1542 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1544 Inst.addOperand(MCOperand::CreateImm(0));
1546 Inst.addOperand(MCOperand::CreateImm(4 << align));
1551 static DecodeStatus DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Insn,
1552 uint64_t Address, const void *Decoder) {
1553 DecodeStatus S = Success;
1555 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1556 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1557 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1558 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1559 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1560 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1562 // First output register
1563 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1565 // Second output register
1566 switch (Inst.getOpcode()) {
1571 case ARM::VLD1q8_UPD:
1572 case ARM::VLD1q16_UPD:
1573 case ARM::VLD1q32_UPD:
1574 case ARM::VLD1q64_UPD:
1579 case ARM::VLD1d8T_UPD:
1580 case ARM::VLD1d16T_UPD:
1581 case ARM::VLD1d32T_UPD:
1582 case ARM::VLD1d64T_UPD:
1587 case ARM::VLD1d8Q_UPD:
1588 case ARM::VLD1d16Q_UPD:
1589 case ARM::VLD1d32Q_UPD:
1590 case ARM::VLD1d64Q_UPD:
1594 case ARM::VLD2d8_UPD:
1595 case ARM::VLD2d16_UPD:
1596 case ARM::VLD2d32_UPD:
1600 case ARM::VLD2q8_UPD:
1601 case ARM::VLD2q16_UPD:
1602 case ARM::VLD2q32_UPD:
1606 case ARM::VLD3d8_UPD:
1607 case ARM::VLD3d16_UPD:
1608 case ARM::VLD3d32_UPD:
1612 case ARM::VLD4d8_UPD:
1613 case ARM::VLD4d16_UPD:
1614 case ARM::VLD4d32_UPD:
1615 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder));
1620 case ARM::VLD2b8_UPD:
1621 case ARM::VLD2b16_UPD:
1622 case ARM::VLD2b32_UPD:
1626 case ARM::VLD3q8_UPD:
1627 case ARM::VLD3q16_UPD:
1628 case ARM::VLD3q32_UPD:
1632 case ARM::VLD4q8_UPD:
1633 case ARM::VLD4q16_UPD:
1634 case ARM::VLD4q32_UPD:
1635 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1640 // Third output register
1641 switch(Inst.getOpcode()) {
1646 case ARM::VLD1d8T_UPD:
1647 case ARM::VLD1d16T_UPD:
1648 case ARM::VLD1d32T_UPD:
1649 case ARM::VLD1d64T_UPD:
1654 case ARM::VLD1d8Q_UPD:
1655 case ARM::VLD1d16Q_UPD:
1656 case ARM::VLD1d32Q_UPD:
1657 case ARM::VLD1d64Q_UPD:
1661 case ARM::VLD2q8_UPD:
1662 case ARM::VLD2q16_UPD:
1663 case ARM::VLD2q32_UPD:
1667 case ARM::VLD3d8_UPD:
1668 case ARM::VLD3d16_UPD:
1669 case ARM::VLD3d32_UPD:
1673 case ARM::VLD4d8_UPD:
1674 case ARM::VLD4d16_UPD:
1675 case ARM::VLD4d32_UPD:
1676 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1681 case ARM::VLD3q8_UPD:
1682 case ARM::VLD3q16_UPD:
1683 case ARM::VLD3q32_UPD:
1687 case ARM::VLD4q8_UPD:
1688 case ARM::VLD4q16_UPD:
1689 case ARM::VLD4q32_UPD:
1690 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder));
1696 // Fourth output register
1697 switch (Inst.getOpcode()) {
1702 case ARM::VLD1d8Q_UPD:
1703 case ARM::VLD1d16Q_UPD:
1704 case ARM::VLD1d32Q_UPD:
1705 case ARM::VLD1d64Q_UPD:
1709 case ARM::VLD2q8_UPD:
1710 case ARM::VLD2q16_UPD:
1711 case ARM::VLD2q32_UPD:
1715 case ARM::VLD4d8_UPD:
1716 case ARM::VLD4d16_UPD:
1717 case ARM::VLD4d32_UPD:
1718 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder));
1723 case ARM::VLD4q8_UPD:
1724 case ARM::VLD4q16_UPD:
1725 case ARM::VLD4q32_UPD:
1726 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder));
1732 // Writeback operand
1733 switch (Inst.getOpcode()) {
1734 case ARM::VLD1d8_UPD:
1735 case ARM::VLD1d16_UPD:
1736 case ARM::VLD1d32_UPD:
1737 case ARM::VLD1d64_UPD:
1738 case ARM::VLD1q8_UPD:
1739 case ARM::VLD1q16_UPD:
1740 case ARM::VLD1q32_UPD:
1741 case ARM::VLD1q64_UPD:
1742 case ARM::VLD1d8T_UPD:
1743 case ARM::VLD1d16T_UPD:
1744 case ARM::VLD1d32T_UPD:
1745 case ARM::VLD1d64T_UPD:
1746 case ARM::VLD1d8Q_UPD:
1747 case ARM::VLD1d16Q_UPD:
1748 case ARM::VLD1d32Q_UPD:
1749 case ARM::VLD1d64Q_UPD:
1750 case ARM::VLD2d8_UPD:
1751 case ARM::VLD2d16_UPD:
1752 case ARM::VLD2d32_UPD:
1753 case ARM::VLD2q8_UPD:
1754 case ARM::VLD2q16_UPD:
1755 case ARM::VLD2q32_UPD:
1756 case ARM::VLD2b8_UPD:
1757 case ARM::VLD2b16_UPD:
1758 case ARM::VLD2b32_UPD:
1759 case ARM::VLD3d8_UPD:
1760 case ARM::VLD3d16_UPD:
1761 case ARM::VLD3d32_UPD:
1762 case ARM::VLD3q8_UPD:
1763 case ARM::VLD3q16_UPD:
1764 case ARM::VLD3q32_UPD:
1765 case ARM::VLD4d8_UPD:
1766 case ARM::VLD4d16_UPD:
1767 case ARM::VLD4d32_UPD:
1768 case ARM::VLD4q8_UPD:
1769 case ARM::VLD4q16_UPD:
1770 case ARM::VLD4q32_UPD:
1771 CHECK(S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder));
1777 // AddrMode6 Base (register+alignment)
1778 CHECK(S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder));
1780 // AddrMode6 Offset (register)
1782 Inst.addOperand(MCOperand::CreateReg(0));
1783 else if (Rm != 0xF) {
1784 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1790 static DecodeStatus DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Insn,
1791 uint64_t Address, const void *Decoder) {
1792 DecodeStatus S = Success;
1794 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1795 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1796 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1797 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1798 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1799 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1801 // Writeback Operand
1802 switch (Inst.getOpcode()) {
1803 case ARM::VST1d8_UPD:
1804 case ARM::VST1d16_UPD:
1805 case ARM::VST1d32_UPD:
1806 case ARM::VST1d64_UPD:
1807 case ARM::VST1q8_UPD:
1808 case ARM::VST1q16_UPD:
1809 case ARM::VST1q32_UPD:
1810 case ARM::VST1q64_UPD:
1811 case ARM::VST1d8T_UPD:
1812 case ARM::VST1d16T_UPD:
1813 case ARM::VST1d32T_UPD:
1814 case ARM::VST1d64T_UPD:
1815 case ARM::VST1d8Q_UPD:
1816 case ARM::VST1d16Q_UPD:
1817 case ARM::VST1d32Q_UPD:
1818 case ARM::VST1d64Q_UPD:
1819 case ARM::VST2d8_UPD:
1820 case ARM::VST2d16_UPD:
1821 case ARM::VST2d32_UPD:
1822 case ARM::VST2q8_UPD:
1823 case ARM::VST2q16_UPD:
1824 case ARM::VST2q32_UPD:
1825 case ARM::VST2b8_UPD:
1826 case ARM::VST2b16_UPD:
1827 case ARM::VST2b32_UPD:
1828 case ARM::VST3d8_UPD:
1829 case ARM::VST3d16_UPD:
1830 case ARM::VST3d32_UPD:
1831 case ARM::VST3q8_UPD:
1832 case ARM::VST3q16_UPD:
1833 case ARM::VST3q32_UPD:
1834 case ARM::VST4d8_UPD:
1835 case ARM::VST4d16_UPD:
1836 case ARM::VST4d32_UPD:
1837 case ARM::VST4q8_UPD:
1838 case ARM::VST4q16_UPD:
1839 case ARM::VST4q32_UPD:
1840 CHECK(S, DecodeGPRRegisterClass(Inst, wb, Address, Decoder));
1846 // AddrMode6 Base (register+alignment)
1847 CHECK(S, DecodeAddrMode6Operand(Inst, Rn, Address, Decoder));
1849 // AddrMode6 Offset (register)
1851 Inst.addOperand(MCOperand::CreateReg(0));
1852 else if (Rm != 0xF) {
1853 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
1856 // First input register
1857 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
1859 // Second input register
1860 switch (Inst.getOpcode()) {
1865 case ARM::VST1q8_UPD:
1866 case ARM::VST1q16_UPD:
1867 case ARM::VST1q32_UPD:
1868 case ARM::VST1q64_UPD:
1873 case ARM::VST1d8T_UPD:
1874 case ARM::VST1d16T_UPD:
1875 case ARM::VST1d32T_UPD:
1876 case ARM::VST1d64T_UPD:
1881 case ARM::VST1d8Q_UPD:
1882 case ARM::VST1d16Q_UPD:
1883 case ARM::VST1d32Q_UPD:
1884 case ARM::VST1d64Q_UPD:
1888 case ARM::VST2d8_UPD:
1889 case ARM::VST2d16_UPD:
1890 case ARM::VST2d32_UPD:
1894 case ARM::VST2q8_UPD:
1895 case ARM::VST2q16_UPD:
1896 case ARM::VST2q32_UPD:
1900 case ARM::VST3d8_UPD:
1901 case ARM::VST3d16_UPD:
1902 case ARM::VST3d32_UPD:
1906 case ARM::VST4d8_UPD:
1907 case ARM::VST4d16_UPD:
1908 case ARM::VST4d32_UPD:
1909 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder));
1914 case ARM::VST2b8_UPD:
1915 case ARM::VST2b16_UPD:
1916 case ARM::VST2b32_UPD:
1920 case ARM::VST3q8_UPD:
1921 case ARM::VST3q16_UPD:
1922 case ARM::VST3q32_UPD:
1926 case ARM::VST4q8_UPD:
1927 case ARM::VST4q16_UPD:
1928 case ARM::VST4q32_UPD:
1929 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1935 // Third input register
1936 switch (Inst.getOpcode()) {
1941 case ARM::VST1d8T_UPD:
1942 case ARM::VST1d16T_UPD:
1943 case ARM::VST1d32T_UPD:
1944 case ARM::VST1d64T_UPD:
1949 case ARM::VST1d8Q_UPD:
1950 case ARM::VST1d16Q_UPD:
1951 case ARM::VST1d32Q_UPD:
1952 case ARM::VST1d64Q_UPD:
1956 case ARM::VST2q8_UPD:
1957 case ARM::VST2q16_UPD:
1958 case ARM::VST2q32_UPD:
1962 case ARM::VST3d8_UPD:
1963 case ARM::VST3d16_UPD:
1964 case ARM::VST3d32_UPD:
1968 case ARM::VST4d8_UPD:
1969 case ARM::VST4d16_UPD:
1970 case ARM::VST4d32_UPD:
1971 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder));
1976 case ARM::VST3q8_UPD:
1977 case ARM::VST3q16_UPD:
1978 case ARM::VST3q32_UPD:
1982 case ARM::VST4q8_UPD:
1983 case ARM::VST4q16_UPD:
1984 case ARM::VST4q32_UPD:
1985 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder));
1991 // Fourth input register
1992 switch (Inst.getOpcode()) {
1997 case ARM::VST1d8Q_UPD:
1998 case ARM::VST1d16Q_UPD:
1999 case ARM::VST1d32Q_UPD:
2000 case ARM::VST1d64Q_UPD:
2004 case ARM::VST2q8_UPD:
2005 case ARM::VST2q16_UPD:
2006 case ARM::VST2q32_UPD:
2010 case ARM::VST4d8_UPD:
2011 case ARM::VST4d16_UPD:
2012 case ARM::VST4d32_UPD:
2013 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder));
2018 case ARM::VST4q8_UPD:
2019 case ARM::VST4q16_UPD:
2020 case ARM::VST4q32_UPD:
2021 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder));
2030 static DecodeStatus DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Insn,
2031 uint64_t Address, const void *Decoder) {
2032 DecodeStatus S = Success;
2034 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2035 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2036 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2037 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2038 unsigned align = fieldFromInstruction32(Insn, 4, 1);
2039 unsigned size = fieldFromInstruction32(Insn, 6, 2);
2040 unsigned regs = fieldFromInstruction32(Insn, 5, 1) + 1;
2042 align *= (1 << size);
2044 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2046 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder));
2049 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2052 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2053 Inst.addOperand(MCOperand::CreateImm(align));
2056 Inst.addOperand(MCOperand::CreateReg(0));
2057 else if (Rm != 0xF) {
2058 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2064 static DecodeStatus DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Insn,
2065 uint64_t Address, const void *Decoder) {
2066 DecodeStatus S = Success;
2068 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2069 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2070 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2071 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2072 unsigned align = fieldFromInstruction32(Insn, 4, 1);
2073 unsigned size = 1 << fieldFromInstruction32(Insn, 6, 2);
2074 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
2077 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2078 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder));
2080 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2083 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2084 Inst.addOperand(MCOperand::CreateImm(align));
2087 Inst.addOperand(MCOperand::CreateReg(0));
2088 else if (Rm != 0xF) {
2089 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2095 static DecodeStatus DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Insn,
2096 uint64_t Address, const void *Decoder) {
2097 DecodeStatus S = Success;
2099 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2100 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2101 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2102 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2103 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
2105 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2106 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder));
2107 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder));
2109 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2112 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2113 Inst.addOperand(MCOperand::CreateImm(0));
2116 Inst.addOperand(MCOperand::CreateReg(0));
2117 else if (Rm != 0xF) {
2118 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2124 static DecodeStatus DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Insn,
2125 uint64_t Address, const void *Decoder) {
2126 DecodeStatus S = Success;
2128 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2129 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2130 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2131 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2132 unsigned size = fieldFromInstruction32(Insn, 6, 2);
2133 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
2134 unsigned align = fieldFromInstruction32(Insn, 4, 1);
2149 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2150 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder));
2151 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder));
2152 CHECK(S, DecodeDPRRegisterClass(Inst, (Rd+3*inc)%32, Address, Decoder));
2154 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2157 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2158 Inst.addOperand(MCOperand::CreateImm(align));
2161 Inst.addOperand(MCOperand::CreateReg(0));
2162 else if (Rm != 0xF) {
2163 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2170 DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Insn,
2171 uint64_t Address, const void *Decoder) {
2172 DecodeStatus S = Success;
2174 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2175 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2176 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2177 imm |= fieldFromInstruction32(Insn, 16, 3) << 4;
2178 imm |= fieldFromInstruction32(Insn, 24, 1) << 7;
2179 imm |= fieldFromInstruction32(Insn, 8, 4) << 8;
2180 imm |= fieldFromInstruction32(Insn, 5, 1) << 12;
2181 unsigned Q = fieldFromInstruction32(Insn, 6, 1);
2184 CHECK(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder));
2186 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2189 Inst.addOperand(MCOperand::CreateImm(imm));
2191 switch (Inst.getOpcode()) {
2192 case ARM::VORRiv4i16:
2193 case ARM::VORRiv2i32:
2194 case ARM::VBICiv4i16:
2195 case ARM::VBICiv2i32:
2196 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2198 case ARM::VORRiv8i16:
2199 case ARM::VORRiv4i32:
2200 case ARM::VBICiv8i16:
2201 case ARM::VBICiv4i32:
2202 CHECK(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder));
2211 static DecodeStatus DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Insn,
2212 uint64_t Address, const void *Decoder) {
2213 DecodeStatus S = Success;
2215 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2216 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2217 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2218 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2219 unsigned size = fieldFromInstruction32(Insn, 18, 2);
2221 CHECK(S, DecodeQPRRegisterClass(Inst, Rd, Address, Decoder));
2222 CHECK(S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder));
2223 Inst.addOperand(MCOperand::CreateImm(8 << size));
2228 static DecodeStatus DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
2229 uint64_t Address, const void *Decoder) {
2230 Inst.addOperand(MCOperand::CreateImm(8 - Val));
2234 static DecodeStatus DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
2235 uint64_t Address, const void *Decoder) {
2236 Inst.addOperand(MCOperand::CreateImm(16 - Val));
2240 static DecodeStatus DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
2241 uint64_t Address, const void *Decoder) {
2242 Inst.addOperand(MCOperand::CreateImm(32 - Val));
2246 static DecodeStatus DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
2247 uint64_t Address, const void *Decoder) {
2248 Inst.addOperand(MCOperand::CreateImm(64 - Val));
2252 static DecodeStatus DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
2253 uint64_t Address, const void *Decoder) {
2254 DecodeStatus S = Success;
2256 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2257 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2258 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2259 Rn |= fieldFromInstruction32(Insn, 7, 1) << 4;
2260 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2261 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
2262 unsigned op = fieldFromInstruction32(Insn, 6, 1);
2263 unsigned length = fieldFromInstruction32(Insn, 8, 2) + 1;
2265 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2267 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder)); // Writeback
2270 for (unsigned i = 0; i < length; ++i) {
2271 CHECK(S, DecodeDPRRegisterClass(Inst, (Rn+i)%32, Address, Decoder));
2274 CHECK(S, DecodeDPRRegisterClass(Inst, Rm, Address, Decoder));
2279 static DecodeStatus DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
2280 uint64_t Address, const void *Decoder) {
2281 // The immediate needs to be a fully instantiated float. However, the
2282 // auto-generated decoder is only able to fill in some of the bits
2283 // necessary. For instance, the 'b' bit is replicated multiple times,
2284 // and is even present in inverted form in one bit. We do a little
2285 // binary parsing here to fill in those missing bits, and then
2286 // reinterpret it all as a float.
2292 fp_conv.integer = Val;
2293 uint32_t b = fieldFromInstruction32(Val, 25, 1);
2294 fp_conv.integer |= b << 26;
2295 fp_conv.integer |= b << 27;
2296 fp_conv.integer |= b << 28;
2297 fp_conv.integer |= b << 29;
2298 fp_conv.integer |= (~b & 0x1) << 30;
2300 Inst.addOperand(MCOperand::CreateFPImm(fp_conv.fp));
2304 static DecodeStatus DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
2305 uint64_t Address, const void *Decoder) {
2306 DecodeStatus S = Success;
2308 unsigned dst = fieldFromInstruction16(Insn, 8, 3);
2309 unsigned imm = fieldFromInstruction16(Insn, 0, 8);
2311 CHECK(S, DecodetGPRRegisterClass(Inst, dst, Address, Decoder));
2313 if (Inst.getOpcode() == ARM::tADR)
2314 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2315 else if (Inst.getOpcode() == ARM::tADDrSPi)
2316 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2320 Inst.addOperand(MCOperand::CreateImm(imm));
2324 static DecodeStatus DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
2325 uint64_t Address, const void *Decoder) {
2326 Inst.addOperand(MCOperand::CreateImm(SignExtend32<12>(Val << 1)));
2330 static DecodeStatus DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
2331 uint64_t Address, const void *Decoder) {
2332 Inst.addOperand(MCOperand::CreateImm(SignExtend32<21>(Val)));
2336 static DecodeStatus DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
2337 uint64_t Address, const void *Decoder) {
2338 Inst.addOperand(MCOperand::CreateImm(SignExtend32<7>(Val << 1)));
2342 static DecodeStatus DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
2343 uint64_t Address, const void *Decoder) {
2344 DecodeStatus S = Success;
2346 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2347 unsigned Rm = fieldFromInstruction32(Val, 3, 3);
2349 CHECK(S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder));
2350 CHECK(S, DecodetGPRRegisterClass(Inst, Rm, Address, Decoder));
2355 static DecodeStatus DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
2356 uint64_t Address, const void *Decoder) {
2357 DecodeStatus S = Success;
2359 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2360 unsigned imm = fieldFromInstruction32(Val, 3, 5);
2362 CHECK(S, DecodetGPRRegisterClass(Inst, Rn, Address, Decoder));
2363 Inst.addOperand(MCOperand::CreateImm(imm));
2368 static DecodeStatus DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
2369 uint64_t Address, const void *Decoder) {
2370 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2375 static DecodeStatus DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
2376 uint64_t Address, const void *Decoder) {
2377 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2378 Inst.addOperand(MCOperand::CreateImm(Val));
2383 static DecodeStatus DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
2384 uint64_t Address, const void *Decoder) {
2385 DecodeStatus S = Success;
2387 unsigned Rn = fieldFromInstruction32(Val, 6, 4);
2388 unsigned Rm = fieldFromInstruction32(Val, 2, 4);
2389 unsigned imm = fieldFromInstruction32(Val, 0, 2);
2391 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2392 CHECK(S, DecoderGPRRegisterClass(Inst, Rm, Address, Decoder));
2393 Inst.addOperand(MCOperand::CreateImm(imm));
2398 static DecodeStatus DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Insn,
2399 uint64_t Address, const void *Decoder) {
2400 DecodeStatus S = Success;
2402 switch (Inst.getOpcode()) {
2408 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2409 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2413 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2415 switch (Inst.getOpcode()) {
2417 Inst.setOpcode(ARM::t2LDRBpci);
2420 Inst.setOpcode(ARM::t2LDRHpci);
2423 Inst.setOpcode(ARM::t2LDRSHpci);
2426 Inst.setOpcode(ARM::t2LDRSBpci);
2429 Inst.setOpcode(ARM::t2PLDi12);
2430 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2436 int imm = fieldFromInstruction32(Insn, 0, 12);
2437 if (!fieldFromInstruction32(Insn, 23, 1)) imm *= -1;
2438 Inst.addOperand(MCOperand::CreateImm(imm));
2443 unsigned addrmode = fieldFromInstruction32(Insn, 4, 2);
2444 addrmode |= fieldFromInstruction32(Insn, 0, 4) << 2;
2445 addrmode |= fieldFromInstruction32(Insn, 16, 4) << 6;
2446 CHECK(S, DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder));
2451 static DecodeStatus DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
2452 uint64_t Address, const void *Decoder) {
2453 int imm = Val & 0xFF;
2454 if (!(Val & 0x100)) imm *= -1;
2455 Inst.addOperand(MCOperand::CreateImm(imm << 2));
2460 static DecodeStatus DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
2461 uint64_t Address, const void *Decoder) {
2462 DecodeStatus S = Success;
2464 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2465 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2467 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2468 CHECK(S, DecodeT2Imm8S4(Inst, imm, Address, Decoder));
2473 static DecodeStatus DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
2474 uint64_t Address, const void *Decoder) {
2475 int imm = Val & 0xFF;
2476 if (!(Val & 0x100)) imm *= -1;
2477 Inst.addOperand(MCOperand::CreateImm(imm));
2483 static DecodeStatus DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
2484 uint64_t Address, const void *Decoder) {
2485 DecodeStatus S = Success;
2487 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2488 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2490 // Some instructions always use an additive offset.
2491 switch (Inst.getOpcode()) {
2503 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2504 CHECK(S, DecodeT2Imm8(Inst, imm, Address, Decoder));
2510 static DecodeStatus DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
2511 uint64_t Address, const void *Decoder) {
2512 DecodeStatus S = Success;
2514 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
2515 unsigned imm = fieldFromInstruction32(Val, 0, 12);
2517 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2518 Inst.addOperand(MCOperand::CreateImm(imm));
2524 static DecodeStatus DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Insn,
2525 uint64_t Address, const void *Decoder) {
2526 unsigned imm = fieldFromInstruction16(Insn, 0, 7);
2528 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2529 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2530 Inst.addOperand(MCOperand::CreateImm(imm));
2535 static DecodeStatus DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
2536 uint64_t Address, const void *Decoder) {
2537 DecodeStatus S = Success;
2539 if (Inst.getOpcode() == ARM::tADDrSP) {
2540 unsigned Rdm = fieldFromInstruction16(Insn, 0, 3);
2541 Rdm |= fieldFromInstruction16(Insn, 7, 1) << 3;
2543 CHECK(S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder));
2544 CHECK(S, DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder));
2545 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2546 } else if (Inst.getOpcode() == ARM::tADDspr) {
2547 unsigned Rm = fieldFromInstruction16(Insn, 3, 4);
2549 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2550 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2551 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2557 static DecodeStatus DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
2558 uint64_t Address, const void *Decoder) {
2559 unsigned imod = fieldFromInstruction16(Insn, 4, 1) | 0x2;
2560 unsigned flags = fieldFromInstruction16(Insn, 0, 3);
2562 Inst.addOperand(MCOperand::CreateImm(imod));
2563 Inst.addOperand(MCOperand::CreateImm(flags));
2568 static DecodeStatus DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
2569 uint64_t Address, const void *Decoder) {
2570 DecodeStatus S = Success;
2571 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2572 unsigned add = fieldFromInstruction32(Insn, 4, 1);
2574 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder)) ;
2575 Inst.addOperand(MCOperand::CreateImm(add));
2580 static DecodeStatus DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Val,
2581 uint64_t Address, const void *Decoder) {
2582 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2586 static DecodeStatus DecodeCoprocessor(llvm::MCInst &Inst, unsigned Val,
2587 uint64_t Address, const void *Decoder) {
2588 if (Val == 0xA || Val == 0xB)
2591 Inst.addOperand(MCOperand::CreateImm(Val));
2596 DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Insn,
2597 uint64_t Address, const void *Decoder) {
2598 DecodeStatus S = Success;
2600 unsigned pred = fieldFromInstruction32(Insn, 22, 4);
2601 if (pred == 0xE || pred == 0xF) {
2602 unsigned opc = fieldFromInstruction32(Insn, 4, 2);
2607 Inst.setOpcode(ARM::t2DSB);
2610 Inst.setOpcode(ARM::t2DMB);
2613 Inst.setOpcode(ARM::t2ISB);
2617 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2618 return DecodeMemBarrierOption(Inst, imm, Address, Decoder);
2621 unsigned brtarget = fieldFromInstruction32(Insn, 0, 11) << 1;
2622 brtarget |= fieldFromInstruction32(Insn, 11, 1) << 19;
2623 brtarget |= fieldFromInstruction32(Insn, 13, 1) << 18;
2624 brtarget |= fieldFromInstruction32(Insn, 16, 6) << 12;
2625 brtarget |= fieldFromInstruction32(Insn, 26, 1) << 20;
2627 CHECK(S, DecodeT2BROperand(Inst, brtarget, Address, Decoder));
2628 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2633 // Decode a shifted immediate operand. These basically consist
2634 // of an 8-bit value, and a 4-bit directive that specifies either
2635 // a splat operation or a rotation.
2636 static DecodeStatus DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
2637 uint64_t Address, const void *Decoder) {
2638 unsigned ctrl = fieldFromInstruction32(Val, 10, 2);
2640 unsigned byte = fieldFromInstruction32(Val, 8, 2);
2641 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2644 Inst.addOperand(MCOperand::CreateImm(imm));
2647 Inst.addOperand(MCOperand::CreateImm((imm << 16) | imm));
2650 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 8)));
2653 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 16) |
2658 unsigned unrot = fieldFromInstruction32(Val, 0, 7) | 0x80;
2659 unsigned rot = fieldFromInstruction32(Val, 7, 5);
2660 unsigned imm = (unrot >> rot) | (unrot << ((32-rot)&31));
2661 Inst.addOperand(MCOperand::CreateImm(imm));
2668 DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
2669 uint64_t Address, const void *Decoder){
2670 Inst.addOperand(MCOperand::CreateImm(Val << 1));
2674 static DecodeStatus DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
2675 uint64_t Address, const void *Decoder){
2676 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2680 static DecodeStatus DecodeMemBarrierOption(llvm::MCInst &Inst, unsigned Val,
2681 uint64_t Address, const void *Decoder) {
2696 Inst.addOperand(MCOperand::CreateImm(Val));
2700 static DecodeStatus DecodeMSRMask(llvm::MCInst &Inst, unsigned Val,
2701 uint64_t Address, const void *Decoder) {
2702 if (!Val) return Fail;
2703 Inst.addOperand(MCOperand::CreateImm(Val));
2707 static DecodeStatus DecodeDoubleRegLoad(llvm::MCInst &Inst, unsigned Insn,
2708 uint64_t Address, const void *Decoder) {
2709 DecodeStatus S = Success;
2711 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2712 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2713 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2715 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return Fail;
2717 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2718 CHECK(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder));
2719 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2720 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2726 static DecodeStatus DecodeDoubleRegStore(llvm::MCInst &Inst, unsigned Insn,
2727 uint64_t Address, const void *Decoder){
2728 DecodeStatus S = Success;
2730 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2731 unsigned Rt = fieldFromInstruction32(Insn, 0, 4);
2732 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2733 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2735 CHECK(S, DecoderGPRRegisterClass(Inst, Rd, Address, Decoder));
2737 if ((Rt & 1) || Rt == 0xE || Rn == 0xF) return Fail;
2738 if (Rd == Rn || Rd == Rt || Rd == Rt+1) return Fail;
2740 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2741 CHECK(S, DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder));
2742 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2743 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2748 static DecodeStatus DecodeSTRPreImm(llvm::MCInst &Inst, unsigned Insn,
2749 uint64_t Address, const void *Decoder) {
2750 DecodeStatus S = Success;
2752 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2753 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2754 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
2755 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
2756 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
2757 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2759 if (Rn == 0xF || Rn == Rt) CHECK(S, Unpredictable);
2761 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2762 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2763 CHECK(S, DecodeAddrModeImm12Operand(Inst, imm, Address, Decoder));
2764 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2769 static DecodeStatus DecodeSTRPreReg(llvm::MCInst &Inst, unsigned Insn,
2770 uint64_t Address, const void *Decoder) {
2771 DecodeStatus S = Success;
2773 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2774 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2775 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
2776 imm |= fieldFromInstruction32(Insn, 16, 4) << 13;
2777 imm |= fieldFromInstruction32(Insn, 23, 1) << 12;
2778 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
2780 if (Rn == 0xF || Rn == Rt) CHECK(S, Unpredictable);
2782 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2783 CHECK(S, DecodeGPRRegisterClass(Inst, Rt, Address, Decoder));
2784 CHECK(S, DecodeSORegMemOperand(Inst, imm, Address, Decoder));
2785 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
2790 static DecodeStatus DecodeVLD1LN(llvm::MCInst &Inst, unsigned Insn,
2791 uint64_t Address, const void *Decoder) {
2792 DecodeStatus S = Success;
2794 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2795 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2796 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2797 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2798 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2806 if (fieldFromInstruction32(Insn, 4, 1))
2807 return Fail; // UNDEFINED
2808 index = fieldFromInstruction32(Insn, 5, 3);
2811 if (fieldFromInstruction32(Insn, 5, 1))
2812 return Fail; // UNDEFINED
2813 index = fieldFromInstruction32(Insn, 6, 2);
2814 if (fieldFromInstruction32(Insn, 4, 1))
2818 if (fieldFromInstruction32(Insn, 6, 1))
2819 return Fail; // UNDEFINED
2820 index = fieldFromInstruction32(Insn, 7, 1);
2821 if (fieldFromInstruction32(Insn, 4, 2) != 0)
2825 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2826 if (Rm != 0xF) { // Writeback
2827 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2829 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2830 Inst.addOperand(MCOperand::CreateImm(align));
2833 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2835 Inst.addOperand(MCOperand::CreateReg(0));
2838 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2839 Inst.addOperand(MCOperand::CreateImm(index));
2844 static DecodeStatus DecodeVST1LN(llvm::MCInst &Inst, unsigned Insn,
2845 uint64_t Address, const void *Decoder) {
2846 DecodeStatus S = Success;
2848 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2849 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2850 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2851 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2852 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2860 if (fieldFromInstruction32(Insn, 4, 1))
2861 return Fail; // UNDEFINED
2862 index = fieldFromInstruction32(Insn, 5, 3);
2865 if (fieldFromInstruction32(Insn, 5, 1))
2866 return Fail; // UNDEFINED
2867 index = fieldFromInstruction32(Insn, 6, 2);
2868 if (fieldFromInstruction32(Insn, 4, 1))
2872 if (fieldFromInstruction32(Insn, 6, 1))
2873 return Fail; // UNDEFINED
2874 index = fieldFromInstruction32(Insn, 7, 1);
2875 if (fieldFromInstruction32(Insn, 4, 2) != 0)
2879 if (Rm != 0xF) { // Writeback
2880 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2882 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2883 Inst.addOperand(MCOperand::CreateImm(align));
2886 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2888 Inst.addOperand(MCOperand::CreateReg(0));
2891 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2892 Inst.addOperand(MCOperand::CreateImm(index));
2898 static DecodeStatus DecodeVLD2LN(llvm::MCInst &Inst, unsigned Insn,
2899 uint64_t Address, const void *Decoder) {
2900 DecodeStatus S = Success;
2902 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2903 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2904 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2905 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2906 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2915 index = fieldFromInstruction32(Insn, 5, 3);
2916 if (fieldFromInstruction32(Insn, 4, 1))
2920 index = fieldFromInstruction32(Insn, 6, 2);
2921 if (fieldFromInstruction32(Insn, 4, 1))
2923 if (fieldFromInstruction32(Insn, 5, 1))
2927 if (fieldFromInstruction32(Insn, 5, 1))
2928 return Fail; // UNDEFINED
2929 index = fieldFromInstruction32(Insn, 7, 1);
2930 if (fieldFromInstruction32(Insn, 4, 1) != 0)
2932 if (fieldFromInstruction32(Insn, 6, 1))
2937 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2938 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2939 if (Rm != 0xF) { // Writeback
2940 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2942 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
2943 Inst.addOperand(MCOperand::CreateImm(align));
2946 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
2948 Inst.addOperand(MCOperand::CreateReg(0));
2951 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
2952 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
2953 Inst.addOperand(MCOperand::CreateImm(index));
2958 static DecodeStatus DecodeVST2LN(llvm::MCInst &Inst, unsigned Insn,
2959 uint64_t Address, const void *Decoder) {
2960 DecodeStatus S = Success;
2962 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2963 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2964 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
2965 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
2966 unsigned size = fieldFromInstruction32(Insn, 10, 2);
2975 index = fieldFromInstruction32(Insn, 5, 3);
2976 if (fieldFromInstruction32(Insn, 4, 1))
2980 index = fieldFromInstruction32(Insn, 6, 2);
2981 if (fieldFromInstruction32(Insn, 4, 1))
2983 if (fieldFromInstruction32(Insn, 5, 1))
2987 if (fieldFromInstruction32(Insn, 5, 1))
2988 return Fail; // UNDEFINED
2989 index = fieldFromInstruction32(Insn, 7, 1);
2990 if (fieldFromInstruction32(Insn, 4, 1) != 0)
2992 if (fieldFromInstruction32(Insn, 6, 1))
2997 if (Rm != 0xF) { // Writeback
2998 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3000 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3001 Inst.addOperand(MCOperand::CreateImm(align));
3004 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
3006 Inst.addOperand(MCOperand::CreateReg(0));
3009 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3010 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3011 Inst.addOperand(MCOperand::CreateImm(index));
3017 static DecodeStatus DecodeVLD3LN(llvm::MCInst &Inst, unsigned Insn,
3018 uint64_t Address, const void *Decoder) {
3019 DecodeStatus S = Success;
3021 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3022 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3023 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3024 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3025 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3034 if (fieldFromInstruction32(Insn, 4, 1))
3035 return Fail; // UNDEFINED
3036 index = fieldFromInstruction32(Insn, 5, 3);
3039 if (fieldFromInstruction32(Insn, 4, 1))
3040 return Fail; // UNDEFINED
3041 index = fieldFromInstruction32(Insn, 6, 2);
3042 if (fieldFromInstruction32(Insn, 5, 1))
3046 if (fieldFromInstruction32(Insn, 4, 2))
3047 return Fail; // UNDEFINED
3048 index = fieldFromInstruction32(Insn, 7, 1);
3049 if (fieldFromInstruction32(Insn, 6, 1))
3054 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3055 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3056 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3058 if (Rm != 0xF) { // Writeback
3059 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3061 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3062 Inst.addOperand(MCOperand::CreateImm(align));
3065 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
3067 Inst.addOperand(MCOperand::CreateReg(0));
3070 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3071 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3072 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3073 Inst.addOperand(MCOperand::CreateImm(index));
3078 static DecodeStatus DecodeVST3LN(llvm::MCInst &Inst, unsigned Insn,
3079 uint64_t Address, const void *Decoder) {
3080 DecodeStatus S = Success;
3082 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3083 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3084 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3085 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3086 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3095 if (fieldFromInstruction32(Insn, 4, 1))
3096 return Fail; // UNDEFINED
3097 index = fieldFromInstruction32(Insn, 5, 3);
3100 if (fieldFromInstruction32(Insn, 4, 1))
3101 return Fail; // UNDEFINED
3102 index = fieldFromInstruction32(Insn, 6, 2);
3103 if (fieldFromInstruction32(Insn, 5, 1))
3107 if (fieldFromInstruction32(Insn, 4, 2))
3108 return Fail; // UNDEFINED
3109 index = fieldFromInstruction32(Insn, 7, 1);
3110 if (fieldFromInstruction32(Insn, 6, 1))
3115 if (Rm != 0xF) { // Writeback
3116 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3118 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3119 Inst.addOperand(MCOperand::CreateImm(align));
3122 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
3124 Inst.addOperand(MCOperand::CreateReg(0));
3127 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3128 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3129 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3130 Inst.addOperand(MCOperand::CreateImm(index));
3136 static DecodeStatus DecodeVLD4LN(llvm::MCInst &Inst, unsigned Insn,
3137 uint64_t Address, const void *Decoder) {
3138 DecodeStatus S = Success;
3140 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3141 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3142 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3143 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3144 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3153 if (fieldFromInstruction32(Insn, 4, 1))
3155 index = fieldFromInstruction32(Insn, 5, 3);
3158 if (fieldFromInstruction32(Insn, 4, 1))
3160 index = fieldFromInstruction32(Insn, 6, 2);
3161 if (fieldFromInstruction32(Insn, 5, 1))
3165 if (fieldFromInstruction32(Insn, 4, 2))
3166 align = 4 << fieldFromInstruction32(Insn, 4, 2);
3167 index = fieldFromInstruction32(Insn, 7, 1);
3168 if (fieldFromInstruction32(Insn, 6, 1))
3173 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3174 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3175 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3176 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder));
3178 if (Rm != 0xF) { // Writeback
3179 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3181 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3182 Inst.addOperand(MCOperand::CreateImm(align));
3185 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
3187 Inst.addOperand(MCOperand::CreateReg(0));
3190 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3191 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3192 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3193 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder));
3194 Inst.addOperand(MCOperand::CreateImm(index));
3199 static DecodeStatus DecodeVST4LN(llvm::MCInst &Inst, unsigned Insn,
3200 uint64_t Address, const void *Decoder) {
3201 DecodeStatus S = Success;
3203 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
3204 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3205 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
3206 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
3207 unsigned size = fieldFromInstruction32(Insn, 10, 2);
3216 if (fieldFromInstruction32(Insn, 4, 1))
3218 index = fieldFromInstruction32(Insn, 5, 3);
3221 if (fieldFromInstruction32(Insn, 4, 1))
3223 index = fieldFromInstruction32(Insn, 6, 2);
3224 if (fieldFromInstruction32(Insn, 5, 1))
3228 if (fieldFromInstruction32(Insn, 4, 2))
3229 align = 4 << fieldFromInstruction32(Insn, 4, 2);
3230 index = fieldFromInstruction32(Insn, 7, 1);
3231 if (fieldFromInstruction32(Insn, 6, 1))
3236 if (Rm != 0xF) { // Writeback
3237 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3239 CHECK(S, DecodeGPRRegisterClass(Inst, Rn, Address, Decoder));
3240 Inst.addOperand(MCOperand::CreateImm(align));
3243 CHECK(S, DecodeGPRRegisterClass(Inst, Rm, Address, Decoder));
3245 Inst.addOperand(MCOperand::CreateReg(0));
3248 CHECK(S, DecodeDPRRegisterClass(Inst, Rd, Address, Decoder));
3249 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+inc, Address, Decoder));
3250 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+2*inc, Address, Decoder));
3251 CHECK(S, DecodeDPRRegisterClass(Inst, Rd+3*inc, Address, Decoder));
3252 Inst.addOperand(MCOperand::CreateImm(index));
3257 static DecodeStatus DecodeVMOVSRR(llvm::MCInst &Inst, unsigned Insn,
3258 uint64_t Address, const void *Decoder) {
3259 DecodeStatus S = Success;
3260 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
3261 unsigned Rt2 = fieldFromInstruction32(Insn, 16, 4);
3262 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3263 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
3264 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
3266 if (Rt == 0xF || Rt2 == 0xF || Rm == 0x1F)
3267 CHECK(S, Unpredictable);
3269 CHECK(S, DecodeSPRRegisterClass(Inst, Rm , Address, Decoder));
3270 CHECK(S, DecodeSPRRegisterClass(Inst, Rm+1, Address, Decoder));
3271 CHECK(S, DecodeGPRRegisterClass(Inst, Rt , Address, Decoder));
3272 CHECK(S, DecodeGPRRegisterClass(Inst, Rt2 , Address, Decoder));
3273 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
3278 static DecodeStatus DecodeVMOVRRS(llvm::MCInst &Inst, unsigned Insn,
3279 uint64_t Address, const void *Decoder) {
3280 DecodeStatus S = Success;
3281 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
3282 unsigned Rt2 = fieldFromInstruction32(Insn, 16, 4);
3283 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
3284 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
3285 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
3287 if (Rt == 0xF || Rt2 == 0xF || Rm == 0x1F)
3288 CHECK(S, Unpredictable);
3290 CHECK(S, DecodeGPRRegisterClass(Inst, Rt , Address, Decoder));
3291 CHECK(S, DecodeGPRRegisterClass(Inst, Rt2 , Address, Decoder));
3292 CHECK(S, DecodeSPRRegisterClass(Inst, Rm , Address, Decoder));
3293 CHECK(S, DecodeSPRRegisterClass(Inst, Rm+1, Address, Decoder));
3294 CHECK(S, DecodePredicateOperand(Inst, pred, Address, Decoder));
3299 static DecodeStatus DecodeITCond(llvm::MCInst &Inst, unsigned Cond,
3300 uint64_t Address, const void *Decoder) {
3301 DecodeStatus S = Success;
3304 CHECK(S, Unpredictable);
3307 Inst.addOperand(MCOperand::CreateImm(Cond));
3311 static DecodeStatus DecodeITMask(llvm::MCInst &Inst, unsigned Mask,
3312 uint64_t Address, const void *Decoder) {
3313 DecodeStatus S = Success;
3316 CHECK(S, Unpredictable);
3318 Inst.addOperand(MCOperand::CreateImm(Mask));