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/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"
27 // Forward declare these because the autogenerated code will reference them.
28 // Definitions are further down.
29 static bool DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
30 uint64_t Address, const void *Decoder);
31 static bool DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
32 uint64_t Address, const void *Decoder);
33 static bool DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
34 uint64_t Address, const void *Decoder);
35 static bool DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
36 uint64_t Address, const void *Decoder);
37 static bool DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
38 uint64_t Address, const void *Decoder);
39 static bool DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
40 uint64_t Address, const void *Decoder);
41 static bool DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
42 uint64_t Address, const void *Decoder);
43 static bool DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
44 uint64_t Address, const void *Decoder);
45 static bool DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
46 uint64_t Address, const void *Decoder);
47 static bool DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
48 uint64_t Address, const void *Decoder);
50 static bool DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
51 uint64_t Address, const void *Decoder);
52 static bool DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
53 uint64_t Address, const void *Decoder);
54 static bool DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
55 uint64_t Address, const void *Decoder);
56 static bool DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
57 uint64_t Address, const void *Decoder);
58 static bool DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
59 uint64_t Address, const void *Decoder);
60 static bool DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
61 uint64_t Address, const void *Decoder);
62 static bool DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
63 uint64_t Address, const void *Decoder);
65 static bool DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Insn,
66 uint64_t Address, const void *Decoder);
67 static bool DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
68 uint64_t Address, const void *Decoder);
69 static bool DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
70 uint64_t Address, const void *Decoder);
71 static bool DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Insn,
72 uint64_t Address, const void *Decoder);
73 static bool DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
74 uint64_t Address, const void *Decoder);
75 static bool DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Insn,
76 uint64_t Address, const void *Decoder);
77 static bool DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Insn,
78 uint64_t Address, const void *Decoder);
80 static bool DecodeMemMultipleWritebackInstruction(llvm::MCInst & Inst,
84 static bool DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
85 uint64_t Address, const void *Decoder);
86 static bool DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
87 uint64_t Address, const void *Decoder);
88 static bool DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
89 uint64_t Address, const void *Decoder);
90 static bool DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
91 uint64_t Address, const void *Decoder);
92 static bool DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
93 uint64_t Address, const void *Decoder);
94 static bool DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
95 uint64_t Address, const void *Decoder);
96 static bool DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
97 uint64_t Address, const void *Decoder);
98 static bool DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Val,
99 uint64_t Address, const void *Decoder);
100 static bool DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Val,
101 uint64_t Address, const void *Decoder);
102 static bool DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Val,
103 uint64_t Address, const void *Decoder);
104 static bool DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Val,
105 uint64_t Address, const void *Decoder);
106 static bool DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Val,
107 uint64_t Address, const void *Decoder);
108 static bool DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Val,
109 uint64_t Address, const void *Decoder);
110 static bool DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Val,
111 uint64_t Address, const void *Decoder);
112 static bool DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Val,
113 uint64_t Address, const void *Decoder);
114 static bool DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
115 uint64_t Address, const void *Decoder);
116 static bool DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
117 uint64_t Address, const void *Decoder);
118 static bool DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
119 uint64_t Address, const void *Decoder);
120 static bool DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
121 uint64_t Address, const void *Decoder);
122 static bool DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
123 uint64_t Address, const void *Decoder);
124 static bool DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
125 uint64_t Address, const void *Decoder);
126 static bool DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
127 uint64_t Address, const void *Decoder);
128 static bool DecodeCoprocessor(llvm::MCInst &Inst, unsigned Insn,
129 uint64_t Address, const void *Decoder);
130 static bool DecodeAddrMode3Offset(llvm::MCInst &Inst, unsigned Insn,
131 uint64_t Address, const void *Decoder);
134 static bool DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
135 uint64_t Address, const void *Decoder);
136 static bool DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
137 uint64_t Address, const void *Decoder);
138 static bool DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
139 uint64_t Address, const void *Decoder);
140 static bool DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
141 uint64_t Address, const void *Decoder);
142 static bool DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
143 uint64_t Address, const void *Decoder);
144 static bool DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
145 uint64_t Address, const void *Decoder);
146 static bool DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
147 uint64_t Address, const void *Decoder);
148 static bool DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
149 uint64_t Address, const void *Decoder);
150 static bool DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
151 uint64_t Address, const void *Decoder);
152 static bool DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Val,
153 uint64_t Address, const void *Decoder);
154 static bool DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
155 uint64_t Address, const void *Decoder);
156 static bool DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
157 uint64_t Address, const void *Decoder);
158 static bool DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
159 uint64_t Address, const void *Decoder);
160 static bool DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
161 uint64_t Address, const void *Decoder);
162 static bool DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Val,
163 uint64_t Address, const void *Decoder);
164 static bool DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
165 uint64_t Address, const void *Decoder);
166 static bool DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
167 uint64_t Address, const void *Decoder);
168 static bool DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Insn,
169 uint64_t Address, const void *Decoder);
170 static bool DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
171 uint64_t Address, const void *Decoder);
172 static bool DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
173 uint64_t Address, const void *Decoder);
174 static bool DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Val,
175 uint64_t Address, const void *Decoder);
176 static bool DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
177 uint64_t Address, const void *Decoder);
178 static bool DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
179 uint64_t Address, const void *Decoder);
180 static bool DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
181 uint64_t Address, const void *Decoder);
183 #include "ARMGenDisassemblerTables.inc"
184 #include "ARMGenInstrInfo.inc"
185 #include "ARMGenEDInfo.inc"
187 using namespace llvm;
189 static MCDisassembler *createARMDisassembler(const Target &T) {
190 return new ARMDisassembler;
193 static MCDisassembler *createThumbDisassembler(const Target &T) {
194 return new ThumbDisassembler;
197 EDInstInfo *ARMDisassembler::getEDInfo() const {
201 EDInstInfo *ThumbDisassembler::getEDInfo() const {
206 bool ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
207 const MemoryObject &Region,
208 uint64_t Address,raw_ostream &os) const {
211 // We want to read exactly 4 bytes of data.
212 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
215 // Encoded as a small-endian 32-bit word in the stream.
216 uint32_t insn = (bytes[3] << 24) |
221 // Calling the auto-generated decoder function.
222 bool result = decodeARMInstruction32(MI, insn, Address, this);
228 // Instructions that are shared between ARM and Thumb modes.
229 // FIXME: This shouldn't really exist. It's an artifact of the
230 // fact that we fail to encode a few instructions properly for Thumb.
232 result = decodeCommonInstruction32(MI, insn, Address, this);
238 // VFP and NEON instructions, similarly, are shared between ARM
241 result = decodeVFPInstruction32(MI, insn, Address, this);
248 result = decodeNEONInstruction32(MI, insn, Address, this);
250 // Add a fake predicate operand, because we share these instruction
251 // definitions with Thumb2 where these instructions are predicable.
252 if (!DecodePredicateOperand(MI, 0xE, Address, this)) return false;
263 extern MCInstrDesc ARMInsts[];
266 // Thumb1 instructions don't have explicit S bits. Rather, they
267 // implicitly set CPSR. Since it's not represented in the encoding, the
268 // auto-generated decoder won't inject the CPSR operand. We need to fix
269 // that as a post-pass.
270 static void AddThumb1SBit(MCInst &MI, bool InITBlock) {
271 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
272 MCInst::iterator I = MI.begin();
273 for (unsigned i = 0; i < MI.size(); ++i, ++I) {
274 if (OpInfo[i].isOptionalDef() && OpInfo[i].RegClass == ARM::CCRRegClassID) {
275 MI.insert(I, MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
280 if (OpInfo[MI.size()].isOptionalDef() &&
281 OpInfo[MI.size()].RegClass == ARM::CCRRegClassID)
282 MI.insert(MI.end(), MCOperand::CreateReg(InITBlock ? 0 : ARM::CPSR));
285 // Most Thumb instructions don't have explicit predicates in the
286 // encoding, but rather get their predicates from IT context. We need
287 // to fix up the predicate operands using this context information as a
289 void ThumbDisassembler::AddThumbPredicate(MCInst &MI) const {
290 // A few instructions actually have predicates encoded in them. Don't
291 // try to overwrite it if we're seeing one of those.
292 switch (MI.getOpcode()) {
300 // If we're in an IT block, base the predicate on that. Otherwise,
301 // assume a predicate of AL.
303 if (ITBlock.size()) {
309 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
310 MCInst::iterator I = MI.begin();
311 for (unsigned i = 0; i < MI.size(); ++i, ++I) {
312 if (OpInfo[i].isPredicate()) {
313 I = MI.insert(I, MCOperand::CreateImm(CC));
316 MI.insert(I, MCOperand::CreateReg(0));
318 MI.insert(I, MCOperand::CreateReg(ARM::CPSR));
323 MI.insert(MI.end(), MCOperand::CreateImm(CC));
325 MI.insert(MI.end(), MCOperand::CreateReg(0));
327 MI.insert(MI.end(), MCOperand::CreateReg(ARM::CPSR));
330 // Thumb VFP instructions are a special case. Because we share their
331 // encodings between ARM and Thumb modes, and they are predicable in ARM
332 // mode, the auto-generated decoder will give them an (incorrect)
333 // predicate operand. We need to rewrite these operands based on the IT
334 // context as a post-pass.
335 void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst &MI) const {
337 if (ITBlock.size()) {
343 const MCOperandInfo *OpInfo = ARMInsts[MI.getOpcode()].OpInfo;
344 MCInst::iterator I = MI.begin();
345 for (unsigned i = 0; i < MI.size(); ++i, ++I) {
346 if (OpInfo[i].isPredicate() ) {
352 I->setReg(ARM::CPSR);
359 bool ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
360 const MemoryObject &Region,
361 uint64_t Address,raw_ostream &os) const {
364 // We want to read exactly 2 bytes of data.
365 if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1)
368 uint16_t insn16 = (bytes[1] << 8) | bytes[0];
369 bool result = decodeThumbInstruction16(MI, insn16, Address, this);
372 bool InITBlock = ITBlock.size();
373 AddThumbPredicate(MI);
374 AddThumb1SBit(MI, InITBlock);
379 result = decodeThumb2Instruction16(MI, insn16, Address, this);
382 AddThumbPredicate(MI);
384 // If we find an IT instruction, we need to parse its condition
385 // code and mask operands so that we can apply them correctly
386 // to the subsequent instructions.
387 if (MI.getOpcode() == ARM::t2IT) {
388 unsigned firstcond = MI.getOperand(0).getImm();
389 uint32_t mask = MI.getOperand(1).getImm();
390 unsigned zeros = CountTrailingZeros_32(mask);
393 for (unsigned i = 0; i < 4 - (zeros+1); ++i) {
394 if (firstcond ^ (mask & 1))
395 ITBlock.push_back(firstcond ^ 1);
397 ITBlock.push_back(firstcond);
400 ITBlock.push_back(firstcond);
406 // We want to read exactly 4 bytes of data.
407 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1)
410 uint32_t insn32 = (bytes[3] << 8) |
415 result = decodeThumbInstruction32(MI, insn32, Address, this);
418 bool InITBlock = ITBlock.size();
419 AddThumbPredicate(MI);
420 AddThumb1SBit(MI, InITBlock);
425 result = decodeThumb2Instruction32(MI, insn32, Address, this);
428 AddThumbPredicate(MI);
433 result = decodeVFPInstruction32(MI, insn32, Address, this);
436 UpdateThumbVFPPredicate(MI);
441 result = decodeCommonInstruction32(MI, insn32, Address, this);
444 AddThumbPredicate(MI);
452 extern "C" void LLVMInitializeARMDisassembler() {
453 TargetRegistry::RegisterMCDisassembler(TheARMTarget,
454 createARMDisassembler);
455 TargetRegistry::RegisterMCDisassembler(TheThumbTarget,
456 createThumbDisassembler);
459 static const unsigned GPRDecoderTable[] = {
460 ARM::R0, ARM::R1, ARM::R2, ARM::R3,
461 ARM::R4, ARM::R5, ARM::R6, ARM::R7,
462 ARM::R8, ARM::R9, ARM::R10, ARM::R11,
463 ARM::R12, ARM::SP, ARM::LR, ARM::PC
466 static bool DecodeGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
467 uint64_t Address, const void *Decoder) {
471 unsigned Register = GPRDecoderTable[RegNo];
472 Inst.addOperand(MCOperand::CreateReg(Register));
476 static bool DecodeGPRnopcRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
477 uint64_t Address, const void *Decoder) {
478 if (RegNo == 15) return false;
479 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
482 static bool DecodetGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
483 uint64_t Address, const void *Decoder) {
486 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
489 static bool DecodetcGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
490 uint64_t Address, const void *Decoder) {
491 unsigned Register = 0;
515 Inst.addOperand(MCOperand::CreateReg(Register));
519 static bool DecoderGPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
520 uint64_t Address, const void *Decoder) {
521 if (RegNo == 13 || RegNo == 15) return false;
522 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
525 static const unsigned SPRDecoderTable[] = {
526 ARM::S0, ARM::S1, ARM::S2, ARM::S3,
527 ARM::S4, ARM::S5, ARM::S6, ARM::S7,
528 ARM::S8, ARM::S9, ARM::S10, ARM::S11,
529 ARM::S12, ARM::S13, ARM::S14, ARM::S15,
530 ARM::S16, ARM::S17, ARM::S18, ARM::S19,
531 ARM::S20, ARM::S21, ARM::S22, ARM::S23,
532 ARM::S24, ARM::S25, ARM::S26, ARM::S27,
533 ARM::S28, ARM::S29, ARM::S30, ARM::S31
536 static bool DecodeSPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
537 uint64_t Address, const void *Decoder) {
541 unsigned Register = SPRDecoderTable[RegNo];
542 Inst.addOperand(MCOperand::CreateReg(Register));
546 static const unsigned DPRDecoderTable[] = {
547 ARM::D0, ARM::D1, ARM::D2, ARM::D3,
548 ARM::D4, ARM::D5, ARM::D6, ARM::D7,
549 ARM::D8, ARM::D9, ARM::D10, ARM::D11,
550 ARM::D12, ARM::D13, ARM::D14, ARM::D15,
551 ARM::D16, ARM::D17, ARM::D18, ARM::D19,
552 ARM::D20, ARM::D21, ARM::D22, ARM::D23,
553 ARM::D24, ARM::D25, ARM::D26, ARM::D27,
554 ARM::D28, ARM::D29, ARM::D30, ARM::D31
557 static bool DecodeDPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
558 uint64_t Address, const void *Decoder) {
562 unsigned Register = DPRDecoderTable[RegNo];
563 Inst.addOperand(MCOperand::CreateReg(Register));
567 static bool DecodeDPR_8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
568 uint64_t Address, const void *Decoder) {
571 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
574 static bool DecodeDPR_VFP2RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
575 uint64_t Address, const void *Decoder) {
578 return DecodeDPRRegisterClass(Inst, RegNo, Address, Decoder);
581 static const unsigned QPRDecoderTable[] = {
582 ARM::Q0, ARM::Q1, ARM::Q2, ARM::Q3,
583 ARM::Q4, ARM::Q5, ARM::Q6, ARM::Q7,
584 ARM::Q8, ARM::Q9, ARM::Q10, ARM::Q11,
585 ARM::Q12, ARM::Q13, ARM::Q14, ARM::Q15
589 static bool DecodeQPRRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
590 uint64_t Address, const void *Decoder) {
595 unsigned Register = QPRDecoderTable[RegNo];
596 Inst.addOperand(MCOperand::CreateReg(Register));
600 static bool DecodePredicateOperand(llvm::MCInst &Inst, unsigned Val,
601 uint64_t Address, const void *Decoder) {
602 if (Val == 0xF) return false;
603 // AL predicate is not allowed on Thumb1 branches.
604 if (Inst.getOpcode() == ARM::tBcc && Val == 0xE)
606 Inst.addOperand(MCOperand::CreateImm(Val));
607 if (Val == ARMCC::AL) {
608 Inst.addOperand(MCOperand::CreateReg(0));
610 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
614 static bool DecodeCCOutOperand(llvm::MCInst &Inst, unsigned Val,
615 uint64_t Address, const void *Decoder) {
617 Inst.addOperand(MCOperand::CreateReg(ARM::CPSR));
619 Inst.addOperand(MCOperand::CreateReg(0));
623 static bool DecodeSOImmOperand(llvm::MCInst &Inst, unsigned Val,
624 uint64_t Address, const void *Decoder) {
625 uint32_t imm = Val & 0xFF;
626 uint32_t rot = (Val & 0xF00) >> 7;
627 uint32_t rot_imm = (imm >> rot) | (imm << (32-rot));
628 Inst.addOperand(MCOperand::CreateImm(rot_imm));
632 static bool DecodeBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
633 uint64_t Address, const void *Decoder) {
635 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(Val)));
639 static bool DecodeSORegImmOperand(llvm::MCInst &Inst, unsigned Val,
640 uint64_t Address, const void *Decoder) {
642 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
643 unsigned type = fieldFromInstruction32(Val, 5, 2);
644 unsigned imm = fieldFromInstruction32(Val, 7, 5);
646 // Register-immediate
647 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
649 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
665 if (Shift == ARM_AM::ror && imm == 0)
668 unsigned Op = Shift | (imm << 3);
669 Inst.addOperand(MCOperand::CreateImm(Op));
674 static bool DecodeSORegRegOperand(llvm::MCInst &Inst, unsigned Val,
675 uint64_t Address, const void *Decoder) {
677 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
678 unsigned type = fieldFromInstruction32(Val, 5, 2);
679 unsigned Rs = fieldFromInstruction32(Val, 8, 4);
682 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
683 DecodeGPRRegisterClass(Inst, Rs, Address, Decoder);
685 ARM_AM::ShiftOpc Shift = ARM_AM::lsl;
701 Inst.addOperand(MCOperand::CreateImm(Shift));
706 static bool DecodeRegListOperand(llvm::MCInst &Inst, unsigned Val,
707 uint64_t Address, const void *Decoder) {
708 for (unsigned i = 0; i < 16; ++i) {
710 DecodeGPRRegisterClass(Inst, i, Address, Decoder);
716 static bool DecodeSPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
717 uint64_t Address, const void *Decoder) {
718 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
719 unsigned regs = Val & 0xFF;
721 DecodeSPRRegisterClass(Inst, Vd, Address, Decoder);
722 for (unsigned i = 0; i < (regs - 1); ++i)
723 DecodeSPRRegisterClass(Inst, ++Vd, Address, Decoder);
728 static bool DecodeDPRRegListOperand(llvm::MCInst &Inst, unsigned Val,
729 uint64_t Address, const void *Decoder) {
730 unsigned Vd = fieldFromInstruction32(Val, 8, 4);
731 unsigned regs = (Val & 0xFF) / 2;
733 DecodeDPRRegisterClass(Inst, Vd, Address, Decoder);
734 for (unsigned i = 0; i < (regs - 1); ++i)
735 DecodeDPRRegisterClass(Inst, ++Vd, Address, Decoder);
740 static bool DecodeBitfieldMaskOperand(llvm::MCInst &Inst, unsigned Val,
741 uint64_t Address, const void *Decoder) {
742 unsigned msb = fieldFromInstruction32(Val, 5, 5);
743 unsigned lsb = fieldFromInstruction32(Val, 0, 5);
744 uint32_t msb_mask = (1 << (msb+1)) - 1;
745 uint32_t lsb_mask = (1 << lsb) - 1;
746 Inst.addOperand(MCOperand::CreateImm(~(msb_mask ^ lsb_mask)));
750 static bool DecodeCopMemInstruction(llvm::MCInst &Inst, unsigned Insn,
751 uint64_t Address, const void *Decoder) {
752 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
753 unsigned CRd = fieldFromInstruction32(Insn, 12, 4);
754 unsigned coproc = fieldFromInstruction32(Insn, 8, 4);
755 unsigned imm = fieldFromInstruction32(Insn, 0, 8);
756 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
757 unsigned U = fieldFromInstruction32(Insn, 23, 1);
759 switch (Inst.getOpcode()) {
760 case ARM::LDC_OFFSET:
763 case ARM::LDC_OPTION:
764 case ARM::LDCL_OFFSET:
767 case ARM::LDCL_OPTION:
768 case ARM::STC_OFFSET:
771 case ARM::STC_OPTION:
772 case ARM::STCL_OFFSET:
775 case ARM::STCL_OPTION:
776 if (coproc == 0xA || coproc == 0xB)
783 Inst.addOperand(MCOperand::CreateImm(coproc));
784 Inst.addOperand(MCOperand::CreateImm(CRd));
785 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
786 switch (Inst.getOpcode()) {
787 case ARM::LDC_OPTION:
788 case ARM::LDCL_OPTION:
789 case ARM::LDC2_OPTION:
790 case ARM::LDC2L_OPTION:
791 case ARM::STC_OPTION:
792 case ARM::STCL_OPTION:
793 case ARM::STC2_OPTION:
794 case ARM::STC2L_OPTION:
799 Inst.addOperand(MCOperand::CreateReg(0));
803 unsigned P = fieldFromInstruction32(Insn, 24, 1);
804 unsigned W = fieldFromInstruction32(Insn, 21, 1);
806 bool writeback = (P == 0) || (W == 1);
807 unsigned idx_mode = 0;
809 idx_mode = ARMII::IndexModePre;
810 else if (!P && writeback)
811 idx_mode = ARMII::IndexModePost;
813 switch (Inst.getOpcode()) {
817 case ARM::LDC_OPTION:
818 case ARM::LDCL_OPTION:
819 case ARM::LDC2_OPTION:
820 case ARM::LDC2L_OPTION:
821 case ARM::STC_OPTION:
822 case ARM::STCL_OPTION:
823 case ARM::STC2_OPTION:
824 case ARM::STC2L_OPTION:
825 Inst.addOperand(MCOperand::CreateImm(imm));
829 Inst.addOperand(MCOperand::CreateImm(
830 ARM_AM::getAM2Opc(ARM_AM::add, imm, ARM_AM::lsl, idx_mode)));
832 Inst.addOperand(MCOperand::CreateImm(
833 ARM_AM::getAM2Opc(ARM_AM::sub, imm, ARM_AM::lsl, idx_mode)));
837 switch (Inst.getOpcode()) {
838 case ARM::LDC_OFFSET:
841 case ARM::LDC_OPTION:
842 case ARM::LDCL_OFFSET:
845 case ARM::LDCL_OPTION:
846 case ARM::STC_OFFSET:
849 case ARM::STC_OPTION:
850 case ARM::STCL_OFFSET:
853 case ARM::STCL_OPTION:
854 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
863 static bool DecodeAddrMode2IdxInstruction(llvm::MCInst &Inst, unsigned Insn,
864 uint64_t Address, const void *Decoder) {
865 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
866 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
867 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
868 unsigned imm = fieldFromInstruction32(Insn, 0, 12);
869 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
870 unsigned reg = fieldFromInstruction32(Insn, 25, 1);
871 unsigned P = fieldFromInstruction32(Insn, 24, 1);
872 unsigned W = fieldFromInstruction32(Insn, 21, 1);
874 // On stores, the writeback operand precedes Rt.
875 switch (Inst.getOpcode()) {
876 case ARM::STR_POST_IMM:
877 case ARM::STR_POST_REG:
882 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
888 DecodeGPRRegisterClass(Inst, Rt, Address, Decoder);
890 // On loads, the writeback operand comes after Rt.
891 switch (Inst.getOpcode()) {
892 case ARM::LDR_POST_IMM:
893 case ARM::LDR_POST_REG:
895 case ARM::LDRBT_POST_REG:
896 case ARM::LDRBT_POST_IMM:
899 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
905 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
907 ARM_AM::AddrOpc Op = ARM_AM::add;
908 if (!fieldFromInstruction32(Insn, 23, 1))
911 bool writeback = (P == 0) || (W == 1);
912 unsigned idx_mode = 0;
914 idx_mode = ARMII::IndexModePre;
915 else if (!P && writeback)
916 idx_mode = ARMII::IndexModePost;
919 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
920 ARM_AM::ShiftOpc Opc = ARM_AM::lsl;
921 switch( fieldFromInstruction32(Insn, 5, 2)) {
937 unsigned amt = fieldFromInstruction32(Insn, 7, 5);
938 unsigned imm = ARM_AM::getAM2Opc(Op, amt, Opc, idx_mode);
940 Inst.addOperand(MCOperand::CreateImm(imm));
942 Inst.addOperand(MCOperand::CreateReg(0));
943 unsigned tmp = ARM_AM::getAM2Opc(Op, imm, ARM_AM::lsl, idx_mode);
944 Inst.addOperand(MCOperand::CreateImm(tmp));
947 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
952 static bool DecodeSORegMemOperand(llvm::MCInst &Inst, unsigned Val,
953 uint64_t Address, const void *Decoder) {
954 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
955 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
956 unsigned type = fieldFromInstruction32(Val, 5, 2);
957 unsigned imm = fieldFromInstruction32(Val, 7, 5);
958 unsigned U = fieldFromInstruction32(Val, 12, 1);
960 ARM_AM::ShiftOpc ShOp = ARM_AM::lsl;
976 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
977 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
980 shift = ARM_AM::getAM2Opc(ARM_AM::add, imm, ShOp);
982 shift = ARM_AM::getAM2Opc(ARM_AM::sub, imm, ShOp);
983 Inst.addOperand(MCOperand::CreateImm(shift));
988 static bool DecodeAddrMode3Instruction(llvm::MCInst &Inst, unsigned Insn,
989 uint64_t Address, const void *Decoder) {
990 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
991 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
992 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
993 unsigned type = fieldFromInstruction32(Insn, 22, 1);
994 unsigned imm = fieldFromInstruction32(Insn, 8, 4);
995 unsigned U = ((~fieldFromInstruction32(Insn, 23, 1)) & 1) << 8;
996 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
997 unsigned W = fieldFromInstruction32(Insn, 21, 1);
998 unsigned P = fieldFromInstruction32(Insn, 24, 1);
1000 bool writeback = (W == 1) | (P == 0);
1001 if (writeback) { // Writeback
1003 U |= ARMII::IndexModePre << 9;
1005 U |= ARMII::IndexModePost << 9;
1007 // On stores, the writeback operand precedes Rt.
1008 switch (Inst.getOpcode()) {
1011 case ARM::STRD_POST:
1012 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1019 DecodeGPRRegisterClass(Inst, Rt, Address, Decoder);
1020 switch (Inst.getOpcode()) {
1023 case ARM::STRD_POST:
1026 case ARM::LDRD_POST:
1027 DecodeGPRRegisterClass(Inst, Rt+1, Address, Decoder);
1034 // On loads, the writeback operand comes after Rt.
1035 switch (Inst.getOpcode()) {
1038 case ARM::LDRD_POST:
1041 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1048 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1051 Inst.addOperand(MCOperand::CreateReg(0));
1052 Inst.addOperand(MCOperand::CreateImm(U | (imm << 4) | Rm));
1054 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
1055 Inst.addOperand(MCOperand::CreateImm(U));
1058 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1063 static bool DecodeRFEInstruction(llvm::MCInst &Inst, unsigned Insn,
1064 uint64_t Address, const void *Decoder) {
1065 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1066 unsigned mode = fieldFromInstruction32(Insn, 23, 2);
1083 Inst.addOperand(MCOperand::CreateImm(mode));
1084 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1089 static bool DecodeMemMultipleWritebackInstruction(llvm::MCInst &Inst,
1091 uint64_t Address, const void *Decoder) {
1092 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1093 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1094 unsigned reglist = fieldFromInstruction32(Insn, 0, 16);
1097 switch (Inst.getOpcode()) {
1099 Inst.setOpcode(ARM::RFEDA);
1101 case ARM::STMDA_UPD:
1102 Inst.setOpcode(ARM::RFEDA_UPD);
1105 Inst.setOpcode(ARM::RFEDB);
1107 case ARM::STMDB_UPD:
1108 Inst.setOpcode(ARM::RFEDB_UPD);
1111 Inst.setOpcode(ARM::RFEIA);
1113 case ARM::STMIA_UPD:
1114 Inst.setOpcode(ARM::RFEIA_UPD);
1117 Inst.setOpcode(ARM::RFEIB);
1119 case ARM::STMIB_UPD:
1120 Inst.setOpcode(ARM::RFEIB_UPD);
1124 return DecodeRFEInstruction(Inst, Insn, Address, Decoder);
1127 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1128 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder); // Tied
1129 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1130 DecodeRegListOperand(Inst, reglist, Address, Decoder);
1135 static bool DecodeCPSInstruction(llvm::MCInst &Inst, unsigned Insn,
1136 uint64_t Address, const void *Decoder) {
1137 unsigned imod = fieldFromInstruction32(Insn, 18, 2);
1138 unsigned M = fieldFromInstruction32(Insn, 17, 1);
1139 unsigned iflags = fieldFromInstruction32(Insn, 6, 3);
1140 unsigned mode = fieldFromInstruction32(Insn, 0, 5);
1142 if (M && mode && imod && iflags) {
1143 Inst.setOpcode(ARM::CPS3p);
1144 Inst.addOperand(MCOperand::CreateImm(imod));
1145 Inst.addOperand(MCOperand::CreateImm(iflags));
1146 Inst.addOperand(MCOperand::CreateImm(mode));
1148 } else if (!mode && !M) {
1149 Inst.setOpcode(ARM::CPS2p);
1150 Inst.addOperand(MCOperand::CreateImm(imod));
1151 Inst.addOperand(MCOperand::CreateImm(iflags));
1153 } else if (!imod && !iflags && M) {
1154 Inst.setOpcode(ARM::CPS1p);
1155 Inst.addOperand(MCOperand::CreateImm(mode));
1162 static bool DecodeSMLAInstruction(llvm::MCInst &Inst, unsigned Insn,
1163 uint64_t Address, const void *Decoder) {
1164 unsigned Rd = fieldFromInstruction32(Insn, 16, 4);
1165 unsigned Rn = fieldFromInstruction32(Insn, 0, 4);
1166 unsigned Rm = fieldFromInstruction32(Insn, 8, 4);
1167 unsigned Ra = fieldFromInstruction32(Insn, 12, 4);
1168 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1171 return DecodeCPSInstruction(Inst, Insn, Address, Decoder);
1173 DecodeGPRRegisterClass(Inst, Rd, Address, Decoder);
1174 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1175 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
1176 DecodeGPRRegisterClass(Inst, Ra, Address, Decoder);
1181 static bool DecodeAddrModeImm12Operand(llvm::MCInst &Inst, unsigned Val,
1182 uint64_t Address, const void *Decoder) {
1183 unsigned add = fieldFromInstruction32(Val, 12, 1);
1184 unsigned imm = fieldFromInstruction32(Val, 0, 12);
1185 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
1187 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1189 if (!add) imm *= -1;
1190 if (imm == 0 && !add) imm = INT32_MIN;
1191 Inst.addOperand(MCOperand::CreateImm(imm));
1196 static bool DecodeAddrMode5Operand(llvm::MCInst &Inst, unsigned Val,
1197 uint64_t Address, const void *Decoder) {
1198 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
1199 unsigned U = fieldFromInstruction32(Val, 8, 1);
1200 unsigned imm = fieldFromInstruction32(Val, 0, 8);
1202 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1205 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add, imm)));
1207 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub, imm)));
1212 static bool DecodeAddrMode7Operand(llvm::MCInst &Inst, unsigned Val,
1213 uint64_t Address, const void *Decoder) {
1214 return DecodeGPRRegisterClass(Inst, Val, Address, Decoder);
1217 static bool DecodeBranchImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1218 uint64_t Address, const void *Decoder) {
1219 unsigned pred = fieldFromInstruction32(Insn, 28, 4);
1220 unsigned imm = fieldFromInstruction32(Insn, 0, 24) << 2;
1223 Inst.setOpcode(ARM::BLXi);
1224 imm |= fieldFromInstruction32(Insn, 24, 1) << 1;
1225 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1229 Inst.addOperand(MCOperand::CreateImm(SignExtend32<26>(imm)));
1230 if (!DecodePredicateOperand(Inst, pred, Address, Decoder)) return false;
1236 static bool DecodeVCVTImmOperand(llvm::MCInst &Inst, unsigned Val,
1237 uint64_t Address, const void *Decoder) {
1238 Inst.addOperand(MCOperand::CreateImm(64 - Val));
1242 static bool DecodeAddrMode6Operand(llvm::MCInst &Inst, unsigned Val,
1243 uint64_t Address, const void *Decoder) {
1244 unsigned Rm = fieldFromInstruction32(Val, 0, 4);
1245 unsigned align = fieldFromInstruction32(Val, 4, 2);
1247 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
1249 Inst.addOperand(MCOperand::CreateImm(0));
1251 Inst.addOperand(MCOperand::CreateImm(4 << align));
1256 static bool DecodeVLDInstruction(llvm::MCInst &Inst, unsigned Insn,
1257 uint64_t Address, const void *Decoder) {
1258 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1259 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1260 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1261 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1262 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1263 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1265 // First output register
1266 DecodeDPRRegisterClass(Inst, Rd, Address, Decoder);
1268 // Second output register
1269 switch (Inst.getOpcode()) {
1274 case ARM::VLD1q8_UPD:
1275 case ARM::VLD1q16_UPD:
1276 case ARM::VLD1q32_UPD:
1277 case ARM::VLD1q64_UPD:
1282 case ARM::VLD1d8T_UPD:
1283 case ARM::VLD1d16T_UPD:
1284 case ARM::VLD1d32T_UPD:
1285 case ARM::VLD1d64T_UPD:
1290 case ARM::VLD1d8Q_UPD:
1291 case ARM::VLD1d16Q_UPD:
1292 case ARM::VLD1d32Q_UPD:
1293 case ARM::VLD1d64Q_UPD:
1297 case ARM::VLD2d8_UPD:
1298 case ARM::VLD2d16_UPD:
1299 case ARM::VLD2d32_UPD:
1303 case ARM::VLD2q8_UPD:
1304 case ARM::VLD2q16_UPD:
1305 case ARM::VLD2q32_UPD:
1309 case ARM::VLD3d8_UPD:
1310 case ARM::VLD3d16_UPD:
1311 case ARM::VLD3d32_UPD:
1315 case ARM::VLD4d8_UPD:
1316 case ARM::VLD4d16_UPD:
1317 case ARM::VLD4d32_UPD:
1318 DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder);
1323 case ARM::VLD2b8_UPD:
1324 case ARM::VLD2b16_UPD:
1325 case ARM::VLD2b32_UPD:
1329 case ARM::VLD3q8_UPD:
1330 case ARM::VLD3q16_UPD:
1331 case ARM::VLD3q32_UPD:
1335 case ARM::VLD4q8_UPD:
1336 case ARM::VLD4q16_UPD:
1337 case ARM::VLD4q32_UPD:
1338 DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder);
1343 // Third output register
1344 switch(Inst.getOpcode()) {
1349 case ARM::VLD1d8T_UPD:
1350 case ARM::VLD1d16T_UPD:
1351 case ARM::VLD1d32T_UPD:
1352 case ARM::VLD1d64T_UPD:
1357 case ARM::VLD1d8Q_UPD:
1358 case ARM::VLD1d16Q_UPD:
1359 case ARM::VLD1d32Q_UPD:
1360 case ARM::VLD1d64Q_UPD:
1364 case ARM::VLD2q8_UPD:
1365 case ARM::VLD2q16_UPD:
1366 case ARM::VLD2q32_UPD:
1370 case ARM::VLD3d8_UPD:
1371 case ARM::VLD3d16_UPD:
1372 case ARM::VLD3d32_UPD:
1376 case ARM::VLD4d8_UPD:
1377 case ARM::VLD4d16_UPD:
1378 case ARM::VLD4d32_UPD:
1379 DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder);
1384 case ARM::VLD3q8_UPD:
1385 case ARM::VLD3q16_UPD:
1386 case ARM::VLD3q32_UPD:
1390 case ARM::VLD4q8_UPD:
1391 case ARM::VLD4q16_UPD:
1392 case ARM::VLD4q32_UPD:
1393 DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder);
1399 // Fourth output register
1400 switch (Inst.getOpcode()) {
1405 case ARM::VLD1d8Q_UPD:
1406 case ARM::VLD1d16Q_UPD:
1407 case ARM::VLD1d32Q_UPD:
1408 case ARM::VLD1d64Q_UPD:
1412 case ARM::VLD2q8_UPD:
1413 case ARM::VLD2q16_UPD:
1414 case ARM::VLD2q32_UPD:
1418 case ARM::VLD4d8_UPD:
1419 case ARM::VLD4d16_UPD:
1420 case ARM::VLD4d32_UPD:
1421 DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder);
1426 case ARM::VLD4q8_UPD:
1427 case ARM::VLD4q16_UPD:
1428 case ARM::VLD4q32_UPD:
1429 DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder);
1435 // Writeback operand
1436 switch (Inst.getOpcode()) {
1437 case ARM::VLD1d8_UPD:
1438 case ARM::VLD1d16_UPD:
1439 case ARM::VLD1d32_UPD:
1440 case ARM::VLD1d64_UPD:
1441 case ARM::VLD1q8_UPD:
1442 case ARM::VLD1q16_UPD:
1443 case ARM::VLD1q32_UPD:
1444 case ARM::VLD1q64_UPD:
1445 case ARM::VLD1d8T_UPD:
1446 case ARM::VLD1d16T_UPD:
1447 case ARM::VLD1d32T_UPD:
1448 case ARM::VLD1d64T_UPD:
1449 case ARM::VLD1d8Q_UPD:
1450 case ARM::VLD1d16Q_UPD:
1451 case ARM::VLD1d32Q_UPD:
1452 case ARM::VLD1d64Q_UPD:
1453 case ARM::VLD2d8_UPD:
1454 case ARM::VLD2d16_UPD:
1455 case ARM::VLD2d32_UPD:
1456 case ARM::VLD2q8_UPD:
1457 case ARM::VLD2q16_UPD:
1458 case ARM::VLD2q32_UPD:
1459 case ARM::VLD2b8_UPD:
1460 case ARM::VLD2b16_UPD:
1461 case ARM::VLD2b32_UPD:
1462 case ARM::VLD3d8_UPD:
1463 case ARM::VLD3d16_UPD:
1464 case ARM::VLD3d32_UPD:
1465 case ARM::VLD3q8_UPD:
1466 case ARM::VLD3q16_UPD:
1467 case ARM::VLD3q32_UPD:
1468 case ARM::VLD4d8_UPD:
1469 case ARM::VLD4d16_UPD:
1470 case ARM::VLD4d32_UPD:
1471 case ARM::VLD4q8_UPD:
1472 case ARM::VLD4q16_UPD:
1473 case ARM::VLD4q32_UPD:
1474 DecodeGPRRegisterClass(Inst, wb, Address, Decoder);
1480 // AddrMode6 Base (register+alignment)
1481 DecodeAddrMode6Operand(Inst, Rn, Address, Decoder);
1483 // AddrMode6 Offset (register)
1485 Inst.addOperand(MCOperand::CreateReg(0));
1487 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
1492 static bool DecodeVSTInstruction(llvm::MCInst &Inst, unsigned Insn,
1493 uint64_t Address, const void *Decoder) {
1494 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1495 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1496 unsigned wb = fieldFromInstruction32(Insn, 16, 4);
1497 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1498 Rn |= fieldFromInstruction32(Insn, 4, 2) << 4;
1499 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1501 // Writeback Operand
1502 switch (Inst.getOpcode()) {
1503 case ARM::VST1d8_UPD:
1504 case ARM::VST1d16_UPD:
1505 case ARM::VST1d32_UPD:
1506 case ARM::VST1d64_UPD:
1507 case ARM::VST1q8_UPD:
1508 case ARM::VST1q16_UPD:
1509 case ARM::VST1q32_UPD:
1510 case ARM::VST1q64_UPD:
1511 case ARM::VST1d8T_UPD:
1512 case ARM::VST1d16T_UPD:
1513 case ARM::VST1d32T_UPD:
1514 case ARM::VST1d64T_UPD:
1515 case ARM::VST1d8Q_UPD:
1516 case ARM::VST1d16Q_UPD:
1517 case ARM::VST1d32Q_UPD:
1518 case ARM::VST1d64Q_UPD:
1519 case ARM::VST2d8_UPD:
1520 case ARM::VST2d16_UPD:
1521 case ARM::VST2d32_UPD:
1522 case ARM::VST2q8_UPD:
1523 case ARM::VST2q16_UPD:
1524 case ARM::VST2q32_UPD:
1525 case ARM::VST2b8_UPD:
1526 case ARM::VST2b16_UPD:
1527 case ARM::VST2b32_UPD:
1528 case ARM::VST3d8_UPD:
1529 case ARM::VST3d16_UPD:
1530 case ARM::VST3d32_UPD:
1531 case ARM::VST3q8_UPD:
1532 case ARM::VST3q16_UPD:
1533 case ARM::VST3q32_UPD:
1534 case ARM::VST4d8_UPD:
1535 case ARM::VST4d16_UPD:
1536 case ARM::VST4d32_UPD:
1537 case ARM::VST4q8_UPD:
1538 case ARM::VST4q16_UPD:
1539 case ARM::VST4q32_UPD:
1540 DecodeGPRRegisterClass(Inst, wb, Address, Decoder);
1546 // AddrMode6 Base (register+alignment)
1547 DecodeAddrMode6Operand(Inst, Rn, Address, Decoder);
1549 // AddrMode6 Offset (register)
1551 Inst.addOperand(MCOperand::CreateReg(0));
1553 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
1555 // First input register
1556 DecodeDPRRegisterClass(Inst, Rd, Address, Decoder);
1558 // Second input register
1559 switch (Inst.getOpcode()) {
1564 case ARM::VST1q8_UPD:
1565 case ARM::VST1q16_UPD:
1566 case ARM::VST1q32_UPD:
1567 case ARM::VST1q64_UPD:
1572 case ARM::VST1d8T_UPD:
1573 case ARM::VST1d16T_UPD:
1574 case ARM::VST1d32T_UPD:
1575 case ARM::VST1d64T_UPD:
1580 case ARM::VST1d8Q_UPD:
1581 case ARM::VST1d16Q_UPD:
1582 case ARM::VST1d32Q_UPD:
1583 case ARM::VST1d64Q_UPD:
1587 case ARM::VST2d8_UPD:
1588 case ARM::VST2d16_UPD:
1589 case ARM::VST2d32_UPD:
1593 case ARM::VST2q8_UPD:
1594 case ARM::VST2q16_UPD:
1595 case ARM::VST2q32_UPD:
1599 case ARM::VST3d8_UPD:
1600 case ARM::VST3d16_UPD:
1601 case ARM::VST3d32_UPD:
1605 case ARM::VST4d8_UPD:
1606 case ARM::VST4d16_UPD:
1607 case ARM::VST4d32_UPD:
1608 DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder);
1613 case ARM::VST2b8_UPD:
1614 case ARM::VST2b16_UPD:
1615 case ARM::VST2b32_UPD:
1619 case ARM::VST3q8_UPD:
1620 case ARM::VST3q16_UPD:
1621 case ARM::VST3q32_UPD:
1625 case ARM::VST4q8_UPD:
1626 case ARM::VST4q16_UPD:
1627 case ARM::VST4q32_UPD:
1628 DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder);
1634 // Third input register
1635 switch (Inst.getOpcode()) {
1640 case ARM::VST1d8T_UPD:
1641 case ARM::VST1d16T_UPD:
1642 case ARM::VST1d32T_UPD:
1643 case ARM::VST1d64T_UPD:
1648 case ARM::VST1d8Q_UPD:
1649 case ARM::VST1d16Q_UPD:
1650 case ARM::VST1d32Q_UPD:
1651 case ARM::VST1d64Q_UPD:
1655 case ARM::VST2q8_UPD:
1656 case ARM::VST2q16_UPD:
1657 case ARM::VST2q32_UPD:
1661 case ARM::VST3d8_UPD:
1662 case ARM::VST3d16_UPD:
1663 case ARM::VST3d32_UPD:
1667 case ARM::VST4d8_UPD:
1668 case ARM::VST4d16_UPD:
1669 case ARM::VST4d32_UPD:
1670 DecodeDPRRegisterClass(Inst, (Rd+2)%32, Address, Decoder);
1675 case ARM::VST3q8_UPD:
1676 case ARM::VST3q16_UPD:
1677 case ARM::VST3q32_UPD:
1681 case ARM::VST4q8_UPD:
1682 case ARM::VST4q16_UPD:
1683 case ARM::VST4q32_UPD:
1684 DecodeDPRRegisterClass(Inst, (Rd+4)%32, Address, Decoder);
1690 // Fourth input register
1691 switch (Inst.getOpcode()) {
1696 case ARM::VST1d8Q_UPD:
1697 case ARM::VST1d16Q_UPD:
1698 case ARM::VST1d32Q_UPD:
1699 case ARM::VST1d64Q_UPD:
1703 case ARM::VST2q8_UPD:
1704 case ARM::VST2q16_UPD:
1705 case ARM::VST2q32_UPD:
1709 case ARM::VST4d8_UPD:
1710 case ARM::VST4d16_UPD:
1711 case ARM::VST4d32_UPD:
1712 DecodeDPRRegisterClass(Inst, (Rd+3)%32, Address, Decoder);
1717 case ARM::VST4q8_UPD:
1718 case ARM::VST4q16_UPD:
1719 case ARM::VST4q32_UPD:
1720 DecodeDPRRegisterClass(Inst, (Rd+6)%32, Address, Decoder);
1729 static bool DecodeVLD1DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1730 uint64_t Address, const void *Decoder) {
1731 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1732 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1733 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1734 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1735 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1736 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1737 unsigned regs = fieldFromInstruction32(Insn, 5, 1) + 1;
1739 align *= (1 << size);
1741 DecodeDPRRegisterClass(Inst, Rd, Address, Decoder);
1742 if (regs == 2) DecodeDPRRegisterClass(Inst, (Rd+1)%32, Address, Decoder);
1743 if (Rm == 0xD) DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1745 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1746 Inst.addOperand(MCOperand::CreateImm(align));
1749 Inst.addOperand(MCOperand::CreateReg(0));
1751 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
1756 static bool DecodeVLD2DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1757 uint64_t Address, const void *Decoder) {
1758 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1759 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1760 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1761 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1762 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1763 unsigned size = 1 << fieldFromInstruction32(Insn, 6, 2);
1764 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1767 DecodeDPRRegisterClass(Inst, Rd, Address, Decoder);
1768 DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder);
1769 if (Rm == 0xD) DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1771 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1772 Inst.addOperand(MCOperand::CreateImm(align));
1775 Inst.addOperand(MCOperand::CreateReg(0));
1777 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
1782 static bool DecodeVLD3DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1783 uint64_t Address, const void *Decoder) {
1784 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1785 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1786 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1787 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1788 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1790 DecodeDPRRegisterClass(Inst, Rd, Address, Decoder);
1791 DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder);
1792 DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder);
1793 if (Rm == 0xD) DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1795 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1796 Inst.addOperand(MCOperand::CreateImm(0));
1799 Inst.addOperand(MCOperand::CreateReg(0));
1801 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
1806 static bool DecodeVLD4DupInstruction(llvm::MCInst &Inst, unsigned Insn,
1807 uint64_t Address, const void *Decoder) {
1808 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1809 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1810 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1811 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1812 unsigned size = fieldFromInstruction32(Insn, 6, 2);
1813 unsigned inc = fieldFromInstruction32(Insn, 5, 1) + 1;
1814 unsigned align = fieldFromInstruction32(Insn, 4, 1);
1829 DecodeDPRRegisterClass(Inst, Rd, Address, Decoder);
1830 DecodeDPRRegisterClass(Inst, (Rd+inc)%32, Address, Decoder);
1831 DecodeDPRRegisterClass(Inst, (Rd+2*inc)%32, Address, Decoder);
1832 DecodeDPRRegisterClass(Inst, (Rd+3*inc)%32, Address, Decoder);
1833 if (Rm == 0xD) DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1835 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
1836 Inst.addOperand(MCOperand::CreateImm(align));
1839 Inst.addOperand(MCOperand::CreateReg(0));
1841 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
1846 static bool DecodeNEONModImmInstruction(llvm::MCInst &Inst, unsigned Insn,
1847 uint64_t Address, const void *Decoder) {
1848 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1849 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1850 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
1851 imm |= fieldFromInstruction32(Insn, 16, 3) << 4;
1852 imm |= fieldFromInstruction32(Insn, 24, 1) << 7;
1853 imm |= fieldFromInstruction32(Insn, 8, 4) << 8;
1854 imm |= fieldFromInstruction32(Insn, 5, 1) << 12;
1855 unsigned Q = fieldFromInstruction32(Insn, 6, 1);
1858 DecodeQPRRegisterClass(Inst, Rd, Address, Decoder);
1860 DecodeDPRRegisterClass(Inst, Rd, Address, Decoder);
1862 Inst.addOperand(MCOperand::CreateImm(imm));
1864 switch (Inst.getOpcode()) {
1865 case ARM::VORRiv4i16:
1866 case ARM::VORRiv2i32:
1867 case ARM::VBICiv4i16:
1868 case ARM::VBICiv2i32:
1869 DecodeDPRRegisterClass(Inst, Rd, Address, Decoder);
1871 case ARM::VORRiv8i16:
1872 case ARM::VORRiv4i32:
1873 case ARM::VBICiv8i16:
1874 case ARM::VBICiv4i32:
1875 DecodeQPRRegisterClass(Inst, Rd, Address, Decoder);
1885 static bool DecodeVSHLMaxInstruction(llvm::MCInst &Inst, unsigned Insn,
1886 uint64_t Address, const void *Decoder) {
1887 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1888 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1889 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1890 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
1891 unsigned size = fieldFromInstruction32(Insn, 18, 2);
1893 DecodeQPRRegisterClass(Inst, Rd, Address, Decoder);
1894 DecodeDPRRegisterClass(Inst, Rm, Address, Decoder);
1895 Inst.addOperand(MCOperand::CreateImm(8 << size));
1900 static bool DecodeShiftRight8Imm(llvm::MCInst &Inst, unsigned Val,
1901 uint64_t Address, const void *Decoder) {
1902 Inst.addOperand(MCOperand::CreateImm(8 - Val));
1906 static bool DecodeShiftRight16Imm(llvm::MCInst &Inst, unsigned Val,
1907 uint64_t Address, const void *Decoder) {
1908 Inst.addOperand(MCOperand::CreateImm(16 - Val));
1912 static bool DecodeShiftRight32Imm(llvm::MCInst &Inst, unsigned Val,
1913 uint64_t Address, const void *Decoder) {
1914 Inst.addOperand(MCOperand::CreateImm(32 - Val));
1918 static bool DecodeShiftRight64Imm(llvm::MCInst &Inst, unsigned Val,
1919 uint64_t Address, const void *Decoder) {
1920 Inst.addOperand(MCOperand::CreateImm(64 - Val));
1924 static bool DecodeTBLInstruction(llvm::MCInst &Inst, unsigned Insn,
1925 uint64_t Address, const void *Decoder) {
1926 unsigned Rd = fieldFromInstruction32(Insn, 12, 4);
1927 Rd |= fieldFromInstruction32(Insn, 22, 1) << 4;
1928 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
1929 Rn |= fieldFromInstruction32(Insn, 7, 1) << 4;
1930 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
1931 Rm |= fieldFromInstruction32(Insn, 5, 1) << 4;
1932 unsigned op = fieldFromInstruction32(Insn, 6, 1);
1933 unsigned length = fieldFromInstruction32(Insn, 8, 2) + 1;
1935 DecodeDPRRegisterClass(Inst, Rd, Address, Decoder);
1936 if (op) DecodeDPRRegisterClass(Inst, Rd, Address, Decoder); // Writeback
1938 for (unsigned i = 0; i < length; ++i)
1939 DecodeDPRRegisterClass(Inst, (Rn+i)%32, Address, Decoder);
1941 DecodeDPRRegisterClass(Inst, Rm, Address, Decoder);
1946 static bool DecodeVFPfpImm(llvm::MCInst &Inst, unsigned Val,
1947 uint64_t Address, const void *Decoder) {
1948 // The immediate needs to be a fully instantiated float. However, the
1949 // auto-generated decoder is only able to fill in some of the bits
1950 // necessary. For instance, the 'b' bit is replicated multiple times,
1951 // and is even present in inverted form in one bit. We do a little
1952 // binary parsing here to fill in those missing bits, and then
1953 // reinterpret it all as a float.
1959 fp_conv.integer = Val;
1960 uint32_t b = fieldFromInstruction32(Val, 25, 1);
1961 fp_conv.integer |= b << 26;
1962 fp_conv.integer |= b << 27;
1963 fp_conv.integer |= b << 28;
1964 fp_conv.integer |= b << 29;
1965 fp_conv.integer |= (~b & 0x1) << 30;
1967 Inst.addOperand(MCOperand::CreateFPImm(fp_conv.fp));
1971 static bool DecodeThumbAddSpecialReg(llvm::MCInst &Inst, uint16_t Insn,
1972 uint64_t Address, const void *Decoder) {
1973 unsigned dst = fieldFromInstruction16(Insn, 8, 3);
1974 unsigned imm = fieldFromInstruction16(Insn, 0, 8);
1976 DecodetGPRRegisterClass(Inst, dst, Address, Decoder);
1978 if (Inst.getOpcode() == ARM::tADR)
1979 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
1980 else if (Inst.getOpcode() == ARM::tADDrSPi)
1981 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
1985 Inst.addOperand(MCOperand::CreateImm(imm));
1989 static bool DecodeThumbBROperand(llvm::MCInst &Inst, unsigned Val,
1990 uint64_t Address, const void *Decoder) {
1991 Inst.addOperand(MCOperand::CreateImm(SignExtend32<12>(Val << 1)));
1995 static bool DecodeT2BROperand(llvm::MCInst &Inst, unsigned Val,
1996 uint64_t Address, const void *Decoder) {
1997 Inst.addOperand(MCOperand::CreateImm(SignExtend32<21>(Val)));
2001 static bool DecodeThumbCmpBROperand(llvm::MCInst &Inst, unsigned Val,
2002 uint64_t Address, const void *Decoder) {
2003 Inst.addOperand(MCOperand::CreateImm(SignExtend32<7>(Val << 1)));
2007 static bool DecodeThumbAddrModeRR(llvm::MCInst &Inst, unsigned Val,
2008 uint64_t Address, const void *Decoder) {
2009 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2010 unsigned Rm = fieldFromInstruction32(Val, 3, 3);
2012 DecodetGPRRegisterClass(Inst, Rn, Address, Decoder);
2013 DecodetGPRRegisterClass(Inst, Rm, Address, Decoder);
2018 static bool DecodeThumbAddrModeIS(llvm::MCInst &Inst, unsigned Val,
2019 uint64_t Address, const void *Decoder) {
2020 unsigned Rn = fieldFromInstruction32(Val, 0, 3);
2021 unsigned imm = fieldFromInstruction32(Val, 3, 5);
2023 DecodetGPRRegisterClass(Inst, Rn, Address, Decoder);
2024 Inst.addOperand(MCOperand::CreateImm(imm));
2029 static bool DecodeThumbAddrModePC(llvm::MCInst &Inst, unsigned Val,
2030 uint64_t Address, const void *Decoder) {
2031 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2036 static bool DecodeThumbAddrModeSP(llvm::MCInst &Inst, unsigned Val,
2037 uint64_t Address, const void *Decoder) {
2038 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2039 Inst.addOperand(MCOperand::CreateImm(Val << 2));
2044 static bool DecodeT2AddrModeSOReg(llvm::MCInst &Inst, unsigned Val,
2045 uint64_t Address, const void *Decoder) {
2046 unsigned Rn = fieldFromInstruction32(Val, 6, 4);
2047 unsigned Rm = fieldFromInstruction32(Val, 2, 4);
2048 unsigned imm = fieldFromInstruction32(Val, 0, 2);
2050 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
2051 DecoderGPRRegisterClass(Inst, Rm, Address, Decoder);
2052 Inst.addOperand(MCOperand::CreateImm(imm));
2057 static bool DecodeT2LoadShift(llvm::MCInst &Inst, unsigned Insn,
2058 uint64_t Address, const void *Decoder) {
2059 if (Inst.getOpcode() != ARM::t2PLDs) {
2060 unsigned Rt = fieldFromInstruction32(Insn, 12, 4);
2061 DecodeGPRRegisterClass(Inst, Rt, Address, Decoder);
2064 unsigned Rn = fieldFromInstruction32(Insn, 16, 4);
2066 switch (Inst.getOpcode()) {
2068 Inst.setOpcode(ARM::t2LDRBpci);
2071 Inst.setOpcode(ARM::t2LDRHpci);
2074 Inst.setOpcode(ARM::t2LDRSHpci);
2077 Inst.setOpcode(ARM::t2LDRSBpci);
2080 Inst.setOpcode(ARM::t2PLDi12);
2081 Inst.addOperand(MCOperand::CreateReg(ARM::PC));
2087 int imm = fieldFromInstruction32(Insn, 0, 12);
2088 if (!fieldFromInstruction32(Insn, 23, 1)) imm *= -1;
2089 Inst.addOperand(MCOperand::CreateImm(imm));
2094 unsigned addrmode = fieldFromInstruction32(Insn, 4, 2);
2095 addrmode |= fieldFromInstruction32(Insn, 0, 4) << 2;
2096 addrmode |= fieldFromInstruction32(Insn, 16, 4) << 6;
2097 DecodeT2AddrModeSOReg(Inst, addrmode, Address, Decoder);
2102 static bool DecodeT2Imm8S4(llvm::MCInst &Inst, unsigned Val,
2103 uint64_t Address, const void *Decoder) {
2104 int imm = Val & 0xFF;
2105 if (!(Val & 0x100)) imm *= -1;
2106 Inst.addOperand(MCOperand::CreateImm(imm << 2));
2111 static bool DecodeT2AddrModeImm8s4(llvm::MCInst &Inst, unsigned Val,
2112 uint64_t Address, const void *Decoder) {
2113 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2114 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2116 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
2117 DecodeT2Imm8S4(Inst, imm, Address, Decoder);
2122 static bool DecodeT2Imm8(llvm::MCInst &Inst, unsigned Val,
2123 uint64_t Address, const void *Decoder) {
2124 int imm = Val & 0xFF;
2125 if (!(Val & 0x100)) imm *= -1;
2126 Inst.addOperand(MCOperand::CreateImm(imm));
2132 static bool DecodeT2AddrModeImm8(llvm::MCInst &Inst, unsigned Val,
2133 uint64_t Address, const void *Decoder) {
2134 unsigned Rn = fieldFromInstruction32(Val, 9, 4);
2135 unsigned imm = fieldFromInstruction32(Val, 0, 9);
2137 // Some instructions always use an additive offset.
2138 switch (Inst.getOpcode()) {
2150 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
2151 DecodeT2Imm8(Inst, imm, Address, Decoder);
2157 static bool DecodeT2AddrModeImm12(llvm::MCInst &Inst, unsigned Val,
2158 uint64_t Address, const void *Decoder) {
2159 unsigned Rn = fieldFromInstruction32(Val, 13, 4);
2160 unsigned imm = fieldFromInstruction32(Val, 0, 12);
2162 DecodeGPRRegisterClass(Inst, Rn, Address, Decoder);
2163 Inst.addOperand(MCOperand::CreateImm(imm));
2169 static bool DecodeThumbAddSPImm(llvm::MCInst &Inst, uint16_t Insn,
2170 uint64_t Address, const void *Decoder) {
2171 unsigned imm = fieldFromInstruction16(Insn, 0, 7);
2173 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2174 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2175 Inst.addOperand(MCOperand::CreateImm(imm));
2180 static bool DecodeThumbAddSPReg(llvm::MCInst &Inst, uint16_t Insn,
2181 uint64_t Address, const void *Decoder) {
2182 if (Inst.getOpcode() == ARM::tADDrSP) {
2183 unsigned Rdm = fieldFromInstruction16(Insn, 0, 3);
2184 Rdm |= fieldFromInstruction16(Insn, 7, 1) << 3;
2186 DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder);
2187 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2188 DecodeGPRRegisterClass(Inst, Rdm, Address, Decoder);
2189 } else if (Inst.getOpcode() == ARM::tADDspr) {
2190 unsigned Rm = fieldFromInstruction16(Insn, 3, 4);
2192 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2193 Inst.addOperand(MCOperand::CreateReg(ARM::SP));
2194 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
2200 static bool DecodeThumbCPS(llvm::MCInst &Inst, uint16_t Insn,
2201 uint64_t Address, const void *Decoder) {
2202 unsigned imod = fieldFromInstruction16(Insn, 4, 1) | 0x2;
2203 unsigned flags = fieldFromInstruction16(Insn, 0, 3);
2205 Inst.addOperand(MCOperand::CreateImm(imod));
2206 Inst.addOperand(MCOperand::CreateImm(flags));
2211 static bool DecodePostIdxReg(llvm::MCInst &Inst, unsigned Insn,
2212 uint64_t Address, const void *Decoder) {
2213 unsigned Rm = fieldFromInstruction32(Insn, 0, 4);
2214 unsigned add = fieldFromInstruction32(Insn, 4, 1);
2216 DecodeGPRRegisterClass(Inst, Rm, Address, Decoder);
2217 Inst.addOperand(MCOperand::CreateImm(add));
2222 static bool DecodeThumbBLXOffset(llvm::MCInst &Inst, unsigned Val,
2223 uint64_t Address, const void *Decoder) {
2224 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2228 static bool DecodeCoprocessor(llvm::MCInst &Inst, unsigned Val,
2229 uint64_t Address, const void *Decoder) {
2230 if (Val == 0xA || Val == 0xB)
2233 Inst.addOperand(MCOperand::CreateImm(Val));
2237 static bool DecodeThumbSRImm(llvm::MCInst &Inst, unsigned Val,
2238 uint64_t Address, const void *Decoder) {
2240 Inst.addOperand(MCOperand::CreateImm(32));
2242 Inst.addOperand(MCOperand::CreateImm(Val));
2246 static bool DecodeThumb2BCCInstruction(llvm::MCInst &Inst, unsigned Insn,
2247 uint64_t Address, const void *Decoder) {
2248 unsigned pred = fieldFromInstruction32(Insn, 22, 4);
2249 if (pred == 0xE || pred == 0xF) {
2250 unsigned opc = fieldFromInstruction32(Insn, 4, 2);
2255 Inst.setOpcode(ARM::t2DSB);
2258 Inst.setOpcode(ARM::t2DMB);
2261 Inst.setOpcode(ARM::t2ISB);
2265 unsigned imm = fieldFromInstruction32(Insn, 0, 4);
2266 Inst.addOperand(MCOperand::CreateImm(imm));
2270 unsigned brtarget = fieldFromInstruction32(Insn, 0, 11) << 1;
2271 brtarget |= fieldFromInstruction32(Insn, 11, 1) << 19;
2272 brtarget |= fieldFromInstruction32(Insn, 13, 1) << 18;
2273 brtarget |= fieldFromInstruction32(Insn, 16, 6) << 12;
2274 brtarget |= fieldFromInstruction32(Insn, 26, 1) << 20;
2276 DecodeT2BROperand(Inst, brtarget, Address, Decoder);
2277 if (!DecodePredicateOperand(Inst, pred, Address, Decoder))
2283 // Decode a shifted immediate operand. These basically consist
2284 // of an 8-bit value, and a 4-bit directive that specifies either
2285 // a splat operation or a rotation.
2286 static bool DecodeT2SOImm(llvm::MCInst &Inst, unsigned Val,
2287 uint64_t Address, const void *Decoder) {
2288 unsigned ctrl = fieldFromInstruction32(Val, 10, 2);
2290 unsigned byte = fieldFromInstruction32(Val, 8, 2);
2291 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2294 Inst.addOperand(MCOperand::CreateImm(imm));
2297 Inst.addOperand(MCOperand::CreateImm((imm << 16) | imm));
2300 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 8)));
2303 Inst.addOperand(MCOperand::CreateImm((imm << 24) | (imm << 16) |
2308 unsigned unrot = fieldFromInstruction32(Val, 0, 7) | 0x80;
2309 unsigned rot = fieldFromInstruction32(Val, 7, 5);
2310 unsigned imm = (unrot >> rot) | (unrot << ((32-rot)&31));
2311 Inst.addOperand(MCOperand::CreateImm(imm));
2317 static bool DecodeThumbBCCTargetOperand(llvm::MCInst &Inst, unsigned Val,
2318 uint64_t Address, const void *Decoder){
2319 Inst.addOperand(MCOperand::CreateImm(Val << 1));
2323 static bool DecodeThumbBLTargetOperand(llvm::MCInst &Inst, unsigned Val,
2324 uint64_t Address, const void *Decoder){
2325 Inst.addOperand(MCOperand::CreateImm(SignExtend32<22>(Val << 1)));
2329 static bool DecodeAddrMode3Offset(llvm::MCInst &Inst, unsigned Val,
2330 uint64_t Address, const void *Decoder) {
2331 bool isImm = fieldFromInstruction32(Val, 9, 1);
2332 bool isAdd = fieldFromInstruction32(Val, 8, 1);
2333 unsigned imm = fieldFromInstruction32(Val, 0, 8);
2336 DecodeGPRRegisterClass(Inst, imm, Address, Decoder);
2337 Inst.addOperand(MCOperand::CreateImm(!isAdd << 8));
2339 Inst.addOperand(MCOperand::CreateReg(0));
2340 Inst.addOperand(MCOperand::CreateImm(imm | (!isAdd << 8)));