1 //===- ARMDisassembler.cpp - Disassembler for ARM/Thumb ISA ---------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "MCTargetDesc/ARMAddressingModes.h"
10 #include "MCTargetDesc/ARMBaseInfo.h"
11 #include "MCTargetDesc/ARMMCTargetDesc.h"
12 #include "Utils/ARMBaseInfo.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
15 #include "llvm/MC/MCFixedLenDisassembler.h"
16 #include "llvm/MC/MCInst.h"
17 #include "llvm/MC/MCInstrDesc.h"
18 #include "llvm/MC/MCSubtargetInfo.h"
19 #include "llvm/MC/SubtargetFeature.h"
20 #include "llvm/Support/Compiler.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/MathExtras.h"
23 #include "llvm/Support/TargetRegistry.h"
24 #include "llvm/Support/raw_ostream.h"
32 #define DEBUG_TYPE "arm-disassembler"
34 using DecodeStatus
= MCDisassembler::DecodeStatus
;
38 // Handles the condition code status of instructions in IT blocks
42 // Returns the condition code for instruction in IT block
44 unsigned CC
= ARMCC::AL
;
50 // Advances the IT block state to the next T or E
51 void advanceITState() {
55 // Returns true if the current instruction is in an IT block
56 bool instrInITBlock() {
57 return !ITStates
.empty();
60 // Returns true if current instruction is the last instruction in an IT block
61 bool instrLastInITBlock() {
62 return ITStates
.size() == 1;
65 // Called when decoding an IT instruction. Sets the IT state for the following
66 // instructions that for the IT block. Firstcond and Mask correspond to the
67 // fields in the IT instruction encoding.
68 void setITState(char Firstcond
, char Mask
) {
69 // (3 - the number of trailing zeros) is the number of then / else.
70 unsigned CondBit0
= Firstcond
& 1;
71 unsigned NumTZ
= countTrailingZeros
<uint8_t>(Mask
);
72 unsigned char CCBits
= static_cast<unsigned char>(Firstcond
& 0xf);
73 assert(NumTZ
<= 3 && "Invalid IT mask!");
74 // push condition codes onto the stack the correct order for the pops
75 for (unsigned Pos
= NumTZ
+1; Pos
<= 3; ++Pos
) {
76 bool T
= ((Mask
>> Pos
) & 1) == CondBit0
;
78 ITStates
.push_back(CCBits
);
80 ITStates
.push_back(CCBits
^ 1);
82 ITStates
.push_back(CCBits
);
86 std::vector
<unsigned char> ITStates
;
89 /// ARM disassembler for all ARM platforms.
90 class ARMDisassembler
: public MCDisassembler
{
92 ARMDisassembler(const MCSubtargetInfo
&STI
, MCContext
&Ctx
) :
93 MCDisassembler(STI
, Ctx
) {
96 ~ARMDisassembler() override
= default;
98 DecodeStatus
getInstruction(MCInst
&Instr
, uint64_t &Size
,
99 ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
100 raw_ostream
&VStream
,
101 raw_ostream
&CStream
) const override
;
104 /// Thumb disassembler for all Thumb platforms.
105 class ThumbDisassembler
: public MCDisassembler
{
107 ThumbDisassembler(const MCSubtargetInfo
&STI
, MCContext
&Ctx
) :
108 MCDisassembler(STI
, Ctx
) {
111 ~ThumbDisassembler() override
= default;
113 DecodeStatus
getInstruction(MCInst
&Instr
, uint64_t &Size
,
114 ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
115 raw_ostream
&VStream
,
116 raw_ostream
&CStream
) const override
;
119 mutable ITStatus ITBlock
;
121 DecodeStatus
AddThumbPredicate(MCInst
&) const;
122 void UpdateThumbVFPPredicate(MCInst
&) const;
125 } // end anonymous namespace
127 static bool Check(DecodeStatus
&Out
, DecodeStatus In
) {
129 case MCDisassembler::Success
:
130 // Out stays the same.
132 case MCDisassembler::SoftFail
:
135 case MCDisassembler::Fail
:
139 llvm_unreachable("Invalid DecodeStatus!");
142 // Forward declare these because the autogenerated code will reference them.
143 // Definitions are further down.
144 static DecodeStatus
DecodeGPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
145 uint64_t Address
, const void *Decoder
);
146 static DecodeStatus
DecodeGPRnopcRegisterClass(MCInst
&Inst
,
147 unsigned RegNo
, uint64_t Address
,
148 const void *Decoder
);
149 static DecodeStatus
DecodeGPRwithAPSRRegisterClass(MCInst
&Inst
,
150 unsigned RegNo
, uint64_t Address
,
151 const void *Decoder
);
152 static DecodeStatus
DecodetGPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
153 uint64_t Address
, const void *Decoder
);
154 static DecodeStatus
DecodetcGPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
155 uint64_t Address
, const void *Decoder
);
156 static DecodeStatus
DecoderGPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
157 uint64_t Address
, const void *Decoder
);
158 static DecodeStatus
DecodeGPRPairRegisterClass(MCInst
&Inst
, unsigned RegNo
,
159 uint64_t Address
, const void *Decoder
);
160 static DecodeStatus
DecodeHPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
161 uint64_t Address
, const void *Decoder
);
162 static DecodeStatus
DecodeSPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
163 uint64_t Address
, const void *Decoder
);
164 static DecodeStatus
DecodeDPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
165 uint64_t Address
, const void *Decoder
);
166 static DecodeStatus
DecodeDPR_8RegisterClass(MCInst
&Inst
, unsigned RegNo
,
167 uint64_t Address
, const void *Decoder
);
168 static DecodeStatus
DecodeDPR_VFP2RegisterClass(MCInst
&Inst
,
171 const void *Decoder
);
172 static DecodeStatus
DecodeQPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
173 uint64_t Address
, const void *Decoder
);
174 static DecodeStatus
DecodeDPairRegisterClass(MCInst
&Inst
, unsigned RegNo
,
175 uint64_t Address
, const void *Decoder
);
176 static DecodeStatus
DecodeDPairSpacedRegisterClass(MCInst
&Inst
,
177 unsigned RegNo
, uint64_t Address
,
178 const void *Decoder
);
180 static DecodeStatus
DecodePredicateOperand(MCInst
&Inst
, unsigned Val
,
181 uint64_t Address
, const void *Decoder
);
182 static DecodeStatus
DecodeCCOutOperand(MCInst
&Inst
, unsigned Val
,
183 uint64_t Address
, const void *Decoder
);
184 static DecodeStatus
DecodeRegListOperand(MCInst
&Inst
, unsigned Val
,
185 uint64_t Address
, const void *Decoder
);
186 static DecodeStatus
DecodeSPRRegListOperand(MCInst
&Inst
, unsigned Val
,
187 uint64_t Address
, const void *Decoder
);
188 static DecodeStatus
DecodeDPRRegListOperand(MCInst
&Inst
, unsigned Val
,
189 uint64_t Address
, const void *Decoder
);
191 static DecodeStatus
DecodeBitfieldMaskOperand(MCInst
&Inst
, unsigned Insn
,
192 uint64_t Address
, const void *Decoder
);
193 static DecodeStatus
DecodeCopMemInstruction(MCInst
&Inst
, unsigned Insn
,
194 uint64_t Address
, const void *Decoder
);
195 static DecodeStatus
DecodeAddrMode2IdxInstruction(MCInst
&Inst
,
198 const void *Decoder
);
199 static DecodeStatus
DecodeSORegMemOperand(MCInst
&Inst
, unsigned Insn
,
200 uint64_t Address
, const void *Decoder
);
201 static DecodeStatus
DecodeAddrMode3Instruction(MCInst
&Inst
,unsigned Insn
,
202 uint64_t Address
, const void *Decoder
);
203 static DecodeStatus
DecodeSORegImmOperand(MCInst
&Inst
, unsigned Insn
,
204 uint64_t Address
, const void *Decoder
);
205 static DecodeStatus
DecodeSORegRegOperand(MCInst
&Inst
, unsigned Insn
,
206 uint64_t Address
, const void *Decoder
);
208 static DecodeStatus
DecodeMemMultipleWritebackInstruction(MCInst
& Inst
,
211 const void *Decoder
);
212 static DecodeStatus
DecodeT2MOVTWInstruction(MCInst
&Inst
, unsigned Insn
,
213 uint64_t Address
, const void *Decoder
);
214 static DecodeStatus
DecodeArmMOVTWInstruction(MCInst
&Inst
, unsigned Insn
,
215 uint64_t Address
, const void *Decoder
);
216 static DecodeStatus
DecodeSMLAInstruction(MCInst
&Inst
, unsigned Insn
,
217 uint64_t Address
, const void *Decoder
);
218 static DecodeStatus
DecodeHINTInstruction(MCInst
&Inst
, unsigned Insn
,
219 uint64_t Address
, const void *Decoder
);
220 static DecodeStatus
DecodeCPSInstruction(MCInst
&Inst
, unsigned Insn
,
221 uint64_t Address
, const void *Decoder
);
222 static DecodeStatus
DecodeTSTInstruction(MCInst
&Inst
, unsigned Insn
,
223 uint64_t Address
, const void *Decoder
);
224 static DecodeStatus
DecodeSETPANInstruction(MCInst
&Inst
, unsigned Insn
,
225 uint64_t Address
, const void *Decoder
);
226 static DecodeStatus
DecodeT2CPSInstruction(MCInst
&Inst
, unsigned Insn
,
227 uint64_t Address
, const void *Decoder
);
228 static DecodeStatus
DecodeAddrModeImm12Operand(MCInst
&Inst
, unsigned Val
,
229 uint64_t Address
, const void *Decoder
);
230 static DecodeStatus
DecodeAddrMode5Operand(MCInst
&Inst
, unsigned Val
,
231 uint64_t Address
, const void *Decoder
);
232 static DecodeStatus
DecodeAddrMode5FP16Operand(MCInst
&Inst
, unsigned Val
,
233 uint64_t Address
, const void *Decoder
);
234 static DecodeStatus
DecodeAddrMode7Operand(MCInst
&Inst
, unsigned Val
,
235 uint64_t Address
, const void *Decoder
);
236 static DecodeStatus
DecodeT2BInstruction(MCInst
&Inst
, unsigned Insn
,
237 uint64_t Address
, const void *Decoder
);
238 static DecodeStatus
DecodeBranchImmInstruction(MCInst
&Inst
,unsigned Insn
,
239 uint64_t Address
, const void *Decoder
);
240 static DecodeStatus
DecodeAddrMode6Operand(MCInst
&Inst
, unsigned Val
,
241 uint64_t Address
, const void *Decoder
);
242 static DecodeStatus
DecodeVLDST1Instruction(MCInst
&Inst
, unsigned Val
,
243 uint64_t Address
, const void *Decoder
);
244 static DecodeStatus
DecodeVLDST2Instruction(MCInst
&Inst
, unsigned Val
,
245 uint64_t Address
, const void *Decoder
);
246 static DecodeStatus
DecodeVLDST3Instruction(MCInst
&Inst
, unsigned Val
,
247 uint64_t Address
, const void *Decoder
);
248 static DecodeStatus
DecodeVLDST4Instruction(MCInst
&Inst
, unsigned Val
,
249 uint64_t Address
, const void *Decoder
);
250 static DecodeStatus
DecodeVLDInstruction(MCInst
&Inst
, unsigned Val
,
251 uint64_t Address
, const void *Decoder
);
252 static DecodeStatus
DecodeVSTInstruction(MCInst
&Inst
, unsigned Val
,
253 uint64_t Address
, const void *Decoder
);
254 static DecodeStatus
DecodeVLD1DupInstruction(MCInst
&Inst
, unsigned Val
,
255 uint64_t Address
, const void *Decoder
);
256 static DecodeStatus
DecodeVLD2DupInstruction(MCInst
&Inst
, unsigned Val
,
257 uint64_t Address
, const void *Decoder
);
258 static DecodeStatus
DecodeVLD3DupInstruction(MCInst
&Inst
, unsigned Val
,
259 uint64_t Address
, const void *Decoder
);
260 static DecodeStatus
DecodeVLD4DupInstruction(MCInst
&Inst
, unsigned Val
,
261 uint64_t Address
, const void *Decoder
);
262 static DecodeStatus
DecodeNEONModImmInstruction(MCInst
&Inst
,unsigned Val
,
263 uint64_t Address
, const void *Decoder
);
264 static DecodeStatus
DecodeVSHLMaxInstruction(MCInst
&Inst
, unsigned Val
,
265 uint64_t Address
, const void *Decoder
);
266 static DecodeStatus
DecodeShiftRight8Imm(MCInst
&Inst
, unsigned Val
,
267 uint64_t Address
, const void *Decoder
);
268 static DecodeStatus
DecodeShiftRight16Imm(MCInst
&Inst
, unsigned Val
,
269 uint64_t Address
, const void *Decoder
);
270 static DecodeStatus
DecodeShiftRight32Imm(MCInst
&Inst
, unsigned Val
,
271 uint64_t Address
, const void *Decoder
);
272 static DecodeStatus
DecodeShiftRight64Imm(MCInst
&Inst
, unsigned Val
,
273 uint64_t Address
, const void *Decoder
);
274 static DecodeStatus
DecodeTBLInstruction(MCInst
&Inst
, unsigned Insn
,
275 uint64_t Address
, const void *Decoder
);
276 static DecodeStatus
DecodePostIdxReg(MCInst
&Inst
, unsigned Insn
,
277 uint64_t Address
, const void *Decoder
);
278 static DecodeStatus
DecodeCoprocessor(MCInst
&Inst
, unsigned Insn
,
279 uint64_t Address
, const void *Decoder
);
280 static DecodeStatus
DecodeMemBarrierOption(MCInst
&Inst
, unsigned Insn
,
281 uint64_t Address
, const void *Decoder
);
282 static DecodeStatus
DecodeInstSyncBarrierOption(MCInst
&Inst
, unsigned Insn
,
283 uint64_t Address
, const void *Decoder
);
284 static DecodeStatus
DecodeMSRMask(MCInst
&Inst
, unsigned Insn
,
285 uint64_t Address
, const void *Decoder
);
286 static DecodeStatus
DecodeBankedReg(MCInst
&Inst
, unsigned Insn
,
287 uint64_t Address
, const void *Decoder
);
288 static DecodeStatus
DecodeDoubleRegLoad(MCInst
&Inst
, unsigned Insn
,
289 uint64_t Address
, const void *Decoder
);
290 static DecodeStatus
DecodeDoubleRegStore(MCInst
&Inst
, unsigned Insn
,
291 uint64_t Address
, const void *Decoder
);
292 static DecodeStatus
DecodeLDRPreImm(MCInst
&Inst
, unsigned Insn
,
293 uint64_t Address
, const void *Decoder
);
294 static DecodeStatus
DecodeLDRPreReg(MCInst
&Inst
, unsigned Insn
,
295 uint64_t Address
, const void *Decoder
);
296 static DecodeStatus
DecodeSTRPreImm(MCInst
&Inst
, unsigned Insn
,
297 uint64_t Address
, const void *Decoder
);
298 static DecodeStatus
DecodeSTRPreReg(MCInst
&Inst
, unsigned Insn
,
299 uint64_t Address
, const void *Decoder
);
300 static DecodeStatus
DecodeVLD1LN(MCInst
&Inst
, unsigned Insn
,
301 uint64_t Address
, const void *Decoder
);
302 static DecodeStatus
DecodeVLD2LN(MCInst
&Inst
, unsigned Insn
,
303 uint64_t Address
, const void *Decoder
);
304 static DecodeStatus
DecodeVLD3LN(MCInst
&Inst
, unsigned Insn
,
305 uint64_t Address
, const void *Decoder
);
306 static DecodeStatus
DecodeVLD4LN(MCInst
&Inst
, unsigned Insn
,
307 uint64_t Address
, const void *Decoder
);
308 static DecodeStatus
DecodeVST1LN(MCInst
&Inst
, unsigned Insn
,
309 uint64_t Address
, const void *Decoder
);
310 static DecodeStatus
DecodeVST2LN(MCInst
&Inst
, unsigned Insn
,
311 uint64_t Address
, const void *Decoder
);
312 static DecodeStatus
DecodeVST3LN(MCInst
&Inst
, unsigned Insn
,
313 uint64_t Address
, const void *Decoder
);
314 static DecodeStatus
DecodeVST4LN(MCInst
&Inst
, unsigned Insn
,
315 uint64_t Address
, const void *Decoder
);
316 static DecodeStatus
DecodeVMOVSRR(MCInst
&Inst
, unsigned Insn
,
317 uint64_t Address
, const void *Decoder
);
318 static DecodeStatus
DecodeVMOVRRS(MCInst
&Inst
, unsigned Insn
,
319 uint64_t Address
, const void *Decoder
);
320 static DecodeStatus
DecodeSwap(MCInst
&Inst
, unsigned Insn
,
321 uint64_t Address
, const void *Decoder
);
322 static DecodeStatus
DecodeVCVTD(MCInst
&Inst
, unsigned Insn
,
323 uint64_t Address
, const void *Decoder
);
324 static DecodeStatus
DecodeVCVTQ(MCInst
&Inst
, unsigned Insn
,
325 uint64_t Address
, const void *Decoder
);
326 static DecodeStatus
DecodeNEONComplexLane64Instruction(MCInst
&Inst
,
329 const void *Decoder
);
331 static DecodeStatus
DecodeThumbAddSpecialReg(MCInst
&Inst
, uint16_t Insn
,
332 uint64_t Address
, const void *Decoder
);
333 static DecodeStatus
DecodeThumbBROperand(MCInst
&Inst
, unsigned Val
,
334 uint64_t Address
, const void *Decoder
);
335 static DecodeStatus
DecodeT2BROperand(MCInst
&Inst
, unsigned Val
,
336 uint64_t Address
, const void *Decoder
);
337 static DecodeStatus
DecodeThumbCmpBROperand(MCInst
&Inst
, unsigned Val
,
338 uint64_t Address
, const void *Decoder
);
339 static DecodeStatus
DecodeThumbAddrModeRR(MCInst
&Inst
, unsigned Val
,
340 uint64_t Address
, const void *Decoder
);
341 static DecodeStatus
DecodeThumbAddrModeIS(MCInst
&Inst
, unsigned Val
,
342 uint64_t Address
, const void *Decoder
);
343 static DecodeStatus
DecodeThumbAddrModePC(MCInst
&Inst
, unsigned Val
,
344 uint64_t Address
, const void *Decoder
);
345 static DecodeStatus
DecodeThumbAddrModeSP(MCInst
&Inst
, unsigned Val
,
346 uint64_t Address
, const void *Decoder
);
347 static DecodeStatus
DecodeT2AddrModeSOReg(MCInst
&Inst
, unsigned Val
,
348 uint64_t Address
, const void *Decoder
);
349 static DecodeStatus
DecodeT2LoadShift(MCInst
&Inst
, unsigned Val
,
350 uint64_t Address
, const void *Decoder
);
351 static DecodeStatus
DecodeT2LoadImm8(MCInst
&Inst
, unsigned Insn
,
352 uint64_t Address
, const void* Decoder
);
353 static DecodeStatus
DecodeT2LoadImm12(MCInst
&Inst
, unsigned Insn
,
354 uint64_t Address
, const void* Decoder
);
355 static DecodeStatus
DecodeT2LoadT(MCInst
&Inst
, unsigned Insn
,
356 uint64_t Address
, const void* Decoder
);
357 static DecodeStatus
DecodeT2LoadLabel(MCInst
&Inst
, unsigned Insn
,
358 uint64_t Address
, const void* Decoder
);
359 static DecodeStatus
DecodeT2Imm8S4(MCInst
&Inst
, unsigned Val
,
360 uint64_t Address
, const void *Decoder
);
361 static DecodeStatus
DecodeT2AddrModeImm8s4(MCInst
&Inst
, unsigned Val
,
362 uint64_t Address
, const void *Decoder
);
363 static DecodeStatus
DecodeT2AddrModeImm0_1020s4(MCInst
&Inst
,unsigned Val
,
364 uint64_t Address
, const void *Decoder
);
365 static DecodeStatus
DecodeT2Imm8(MCInst
&Inst
, unsigned Val
,
366 uint64_t Address
, const void *Decoder
);
367 static DecodeStatus
DecodeT2AddrModeImm8(MCInst
&Inst
, unsigned Val
,
368 uint64_t Address
, const void *Decoder
);
369 static DecodeStatus
DecodeThumbAddSPImm(MCInst
&Inst
, uint16_t Val
,
370 uint64_t Address
, const void *Decoder
);
371 static DecodeStatus
DecodeThumbAddSPReg(MCInst
&Inst
, uint16_t Insn
,
372 uint64_t Address
, const void *Decoder
);
373 static DecodeStatus
DecodeThumbCPS(MCInst
&Inst
, uint16_t Insn
,
374 uint64_t Address
, const void *Decoder
);
375 static DecodeStatus
DecodeQADDInstruction(MCInst
&Inst
, unsigned Insn
,
376 uint64_t Address
, const void *Decoder
);
377 static DecodeStatus
DecodeThumbBLXOffset(MCInst
&Inst
, unsigned Insn
,
378 uint64_t Address
, const void *Decoder
);
379 static DecodeStatus
DecodeT2AddrModeImm12(MCInst
&Inst
, unsigned Val
,
380 uint64_t Address
, const void *Decoder
);
381 static DecodeStatus
DecodeThumbTableBranch(MCInst
&Inst
, unsigned Val
,
382 uint64_t Address
, const void *Decoder
);
383 static DecodeStatus
DecodeThumb2BCCInstruction(MCInst
&Inst
, unsigned Val
,
384 uint64_t Address
, const void *Decoder
);
385 static DecodeStatus
DecodeT2SOImm(MCInst
&Inst
, unsigned Val
,
386 uint64_t Address
, const void *Decoder
);
387 static DecodeStatus
DecodeThumbBCCTargetOperand(MCInst
&Inst
,unsigned Val
,
388 uint64_t Address
, const void *Decoder
);
389 static DecodeStatus
DecodeThumbBLTargetOperand(MCInst
&Inst
, unsigned Val
,
390 uint64_t Address
, const void *Decoder
);
391 static DecodeStatus
DecodeIT(MCInst
&Inst
, unsigned Val
,
392 uint64_t Address
, const void *Decoder
);
393 static DecodeStatus
DecodeT2LDRDPreInstruction(MCInst
&Inst
,unsigned Insn
,
394 uint64_t Address
, const void *Decoder
);
395 static DecodeStatus
DecodeT2STRDPreInstruction(MCInst
&Inst
,unsigned Insn
,
396 uint64_t Address
, const void *Decoder
);
397 static DecodeStatus
DecodeT2Adr(MCInst
&Inst
, unsigned Val
,
398 uint64_t Address
, const void *Decoder
);
399 static DecodeStatus
DecodeT2LdStPre(MCInst
&Inst
, unsigned Val
,
400 uint64_t Address
, const void *Decoder
);
401 static DecodeStatus
DecodeT2ShifterImmOperand(MCInst
&Inst
, unsigned Val
,
402 uint64_t Address
, const void *Decoder
);
404 static DecodeStatus
DecodeLDR(MCInst
&Inst
, unsigned Val
,
405 uint64_t Address
, const void *Decoder
);
406 static DecodeStatus
DecoderForMRRC2AndMCRR2(MCInst
&Inst
, unsigned Val
,
407 uint64_t Address
, const void *Decoder
);
408 static DecodeStatus
DecodeForVMRSandVMSR(MCInst
&Inst
, unsigned Val
,
409 uint64_t Address
, const void *Decoder
);
411 #include "ARMGenDisassemblerTables.inc"
413 static MCDisassembler
*createARMDisassembler(const Target
&T
,
414 const MCSubtargetInfo
&STI
,
416 return new ARMDisassembler(STI
, Ctx
);
419 static MCDisassembler
*createThumbDisassembler(const Target
&T
,
420 const MCSubtargetInfo
&STI
,
422 return new ThumbDisassembler(STI
, Ctx
);
425 // Post-decoding checks
426 static DecodeStatus
checkDecodedInstruction(MCInst
&MI
, uint64_t &Size
,
427 uint64_t Address
, raw_ostream
&OS
,
430 DecodeStatus Result
) {
431 switch (MI
.getOpcode()) {
433 // HVC is undefined if condition = 0xf otherwise upredictable
434 // if condition != 0xe
435 uint32_t Cond
= (Insn
>> 28) & 0xF;
437 return MCDisassembler::Fail
;
439 return MCDisassembler::SoftFail
;
442 default: return Result
;
446 DecodeStatus
ARMDisassembler::getInstruction(MCInst
&MI
, uint64_t &Size
,
447 ArrayRef
<uint8_t> Bytes
,
448 uint64_t Address
, raw_ostream
&OS
,
449 raw_ostream
&CS
) const {
452 assert(!STI
.getFeatureBits()[ARM::ModeThumb
] &&
453 "Asked to disassemble an ARM instruction but Subtarget is in Thumb "
456 // We want to read exactly 4 bytes of data.
457 if (Bytes
.size() < 4) {
459 return MCDisassembler::Fail
;
462 // Encoded as a small-endian 32-bit word in the stream.
464 (Bytes
[3] << 24) | (Bytes
[2] << 16) | (Bytes
[1] << 8) | (Bytes
[0] << 0);
466 // Calling the auto-generated decoder function.
467 DecodeStatus Result
=
468 decodeInstruction(DecoderTableARM32
, MI
, Insn
, Address
, this, STI
);
469 if (Result
!= MCDisassembler::Fail
) {
471 return checkDecodedInstruction(MI
, Size
, Address
, OS
, CS
, Insn
, Result
);
479 const DecodeTable Tables
[] = {
480 {DecoderTableVFP32
, false}, {DecoderTableVFPV832
, false},
481 {DecoderTableNEONData32
, true}, {DecoderTableNEONLoadStore32
, true},
482 {DecoderTableNEONDup32
, true}, {DecoderTablev8NEON32
, false},
483 {DecoderTablev8Crypto32
, false},
486 for (auto Table
: Tables
) {
487 Result
= decodeInstruction(Table
.P
, MI
, Insn
, Address
, this, STI
);
488 if (Result
!= MCDisassembler::Fail
) {
490 // Add a fake predicate operand, because we share these instruction
491 // definitions with Thumb2 where these instructions are predicable.
492 if (Table
.DecodePred
&& !DecodePredicateOperand(MI
, 0xE, Address
, this))
493 return MCDisassembler::Fail
;
499 decodeInstruction(DecoderTableCoProc32
, MI
, Insn
, Address
, this, STI
);
500 if (Result
!= MCDisassembler::Fail
) {
502 return checkDecodedInstruction(MI
, Size
, Address
, OS
, CS
, Insn
, Result
);
506 return MCDisassembler::Fail
;
511 extern const MCInstrDesc ARMInsts
[];
513 } // end namespace llvm
515 /// tryAddingSymbolicOperand - trys to add a symbolic operand in place of the
516 /// immediate Value in the MCInst. The immediate Value has had any PC
517 /// adjustment made by the caller. If the instruction is a branch instruction
518 /// then isBranch is true, else false. If the getOpInfo() function was set as
519 /// part of the setupForSymbolicDisassembly() call then that function is called
520 /// to get any symbolic information at the Address for this instruction. If
521 /// that returns non-zero then the symbolic information it returns is used to
522 /// create an MCExpr and that is added as an operand to the MCInst. If
523 /// getOpInfo() returns zero and isBranch is true then a symbol look up for
524 /// Value is done and if a symbol is found an MCExpr is created with that, else
525 /// an MCExpr with Value is created. This function returns true if it adds an
526 /// operand to the MCInst and false otherwise.
527 static bool tryAddingSymbolicOperand(uint64_t Address
, int32_t Value
,
528 bool isBranch
, uint64_t InstSize
,
529 MCInst
&MI
, const void *Decoder
) {
530 const MCDisassembler
*Dis
= static_cast<const MCDisassembler
*>(Decoder
);
531 // FIXME: Does it make sense for value to be negative?
532 return Dis
->tryAddingSymbolicOperand(MI
, (uint32_t)Value
, Address
, isBranch
,
533 /* Offset */ 0, InstSize
);
536 /// tryAddingPcLoadReferenceComment - trys to add a comment as to what is being
537 /// referenced by a load instruction with the base register that is the Pc.
538 /// These can often be values in a literal pool near the Address of the
539 /// instruction. The Address of the instruction and its immediate Value are
540 /// used as a possible literal pool entry. The SymbolLookUp call back will
541 /// return the name of a symbol referenced by the literal pool's entry if
542 /// the referenced address is that of a symbol. Or it will return a pointer to
543 /// a literal 'C' string if the referenced address of the literal pool's entry
544 /// is an address into a section with 'C' string literals.
545 static void tryAddingPcLoadReferenceComment(uint64_t Address
, int Value
,
546 const void *Decoder
) {
547 const MCDisassembler
*Dis
= static_cast<const MCDisassembler
*>(Decoder
);
548 Dis
->tryAddingPcLoadReferenceComment(Value
, Address
);
551 // Thumb1 instructions don't have explicit S bits. Rather, they
552 // implicitly set CPSR. Since it's not represented in the encoding, the
553 // auto-generated decoder won't inject the CPSR operand. We need to fix
554 // that as a post-pass.
555 static void AddThumb1SBit(MCInst
&MI
, bool InITBlock
) {
556 const MCOperandInfo
*OpInfo
= ARMInsts
[MI
.getOpcode()].OpInfo
;
557 unsigned short NumOps
= ARMInsts
[MI
.getOpcode()].NumOperands
;
558 MCInst::iterator I
= MI
.begin();
559 for (unsigned i
= 0; i
< NumOps
; ++i
, ++I
) {
560 if (I
== MI
.end()) break;
561 if (OpInfo
[i
].isOptionalDef() && OpInfo
[i
].RegClass
== ARM::CCRRegClassID
) {
562 if (i
> 0 && OpInfo
[i
-1].isPredicate()) continue;
563 MI
.insert(I
, MCOperand::createReg(InITBlock
? 0 : ARM::CPSR
));
568 MI
.insert(I
, MCOperand::createReg(InITBlock
? 0 : ARM::CPSR
));
571 // Most Thumb instructions don't have explicit predicates in the
572 // encoding, but rather get their predicates from IT context. We need
573 // to fix up the predicate operands using this context information as a
575 MCDisassembler::DecodeStatus
576 ThumbDisassembler::AddThumbPredicate(MCInst
&MI
) const {
577 MCDisassembler::DecodeStatus S
= Success
;
579 const FeatureBitset
&FeatureBits
= getSubtargetInfo().getFeatureBits();
581 // A few instructions actually have predicates encoded in them. Don't
582 // try to overwrite it if we're seeing one of those.
583 switch (MI
.getOpcode()) {
594 // Some instructions (mostly conditional branches) are not
595 // allowed in IT blocks.
596 if (ITBlock
.instrInITBlock())
602 if (MI
.getOperand(0).getImm() == 0x10 && (FeatureBits
[ARM::FeatureRAS
]) != 0)
609 // Some instructions (mostly unconditional branches) can
610 // only appears at the end of, or outside of, an IT.
611 if (ITBlock
.instrInITBlock() && !ITBlock
.instrLastInITBlock())
618 // If we're in an IT block, base the predicate on that. Otherwise,
619 // assume a predicate of AL.
621 CC
= ITBlock
.getITCC();
624 if (ITBlock
.instrInITBlock())
625 ITBlock
.advanceITState();
627 const MCOperandInfo
*OpInfo
= ARMInsts
[MI
.getOpcode()].OpInfo
;
628 unsigned short NumOps
= ARMInsts
[MI
.getOpcode()].NumOperands
;
629 MCInst::iterator I
= MI
.begin();
630 for (unsigned i
= 0; i
< NumOps
; ++i
, ++I
) {
631 if (I
== MI
.end()) break;
632 if (OpInfo
[i
].isPredicate()) {
633 I
= MI
.insert(I
, MCOperand::createImm(CC
));
636 MI
.insert(I
, MCOperand::createReg(0));
638 MI
.insert(I
, MCOperand::createReg(ARM::CPSR
));
643 I
= MI
.insert(I
, MCOperand::createImm(CC
));
646 MI
.insert(I
, MCOperand::createReg(0));
648 MI
.insert(I
, MCOperand::createReg(ARM::CPSR
));
653 // Thumb VFP instructions are a special case. Because we share their
654 // encodings between ARM and Thumb modes, and they are predicable in ARM
655 // mode, the auto-generated decoder will give them an (incorrect)
656 // predicate operand. We need to rewrite these operands based on the IT
657 // context as a post-pass.
658 void ThumbDisassembler::UpdateThumbVFPPredicate(MCInst
&MI
) const {
660 CC
= ITBlock
.getITCC();
663 if (ITBlock
.instrInITBlock())
664 ITBlock
.advanceITState();
666 const MCOperandInfo
*OpInfo
= ARMInsts
[MI
.getOpcode()].OpInfo
;
667 MCInst::iterator I
= MI
.begin();
668 unsigned short NumOps
= ARMInsts
[MI
.getOpcode()].NumOperands
;
669 for (unsigned i
= 0; i
< NumOps
; ++i
, ++I
) {
670 if (OpInfo
[i
].isPredicate() ) {
676 I
->setReg(ARM::CPSR
);
682 DecodeStatus
ThumbDisassembler::getInstruction(MCInst
&MI
, uint64_t &Size
,
683 ArrayRef
<uint8_t> Bytes
,
686 raw_ostream
&CS
) const {
689 assert(STI
.getFeatureBits()[ARM::ModeThumb
] &&
690 "Asked to disassemble in Thumb mode but Subtarget is in ARM mode!");
692 // We want to read exactly 2 bytes of data.
693 if (Bytes
.size() < 2) {
695 return MCDisassembler::Fail
;
698 uint16_t Insn16
= (Bytes
[1] << 8) | Bytes
[0];
699 DecodeStatus Result
=
700 decodeInstruction(DecoderTableThumb16
, MI
, Insn16
, Address
, this, STI
);
701 if (Result
!= MCDisassembler::Fail
) {
703 Check(Result
, AddThumbPredicate(MI
));
707 Result
= decodeInstruction(DecoderTableThumbSBit16
, MI
, Insn16
, Address
, this,
711 bool InITBlock
= ITBlock
.instrInITBlock();
712 Check(Result
, AddThumbPredicate(MI
));
713 AddThumb1SBit(MI
, InITBlock
);
718 decodeInstruction(DecoderTableThumb216
, MI
, Insn16
, Address
, this, STI
);
719 if (Result
!= MCDisassembler::Fail
) {
722 // Nested IT blocks are UNPREDICTABLE. Must be checked before we add
723 // the Thumb predicate.
724 if (MI
.getOpcode() == ARM::t2IT
&& ITBlock
.instrInITBlock())
725 Result
= MCDisassembler::SoftFail
;
727 Check(Result
, AddThumbPredicate(MI
));
729 // If we find an IT instruction, we need to parse its condition
730 // code and mask operands so that we can apply them correctly
731 // to the subsequent instructions.
732 if (MI
.getOpcode() == ARM::t2IT
) {
733 unsigned Firstcond
= MI
.getOperand(0).getImm();
734 unsigned Mask
= MI
.getOperand(1).getImm();
735 ITBlock
.setITState(Firstcond
, Mask
);
737 // An IT instruction that would give a 'NV' predicate is unpredictable.
738 if (Firstcond
== ARMCC::AL
&& !isPowerOf2_32(Mask
))
739 CS
<< "unpredictable IT predicate sequence";
745 // We want to read exactly 4 bytes of data.
746 if (Bytes
.size() < 4) {
748 return MCDisassembler::Fail
;
752 (Bytes
[3] << 8) | (Bytes
[2] << 0) | (Bytes
[1] << 24) | (Bytes
[0] << 16);
754 decodeInstruction(DecoderTableThumb32
, MI
, Insn32
, Address
, this, STI
);
755 if (Result
!= MCDisassembler::Fail
) {
757 bool InITBlock
= ITBlock
.instrInITBlock();
758 Check(Result
, AddThumbPredicate(MI
));
759 AddThumb1SBit(MI
, InITBlock
);
764 decodeInstruction(DecoderTableThumb232
, MI
, Insn32
, Address
, this, STI
);
765 if (Result
!= MCDisassembler::Fail
) {
767 Check(Result
, AddThumbPredicate(MI
));
771 if (fieldFromInstruction(Insn32
, 28, 4) == 0xE) {
773 decodeInstruction(DecoderTableVFP32
, MI
, Insn32
, Address
, this, STI
);
774 if (Result
!= MCDisassembler::Fail
) {
776 UpdateThumbVFPPredicate(MI
);
782 decodeInstruction(DecoderTableVFPV832
, MI
, Insn32
, Address
, this, STI
);
783 if (Result
!= MCDisassembler::Fail
) {
788 if (fieldFromInstruction(Insn32
, 28, 4) == 0xE) {
789 Result
= decodeInstruction(DecoderTableNEONDup32
, MI
, Insn32
, Address
, this,
791 if (Result
!= MCDisassembler::Fail
) {
793 Check(Result
, AddThumbPredicate(MI
));
798 if (fieldFromInstruction(Insn32
, 24, 8) == 0xF9) {
799 uint32_t NEONLdStInsn
= Insn32
;
800 NEONLdStInsn
&= 0xF0FFFFFF;
801 NEONLdStInsn
|= 0x04000000;
802 Result
= decodeInstruction(DecoderTableNEONLoadStore32
, MI
, NEONLdStInsn
,
804 if (Result
!= MCDisassembler::Fail
) {
806 Check(Result
, AddThumbPredicate(MI
));
811 if (fieldFromInstruction(Insn32
, 24, 4) == 0xF) {
812 uint32_t NEONDataInsn
= Insn32
;
813 NEONDataInsn
&= 0xF0FFFFFF; // Clear bits 27-24
814 NEONDataInsn
|= (NEONDataInsn
& 0x10000000) >> 4; // Move bit 28 to bit 24
815 NEONDataInsn
|= 0x12000000; // Set bits 28 and 25
816 Result
= decodeInstruction(DecoderTableNEONData32
, MI
, NEONDataInsn
,
818 if (Result
!= MCDisassembler::Fail
) {
820 Check(Result
, AddThumbPredicate(MI
));
824 uint32_t NEONCryptoInsn
= Insn32
;
825 NEONCryptoInsn
&= 0xF0FFFFFF; // Clear bits 27-24
826 NEONCryptoInsn
|= (NEONCryptoInsn
& 0x10000000) >> 4; // Move bit 28 to bit 24
827 NEONCryptoInsn
|= 0x12000000; // Set bits 28 and 25
828 Result
= decodeInstruction(DecoderTablev8Crypto32
, MI
, NEONCryptoInsn
,
830 if (Result
!= MCDisassembler::Fail
) {
835 uint32_t NEONv8Insn
= Insn32
;
836 NEONv8Insn
&= 0xF3FFFFFF; // Clear bits 27-26
837 Result
= decodeInstruction(DecoderTablev8NEON32
, MI
, NEONv8Insn
, Address
,
839 if (Result
!= MCDisassembler::Fail
) {
846 decodeInstruction(DecoderTableThumb2CoProc32
, MI
, Insn32
, Address
, this, STI
);
847 if (Result
!= MCDisassembler::Fail
) {
849 Check(Result
, AddThumbPredicate(MI
));
854 return MCDisassembler::Fail
;
857 extern "C" void LLVMInitializeARMDisassembler() {
858 TargetRegistry::RegisterMCDisassembler(getTheARMLETarget(),
859 createARMDisassembler
);
860 TargetRegistry::RegisterMCDisassembler(getTheARMBETarget(),
861 createARMDisassembler
);
862 TargetRegistry::RegisterMCDisassembler(getTheThumbLETarget(),
863 createThumbDisassembler
);
864 TargetRegistry::RegisterMCDisassembler(getTheThumbBETarget(),
865 createThumbDisassembler
);
868 static const uint16_t GPRDecoderTable
[] = {
869 ARM::R0
, ARM::R1
, ARM::R2
, ARM::R3
,
870 ARM::R4
, ARM::R5
, ARM::R6
, ARM::R7
,
871 ARM::R8
, ARM::R9
, ARM::R10
, ARM::R11
,
872 ARM::R12
, ARM::SP
, ARM::LR
, ARM::PC
875 static DecodeStatus
DecodeGPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
876 uint64_t Address
, const void *Decoder
) {
878 return MCDisassembler::Fail
;
880 unsigned Register
= GPRDecoderTable
[RegNo
];
881 Inst
.addOperand(MCOperand::createReg(Register
));
882 return MCDisassembler::Success
;
886 DecodeGPRnopcRegisterClass(MCInst
&Inst
, unsigned RegNo
,
887 uint64_t Address
, const void *Decoder
) {
888 DecodeStatus S
= MCDisassembler::Success
;
891 S
= MCDisassembler::SoftFail
;
893 Check(S
, DecodeGPRRegisterClass(Inst
, RegNo
, Address
, Decoder
));
899 DecodeGPRwithAPSRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
900 uint64_t Address
, const void *Decoder
) {
901 DecodeStatus S
= MCDisassembler::Success
;
905 Inst
.addOperand(MCOperand::createReg(ARM::APSR_NZCV
));
906 return MCDisassembler::Success
;
909 Check(S
, DecodeGPRRegisterClass(Inst
, RegNo
, Address
, Decoder
));
913 static DecodeStatus
DecodetGPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
914 uint64_t Address
, const void *Decoder
) {
916 return MCDisassembler::Fail
;
917 return DecodeGPRRegisterClass(Inst
, RegNo
, Address
, Decoder
);
920 static const uint16_t GPRPairDecoderTable
[] = {
921 ARM::R0_R1
, ARM::R2_R3
, ARM::R4_R5
, ARM::R6_R7
,
922 ARM::R8_R9
, ARM::R10_R11
, ARM::R12_SP
925 static DecodeStatus
DecodeGPRPairRegisterClass(MCInst
&Inst
, unsigned RegNo
,
926 uint64_t Address
, const void *Decoder
) {
927 DecodeStatus S
= MCDisassembler::Success
;
930 return MCDisassembler::Fail
;
932 if ((RegNo
& 1) || RegNo
== 0xe)
933 S
= MCDisassembler::SoftFail
;
935 unsigned RegisterPair
= GPRPairDecoderTable
[RegNo
/2];
936 Inst
.addOperand(MCOperand::createReg(RegisterPair
));
940 static DecodeStatus
DecodetcGPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
941 uint64_t Address
, const void *Decoder
) {
942 unsigned Register
= 0;
963 return MCDisassembler::Fail
;
966 Inst
.addOperand(MCOperand::createReg(Register
));
967 return MCDisassembler::Success
;
970 static DecodeStatus
DecoderGPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
971 uint64_t Address
, const void *Decoder
) {
972 DecodeStatus S
= MCDisassembler::Success
;
974 const FeatureBitset
&featureBits
=
975 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
977 if ((RegNo
== 13 && !featureBits
[ARM::HasV8Ops
]) || RegNo
== 15)
978 S
= MCDisassembler::SoftFail
;
980 Check(S
, DecodeGPRRegisterClass(Inst
, RegNo
, Address
, Decoder
));
984 static const uint16_t SPRDecoderTable
[] = {
985 ARM::S0
, ARM::S1
, ARM::S2
, ARM::S3
,
986 ARM::S4
, ARM::S5
, ARM::S6
, ARM::S7
,
987 ARM::S8
, ARM::S9
, ARM::S10
, ARM::S11
,
988 ARM::S12
, ARM::S13
, ARM::S14
, ARM::S15
,
989 ARM::S16
, ARM::S17
, ARM::S18
, ARM::S19
,
990 ARM::S20
, ARM::S21
, ARM::S22
, ARM::S23
,
991 ARM::S24
, ARM::S25
, ARM::S26
, ARM::S27
,
992 ARM::S28
, ARM::S29
, ARM::S30
, ARM::S31
995 static DecodeStatus
DecodeSPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
996 uint64_t Address
, const void *Decoder
) {
998 return MCDisassembler::Fail
;
1000 unsigned Register
= SPRDecoderTable
[RegNo
];
1001 Inst
.addOperand(MCOperand::createReg(Register
));
1002 return MCDisassembler::Success
;
1005 static DecodeStatus
DecodeHPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
1006 uint64_t Address
, const void *Decoder
) {
1007 return DecodeSPRRegisterClass(Inst
, RegNo
, Address
, Decoder
);
1010 static const uint16_t DPRDecoderTable
[] = {
1011 ARM::D0
, ARM::D1
, ARM::D2
, ARM::D3
,
1012 ARM::D4
, ARM::D5
, ARM::D6
, ARM::D7
,
1013 ARM::D8
, ARM::D9
, ARM::D10
, ARM::D11
,
1014 ARM::D12
, ARM::D13
, ARM::D14
, ARM::D15
,
1015 ARM::D16
, ARM::D17
, ARM::D18
, ARM::D19
,
1016 ARM::D20
, ARM::D21
, ARM::D22
, ARM::D23
,
1017 ARM::D24
, ARM::D25
, ARM::D26
, ARM::D27
,
1018 ARM::D28
, ARM::D29
, ARM::D30
, ARM::D31
1021 static DecodeStatus
DecodeDPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
1022 uint64_t Address
, const void *Decoder
) {
1023 const FeatureBitset
&featureBits
=
1024 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
1026 bool hasD16
= featureBits
[ARM::FeatureD16
];
1028 if (RegNo
> 31 || (hasD16
&& RegNo
> 15))
1029 return MCDisassembler::Fail
;
1031 unsigned Register
= DPRDecoderTable
[RegNo
];
1032 Inst
.addOperand(MCOperand::createReg(Register
));
1033 return MCDisassembler::Success
;
1036 static DecodeStatus
DecodeDPR_8RegisterClass(MCInst
&Inst
, unsigned RegNo
,
1037 uint64_t Address
, const void *Decoder
) {
1039 return MCDisassembler::Fail
;
1040 return DecodeDPRRegisterClass(Inst
, RegNo
, Address
, Decoder
);
1044 DecodeDPR_VFP2RegisterClass(MCInst
&Inst
, unsigned RegNo
,
1045 uint64_t Address
, const void *Decoder
) {
1047 return MCDisassembler::Fail
;
1048 return DecodeDPRRegisterClass(Inst
, RegNo
, Address
, Decoder
);
1051 static const uint16_t QPRDecoderTable
[] = {
1052 ARM::Q0
, ARM::Q1
, ARM::Q2
, ARM::Q3
,
1053 ARM::Q4
, ARM::Q5
, ARM::Q6
, ARM::Q7
,
1054 ARM::Q8
, ARM::Q9
, ARM::Q10
, ARM::Q11
,
1055 ARM::Q12
, ARM::Q13
, ARM::Q14
, ARM::Q15
1058 static DecodeStatus
DecodeQPRRegisterClass(MCInst
&Inst
, unsigned RegNo
,
1059 uint64_t Address
, const void *Decoder
) {
1060 if (RegNo
> 31 || (RegNo
& 1) != 0)
1061 return MCDisassembler::Fail
;
1064 unsigned Register
= QPRDecoderTable
[RegNo
];
1065 Inst
.addOperand(MCOperand::createReg(Register
));
1066 return MCDisassembler::Success
;
1069 static const uint16_t DPairDecoderTable
[] = {
1070 ARM::Q0
, ARM::D1_D2
, ARM::Q1
, ARM::D3_D4
, ARM::Q2
, ARM::D5_D6
,
1071 ARM::Q3
, ARM::D7_D8
, ARM::Q4
, ARM::D9_D10
, ARM::Q5
, ARM::D11_D12
,
1072 ARM::Q6
, ARM::D13_D14
, ARM::Q7
, ARM::D15_D16
, ARM::Q8
, ARM::D17_D18
,
1073 ARM::Q9
, ARM::D19_D20
, ARM::Q10
, ARM::D21_D22
, ARM::Q11
, ARM::D23_D24
,
1074 ARM::Q12
, ARM::D25_D26
, ARM::Q13
, ARM::D27_D28
, ARM::Q14
, ARM::D29_D30
,
1078 static DecodeStatus
DecodeDPairRegisterClass(MCInst
&Inst
, unsigned RegNo
,
1079 uint64_t Address
, const void *Decoder
) {
1081 return MCDisassembler::Fail
;
1083 unsigned Register
= DPairDecoderTable
[RegNo
];
1084 Inst
.addOperand(MCOperand::createReg(Register
));
1085 return MCDisassembler::Success
;
1088 static const uint16_t DPairSpacedDecoderTable
[] = {
1089 ARM::D0_D2
, ARM::D1_D3
, ARM::D2_D4
, ARM::D3_D5
,
1090 ARM::D4_D6
, ARM::D5_D7
, ARM::D6_D8
, ARM::D7_D9
,
1091 ARM::D8_D10
, ARM::D9_D11
, ARM::D10_D12
, ARM::D11_D13
,
1092 ARM::D12_D14
, ARM::D13_D15
, ARM::D14_D16
, ARM::D15_D17
,
1093 ARM::D16_D18
, ARM::D17_D19
, ARM::D18_D20
, ARM::D19_D21
,
1094 ARM::D20_D22
, ARM::D21_D23
, ARM::D22_D24
, ARM::D23_D25
,
1095 ARM::D24_D26
, ARM::D25_D27
, ARM::D26_D28
, ARM::D27_D29
,
1096 ARM::D28_D30
, ARM::D29_D31
1099 static DecodeStatus
DecodeDPairSpacedRegisterClass(MCInst
&Inst
,
1102 const void *Decoder
) {
1104 return MCDisassembler::Fail
;
1106 unsigned Register
= DPairSpacedDecoderTable
[RegNo
];
1107 Inst
.addOperand(MCOperand::createReg(Register
));
1108 return MCDisassembler::Success
;
1111 static DecodeStatus
DecodePredicateOperand(MCInst
&Inst
, unsigned Val
,
1112 uint64_t Address
, const void *Decoder
) {
1113 if (Val
== 0xF) return MCDisassembler::Fail
;
1114 // AL predicate is not allowed on Thumb1 branches.
1115 if (Inst
.getOpcode() == ARM::tBcc
&& Val
== 0xE)
1116 return MCDisassembler::Fail
;
1117 Inst
.addOperand(MCOperand::createImm(Val
));
1118 if (Val
== ARMCC::AL
) {
1119 Inst
.addOperand(MCOperand::createReg(0));
1121 Inst
.addOperand(MCOperand::createReg(ARM::CPSR
));
1122 return MCDisassembler::Success
;
1125 static DecodeStatus
DecodeCCOutOperand(MCInst
&Inst
, unsigned Val
,
1126 uint64_t Address
, const void *Decoder
) {
1128 Inst
.addOperand(MCOperand::createReg(ARM::CPSR
));
1130 Inst
.addOperand(MCOperand::createReg(0));
1131 return MCDisassembler::Success
;
1134 static DecodeStatus
DecodeSORegImmOperand(MCInst
&Inst
, unsigned Val
,
1135 uint64_t Address
, const void *Decoder
) {
1136 DecodeStatus S
= MCDisassembler::Success
;
1138 unsigned Rm
= fieldFromInstruction(Val
, 0, 4);
1139 unsigned type
= fieldFromInstruction(Val
, 5, 2);
1140 unsigned imm
= fieldFromInstruction(Val
, 7, 5);
1142 // Register-immediate
1143 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
1144 return MCDisassembler::Fail
;
1146 ARM_AM::ShiftOpc Shift
= ARM_AM::lsl
;
1149 Shift
= ARM_AM::lsl
;
1152 Shift
= ARM_AM::lsr
;
1155 Shift
= ARM_AM::asr
;
1158 Shift
= ARM_AM::ror
;
1162 if (Shift
== ARM_AM::ror
&& imm
== 0)
1163 Shift
= ARM_AM::rrx
;
1165 unsigned Op
= Shift
| (imm
<< 3);
1166 Inst
.addOperand(MCOperand::createImm(Op
));
1171 static DecodeStatus
DecodeSORegRegOperand(MCInst
&Inst
, unsigned Val
,
1172 uint64_t Address
, const void *Decoder
) {
1173 DecodeStatus S
= MCDisassembler::Success
;
1175 unsigned Rm
= fieldFromInstruction(Val
, 0, 4);
1176 unsigned type
= fieldFromInstruction(Val
, 5, 2);
1177 unsigned Rs
= fieldFromInstruction(Val
, 8, 4);
1179 // Register-register
1180 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rm
, Address
, Decoder
)))
1181 return MCDisassembler::Fail
;
1182 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rs
, Address
, Decoder
)))
1183 return MCDisassembler::Fail
;
1185 ARM_AM::ShiftOpc Shift
= ARM_AM::lsl
;
1188 Shift
= ARM_AM::lsl
;
1191 Shift
= ARM_AM::lsr
;
1194 Shift
= ARM_AM::asr
;
1197 Shift
= ARM_AM::ror
;
1201 Inst
.addOperand(MCOperand::createImm(Shift
));
1206 static DecodeStatus
DecodeRegListOperand(MCInst
&Inst
, unsigned Val
,
1207 uint64_t Address
, const void *Decoder
) {
1208 DecodeStatus S
= MCDisassembler::Success
;
1210 bool NeedDisjointWriteback
= false;
1211 unsigned WritebackReg
= 0;
1212 switch (Inst
.getOpcode()) {
1215 case ARM::LDMIA_UPD
:
1216 case ARM::LDMDB_UPD
:
1217 case ARM::LDMIB_UPD
:
1218 case ARM::LDMDA_UPD
:
1219 case ARM::t2LDMIA_UPD
:
1220 case ARM::t2LDMDB_UPD
:
1221 case ARM::t2STMIA_UPD
:
1222 case ARM::t2STMDB_UPD
:
1223 NeedDisjointWriteback
= true;
1224 WritebackReg
= Inst
.getOperand(0).getReg();
1228 // Empty register lists are not allowed.
1229 if (Val
== 0) return MCDisassembler::Fail
;
1230 for (unsigned i
= 0; i
< 16; ++i
) {
1231 if (Val
& (1 << i
)) {
1232 if (!Check(S
, DecodeGPRRegisterClass(Inst
, i
, Address
, Decoder
)))
1233 return MCDisassembler::Fail
;
1234 // Writeback not allowed if Rn is in the target list.
1235 if (NeedDisjointWriteback
&& WritebackReg
== Inst
.end()[-1].getReg())
1236 Check(S
, MCDisassembler::SoftFail
);
1243 static DecodeStatus
DecodeSPRRegListOperand(MCInst
&Inst
, unsigned Val
,
1244 uint64_t Address
, const void *Decoder
) {
1245 DecodeStatus S
= MCDisassembler::Success
;
1247 unsigned Vd
= fieldFromInstruction(Val
, 8, 5);
1248 unsigned regs
= fieldFromInstruction(Val
, 0, 8);
1250 // In case of unpredictable encoding, tweak the operands.
1251 if (regs
== 0 || (Vd
+ regs
) > 32) {
1252 regs
= Vd
+ regs
> 32 ? 32 - Vd
: regs
;
1253 regs
= std::max( 1u, regs
);
1254 S
= MCDisassembler::SoftFail
;
1257 if (!Check(S
, DecodeSPRRegisterClass(Inst
, Vd
, Address
, Decoder
)))
1258 return MCDisassembler::Fail
;
1259 for (unsigned i
= 0; i
< (regs
- 1); ++i
) {
1260 if (!Check(S
, DecodeSPRRegisterClass(Inst
, ++Vd
, Address
, Decoder
)))
1261 return MCDisassembler::Fail
;
1267 static DecodeStatus
DecodeDPRRegListOperand(MCInst
&Inst
, unsigned Val
,
1268 uint64_t Address
, const void *Decoder
) {
1269 DecodeStatus S
= MCDisassembler::Success
;
1271 unsigned Vd
= fieldFromInstruction(Val
, 8, 5);
1272 unsigned regs
= fieldFromInstruction(Val
, 1, 7);
1274 // In case of unpredictable encoding, tweak the operands.
1275 if (regs
== 0 || regs
> 16 || (Vd
+ regs
) > 32) {
1276 regs
= Vd
+ regs
> 32 ? 32 - Vd
: regs
;
1277 regs
= std::max( 1u, regs
);
1278 regs
= std::min(16u, regs
);
1279 S
= MCDisassembler::SoftFail
;
1282 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Vd
, Address
, Decoder
)))
1283 return MCDisassembler::Fail
;
1284 for (unsigned i
= 0; i
< (regs
- 1); ++i
) {
1285 if (!Check(S
, DecodeDPRRegisterClass(Inst
, ++Vd
, Address
, Decoder
)))
1286 return MCDisassembler::Fail
;
1292 static DecodeStatus
DecodeBitfieldMaskOperand(MCInst
&Inst
, unsigned Val
,
1293 uint64_t Address
, const void *Decoder
) {
1294 // This operand encodes a mask of contiguous zeros between a specified MSB
1295 // and LSB. To decode it, we create the mask of all bits MSB-and-lower,
1296 // the mask of all bits LSB-and-lower, and then xor them to create
1297 // the mask of that's all ones on [msb, lsb]. Finally we not it to
1298 // create the final mask.
1299 unsigned msb
= fieldFromInstruction(Val
, 5, 5);
1300 unsigned lsb
= fieldFromInstruction(Val
, 0, 5);
1302 DecodeStatus S
= MCDisassembler::Success
;
1304 Check(S
, MCDisassembler::SoftFail
);
1305 // The check above will cause the warning for the "potentially undefined
1306 // instruction encoding" but we can't build a bad MCOperand value here
1307 // with a lsb > msb or else printing the MCInst will cause a crash.
1311 uint32_t msb_mask
= 0xFFFFFFFF;
1312 if (msb
!= 31) msb_mask
= (1U << (msb
+1)) - 1;
1313 uint32_t lsb_mask
= (1U << lsb
) - 1;
1315 Inst
.addOperand(MCOperand::createImm(~(msb_mask
^ lsb_mask
)));
1319 static DecodeStatus
DecodeCopMemInstruction(MCInst
&Inst
, unsigned Insn
,
1320 uint64_t Address
, const void *Decoder
) {
1321 DecodeStatus S
= MCDisassembler::Success
;
1323 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
1324 unsigned CRd
= fieldFromInstruction(Insn
, 12, 4);
1325 unsigned coproc
= fieldFromInstruction(Insn
, 8, 4);
1326 unsigned imm
= fieldFromInstruction(Insn
, 0, 8);
1327 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
1328 unsigned U
= fieldFromInstruction(Insn
, 23, 1);
1330 switch (Inst
.getOpcode()) {
1331 case ARM::LDC_OFFSET
:
1334 case ARM::LDC_OPTION
:
1335 case ARM::LDCL_OFFSET
:
1337 case ARM::LDCL_POST
:
1338 case ARM::LDCL_OPTION
:
1339 case ARM::STC_OFFSET
:
1342 case ARM::STC_OPTION
:
1343 case ARM::STCL_OFFSET
:
1345 case ARM::STCL_POST
:
1346 case ARM::STCL_OPTION
:
1347 case ARM::t2LDC_OFFSET
:
1348 case ARM::t2LDC_PRE
:
1349 case ARM::t2LDC_POST
:
1350 case ARM::t2LDC_OPTION
:
1351 case ARM::t2LDCL_OFFSET
:
1352 case ARM::t2LDCL_PRE
:
1353 case ARM::t2LDCL_POST
:
1354 case ARM::t2LDCL_OPTION
:
1355 case ARM::t2STC_OFFSET
:
1356 case ARM::t2STC_PRE
:
1357 case ARM::t2STC_POST
:
1358 case ARM::t2STC_OPTION
:
1359 case ARM::t2STCL_OFFSET
:
1360 case ARM::t2STCL_PRE
:
1361 case ARM::t2STCL_POST
:
1362 case ARM::t2STCL_OPTION
:
1363 if (coproc
== 0xA || coproc
== 0xB)
1364 return MCDisassembler::Fail
;
1370 const FeatureBitset
&featureBits
=
1371 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
1372 if (featureBits
[ARM::HasV8Ops
] && (coproc
!= 14))
1373 return MCDisassembler::Fail
;
1375 Inst
.addOperand(MCOperand::createImm(coproc
));
1376 Inst
.addOperand(MCOperand::createImm(CRd
));
1377 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1378 return MCDisassembler::Fail
;
1380 switch (Inst
.getOpcode()) {
1381 case ARM::t2LDC2_OFFSET
:
1382 case ARM::t2LDC2L_OFFSET
:
1383 case ARM::t2LDC2_PRE
:
1384 case ARM::t2LDC2L_PRE
:
1385 case ARM::t2STC2_OFFSET
:
1386 case ARM::t2STC2L_OFFSET
:
1387 case ARM::t2STC2_PRE
:
1388 case ARM::t2STC2L_PRE
:
1389 case ARM::LDC2_OFFSET
:
1390 case ARM::LDC2L_OFFSET
:
1392 case ARM::LDC2L_PRE
:
1393 case ARM::STC2_OFFSET
:
1394 case ARM::STC2L_OFFSET
:
1396 case ARM::STC2L_PRE
:
1397 case ARM::t2LDC_OFFSET
:
1398 case ARM::t2LDCL_OFFSET
:
1399 case ARM::t2LDC_PRE
:
1400 case ARM::t2LDCL_PRE
:
1401 case ARM::t2STC_OFFSET
:
1402 case ARM::t2STCL_OFFSET
:
1403 case ARM::t2STC_PRE
:
1404 case ARM::t2STCL_PRE
:
1405 case ARM::LDC_OFFSET
:
1406 case ARM::LDCL_OFFSET
:
1409 case ARM::STC_OFFSET
:
1410 case ARM::STCL_OFFSET
:
1413 imm
= ARM_AM::getAM5Opc(U
? ARM_AM::add
: ARM_AM::sub
, imm
);
1414 Inst
.addOperand(MCOperand::createImm(imm
));
1416 case ARM::t2LDC2_POST
:
1417 case ARM::t2LDC2L_POST
:
1418 case ARM::t2STC2_POST
:
1419 case ARM::t2STC2L_POST
:
1420 case ARM::LDC2_POST
:
1421 case ARM::LDC2L_POST
:
1422 case ARM::STC2_POST
:
1423 case ARM::STC2L_POST
:
1424 case ARM::t2LDC_POST
:
1425 case ARM::t2LDCL_POST
:
1426 case ARM::t2STC_POST
:
1427 case ARM::t2STCL_POST
:
1429 case ARM::LDCL_POST
:
1431 case ARM::STCL_POST
:
1435 // The 'option' variant doesn't encode 'U' in the immediate since
1436 // the immediate is unsigned [0,255].
1437 Inst
.addOperand(MCOperand::createImm(imm
));
1441 switch (Inst
.getOpcode()) {
1442 case ARM::LDC_OFFSET
:
1445 case ARM::LDC_OPTION
:
1446 case ARM::LDCL_OFFSET
:
1448 case ARM::LDCL_POST
:
1449 case ARM::LDCL_OPTION
:
1450 case ARM::STC_OFFSET
:
1453 case ARM::STC_OPTION
:
1454 case ARM::STCL_OFFSET
:
1456 case ARM::STCL_POST
:
1457 case ARM::STCL_OPTION
:
1458 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
1459 return MCDisassembler::Fail
;
1469 DecodeAddrMode2IdxInstruction(MCInst
&Inst
, unsigned Insn
,
1470 uint64_t Address
, const void *Decoder
) {
1471 DecodeStatus S
= MCDisassembler::Success
;
1473 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
1474 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
1475 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
1476 unsigned imm
= fieldFromInstruction(Insn
, 0, 12);
1477 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
1478 unsigned reg
= fieldFromInstruction(Insn
, 25, 1);
1479 unsigned P
= fieldFromInstruction(Insn
, 24, 1);
1480 unsigned W
= fieldFromInstruction(Insn
, 21, 1);
1482 // On stores, the writeback operand precedes Rt.
1483 switch (Inst
.getOpcode()) {
1484 case ARM::STR_POST_IMM
:
1485 case ARM::STR_POST_REG
:
1486 case ARM::STRB_POST_IMM
:
1487 case ARM::STRB_POST_REG
:
1488 case ARM::STRT_POST_REG
:
1489 case ARM::STRT_POST_IMM
:
1490 case ARM::STRBT_POST_REG
:
1491 case ARM::STRBT_POST_IMM
:
1492 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1493 return MCDisassembler::Fail
;
1499 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
1500 return MCDisassembler::Fail
;
1502 // On loads, the writeback operand comes after Rt.
1503 switch (Inst
.getOpcode()) {
1504 case ARM::LDR_POST_IMM
:
1505 case ARM::LDR_POST_REG
:
1506 case ARM::LDRB_POST_IMM
:
1507 case ARM::LDRB_POST_REG
:
1508 case ARM::LDRBT_POST_REG
:
1509 case ARM::LDRBT_POST_IMM
:
1510 case ARM::LDRT_POST_REG
:
1511 case ARM::LDRT_POST_IMM
:
1512 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1513 return MCDisassembler::Fail
;
1519 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1520 return MCDisassembler::Fail
;
1522 ARM_AM::AddrOpc Op
= ARM_AM::add
;
1523 if (!fieldFromInstruction(Insn
, 23, 1))
1526 bool writeback
= (P
== 0) || (W
== 1);
1527 unsigned idx_mode
= 0;
1529 idx_mode
= ARMII::IndexModePre
;
1530 else if (!P
&& writeback
)
1531 idx_mode
= ARMII::IndexModePost
;
1533 if (writeback
&& (Rn
== 15 || Rn
== Rt
))
1534 S
= MCDisassembler::SoftFail
; // UNPREDICTABLE
1537 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rm
, Address
, Decoder
)))
1538 return MCDisassembler::Fail
;
1539 ARM_AM::ShiftOpc Opc
= ARM_AM::lsl
;
1540 switch( fieldFromInstruction(Insn
, 5, 2)) {
1554 return MCDisassembler::Fail
;
1556 unsigned amt
= fieldFromInstruction(Insn
, 7, 5);
1557 if (Opc
== ARM_AM::ror
&& amt
== 0)
1559 unsigned imm
= ARM_AM::getAM2Opc(Op
, amt
, Opc
, idx_mode
);
1561 Inst
.addOperand(MCOperand::createImm(imm
));
1563 Inst
.addOperand(MCOperand::createReg(0));
1564 unsigned tmp
= ARM_AM::getAM2Opc(Op
, imm
, ARM_AM::lsl
, idx_mode
);
1565 Inst
.addOperand(MCOperand::createImm(tmp
));
1568 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
1569 return MCDisassembler::Fail
;
1574 static DecodeStatus
DecodeSORegMemOperand(MCInst
&Inst
, unsigned Val
,
1575 uint64_t Address
, const void *Decoder
) {
1576 DecodeStatus S
= MCDisassembler::Success
;
1578 unsigned Rn
= fieldFromInstruction(Val
, 13, 4);
1579 unsigned Rm
= fieldFromInstruction(Val
, 0, 4);
1580 unsigned type
= fieldFromInstruction(Val
, 5, 2);
1581 unsigned imm
= fieldFromInstruction(Val
, 7, 5);
1582 unsigned U
= fieldFromInstruction(Val
, 12, 1);
1584 ARM_AM::ShiftOpc ShOp
= ARM_AM::lsl
;
1600 if (ShOp
== ARM_AM::ror
&& imm
== 0)
1603 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1604 return MCDisassembler::Fail
;
1605 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
1606 return MCDisassembler::Fail
;
1609 shift
= ARM_AM::getAM2Opc(ARM_AM::add
, imm
, ShOp
);
1611 shift
= ARM_AM::getAM2Opc(ARM_AM::sub
, imm
, ShOp
);
1612 Inst
.addOperand(MCOperand::createImm(shift
));
1618 DecodeAddrMode3Instruction(MCInst
&Inst
, unsigned Insn
,
1619 uint64_t Address
, const void *Decoder
) {
1620 DecodeStatus S
= MCDisassembler::Success
;
1622 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
1623 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
1624 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
1625 unsigned type
= fieldFromInstruction(Insn
, 22, 1);
1626 unsigned imm
= fieldFromInstruction(Insn
, 8, 4);
1627 unsigned U
= ((~fieldFromInstruction(Insn
, 23, 1)) & 1) << 8;
1628 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
1629 unsigned W
= fieldFromInstruction(Insn
, 21, 1);
1630 unsigned P
= fieldFromInstruction(Insn
, 24, 1);
1631 unsigned Rt2
= Rt
+ 1;
1633 bool writeback
= (W
== 1) | (P
== 0);
1635 // For {LD,ST}RD, Rt must be even, else undefined.
1636 switch (Inst
.getOpcode()) {
1639 case ARM::STRD_POST
:
1642 case ARM::LDRD_POST
:
1643 if (Rt
& 0x1) S
= MCDisassembler::SoftFail
;
1648 switch (Inst
.getOpcode()) {
1651 case ARM::STRD_POST
:
1652 if (P
== 0 && W
== 1)
1653 S
= MCDisassembler::SoftFail
;
1655 if (writeback
&& (Rn
== 15 || Rn
== Rt
|| Rn
== Rt2
))
1656 S
= MCDisassembler::SoftFail
;
1657 if (type
&& Rm
== 15)
1658 S
= MCDisassembler::SoftFail
;
1660 S
= MCDisassembler::SoftFail
;
1661 if (!type
&& fieldFromInstruction(Insn
, 8, 4))
1662 S
= MCDisassembler::SoftFail
;
1666 case ARM::STRH_POST
:
1668 S
= MCDisassembler::SoftFail
;
1669 if (writeback
&& (Rn
== 15 || Rn
== Rt
))
1670 S
= MCDisassembler::SoftFail
;
1671 if (!type
&& Rm
== 15)
1672 S
= MCDisassembler::SoftFail
;
1676 case ARM::LDRD_POST
:
1677 if (type
&& Rn
== 15) {
1679 S
= MCDisassembler::SoftFail
;
1682 if (P
== 0 && W
== 1)
1683 S
= MCDisassembler::SoftFail
;
1684 if (!type
&& (Rt2
== 15 || Rm
== 15 || Rm
== Rt
|| Rm
== Rt2
))
1685 S
= MCDisassembler::SoftFail
;
1686 if (!type
&& writeback
&& Rn
== 15)
1687 S
= MCDisassembler::SoftFail
;
1688 if (writeback
&& (Rn
== Rt
|| Rn
== Rt2
))
1689 S
= MCDisassembler::SoftFail
;
1693 case ARM::LDRH_POST
:
1694 if (type
&& Rn
== 15) {
1696 S
= MCDisassembler::SoftFail
;
1700 S
= MCDisassembler::SoftFail
;
1701 if (!type
&& Rm
== 15)
1702 S
= MCDisassembler::SoftFail
;
1703 if (!type
&& writeback
&& (Rn
== 15 || Rn
== Rt
))
1704 S
= MCDisassembler::SoftFail
;
1707 case ARM::LDRSH_PRE
:
1708 case ARM::LDRSH_POST
:
1710 case ARM::LDRSB_PRE
:
1711 case ARM::LDRSB_POST
:
1712 if (type
&& Rn
== 15) {
1714 S
= MCDisassembler::SoftFail
;
1717 if (type
&& (Rt
== 15 || (writeback
&& Rn
== Rt
)))
1718 S
= MCDisassembler::SoftFail
;
1719 if (!type
&& (Rt
== 15 || Rm
== 15))
1720 S
= MCDisassembler::SoftFail
;
1721 if (!type
&& writeback
&& (Rn
== 15 || Rn
== Rt
))
1722 S
= MCDisassembler::SoftFail
;
1728 if (writeback
) { // Writeback
1730 U
|= ARMII::IndexModePre
<< 9;
1732 U
|= ARMII::IndexModePost
<< 9;
1734 // On stores, the writeback operand precedes Rt.
1735 switch (Inst
.getOpcode()) {
1738 case ARM::STRD_POST
:
1741 case ARM::STRH_POST
:
1742 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1743 return MCDisassembler::Fail
;
1750 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
1751 return MCDisassembler::Fail
;
1752 switch (Inst
.getOpcode()) {
1755 case ARM::STRD_POST
:
1758 case ARM::LDRD_POST
:
1759 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
+1, Address
, Decoder
)))
1760 return MCDisassembler::Fail
;
1767 // On loads, the writeback operand comes after Rt.
1768 switch (Inst
.getOpcode()) {
1771 case ARM::LDRD_POST
:
1774 case ARM::LDRH_POST
:
1776 case ARM::LDRSH_PRE
:
1777 case ARM::LDRSH_POST
:
1779 case ARM::LDRSB_PRE
:
1780 case ARM::LDRSB_POST
:
1783 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1784 return MCDisassembler::Fail
;
1791 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1792 return MCDisassembler::Fail
;
1795 Inst
.addOperand(MCOperand::createReg(0));
1796 Inst
.addOperand(MCOperand::createImm(U
| (imm
<< 4) | Rm
));
1798 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
1799 return MCDisassembler::Fail
;
1800 Inst
.addOperand(MCOperand::createImm(U
));
1803 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
1804 return MCDisassembler::Fail
;
1809 static DecodeStatus
DecodeRFEInstruction(MCInst
&Inst
, unsigned Insn
,
1810 uint64_t Address
, const void *Decoder
) {
1811 DecodeStatus S
= MCDisassembler::Success
;
1813 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
1814 unsigned mode
= fieldFromInstruction(Insn
, 23, 2);
1831 Inst
.addOperand(MCOperand::createImm(mode
));
1832 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1833 return MCDisassembler::Fail
;
1838 static DecodeStatus
DecodeQADDInstruction(MCInst
&Inst
, unsigned Insn
,
1839 uint64_t Address
, const void *Decoder
) {
1840 DecodeStatus S
= MCDisassembler::Success
;
1842 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
1843 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
1844 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
1845 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
1848 return DecodeCPSInstruction(Inst
, Insn
, Address
, Decoder
);
1850 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rd
, Address
, Decoder
)))
1851 return MCDisassembler::Fail
;
1852 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rm
, Address
, Decoder
)))
1853 return MCDisassembler::Fail
;
1854 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1855 return MCDisassembler::Fail
;
1856 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
1857 return MCDisassembler::Fail
;
1861 static DecodeStatus
DecodeMemMultipleWritebackInstruction(MCInst
&Inst
,
1863 uint64_t Address
, const void *Decoder
) {
1864 DecodeStatus S
= MCDisassembler::Success
;
1866 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
1867 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
1868 unsigned reglist
= fieldFromInstruction(Insn
, 0, 16);
1871 // Ambiguous with RFE and SRS
1872 switch (Inst
.getOpcode()) {
1874 Inst
.setOpcode(ARM::RFEDA
);
1876 case ARM::LDMDA_UPD
:
1877 Inst
.setOpcode(ARM::RFEDA_UPD
);
1880 Inst
.setOpcode(ARM::RFEDB
);
1882 case ARM::LDMDB_UPD
:
1883 Inst
.setOpcode(ARM::RFEDB_UPD
);
1886 Inst
.setOpcode(ARM::RFEIA
);
1888 case ARM::LDMIA_UPD
:
1889 Inst
.setOpcode(ARM::RFEIA_UPD
);
1892 Inst
.setOpcode(ARM::RFEIB
);
1894 case ARM::LDMIB_UPD
:
1895 Inst
.setOpcode(ARM::RFEIB_UPD
);
1898 Inst
.setOpcode(ARM::SRSDA
);
1900 case ARM::STMDA_UPD
:
1901 Inst
.setOpcode(ARM::SRSDA_UPD
);
1904 Inst
.setOpcode(ARM::SRSDB
);
1906 case ARM::STMDB_UPD
:
1907 Inst
.setOpcode(ARM::SRSDB_UPD
);
1910 Inst
.setOpcode(ARM::SRSIA
);
1912 case ARM::STMIA_UPD
:
1913 Inst
.setOpcode(ARM::SRSIA_UPD
);
1916 Inst
.setOpcode(ARM::SRSIB
);
1918 case ARM::STMIB_UPD
:
1919 Inst
.setOpcode(ARM::SRSIB_UPD
);
1922 return MCDisassembler::Fail
;
1925 // For stores (which become SRS's, the only operand is the mode.
1926 if (fieldFromInstruction(Insn
, 20, 1) == 0) {
1927 // Check SRS encoding constraints
1928 if (!(fieldFromInstruction(Insn
, 22, 1) == 1 &&
1929 fieldFromInstruction(Insn
, 20, 1) == 0))
1930 return MCDisassembler::Fail
;
1933 MCOperand::createImm(fieldFromInstruction(Insn
, 0, 4)));
1937 return DecodeRFEInstruction(Inst
, Insn
, Address
, Decoder
);
1940 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1941 return MCDisassembler::Fail
;
1942 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
1943 return MCDisassembler::Fail
; // Tied
1944 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
1945 return MCDisassembler::Fail
;
1946 if (!Check(S
, DecodeRegListOperand(Inst
, reglist
, Address
, Decoder
)))
1947 return MCDisassembler::Fail
;
1952 // Check for UNPREDICTABLE predicated ESB instruction
1953 static DecodeStatus
DecodeHINTInstruction(MCInst
&Inst
, unsigned Insn
,
1954 uint64_t Address
, const void *Decoder
) {
1955 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
1956 unsigned imm8
= fieldFromInstruction(Insn
, 0, 8);
1957 const MCDisassembler
*Dis
= static_cast<const MCDisassembler
*>(Decoder
);
1958 const FeatureBitset
&FeatureBits
= Dis
->getSubtargetInfo().getFeatureBits();
1960 DecodeStatus S
= MCDisassembler::Success
;
1962 Inst
.addOperand(MCOperand::createImm(imm8
));
1964 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
1965 return MCDisassembler::Fail
;
1967 // ESB is unpredictable if pred != AL. Without the RAS extension, it is a NOP,
1968 // so all predicates should be allowed.
1969 if (imm8
== 0x10 && pred
!= 0xe && ((FeatureBits
[ARM::FeatureRAS
]) != 0))
1970 S
= MCDisassembler::SoftFail
;
1975 static DecodeStatus
DecodeCPSInstruction(MCInst
&Inst
, unsigned Insn
,
1976 uint64_t Address
, const void *Decoder
) {
1977 unsigned imod
= fieldFromInstruction(Insn
, 18, 2);
1978 unsigned M
= fieldFromInstruction(Insn
, 17, 1);
1979 unsigned iflags
= fieldFromInstruction(Insn
, 6, 3);
1980 unsigned mode
= fieldFromInstruction(Insn
, 0, 5);
1982 DecodeStatus S
= MCDisassembler::Success
;
1984 // This decoder is called from multiple location that do not check
1985 // the full encoding is valid before they do.
1986 if (fieldFromInstruction(Insn
, 5, 1) != 0 ||
1987 fieldFromInstruction(Insn
, 16, 1) != 0 ||
1988 fieldFromInstruction(Insn
, 20, 8) != 0x10)
1989 return MCDisassembler::Fail
;
1991 // imod == '01' --> UNPREDICTABLE
1992 // NOTE: Even though this is technically UNPREDICTABLE, we choose to
1993 // return failure here. The '01' imod value is unprintable, so there's
1994 // nothing useful we could do even if we returned UNPREDICTABLE.
1996 if (imod
== 1) return MCDisassembler::Fail
;
1999 Inst
.setOpcode(ARM::CPS3p
);
2000 Inst
.addOperand(MCOperand::createImm(imod
));
2001 Inst
.addOperand(MCOperand::createImm(iflags
));
2002 Inst
.addOperand(MCOperand::createImm(mode
));
2003 } else if (imod
&& !M
) {
2004 Inst
.setOpcode(ARM::CPS2p
);
2005 Inst
.addOperand(MCOperand::createImm(imod
));
2006 Inst
.addOperand(MCOperand::createImm(iflags
));
2007 if (mode
) S
= MCDisassembler::SoftFail
;
2008 } else if (!imod
&& M
) {
2009 Inst
.setOpcode(ARM::CPS1p
);
2010 Inst
.addOperand(MCOperand::createImm(mode
));
2011 if (iflags
) S
= MCDisassembler::SoftFail
;
2013 // imod == '00' && M == '0' --> UNPREDICTABLE
2014 Inst
.setOpcode(ARM::CPS1p
);
2015 Inst
.addOperand(MCOperand::createImm(mode
));
2016 S
= MCDisassembler::SoftFail
;
2022 static DecodeStatus
DecodeT2CPSInstruction(MCInst
&Inst
, unsigned Insn
,
2023 uint64_t Address
, const void *Decoder
) {
2024 unsigned imod
= fieldFromInstruction(Insn
, 9, 2);
2025 unsigned M
= fieldFromInstruction(Insn
, 8, 1);
2026 unsigned iflags
= fieldFromInstruction(Insn
, 5, 3);
2027 unsigned mode
= fieldFromInstruction(Insn
, 0, 5);
2029 DecodeStatus S
= MCDisassembler::Success
;
2031 // imod == '01' --> UNPREDICTABLE
2032 // NOTE: Even though this is technically UNPREDICTABLE, we choose to
2033 // return failure here. The '01' imod value is unprintable, so there's
2034 // nothing useful we could do even if we returned UNPREDICTABLE.
2036 if (imod
== 1) return MCDisassembler::Fail
;
2039 Inst
.setOpcode(ARM::t2CPS3p
);
2040 Inst
.addOperand(MCOperand::createImm(imod
));
2041 Inst
.addOperand(MCOperand::createImm(iflags
));
2042 Inst
.addOperand(MCOperand::createImm(mode
));
2043 } else if (imod
&& !M
) {
2044 Inst
.setOpcode(ARM::t2CPS2p
);
2045 Inst
.addOperand(MCOperand::createImm(imod
));
2046 Inst
.addOperand(MCOperand::createImm(iflags
));
2047 if (mode
) S
= MCDisassembler::SoftFail
;
2048 } else if (!imod
&& M
) {
2049 Inst
.setOpcode(ARM::t2CPS1p
);
2050 Inst
.addOperand(MCOperand::createImm(mode
));
2051 if (iflags
) S
= MCDisassembler::SoftFail
;
2053 // imod == '00' && M == '0' --> this is a HINT instruction
2054 int imm
= fieldFromInstruction(Insn
, 0, 8);
2055 // HINT are defined only for immediate in [0..4]
2056 if(imm
> 4) return MCDisassembler::Fail
;
2057 Inst
.setOpcode(ARM::t2HINT
);
2058 Inst
.addOperand(MCOperand::createImm(imm
));
2064 static DecodeStatus
DecodeT2MOVTWInstruction(MCInst
&Inst
, unsigned Insn
,
2065 uint64_t Address
, const void *Decoder
) {
2066 DecodeStatus S
= MCDisassembler::Success
;
2068 unsigned Rd
= fieldFromInstruction(Insn
, 8, 4);
2071 imm
|= (fieldFromInstruction(Insn
, 0, 8) << 0);
2072 imm
|= (fieldFromInstruction(Insn
, 12, 3) << 8);
2073 imm
|= (fieldFromInstruction(Insn
, 16, 4) << 12);
2074 imm
|= (fieldFromInstruction(Insn
, 26, 1) << 11);
2076 if (Inst
.getOpcode() == ARM::t2MOVTi16
)
2077 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2078 return MCDisassembler::Fail
;
2079 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2080 return MCDisassembler::Fail
;
2082 if (!tryAddingSymbolicOperand(Address
, imm
, false, 4, Inst
, Decoder
))
2083 Inst
.addOperand(MCOperand::createImm(imm
));
2088 static DecodeStatus
DecodeArmMOVTWInstruction(MCInst
&Inst
, unsigned Insn
,
2089 uint64_t Address
, const void *Decoder
) {
2090 DecodeStatus S
= MCDisassembler::Success
;
2092 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
2093 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
2096 imm
|= (fieldFromInstruction(Insn
, 0, 12) << 0);
2097 imm
|= (fieldFromInstruction(Insn
, 16, 4) << 12);
2099 if (Inst
.getOpcode() == ARM::MOVTi16
)
2100 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2101 return MCDisassembler::Fail
;
2103 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2104 return MCDisassembler::Fail
;
2106 if (!tryAddingSymbolicOperand(Address
, imm
, false, 4, Inst
, Decoder
))
2107 Inst
.addOperand(MCOperand::createImm(imm
));
2109 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
2110 return MCDisassembler::Fail
;
2115 static DecodeStatus
DecodeSMLAInstruction(MCInst
&Inst
, unsigned Insn
,
2116 uint64_t Address
, const void *Decoder
) {
2117 DecodeStatus S
= MCDisassembler::Success
;
2119 unsigned Rd
= fieldFromInstruction(Insn
, 16, 4);
2120 unsigned Rn
= fieldFromInstruction(Insn
, 0, 4);
2121 unsigned Rm
= fieldFromInstruction(Insn
, 8, 4);
2122 unsigned Ra
= fieldFromInstruction(Insn
, 12, 4);
2123 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
2126 return DecodeCPSInstruction(Inst
, Insn
, Address
, Decoder
);
2128 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2129 return MCDisassembler::Fail
;
2130 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rn
, Address
, Decoder
)))
2131 return MCDisassembler::Fail
;
2132 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rm
, Address
, Decoder
)))
2133 return MCDisassembler::Fail
;
2134 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Ra
, Address
, Decoder
)))
2135 return MCDisassembler::Fail
;
2137 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
2138 return MCDisassembler::Fail
;
2143 static DecodeStatus
DecodeTSTInstruction(MCInst
&Inst
, unsigned Insn
,
2144 uint64_t Address
, const void *Decoder
) {
2145 DecodeStatus S
= MCDisassembler::Success
;
2147 unsigned Pred
= fieldFromInstruction(Insn
, 28, 4);
2148 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
2149 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
2152 return DecodeSETPANInstruction(Inst
, Insn
, Address
, Decoder
);
2154 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
2155 return MCDisassembler::Fail
;
2156 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
2157 return MCDisassembler::Fail
;
2158 if (!Check(S
, DecodePredicateOperand(Inst
, Pred
, Address
, Decoder
)))
2159 return MCDisassembler::Fail
;
2164 static DecodeStatus
DecodeSETPANInstruction(MCInst
&Inst
, unsigned Insn
,
2165 uint64_t Address
, const void *Decoder
) {
2166 DecodeStatus S
= MCDisassembler::Success
;
2168 unsigned Imm
= fieldFromInstruction(Insn
, 9, 1);
2170 const MCDisassembler
*Dis
= static_cast<const MCDisassembler
*>(Decoder
);
2171 const FeatureBitset
&FeatureBits
= Dis
->getSubtargetInfo().getFeatureBits();
2173 if (!FeatureBits
[ARM::HasV8_1aOps
] ||
2174 !FeatureBits
[ARM::HasV8Ops
])
2175 return MCDisassembler::Fail
;
2177 // Decoder can be called from DecodeTST, which does not check the full
2178 // encoding is valid.
2179 if (fieldFromInstruction(Insn
, 20,12) != 0xf11 ||
2180 fieldFromInstruction(Insn
, 4,4) != 0)
2181 return MCDisassembler::Fail
;
2182 if (fieldFromInstruction(Insn
, 10,10) != 0 ||
2183 fieldFromInstruction(Insn
, 0,4) != 0)
2184 S
= MCDisassembler::SoftFail
;
2186 Inst
.setOpcode(ARM::SETPAN
);
2187 Inst
.addOperand(MCOperand::createImm(Imm
));
2192 static DecodeStatus
DecodeAddrModeImm12Operand(MCInst
&Inst
, unsigned Val
,
2193 uint64_t Address
, const void *Decoder
) {
2194 DecodeStatus S
= MCDisassembler::Success
;
2196 unsigned add
= fieldFromInstruction(Val
, 12, 1);
2197 unsigned imm
= fieldFromInstruction(Val
, 0, 12);
2198 unsigned Rn
= fieldFromInstruction(Val
, 13, 4);
2200 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
2201 return MCDisassembler::Fail
;
2203 if (!add
) imm
*= -1;
2204 if (imm
== 0 && !add
) imm
= INT32_MIN
;
2205 Inst
.addOperand(MCOperand::createImm(imm
));
2207 tryAddingPcLoadReferenceComment(Address
, Address
+ imm
+ 8, Decoder
);
2212 static DecodeStatus
DecodeAddrMode5Operand(MCInst
&Inst
, unsigned Val
,
2213 uint64_t Address
, const void *Decoder
) {
2214 DecodeStatus S
= MCDisassembler::Success
;
2216 unsigned Rn
= fieldFromInstruction(Val
, 9, 4);
2217 // U == 1 to add imm, 0 to subtract it.
2218 unsigned U
= fieldFromInstruction(Val
, 8, 1);
2219 unsigned imm
= fieldFromInstruction(Val
, 0, 8);
2221 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
2222 return MCDisassembler::Fail
;
2225 Inst
.addOperand(MCOperand::createImm(ARM_AM::getAM5Opc(ARM_AM::add
, imm
)));
2227 Inst
.addOperand(MCOperand::createImm(ARM_AM::getAM5Opc(ARM_AM::sub
, imm
)));
2232 static DecodeStatus
DecodeAddrMode5FP16Operand(MCInst
&Inst
, unsigned Val
,
2233 uint64_t Address
, const void *Decoder
) {
2234 DecodeStatus S
= MCDisassembler::Success
;
2236 unsigned Rn
= fieldFromInstruction(Val
, 9, 4);
2237 // U == 1 to add imm, 0 to subtract it.
2238 unsigned U
= fieldFromInstruction(Val
, 8, 1);
2239 unsigned imm
= fieldFromInstruction(Val
, 0, 8);
2241 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
2242 return MCDisassembler::Fail
;
2245 Inst
.addOperand(MCOperand::createImm(ARM_AM::getAM5FP16Opc(ARM_AM::add
, imm
)));
2247 Inst
.addOperand(MCOperand::createImm(ARM_AM::getAM5FP16Opc(ARM_AM::sub
, imm
)));
2252 static DecodeStatus
DecodeAddrMode7Operand(MCInst
&Inst
, unsigned Val
,
2253 uint64_t Address
, const void *Decoder
) {
2254 return DecodeGPRRegisterClass(Inst
, Val
, Address
, Decoder
);
2258 DecodeT2BInstruction(MCInst
&Inst
, unsigned Insn
,
2259 uint64_t Address
, const void *Decoder
) {
2260 DecodeStatus Status
= MCDisassembler::Success
;
2262 // Note the J1 and J2 values are from the encoded instruction. So here
2263 // change them to I1 and I2 values via as documented:
2264 // I1 = NOT(J1 EOR S);
2265 // I2 = NOT(J2 EOR S);
2266 // and build the imm32 with one trailing zero as documented:
2267 // imm32 = SignExtend(S:I1:I2:imm10:imm11:'0', 32);
2268 unsigned S
= fieldFromInstruction(Insn
, 26, 1);
2269 unsigned J1
= fieldFromInstruction(Insn
, 13, 1);
2270 unsigned J2
= fieldFromInstruction(Insn
, 11, 1);
2271 unsigned I1
= !(J1
^ S
);
2272 unsigned I2
= !(J2
^ S
);
2273 unsigned imm10
= fieldFromInstruction(Insn
, 16, 10);
2274 unsigned imm11
= fieldFromInstruction(Insn
, 0, 11);
2275 unsigned tmp
= (S
<< 23) | (I1
<< 22) | (I2
<< 21) | (imm10
<< 11) | imm11
;
2276 int imm32
= SignExtend32
<25>(tmp
<< 1);
2277 if (!tryAddingSymbolicOperand(Address
, Address
+ imm32
+ 4,
2278 true, 4, Inst
, Decoder
))
2279 Inst
.addOperand(MCOperand::createImm(imm32
));
2285 DecodeBranchImmInstruction(MCInst
&Inst
, unsigned Insn
,
2286 uint64_t Address
, const void *Decoder
) {
2287 DecodeStatus S
= MCDisassembler::Success
;
2289 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
2290 unsigned imm
= fieldFromInstruction(Insn
, 0, 24) << 2;
2293 Inst
.setOpcode(ARM::BLXi
);
2294 imm
|= fieldFromInstruction(Insn
, 24, 1) << 1;
2295 if (!tryAddingSymbolicOperand(Address
, Address
+ SignExtend32
<26>(imm
) + 8,
2296 true, 4, Inst
, Decoder
))
2297 Inst
.addOperand(MCOperand::createImm(SignExtend32
<26>(imm
)));
2301 if (!tryAddingSymbolicOperand(Address
, Address
+ SignExtend32
<26>(imm
) + 8,
2302 true, 4, Inst
, Decoder
))
2303 Inst
.addOperand(MCOperand::createImm(SignExtend32
<26>(imm
)));
2304 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
2305 return MCDisassembler::Fail
;
2310 static DecodeStatus
DecodeAddrMode6Operand(MCInst
&Inst
, unsigned Val
,
2311 uint64_t Address
, const void *Decoder
) {
2312 DecodeStatus S
= MCDisassembler::Success
;
2314 unsigned Rm
= fieldFromInstruction(Val
, 0, 4);
2315 unsigned align
= fieldFromInstruction(Val
, 4, 2);
2317 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
2318 return MCDisassembler::Fail
;
2320 Inst
.addOperand(MCOperand::createImm(0));
2322 Inst
.addOperand(MCOperand::createImm(4 << align
));
2327 static DecodeStatus
DecodeVLDInstruction(MCInst
&Inst
, unsigned Insn
,
2328 uint64_t Address
, const void *Decoder
) {
2329 DecodeStatus S
= MCDisassembler::Success
;
2331 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
2332 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
2333 unsigned wb
= fieldFromInstruction(Insn
, 16, 4);
2334 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
2335 Rn
|= fieldFromInstruction(Insn
, 4, 2) << 4;
2336 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
2338 // First output register
2339 switch (Inst
.getOpcode()) {
2340 case ARM::VLD1q16
: case ARM::VLD1q32
: case ARM::VLD1q64
: case ARM::VLD1q8
:
2341 case ARM::VLD1q16wb_fixed
: case ARM::VLD1q16wb_register
:
2342 case ARM::VLD1q32wb_fixed
: case ARM::VLD1q32wb_register
:
2343 case ARM::VLD1q64wb_fixed
: case ARM::VLD1q64wb_register
:
2344 case ARM::VLD1q8wb_fixed
: case ARM::VLD1q8wb_register
:
2345 case ARM::VLD2d16
: case ARM::VLD2d32
: case ARM::VLD2d8
:
2346 case ARM::VLD2d16wb_fixed
: case ARM::VLD2d16wb_register
:
2347 case ARM::VLD2d32wb_fixed
: case ARM::VLD2d32wb_register
:
2348 case ARM::VLD2d8wb_fixed
: case ARM::VLD2d8wb_register
:
2349 if (!Check(S
, DecodeDPairRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2350 return MCDisassembler::Fail
;
2355 case ARM::VLD2b16wb_fixed
:
2356 case ARM::VLD2b16wb_register
:
2357 case ARM::VLD2b32wb_fixed
:
2358 case ARM::VLD2b32wb_register
:
2359 case ARM::VLD2b8wb_fixed
:
2360 case ARM::VLD2b8wb_register
:
2361 if (!Check(S
, DecodeDPairSpacedRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2362 return MCDisassembler::Fail
;
2365 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2366 return MCDisassembler::Fail
;
2369 // Second output register
2370 switch (Inst
.getOpcode()) {
2374 case ARM::VLD3d8_UPD
:
2375 case ARM::VLD3d16_UPD
:
2376 case ARM::VLD3d32_UPD
:
2380 case ARM::VLD4d8_UPD
:
2381 case ARM::VLD4d16_UPD
:
2382 case ARM::VLD4d32_UPD
:
2383 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+1)%32, Address
, Decoder
)))
2384 return MCDisassembler::Fail
;
2389 case ARM::VLD3q8_UPD
:
2390 case ARM::VLD3q16_UPD
:
2391 case ARM::VLD3q32_UPD
:
2395 case ARM::VLD4q8_UPD
:
2396 case ARM::VLD4q16_UPD
:
2397 case ARM::VLD4q32_UPD
:
2398 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+2)%32, Address
, Decoder
)))
2399 return MCDisassembler::Fail
;
2405 // Third output register
2406 switch(Inst
.getOpcode()) {
2410 case ARM::VLD3d8_UPD
:
2411 case ARM::VLD3d16_UPD
:
2412 case ARM::VLD3d32_UPD
:
2416 case ARM::VLD4d8_UPD
:
2417 case ARM::VLD4d16_UPD
:
2418 case ARM::VLD4d32_UPD
:
2419 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+2)%32, Address
, Decoder
)))
2420 return MCDisassembler::Fail
;
2425 case ARM::VLD3q8_UPD
:
2426 case ARM::VLD3q16_UPD
:
2427 case ARM::VLD3q32_UPD
:
2431 case ARM::VLD4q8_UPD
:
2432 case ARM::VLD4q16_UPD
:
2433 case ARM::VLD4q32_UPD
:
2434 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+4)%32, Address
, Decoder
)))
2435 return MCDisassembler::Fail
;
2441 // Fourth output register
2442 switch (Inst
.getOpcode()) {
2446 case ARM::VLD4d8_UPD
:
2447 case ARM::VLD4d16_UPD
:
2448 case ARM::VLD4d32_UPD
:
2449 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+3)%32, Address
, Decoder
)))
2450 return MCDisassembler::Fail
;
2455 case ARM::VLD4q8_UPD
:
2456 case ARM::VLD4q16_UPD
:
2457 case ARM::VLD4q32_UPD
:
2458 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+6)%32, Address
, Decoder
)))
2459 return MCDisassembler::Fail
;
2465 // Writeback operand
2466 switch (Inst
.getOpcode()) {
2467 case ARM::VLD1d8wb_fixed
:
2468 case ARM::VLD1d16wb_fixed
:
2469 case ARM::VLD1d32wb_fixed
:
2470 case ARM::VLD1d64wb_fixed
:
2471 case ARM::VLD1d8wb_register
:
2472 case ARM::VLD1d16wb_register
:
2473 case ARM::VLD1d32wb_register
:
2474 case ARM::VLD1d64wb_register
:
2475 case ARM::VLD1q8wb_fixed
:
2476 case ARM::VLD1q16wb_fixed
:
2477 case ARM::VLD1q32wb_fixed
:
2478 case ARM::VLD1q64wb_fixed
:
2479 case ARM::VLD1q8wb_register
:
2480 case ARM::VLD1q16wb_register
:
2481 case ARM::VLD1q32wb_register
:
2482 case ARM::VLD1q64wb_register
:
2483 case ARM::VLD1d8Twb_fixed
:
2484 case ARM::VLD1d8Twb_register
:
2485 case ARM::VLD1d16Twb_fixed
:
2486 case ARM::VLD1d16Twb_register
:
2487 case ARM::VLD1d32Twb_fixed
:
2488 case ARM::VLD1d32Twb_register
:
2489 case ARM::VLD1d64Twb_fixed
:
2490 case ARM::VLD1d64Twb_register
:
2491 case ARM::VLD1d8Qwb_fixed
:
2492 case ARM::VLD1d8Qwb_register
:
2493 case ARM::VLD1d16Qwb_fixed
:
2494 case ARM::VLD1d16Qwb_register
:
2495 case ARM::VLD1d32Qwb_fixed
:
2496 case ARM::VLD1d32Qwb_register
:
2497 case ARM::VLD1d64Qwb_fixed
:
2498 case ARM::VLD1d64Qwb_register
:
2499 case ARM::VLD2d8wb_fixed
:
2500 case ARM::VLD2d16wb_fixed
:
2501 case ARM::VLD2d32wb_fixed
:
2502 case ARM::VLD2q8wb_fixed
:
2503 case ARM::VLD2q16wb_fixed
:
2504 case ARM::VLD2q32wb_fixed
:
2505 case ARM::VLD2d8wb_register
:
2506 case ARM::VLD2d16wb_register
:
2507 case ARM::VLD2d32wb_register
:
2508 case ARM::VLD2q8wb_register
:
2509 case ARM::VLD2q16wb_register
:
2510 case ARM::VLD2q32wb_register
:
2511 case ARM::VLD2b8wb_fixed
:
2512 case ARM::VLD2b16wb_fixed
:
2513 case ARM::VLD2b32wb_fixed
:
2514 case ARM::VLD2b8wb_register
:
2515 case ARM::VLD2b16wb_register
:
2516 case ARM::VLD2b32wb_register
:
2517 Inst
.addOperand(MCOperand::createImm(0));
2519 case ARM::VLD3d8_UPD
:
2520 case ARM::VLD3d16_UPD
:
2521 case ARM::VLD3d32_UPD
:
2522 case ARM::VLD3q8_UPD
:
2523 case ARM::VLD3q16_UPD
:
2524 case ARM::VLD3q32_UPD
:
2525 case ARM::VLD4d8_UPD
:
2526 case ARM::VLD4d16_UPD
:
2527 case ARM::VLD4d32_UPD
:
2528 case ARM::VLD4q8_UPD
:
2529 case ARM::VLD4q16_UPD
:
2530 case ARM::VLD4q32_UPD
:
2531 if (!Check(S
, DecodeGPRRegisterClass(Inst
, wb
, Address
, Decoder
)))
2532 return MCDisassembler::Fail
;
2538 // AddrMode6 Base (register+alignment)
2539 if (!Check(S
, DecodeAddrMode6Operand(Inst
, Rn
, Address
, Decoder
)))
2540 return MCDisassembler::Fail
;
2542 // AddrMode6 Offset (register)
2543 switch (Inst
.getOpcode()) {
2545 // The below have been updated to have explicit am6offset split
2546 // between fixed and register offset. For those instructions not
2547 // yet updated, we need to add an additional reg0 operand for the
2550 // The fixed offset encodes as Rm == 0xd, so we check for that.
2552 Inst
.addOperand(MCOperand::createReg(0));
2555 // Fall through to handle the register offset variant.
2557 case ARM::VLD1d8wb_fixed
:
2558 case ARM::VLD1d16wb_fixed
:
2559 case ARM::VLD1d32wb_fixed
:
2560 case ARM::VLD1d64wb_fixed
:
2561 case ARM::VLD1d8Twb_fixed
:
2562 case ARM::VLD1d16Twb_fixed
:
2563 case ARM::VLD1d32Twb_fixed
:
2564 case ARM::VLD1d64Twb_fixed
:
2565 case ARM::VLD1d8Qwb_fixed
:
2566 case ARM::VLD1d16Qwb_fixed
:
2567 case ARM::VLD1d32Qwb_fixed
:
2568 case ARM::VLD1d64Qwb_fixed
:
2569 case ARM::VLD1d8wb_register
:
2570 case ARM::VLD1d16wb_register
:
2571 case ARM::VLD1d32wb_register
:
2572 case ARM::VLD1d64wb_register
:
2573 case ARM::VLD1q8wb_fixed
:
2574 case ARM::VLD1q16wb_fixed
:
2575 case ARM::VLD1q32wb_fixed
:
2576 case ARM::VLD1q64wb_fixed
:
2577 case ARM::VLD1q8wb_register
:
2578 case ARM::VLD1q16wb_register
:
2579 case ARM::VLD1q32wb_register
:
2580 case ARM::VLD1q64wb_register
:
2581 // The fixed offset post-increment encodes Rm == 0xd. The no-writeback
2582 // variant encodes Rm == 0xf. Anything else is a register offset post-
2583 // increment and we need to add the register operand to the instruction.
2584 if (Rm
!= 0xD && Rm
!= 0xF &&
2585 !Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
2586 return MCDisassembler::Fail
;
2588 case ARM::VLD2d8wb_fixed
:
2589 case ARM::VLD2d16wb_fixed
:
2590 case ARM::VLD2d32wb_fixed
:
2591 case ARM::VLD2b8wb_fixed
:
2592 case ARM::VLD2b16wb_fixed
:
2593 case ARM::VLD2b32wb_fixed
:
2594 case ARM::VLD2q8wb_fixed
:
2595 case ARM::VLD2q16wb_fixed
:
2596 case ARM::VLD2q32wb_fixed
:
2603 static DecodeStatus
DecodeVLDST1Instruction(MCInst
&Inst
, unsigned Insn
,
2604 uint64_t Address
, const void *Decoder
) {
2605 unsigned type
= fieldFromInstruction(Insn
, 8, 4);
2606 unsigned align
= fieldFromInstruction(Insn
, 4, 2);
2607 if (type
== 6 && (align
& 2)) return MCDisassembler::Fail
;
2608 if (type
== 7 && (align
& 2)) return MCDisassembler::Fail
;
2609 if (type
== 10 && align
== 3) return MCDisassembler::Fail
;
2611 unsigned load
= fieldFromInstruction(Insn
, 21, 1);
2612 return load
? DecodeVLDInstruction(Inst
, Insn
, Address
, Decoder
)
2613 : DecodeVSTInstruction(Inst
, Insn
, Address
, Decoder
);
2616 static DecodeStatus
DecodeVLDST2Instruction(MCInst
&Inst
, unsigned Insn
,
2617 uint64_t Address
, const void *Decoder
) {
2618 unsigned size
= fieldFromInstruction(Insn
, 6, 2);
2619 if (size
== 3) return MCDisassembler::Fail
;
2621 unsigned type
= fieldFromInstruction(Insn
, 8, 4);
2622 unsigned align
= fieldFromInstruction(Insn
, 4, 2);
2623 if (type
== 8 && align
== 3) return MCDisassembler::Fail
;
2624 if (type
== 9 && align
== 3) return MCDisassembler::Fail
;
2626 unsigned load
= fieldFromInstruction(Insn
, 21, 1);
2627 return load
? DecodeVLDInstruction(Inst
, Insn
, Address
, Decoder
)
2628 : DecodeVSTInstruction(Inst
, Insn
, Address
, Decoder
);
2631 static DecodeStatus
DecodeVLDST3Instruction(MCInst
&Inst
, unsigned Insn
,
2632 uint64_t Address
, const void *Decoder
) {
2633 unsigned size
= fieldFromInstruction(Insn
, 6, 2);
2634 if (size
== 3) return MCDisassembler::Fail
;
2636 unsigned align
= fieldFromInstruction(Insn
, 4, 2);
2637 if (align
& 2) return MCDisassembler::Fail
;
2639 unsigned load
= fieldFromInstruction(Insn
, 21, 1);
2640 return load
? DecodeVLDInstruction(Inst
, Insn
, Address
, Decoder
)
2641 : DecodeVSTInstruction(Inst
, Insn
, Address
, Decoder
);
2644 static DecodeStatus
DecodeVLDST4Instruction(MCInst
&Inst
, unsigned Insn
,
2645 uint64_t Address
, const void *Decoder
) {
2646 unsigned size
= fieldFromInstruction(Insn
, 6, 2);
2647 if (size
== 3) return MCDisassembler::Fail
;
2649 unsigned load
= fieldFromInstruction(Insn
, 21, 1);
2650 return load
? DecodeVLDInstruction(Inst
, Insn
, Address
, Decoder
)
2651 : DecodeVSTInstruction(Inst
, Insn
, Address
, Decoder
);
2654 static DecodeStatus
DecodeVSTInstruction(MCInst
&Inst
, unsigned Insn
,
2655 uint64_t Address
, const void *Decoder
) {
2656 DecodeStatus S
= MCDisassembler::Success
;
2658 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
2659 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
2660 unsigned wb
= fieldFromInstruction(Insn
, 16, 4);
2661 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
2662 Rn
|= fieldFromInstruction(Insn
, 4, 2) << 4;
2663 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
2665 // Writeback Operand
2666 switch (Inst
.getOpcode()) {
2667 case ARM::VST1d8wb_fixed
:
2668 case ARM::VST1d16wb_fixed
:
2669 case ARM::VST1d32wb_fixed
:
2670 case ARM::VST1d64wb_fixed
:
2671 case ARM::VST1d8wb_register
:
2672 case ARM::VST1d16wb_register
:
2673 case ARM::VST1d32wb_register
:
2674 case ARM::VST1d64wb_register
:
2675 case ARM::VST1q8wb_fixed
:
2676 case ARM::VST1q16wb_fixed
:
2677 case ARM::VST1q32wb_fixed
:
2678 case ARM::VST1q64wb_fixed
:
2679 case ARM::VST1q8wb_register
:
2680 case ARM::VST1q16wb_register
:
2681 case ARM::VST1q32wb_register
:
2682 case ARM::VST1q64wb_register
:
2683 case ARM::VST1d8Twb_fixed
:
2684 case ARM::VST1d16Twb_fixed
:
2685 case ARM::VST1d32Twb_fixed
:
2686 case ARM::VST1d64Twb_fixed
:
2687 case ARM::VST1d8Twb_register
:
2688 case ARM::VST1d16Twb_register
:
2689 case ARM::VST1d32Twb_register
:
2690 case ARM::VST1d64Twb_register
:
2691 case ARM::VST1d8Qwb_fixed
:
2692 case ARM::VST1d16Qwb_fixed
:
2693 case ARM::VST1d32Qwb_fixed
:
2694 case ARM::VST1d64Qwb_fixed
:
2695 case ARM::VST1d8Qwb_register
:
2696 case ARM::VST1d16Qwb_register
:
2697 case ARM::VST1d32Qwb_register
:
2698 case ARM::VST1d64Qwb_register
:
2699 case ARM::VST2d8wb_fixed
:
2700 case ARM::VST2d16wb_fixed
:
2701 case ARM::VST2d32wb_fixed
:
2702 case ARM::VST2d8wb_register
:
2703 case ARM::VST2d16wb_register
:
2704 case ARM::VST2d32wb_register
:
2705 case ARM::VST2q8wb_fixed
:
2706 case ARM::VST2q16wb_fixed
:
2707 case ARM::VST2q32wb_fixed
:
2708 case ARM::VST2q8wb_register
:
2709 case ARM::VST2q16wb_register
:
2710 case ARM::VST2q32wb_register
:
2711 case ARM::VST2b8wb_fixed
:
2712 case ARM::VST2b16wb_fixed
:
2713 case ARM::VST2b32wb_fixed
:
2714 case ARM::VST2b8wb_register
:
2715 case ARM::VST2b16wb_register
:
2716 case ARM::VST2b32wb_register
:
2718 return MCDisassembler::Fail
;
2719 Inst
.addOperand(MCOperand::createImm(0));
2721 case ARM::VST3d8_UPD
:
2722 case ARM::VST3d16_UPD
:
2723 case ARM::VST3d32_UPD
:
2724 case ARM::VST3q8_UPD
:
2725 case ARM::VST3q16_UPD
:
2726 case ARM::VST3q32_UPD
:
2727 case ARM::VST4d8_UPD
:
2728 case ARM::VST4d16_UPD
:
2729 case ARM::VST4d32_UPD
:
2730 case ARM::VST4q8_UPD
:
2731 case ARM::VST4q16_UPD
:
2732 case ARM::VST4q32_UPD
:
2733 if (!Check(S
, DecodeGPRRegisterClass(Inst
, wb
, Address
, Decoder
)))
2734 return MCDisassembler::Fail
;
2740 // AddrMode6 Base (register+alignment)
2741 if (!Check(S
, DecodeAddrMode6Operand(Inst
, Rn
, Address
, Decoder
)))
2742 return MCDisassembler::Fail
;
2744 // AddrMode6 Offset (register)
2745 switch (Inst
.getOpcode()) {
2748 Inst
.addOperand(MCOperand::createReg(0));
2749 else if (Rm
!= 0xF) {
2750 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
2751 return MCDisassembler::Fail
;
2754 case ARM::VST1d8wb_fixed
:
2755 case ARM::VST1d16wb_fixed
:
2756 case ARM::VST1d32wb_fixed
:
2757 case ARM::VST1d64wb_fixed
:
2758 case ARM::VST1q8wb_fixed
:
2759 case ARM::VST1q16wb_fixed
:
2760 case ARM::VST1q32wb_fixed
:
2761 case ARM::VST1q64wb_fixed
:
2762 case ARM::VST1d8Twb_fixed
:
2763 case ARM::VST1d16Twb_fixed
:
2764 case ARM::VST1d32Twb_fixed
:
2765 case ARM::VST1d64Twb_fixed
:
2766 case ARM::VST1d8Qwb_fixed
:
2767 case ARM::VST1d16Qwb_fixed
:
2768 case ARM::VST1d32Qwb_fixed
:
2769 case ARM::VST1d64Qwb_fixed
:
2770 case ARM::VST2d8wb_fixed
:
2771 case ARM::VST2d16wb_fixed
:
2772 case ARM::VST2d32wb_fixed
:
2773 case ARM::VST2q8wb_fixed
:
2774 case ARM::VST2q16wb_fixed
:
2775 case ARM::VST2q32wb_fixed
:
2776 case ARM::VST2b8wb_fixed
:
2777 case ARM::VST2b16wb_fixed
:
2778 case ARM::VST2b32wb_fixed
:
2782 // First input register
2783 switch (Inst
.getOpcode()) {
2788 case ARM::VST1q16wb_fixed
:
2789 case ARM::VST1q16wb_register
:
2790 case ARM::VST1q32wb_fixed
:
2791 case ARM::VST1q32wb_register
:
2792 case ARM::VST1q64wb_fixed
:
2793 case ARM::VST1q64wb_register
:
2794 case ARM::VST1q8wb_fixed
:
2795 case ARM::VST1q8wb_register
:
2799 case ARM::VST2d16wb_fixed
:
2800 case ARM::VST2d16wb_register
:
2801 case ARM::VST2d32wb_fixed
:
2802 case ARM::VST2d32wb_register
:
2803 case ARM::VST2d8wb_fixed
:
2804 case ARM::VST2d8wb_register
:
2805 if (!Check(S
, DecodeDPairRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2806 return MCDisassembler::Fail
;
2811 case ARM::VST2b16wb_fixed
:
2812 case ARM::VST2b16wb_register
:
2813 case ARM::VST2b32wb_fixed
:
2814 case ARM::VST2b32wb_register
:
2815 case ARM::VST2b8wb_fixed
:
2816 case ARM::VST2b8wb_register
:
2817 if (!Check(S
, DecodeDPairSpacedRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2818 return MCDisassembler::Fail
;
2821 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2822 return MCDisassembler::Fail
;
2825 // Second input register
2826 switch (Inst
.getOpcode()) {
2830 case ARM::VST3d8_UPD
:
2831 case ARM::VST3d16_UPD
:
2832 case ARM::VST3d32_UPD
:
2836 case ARM::VST4d8_UPD
:
2837 case ARM::VST4d16_UPD
:
2838 case ARM::VST4d32_UPD
:
2839 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+1)%32, Address
, Decoder
)))
2840 return MCDisassembler::Fail
;
2845 case ARM::VST3q8_UPD
:
2846 case ARM::VST3q16_UPD
:
2847 case ARM::VST3q32_UPD
:
2851 case ARM::VST4q8_UPD
:
2852 case ARM::VST4q16_UPD
:
2853 case ARM::VST4q32_UPD
:
2854 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+2)%32, Address
, Decoder
)))
2855 return MCDisassembler::Fail
;
2861 // Third input register
2862 switch (Inst
.getOpcode()) {
2866 case ARM::VST3d8_UPD
:
2867 case ARM::VST3d16_UPD
:
2868 case ARM::VST3d32_UPD
:
2872 case ARM::VST4d8_UPD
:
2873 case ARM::VST4d16_UPD
:
2874 case ARM::VST4d32_UPD
:
2875 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+2)%32, Address
, Decoder
)))
2876 return MCDisassembler::Fail
;
2881 case ARM::VST3q8_UPD
:
2882 case ARM::VST3q16_UPD
:
2883 case ARM::VST3q32_UPD
:
2887 case ARM::VST4q8_UPD
:
2888 case ARM::VST4q16_UPD
:
2889 case ARM::VST4q32_UPD
:
2890 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+4)%32, Address
, Decoder
)))
2891 return MCDisassembler::Fail
;
2897 // Fourth input register
2898 switch (Inst
.getOpcode()) {
2902 case ARM::VST4d8_UPD
:
2903 case ARM::VST4d16_UPD
:
2904 case ARM::VST4d32_UPD
:
2905 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+3)%32, Address
, Decoder
)))
2906 return MCDisassembler::Fail
;
2911 case ARM::VST4q8_UPD
:
2912 case ARM::VST4q16_UPD
:
2913 case ARM::VST4q32_UPD
:
2914 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+6)%32, Address
, Decoder
)))
2915 return MCDisassembler::Fail
;
2924 static DecodeStatus
DecodeVLD1DupInstruction(MCInst
&Inst
, unsigned Insn
,
2925 uint64_t Address
, const void *Decoder
) {
2926 DecodeStatus S
= MCDisassembler::Success
;
2928 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
2929 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
2930 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
2931 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
2932 unsigned align
= fieldFromInstruction(Insn
, 4, 1);
2933 unsigned size
= fieldFromInstruction(Insn
, 6, 2);
2935 if (size
== 0 && align
== 1)
2936 return MCDisassembler::Fail
;
2937 align
*= (1 << size
);
2939 switch (Inst
.getOpcode()) {
2940 case ARM::VLD1DUPq16
: case ARM::VLD1DUPq32
: case ARM::VLD1DUPq8
:
2941 case ARM::VLD1DUPq16wb_fixed
: case ARM::VLD1DUPq16wb_register
:
2942 case ARM::VLD1DUPq32wb_fixed
: case ARM::VLD1DUPq32wb_register
:
2943 case ARM::VLD1DUPq8wb_fixed
: case ARM::VLD1DUPq8wb_register
:
2944 if (!Check(S
, DecodeDPairRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2945 return MCDisassembler::Fail
;
2948 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2949 return MCDisassembler::Fail
;
2953 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
2954 return MCDisassembler::Fail
;
2957 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
2958 return MCDisassembler::Fail
;
2959 Inst
.addOperand(MCOperand::createImm(align
));
2961 // The fixed offset post-increment encodes Rm == 0xd. The no-writeback
2962 // variant encodes Rm == 0xf. Anything else is a register offset post-
2963 // increment and we need to add the register operand to the instruction.
2964 if (Rm
!= 0xD && Rm
!= 0xF &&
2965 !Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
2966 return MCDisassembler::Fail
;
2971 static DecodeStatus
DecodeVLD2DupInstruction(MCInst
&Inst
, unsigned Insn
,
2972 uint64_t Address
, const void *Decoder
) {
2973 DecodeStatus S
= MCDisassembler::Success
;
2975 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
2976 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
2977 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
2978 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
2979 unsigned align
= fieldFromInstruction(Insn
, 4, 1);
2980 unsigned size
= 1 << fieldFromInstruction(Insn
, 6, 2);
2983 switch (Inst
.getOpcode()) {
2984 case ARM::VLD2DUPd16
: case ARM::VLD2DUPd32
: case ARM::VLD2DUPd8
:
2985 case ARM::VLD2DUPd16wb_fixed
: case ARM::VLD2DUPd16wb_register
:
2986 case ARM::VLD2DUPd32wb_fixed
: case ARM::VLD2DUPd32wb_register
:
2987 case ARM::VLD2DUPd8wb_fixed
: case ARM::VLD2DUPd8wb_register
:
2988 if (!Check(S
, DecodeDPairRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2989 return MCDisassembler::Fail
;
2991 case ARM::VLD2DUPd16x2
: case ARM::VLD2DUPd32x2
: case ARM::VLD2DUPd8x2
:
2992 case ARM::VLD2DUPd16x2wb_fixed
: case ARM::VLD2DUPd16x2wb_register
:
2993 case ARM::VLD2DUPd32x2wb_fixed
: case ARM::VLD2DUPd32x2wb_register
:
2994 case ARM::VLD2DUPd8x2wb_fixed
: case ARM::VLD2DUPd8x2wb_register
:
2995 if (!Check(S
, DecodeDPairSpacedRegisterClass(Inst
, Rd
, Address
, Decoder
)))
2996 return MCDisassembler::Fail
;
2999 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
3000 return MCDisassembler::Fail
;
3005 Inst
.addOperand(MCOperand::createImm(0));
3007 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3008 return MCDisassembler::Fail
;
3009 Inst
.addOperand(MCOperand::createImm(align
));
3011 if (Rm
!= 0xD && Rm
!= 0xF) {
3012 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
3013 return MCDisassembler::Fail
;
3019 static DecodeStatus
DecodeVLD3DupInstruction(MCInst
&Inst
, unsigned Insn
,
3020 uint64_t Address
, const void *Decoder
) {
3021 DecodeStatus S
= MCDisassembler::Success
;
3023 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
3024 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
3025 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
3026 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
3027 unsigned inc
= fieldFromInstruction(Insn
, 5, 1) + 1;
3029 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
3030 return MCDisassembler::Fail
;
3031 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+inc
)%32, Address
, Decoder
)))
3032 return MCDisassembler::Fail
;
3033 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+2*inc
)%32, Address
, Decoder
)))
3034 return MCDisassembler::Fail
;
3036 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3037 return MCDisassembler::Fail
;
3040 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3041 return MCDisassembler::Fail
;
3042 Inst
.addOperand(MCOperand::createImm(0));
3045 Inst
.addOperand(MCOperand::createReg(0));
3046 else if (Rm
!= 0xF) {
3047 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
3048 return MCDisassembler::Fail
;
3054 static DecodeStatus
DecodeVLD4DupInstruction(MCInst
&Inst
, unsigned Insn
,
3055 uint64_t Address
, const void *Decoder
) {
3056 DecodeStatus S
= MCDisassembler::Success
;
3058 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
3059 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
3060 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
3061 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
3062 unsigned size
= fieldFromInstruction(Insn
, 6, 2);
3063 unsigned inc
= fieldFromInstruction(Insn
, 5, 1) + 1;
3064 unsigned align
= fieldFromInstruction(Insn
, 4, 1);
3068 return MCDisassembler::Fail
;
3079 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
3080 return MCDisassembler::Fail
;
3081 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+inc
)%32, Address
, Decoder
)))
3082 return MCDisassembler::Fail
;
3083 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+2*inc
)%32, Address
, Decoder
)))
3084 return MCDisassembler::Fail
;
3085 if (!Check(S
, DecodeDPRRegisterClass(Inst
, (Rd
+3*inc
)%32, Address
, Decoder
)))
3086 return MCDisassembler::Fail
;
3088 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3089 return MCDisassembler::Fail
;
3092 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3093 return MCDisassembler::Fail
;
3094 Inst
.addOperand(MCOperand::createImm(align
));
3097 Inst
.addOperand(MCOperand::createReg(0));
3098 else if (Rm
!= 0xF) {
3099 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
3100 return MCDisassembler::Fail
;
3107 DecodeNEONModImmInstruction(MCInst
&Inst
, unsigned Insn
,
3108 uint64_t Address
, const void *Decoder
) {
3109 DecodeStatus S
= MCDisassembler::Success
;
3111 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
3112 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
3113 unsigned imm
= fieldFromInstruction(Insn
, 0, 4);
3114 imm
|= fieldFromInstruction(Insn
, 16, 3) << 4;
3115 imm
|= fieldFromInstruction(Insn
, 24, 1) << 7;
3116 imm
|= fieldFromInstruction(Insn
, 8, 4) << 8;
3117 imm
|= fieldFromInstruction(Insn
, 5, 1) << 12;
3118 unsigned Q
= fieldFromInstruction(Insn
, 6, 1);
3121 if (!Check(S
, DecodeQPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
3122 return MCDisassembler::Fail
;
3124 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
3125 return MCDisassembler::Fail
;
3128 Inst
.addOperand(MCOperand::createImm(imm
));
3130 switch (Inst
.getOpcode()) {
3131 case ARM::VORRiv4i16
:
3132 case ARM::VORRiv2i32
:
3133 case ARM::VBICiv4i16
:
3134 case ARM::VBICiv2i32
:
3135 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
3136 return MCDisassembler::Fail
;
3138 case ARM::VORRiv8i16
:
3139 case ARM::VORRiv4i32
:
3140 case ARM::VBICiv8i16
:
3141 case ARM::VBICiv4i32
:
3142 if (!Check(S
, DecodeQPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
3143 return MCDisassembler::Fail
;
3152 static DecodeStatus
DecodeVSHLMaxInstruction(MCInst
&Inst
, unsigned Insn
,
3153 uint64_t Address
, const void *Decoder
) {
3154 DecodeStatus S
= MCDisassembler::Success
;
3156 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
3157 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
3158 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
3159 Rm
|= fieldFromInstruction(Insn
, 5, 1) << 4;
3160 unsigned size
= fieldFromInstruction(Insn
, 18, 2);
3162 if (!Check(S
, DecodeQPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
3163 return MCDisassembler::Fail
;
3164 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
3165 return MCDisassembler::Fail
;
3166 Inst
.addOperand(MCOperand::createImm(8 << size
));
3171 static DecodeStatus
DecodeShiftRight8Imm(MCInst
&Inst
, unsigned Val
,
3172 uint64_t Address
, const void *Decoder
) {
3173 Inst
.addOperand(MCOperand::createImm(8 - Val
));
3174 return MCDisassembler::Success
;
3177 static DecodeStatus
DecodeShiftRight16Imm(MCInst
&Inst
, unsigned Val
,
3178 uint64_t Address
, const void *Decoder
) {
3179 Inst
.addOperand(MCOperand::createImm(16 - Val
));
3180 return MCDisassembler::Success
;
3183 static DecodeStatus
DecodeShiftRight32Imm(MCInst
&Inst
, unsigned Val
,
3184 uint64_t Address
, const void *Decoder
) {
3185 Inst
.addOperand(MCOperand::createImm(32 - Val
));
3186 return MCDisassembler::Success
;
3189 static DecodeStatus
DecodeShiftRight64Imm(MCInst
&Inst
, unsigned Val
,
3190 uint64_t Address
, const void *Decoder
) {
3191 Inst
.addOperand(MCOperand::createImm(64 - Val
));
3192 return MCDisassembler::Success
;
3195 static DecodeStatus
DecodeTBLInstruction(MCInst
&Inst
, unsigned Insn
,
3196 uint64_t Address
, const void *Decoder
) {
3197 DecodeStatus S
= MCDisassembler::Success
;
3199 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
3200 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
3201 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
3202 Rn
|= fieldFromInstruction(Insn
, 7, 1) << 4;
3203 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
3204 Rm
|= fieldFromInstruction(Insn
, 5, 1) << 4;
3205 unsigned op
= fieldFromInstruction(Insn
, 6, 1);
3207 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
3208 return MCDisassembler::Fail
;
3210 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
3211 return MCDisassembler::Fail
; // Writeback
3214 switch (Inst
.getOpcode()) {
3217 if (!Check(S
, DecodeDPairRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3218 return MCDisassembler::Fail
;
3221 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3222 return MCDisassembler::Fail
;
3225 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
3226 return MCDisassembler::Fail
;
3231 static DecodeStatus
DecodeThumbAddSpecialReg(MCInst
&Inst
, uint16_t Insn
,
3232 uint64_t Address
, const void *Decoder
) {
3233 DecodeStatus S
= MCDisassembler::Success
;
3235 unsigned dst
= fieldFromInstruction(Insn
, 8, 3);
3236 unsigned imm
= fieldFromInstruction(Insn
, 0, 8);
3238 if (!Check(S
, DecodetGPRRegisterClass(Inst
, dst
, Address
, Decoder
)))
3239 return MCDisassembler::Fail
;
3241 switch(Inst
.getOpcode()) {
3243 return MCDisassembler::Fail
;
3245 break; // tADR does not explicitly represent the PC as an operand.
3247 Inst
.addOperand(MCOperand::createReg(ARM::SP
));
3251 Inst
.addOperand(MCOperand::createImm(imm
));
3255 static DecodeStatus
DecodeThumbBROperand(MCInst
&Inst
, unsigned Val
,
3256 uint64_t Address
, const void *Decoder
) {
3257 if (!tryAddingSymbolicOperand(Address
, Address
+ SignExtend32
<12>(Val
<<1) + 4,
3258 true, 2, Inst
, Decoder
))
3259 Inst
.addOperand(MCOperand::createImm(SignExtend32
<12>(Val
<< 1)));
3260 return MCDisassembler::Success
;
3263 static DecodeStatus
DecodeT2BROperand(MCInst
&Inst
, unsigned Val
,
3264 uint64_t Address
, const void *Decoder
) {
3265 if (!tryAddingSymbolicOperand(Address
, Address
+ SignExtend32
<21>(Val
) + 4,
3266 true, 4, Inst
, Decoder
))
3267 Inst
.addOperand(MCOperand::createImm(SignExtend32
<21>(Val
)));
3268 return MCDisassembler::Success
;
3271 static DecodeStatus
DecodeThumbCmpBROperand(MCInst
&Inst
, unsigned Val
,
3272 uint64_t Address
, const void *Decoder
) {
3273 if (!tryAddingSymbolicOperand(Address
, Address
+ (Val
<<1) + 4,
3274 true, 2, Inst
, Decoder
))
3275 Inst
.addOperand(MCOperand::createImm(Val
<< 1));
3276 return MCDisassembler::Success
;
3279 static DecodeStatus
DecodeThumbAddrModeRR(MCInst
&Inst
, unsigned Val
,
3280 uint64_t Address
, const void *Decoder
) {
3281 DecodeStatus S
= MCDisassembler::Success
;
3283 unsigned Rn
= fieldFromInstruction(Val
, 0, 3);
3284 unsigned Rm
= fieldFromInstruction(Val
, 3, 3);
3286 if (!Check(S
, DecodetGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3287 return MCDisassembler::Fail
;
3288 if (!Check(S
, DecodetGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
3289 return MCDisassembler::Fail
;
3294 static DecodeStatus
DecodeThumbAddrModeIS(MCInst
&Inst
, unsigned Val
,
3295 uint64_t Address
, const void *Decoder
) {
3296 DecodeStatus S
= MCDisassembler::Success
;
3298 unsigned Rn
= fieldFromInstruction(Val
, 0, 3);
3299 unsigned imm
= fieldFromInstruction(Val
, 3, 5);
3301 if (!Check(S
, DecodetGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3302 return MCDisassembler::Fail
;
3303 Inst
.addOperand(MCOperand::createImm(imm
));
3308 static DecodeStatus
DecodeThumbAddrModePC(MCInst
&Inst
, unsigned Val
,
3309 uint64_t Address
, const void *Decoder
) {
3310 unsigned imm
= Val
<< 2;
3312 Inst
.addOperand(MCOperand::createImm(imm
));
3313 tryAddingPcLoadReferenceComment(Address
, (Address
& ~2u) + imm
+ 4, Decoder
);
3315 return MCDisassembler::Success
;
3318 static DecodeStatus
DecodeThumbAddrModeSP(MCInst
&Inst
, unsigned Val
,
3319 uint64_t Address
, const void *Decoder
) {
3320 Inst
.addOperand(MCOperand::createReg(ARM::SP
));
3321 Inst
.addOperand(MCOperand::createImm(Val
));
3323 return MCDisassembler::Success
;
3326 static DecodeStatus
DecodeT2AddrModeSOReg(MCInst
&Inst
, unsigned Val
,
3327 uint64_t Address
, const void *Decoder
) {
3328 DecodeStatus S
= MCDisassembler::Success
;
3330 unsigned Rn
= fieldFromInstruction(Val
, 6, 4);
3331 unsigned Rm
= fieldFromInstruction(Val
, 2, 4);
3332 unsigned imm
= fieldFromInstruction(Val
, 0, 2);
3334 // Thumb stores cannot use PC as dest register.
3335 switch (Inst
.getOpcode()) {
3340 return MCDisassembler::Fail
;
3346 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3347 return MCDisassembler::Fail
;
3348 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
3349 return MCDisassembler::Fail
;
3350 Inst
.addOperand(MCOperand::createImm(imm
));
3355 static DecodeStatus
DecodeT2LoadShift(MCInst
&Inst
, unsigned Insn
,
3356 uint64_t Address
, const void *Decoder
) {
3357 DecodeStatus S
= MCDisassembler::Success
;
3359 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
3360 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
3362 const FeatureBitset
&featureBits
=
3363 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
3365 bool hasMP
= featureBits
[ARM::FeatureMP
];
3366 bool hasV7Ops
= featureBits
[ARM::HasV7Ops
];
3369 switch (Inst
.getOpcode()) {
3371 Inst
.setOpcode(ARM::t2LDRBpci
);
3374 Inst
.setOpcode(ARM::t2LDRHpci
);
3377 Inst
.setOpcode(ARM::t2LDRSHpci
);
3380 Inst
.setOpcode(ARM::t2LDRSBpci
);
3383 Inst
.setOpcode(ARM::t2LDRpci
);
3386 Inst
.setOpcode(ARM::t2PLDpci
);
3389 Inst
.setOpcode(ARM::t2PLIpci
);
3392 return MCDisassembler::Fail
;
3395 return DecodeT2LoadLabel(Inst
, Insn
, Address
, Decoder
);
3399 switch (Inst
.getOpcode()) {
3401 return MCDisassembler::Fail
;
3403 Inst
.setOpcode(ARM::t2PLDWs
);
3406 Inst
.setOpcode(ARM::t2PLIs
);
3413 switch (Inst
.getOpcode()) {
3418 return MCDisassembler::Fail
;
3421 if (!hasV7Ops
|| !hasMP
)
3422 return MCDisassembler::Fail
;
3425 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
3426 return MCDisassembler::Fail
;
3429 unsigned addrmode
= fieldFromInstruction(Insn
, 4, 2);
3430 addrmode
|= fieldFromInstruction(Insn
, 0, 4) << 2;
3431 addrmode
|= fieldFromInstruction(Insn
, 16, 4) << 6;
3432 if (!Check(S
, DecodeT2AddrModeSOReg(Inst
, addrmode
, Address
, Decoder
)))
3433 return MCDisassembler::Fail
;
3438 static DecodeStatus
DecodeT2LoadImm8(MCInst
&Inst
, unsigned Insn
,
3439 uint64_t Address
, const void* Decoder
) {
3440 DecodeStatus S
= MCDisassembler::Success
;
3442 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
3443 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
3444 unsigned U
= fieldFromInstruction(Insn
, 9, 1);
3445 unsigned imm
= fieldFromInstruction(Insn
, 0, 8);
3448 unsigned add
= fieldFromInstruction(Insn
, 9, 1);
3450 const FeatureBitset
&featureBits
=
3451 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
3453 bool hasMP
= featureBits
[ARM::FeatureMP
];
3454 bool hasV7Ops
= featureBits
[ARM::HasV7Ops
];
3457 switch (Inst
.getOpcode()) {
3459 Inst
.setOpcode(ARM::t2LDRpci
);
3462 Inst
.setOpcode(ARM::t2LDRBpci
);
3464 case ARM::t2LDRSBi8
:
3465 Inst
.setOpcode(ARM::t2LDRSBpci
);
3468 Inst
.setOpcode(ARM::t2LDRHpci
);
3470 case ARM::t2LDRSHi8
:
3471 Inst
.setOpcode(ARM::t2LDRSHpci
);
3474 Inst
.setOpcode(ARM::t2PLDpci
);
3477 Inst
.setOpcode(ARM::t2PLIpci
);
3480 return MCDisassembler::Fail
;
3482 return DecodeT2LoadLabel(Inst
, Insn
, Address
, Decoder
);
3486 switch (Inst
.getOpcode()) {
3487 case ARM::t2LDRSHi8
:
3488 return MCDisassembler::Fail
;
3491 Inst
.setOpcode(ARM::t2PLDWi8
);
3493 case ARM::t2LDRSBi8
:
3494 Inst
.setOpcode(ARM::t2PLIi8
);
3501 switch (Inst
.getOpcode()) {
3506 return MCDisassembler::Fail
;
3509 if (!hasV7Ops
|| !hasMP
)
3510 return MCDisassembler::Fail
;
3513 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
3514 return MCDisassembler::Fail
;
3517 if (!Check(S
, DecodeT2AddrModeImm8(Inst
, imm
, Address
, Decoder
)))
3518 return MCDisassembler::Fail
;
3522 static DecodeStatus
DecodeT2LoadImm12(MCInst
&Inst
, unsigned Insn
,
3523 uint64_t Address
, const void* Decoder
) {
3524 DecodeStatus S
= MCDisassembler::Success
;
3526 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
3527 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
3528 unsigned imm
= fieldFromInstruction(Insn
, 0, 12);
3531 const FeatureBitset
&featureBits
=
3532 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
3534 bool hasMP
= featureBits
[ARM::FeatureMP
];
3535 bool hasV7Ops
= featureBits
[ARM::HasV7Ops
];
3538 switch (Inst
.getOpcode()) {
3540 Inst
.setOpcode(ARM::t2LDRpci
);
3542 case ARM::t2LDRHi12
:
3543 Inst
.setOpcode(ARM::t2LDRHpci
);
3545 case ARM::t2LDRSHi12
:
3546 Inst
.setOpcode(ARM::t2LDRSHpci
);
3548 case ARM::t2LDRBi12
:
3549 Inst
.setOpcode(ARM::t2LDRBpci
);
3551 case ARM::t2LDRSBi12
:
3552 Inst
.setOpcode(ARM::t2LDRSBpci
);
3555 Inst
.setOpcode(ARM::t2PLDpci
);
3558 Inst
.setOpcode(ARM::t2PLIpci
);
3561 return MCDisassembler::Fail
;
3563 return DecodeT2LoadLabel(Inst
, Insn
, Address
, Decoder
);
3567 switch (Inst
.getOpcode()) {
3568 case ARM::t2LDRSHi12
:
3569 return MCDisassembler::Fail
;
3570 case ARM::t2LDRHi12
:
3571 Inst
.setOpcode(ARM::t2PLDWi12
);
3573 case ARM::t2LDRSBi12
:
3574 Inst
.setOpcode(ARM::t2PLIi12
);
3581 switch (Inst
.getOpcode()) {
3586 return MCDisassembler::Fail
;
3588 case ARM::t2PLDWi12
:
3589 if (!hasV7Ops
|| !hasMP
)
3590 return MCDisassembler::Fail
;
3593 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
3594 return MCDisassembler::Fail
;
3597 if (!Check(S
, DecodeT2AddrModeImm12(Inst
, imm
, Address
, Decoder
)))
3598 return MCDisassembler::Fail
;
3602 static DecodeStatus
DecodeT2LoadT(MCInst
&Inst
, unsigned Insn
,
3603 uint64_t Address
, const void* Decoder
) {
3604 DecodeStatus S
= MCDisassembler::Success
;
3606 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
3607 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
3608 unsigned imm
= fieldFromInstruction(Insn
, 0, 8);
3612 switch (Inst
.getOpcode()) {
3614 Inst
.setOpcode(ARM::t2LDRpci
);
3617 Inst
.setOpcode(ARM::t2LDRBpci
);
3620 Inst
.setOpcode(ARM::t2LDRHpci
);
3623 Inst
.setOpcode(ARM::t2LDRSBpci
);
3626 Inst
.setOpcode(ARM::t2LDRSHpci
);
3629 return MCDisassembler::Fail
;
3631 return DecodeT2LoadLabel(Inst
, Insn
, Address
, Decoder
);
3634 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
3635 return MCDisassembler::Fail
;
3636 if (!Check(S
, DecodeT2AddrModeImm8(Inst
, imm
, Address
, Decoder
)))
3637 return MCDisassembler::Fail
;
3641 static DecodeStatus
DecodeT2LoadLabel(MCInst
&Inst
, unsigned Insn
,
3642 uint64_t Address
, const void* Decoder
) {
3643 DecodeStatus S
= MCDisassembler::Success
;
3645 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
3646 unsigned U
= fieldFromInstruction(Insn
, 23, 1);
3647 int imm
= fieldFromInstruction(Insn
, 0, 12);
3649 const FeatureBitset
&featureBits
=
3650 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
3652 bool hasV7Ops
= featureBits
[ARM::HasV7Ops
];
3655 switch (Inst
.getOpcode()) {
3656 case ARM::t2LDRBpci
:
3657 case ARM::t2LDRHpci
:
3658 Inst
.setOpcode(ARM::t2PLDpci
);
3660 case ARM::t2LDRSBpci
:
3661 Inst
.setOpcode(ARM::t2PLIpci
);
3663 case ARM::t2LDRSHpci
:
3664 return MCDisassembler::Fail
;
3670 switch(Inst
.getOpcode()) {
3675 return MCDisassembler::Fail
;
3678 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
3679 return MCDisassembler::Fail
;
3683 // Special case for #-0.
3689 Inst
.addOperand(MCOperand::createImm(imm
));
3694 static DecodeStatus
DecodeT2Imm8S4(MCInst
&Inst
, unsigned Val
,
3695 uint64_t Address
, const void *Decoder
) {
3697 Inst
.addOperand(MCOperand::createImm(INT32_MIN
));
3699 int imm
= Val
& 0xFF;
3701 if (!(Val
& 0x100)) imm
*= -1;
3702 Inst
.addOperand(MCOperand::createImm(imm
* 4));
3705 return MCDisassembler::Success
;
3708 static DecodeStatus
DecodeT2AddrModeImm8s4(MCInst
&Inst
, unsigned Val
,
3709 uint64_t Address
, const void *Decoder
) {
3710 DecodeStatus S
= MCDisassembler::Success
;
3712 unsigned Rn
= fieldFromInstruction(Val
, 9, 4);
3713 unsigned imm
= fieldFromInstruction(Val
, 0, 9);
3715 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3716 return MCDisassembler::Fail
;
3717 if (!Check(S
, DecodeT2Imm8S4(Inst
, imm
, Address
, Decoder
)))
3718 return MCDisassembler::Fail
;
3723 static DecodeStatus
DecodeT2AddrModeImm0_1020s4(MCInst
&Inst
,unsigned Val
,
3724 uint64_t Address
, const void *Decoder
) {
3725 DecodeStatus S
= MCDisassembler::Success
;
3727 unsigned Rn
= fieldFromInstruction(Val
, 8, 4);
3728 unsigned imm
= fieldFromInstruction(Val
, 0, 8);
3730 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3731 return MCDisassembler::Fail
;
3733 Inst
.addOperand(MCOperand::createImm(imm
));
3738 static DecodeStatus
DecodeT2Imm8(MCInst
&Inst
, unsigned Val
,
3739 uint64_t Address
, const void *Decoder
) {
3740 int imm
= Val
& 0xFF;
3743 else if (!(Val
& 0x100))
3745 Inst
.addOperand(MCOperand::createImm(imm
));
3747 return MCDisassembler::Success
;
3750 static DecodeStatus
DecodeT2AddrModeImm8(MCInst
&Inst
, unsigned Val
,
3751 uint64_t Address
, const void *Decoder
) {
3752 DecodeStatus S
= MCDisassembler::Success
;
3754 unsigned Rn
= fieldFromInstruction(Val
, 9, 4);
3755 unsigned imm
= fieldFromInstruction(Val
, 0, 9);
3757 // Thumb stores cannot use PC as dest register.
3758 switch (Inst
.getOpcode()) {
3766 return MCDisassembler::Fail
;
3772 // Some instructions always use an additive offset.
3773 switch (Inst
.getOpcode()) {
3788 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3789 return MCDisassembler::Fail
;
3790 if (!Check(S
, DecodeT2Imm8(Inst
, imm
, Address
, Decoder
)))
3791 return MCDisassembler::Fail
;
3796 static DecodeStatus
DecodeT2LdStPre(MCInst
&Inst
, unsigned Insn
,
3797 uint64_t Address
, const void *Decoder
) {
3798 DecodeStatus S
= MCDisassembler::Success
;
3800 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
3801 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
3802 unsigned addr
= fieldFromInstruction(Insn
, 0, 8);
3803 addr
|= fieldFromInstruction(Insn
, 9, 1) << 8;
3805 unsigned load
= fieldFromInstruction(Insn
, 20, 1);
3808 switch (Inst
.getOpcode()) {
3809 case ARM::t2LDR_PRE
:
3810 case ARM::t2LDR_POST
:
3811 Inst
.setOpcode(ARM::t2LDRpci
);
3813 case ARM::t2LDRB_PRE
:
3814 case ARM::t2LDRB_POST
:
3815 Inst
.setOpcode(ARM::t2LDRBpci
);
3817 case ARM::t2LDRH_PRE
:
3818 case ARM::t2LDRH_POST
:
3819 Inst
.setOpcode(ARM::t2LDRHpci
);
3821 case ARM::t2LDRSB_PRE
:
3822 case ARM::t2LDRSB_POST
:
3824 Inst
.setOpcode(ARM::t2PLIpci
);
3826 Inst
.setOpcode(ARM::t2LDRSBpci
);
3828 case ARM::t2LDRSH_PRE
:
3829 case ARM::t2LDRSH_POST
:
3830 Inst
.setOpcode(ARM::t2LDRSHpci
);
3833 return MCDisassembler::Fail
;
3835 return DecodeT2LoadLabel(Inst
, Insn
, Address
, Decoder
);
3839 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3840 return MCDisassembler::Fail
;
3843 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
3844 return MCDisassembler::Fail
;
3847 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3848 return MCDisassembler::Fail
;
3851 if (!Check(S
, DecodeT2AddrModeImm8(Inst
, addr
, Address
, Decoder
)))
3852 return MCDisassembler::Fail
;
3857 static DecodeStatus
DecodeT2AddrModeImm12(MCInst
&Inst
, unsigned Val
,
3858 uint64_t Address
, const void *Decoder
) {
3859 DecodeStatus S
= MCDisassembler::Success
;
3861 unsigned Rn
= fieldFromInstruction(Val
, 13, 4);
3862 unsigned imm
= fieldFromInstruction(Val
, 0, 12);
3864 // Thumb stores cannot use PC as dest register.
3865 switch (Inst
.getOpcode()) {
3867 case ARM::t2STRBi12
:
3868 case ARM::t2STRHi12
:
3870 return MCDisassembler::Fail
;
3876 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3877 return MCDisassembler::Fail
;
3878 Inst
.addOperand(MCOperand::createImm(imm
));
3883 static DecodeStatus
DecodeThumbAddSPImm(MCInst
&Inst
, uint16_t Insn
,
3884 uint64_t Address
, const void *Decoder
) {
3885 unsigned imm
= fieldFromInstruction(Insn
, 0, 7);
3887 Inst
.addOperand(MCOperand::createReg(ARM::SP
));
3888 Inst
.addOperand(MCOperand::createReg(ARM::SP
));
3889 Inst
.addOperand(MCOperand::createImm(imm
));
3891 return MCDisassembler::Success
;
3894 static DecodeStatus
DecodeThumbAddSPReg(MCInst
&Inst
, uint16_t Insn
,
3895 uint64_t Address
, const void *Decoder
) {
3896 DecodeStatus S
= MCDisassembler::Success
;
3898 if (Inst
.getOpcode() == ARM::tADDrSP
) {
3899 unsigned Rdm
= fieldFromInstruction(Insn
, 0, 3);
3900 Rdm
|= fieldFromInstruction(Insn
, 7, 1) << 3;
3902 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rdm
, Address
, Decoder
)))
3903 return MCDisassembler::Fail
;
3904 Inst
.addOperand(MCOperand::createReg(ARM::SP
));
3905 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rdm
, Address
, Decoder
)))
3906 return MCDisassembler::Fail
;
3907 } else if (Inst
.getOpcode() == ARM::tADDspr
) {
3908 unsigned Rm
= fieldFromInstruction(Insn
, 3, 4);
3910 Inst
.addOperand(MCOperand::createReg(ARM::SP
));
3911 Inst
.addOperand(MCOperand::createReg(ARM::SP
));
3912 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
3913 return MCDisassembler::Fail
;
3919 static DecodeStatus
DecodeThumbCPS(MCInst
&Inst
, uint16_t Insn
,
3920 uint64_t Address
, const void *Decoder
) {
3921 unsigned imod
= fieldFromInstruction(Insn
, 4, 1) | 0x2;
3922 unsigned flags
= fieldFromInstruction(Insn
, 0, 3);
3924 Inst
.addOperand(MCOperand::createImm(imod
));
3925 Inst
.addOperand(MCOperand::createImm(flags
));
3927 return MCDisassembler::Success
;
3930 static DecodeStatus
DecodePostIdxReg(MCInst
&Inst
, unsigned Insn
,
3931 uint64_t Address
, const void *Decoder
) {
3932 DecodeStatus S
= MCDisassembler::Success
;
3933 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
3934 unsigned add
= fieldFromInstruction(Insn
, 4, 1);
3936 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rm
, Address
, Decoder
)))
3937 return MCDisassembler::Fail
;
3938 Inst
.addOperand(MCOperand::createImm(add
));
3943 static DecodeStatus
DecodeThumbBLXOffset(MCInst
&Inst
, unsigned Val
,
3944 uint64_t Address
, const void *Decoder
) {
3945 // Val is passed in as S:J1:J2:imm10H:imm10L:'0'
3946 // Note only one trailing zero not two. Also the J1 and J2 values are from
3947 // the encoded instruction. So here change to I1 and I2 values via:
3948 // I1 = NOT(J1 EOR S);
3949 // I2 = NOT(J2 EOR S);
3950 // and build the imm32 with two trailing zeros as documented:
3951 // imm32 = SignExtend(S:I1:I2:imm10H:imm10L:'00', 32);
3952 unsigned S
= (Val
>> 23) & 1;
3953 unsigned J1
= (Val
>> 22) & 1;
3954 unsigned J2
= (Val
>> 21) & 1;
3955 unsigned I1
= !(J1
^ S
);
3956 unsigned I2
= !(J2
^ S
);
3957 unsigned tmp
= (Val
& ~0x600000) | (I1
<< 22) | (I2
<< 21);
3958 int imm32
= SignExtend32
<25>(tmp
<< 1);
3960 if (!tryAddingSymbolicOperand(Address
,
3961 (Address
& ~2u) + imm32
+ 4,
3962 true, 4, Inst
, Decoder
))
3963 Inst
.addOperand(MCOperand::createImm(imm32
));
3964 return MCDisassembler::Success
;
3967 static DecodeStatus
DecodeCoprocessor(MCInst
&Inst
, unsigned Val
,
3968 uint64_t Address
, const void *Decoder
) {
3969 if (Val
== 0xA || Val
== 0xB)
3970 return MCDisassembler::Fail
;
3972 const FeatureBitset
&featureBits
=
3973 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
3975 if (featureBits
[ARM::HasV8Ops
] && !(Val
== 14 || Val
== 15))
3976 return MCDisassembler::Fail
;
3978 Inst
.addOperand(MCOperand::createImm(Val
));
3979 return MCDisassembler::Success
;
3983 DecodeThumbTableBranch(MCInst
&Inst
, unsigned Insn
,
3984 uint64_t Address
, const void *Decoder
) {
3985 DecodeStatus S
= MCDisassembler::Success
;
3987 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
3988 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
3990 if (Rn
== ARM::SP
) S
= MCDisassembler::SoftFail
;
3991 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
3992 return MCDisassembler::Fail
;
3993 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
3994 return MCDisassembler::Fail
;
3999 DecodeThumb2BCCInstruction(MCInst
&Inst
, unsigned Insn
,
4000 uint64_t Address
, const void *Decoder
) {
4001 DecodeStatus S
= MCDisassembler::Success
;
4003 unsigned pred
= fieldFromInstruction(Insn
, 22, 4);
4004 if (pred
== 0xE || pred
== 0xF) {
4005 unsigned opc
= fieldFromInstruction(Insn
, 4, 28);
4008 return MCDisassembler::Fail
;
4010 Inst
.setOpcode(ARM::t2DSB
);
4013 Inst
.setOpcode(ARM::t2DMB
);
4016 Inst
.setOpcode(ARM::t2ISB
);
4020 unsigned imm
= fieldFromInstruction(Insn
, 0, 4);
4021 return DecodeMemBarrierOption(Inst
, imm
, Address
, Decoder
);
4024 unsigned brtarget
= fieldFromInstruction(Insn
, 0, 11) << 1;
4025 brtarget
|= fieldFromInstruction(Insn
, 11, 1) << 19;
4026 brtarget
|= fieldFromInstruction(Insn
, 13, 1) << 18;
4027 brtarget
|= fieldFromInstruction(Insn
, 16, 6) << 12;
4028 brtarget
|= fieldFromInstruction(Insn
, 26, 1) << 20;
4030 if (!Check(S
, DecodeT2BROperand(Inst
, brtarget
, Address
, Decoder
)))
4031 return MCDisassembler::Fail
;
4032 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
4033 return MCDisassembler::Fail
;
4038 // Decode a shifted immediate operand. These basically consist
4039 // of an 8-bit value, and a 4-bit directive that specifies either
4040 // a splat operation or a rotation.
4041 static DecodeStatus
DecodeT2SOImm(MCInst
&Inst
, unsigned Val
,
4042 uint64_t Address
, const void *Decoder
) {
4043 unsigned ctrl
= fieldFromInstruction(Val
, 10, 2);
4045 unsigned byte
= fieldFromInstruction(Val
, 8, 2);
4046 unsigned imm
= fieldFromInstruction(Val
, 0, 8);
4049 Inst
.addOperand(MCOperand::createImm(imm
));
4052 Inst
.addOperand(MCOperand::createImm((imm
<< 16) | imm
));
4055 Inst
.addOperand(MCOperand::createImm((imm
<< 24) | (imm
<< 8)));
4058 Inst
.addOperand(MCOperand::createImm((imm
<< 24) | (imm
<< 16) |
4063 unsigned unrot
= fieldFromInstruction(Val
, 0, 7) | 0x80;
4064 unsigned rot
= fieldFromInstruction(Val
, 7, 5);
4065 unsigned imm
= (unrot
>> rot
) | (unrot
<< ((32-rot
)&31));
4066 Inst
.addOperand(MCOperand::createImm(imm
));
4069 return MCDisassembler::Success
;
4073 DecodeThumbBCCTargetOperand(MCInst
&Inst
, unsigned Val
,
4074 uint64_t Address
, const void *Decoder
) {
4075 if (!tryAddingSymbolicOperand(Address
, Address
+ SignExtend32
<9>(Val
<<1) + 4,
4076 true, 2, Inst
, Decoder
))
4077 Inst
.addOperand(MCOperand::createImm(SignExtend32
<9>(Val
<< 1)));
4078 return MCDisassembler::Success
;
4081 static DecodeStatus
DecodeThumbBLTargetOperand(MCInst
&Inst
, unsigned Val
,
4083 const void *Decoder
) {
4084 // Val is passed in as S:J1:J2:imm10:imm11
4085 // Note no trailing zero after imm11. Also the J1 and J2 values are from
4086 // the encoded instruction. So here change to I1 and I2 values via:
4087 // I1 = NOT(J1 EOR S);
4088 // I2 = NOT(J2 EOR S);
4089 // and build the imm32 with one trailing zero as documented:
4090 // imm32 = SignExtend(S:I1:I2:imm10:imm11:'0', 32);
4091 unsigned S
= (Val
>> 23) & 1;
4092 unsigned J1
= (Val
>> 22) & 1;
4093 unsigned J2
= (Val
>> 21) & 1;
4094 unsigned I1
= !(J1
^ S
);
4095 unsigned I2
= !(J2
^ S
);
4096 unsigned tmp
= (Val
& ~0x600000) | (I1
<< 22) | (I2
<< 21);
4097 int imm32
= SignExtend32
<25>(tmp
<< 1);
4099 if (!tryAddingSymbolicOperand(Address
, Address
+ imm32
+ 4,
4100 true, 4, Inst
, Decoder
))
4101 Inst
.addOperand(MCOperand::createImm(imm32
));
4102 return MCDisassembler::Success
;
4105 static DecodeStatus
DecodeMemBarrierOption(MCInst
&Inst
, unsigned Val
,
4106 uint64_t Address
, const void *Decoder
) {
4108 return MCDisassembler::Fail
;
4110 Inst
.addOperand(MCOperand::createImm(Val
));
4111 return MCDisassembler::Success
;
4114 static DecodeStatus
DecodeInstSyncBarrierOption(MCInst
&Inst
, unsigned Val
,
4115 uint64_t Address
, const void *Decoder
) {
4117 return MCDisassembler::Fail
;
4119 Inst
.addOperand(MCOperand::createImm(Val
));
4120 return MCDisassembler::Success
;
4123 static DecodeStatus
DecodeMSRMask(MCInst
&Inst
, unsigned Val
,
4124 uint64_t Address
, const void *Decoder
) {
4125 DecodeStatus S
= MCDisassembler::Success
;
4126 const FeatureBitset
&FeatureBits
=
4127 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
4129 if (FeatureBits
[ARM::FeatureMClass
]) {
4130 unsigned ValLow
= Val
& 0xff;
4132 // Validate the SYSm value first.
4147 case 18: // basepri_max
4148 case 19: // faultmask
4149 if (!(FeatureBits
[ARM::HasV7Ops
]))
4150 // Values basepri, basepri_max and faultmask are only valid for v7m.
4151 return MCDisassembler::Fail
;
4153 case 0x8a: // msplim_ns
4154 case 0x8b: // psplim_ns
4155 case 0x91: // basepri_ns
4156 case 0x93: // faultmask_ns
4157 if (!(FeatureBits
[ARM::HasV8MMainlineOps
]))
4158 return MCDisassembler::Fail
;
4162 case 0x88: // msp_ns
4163 case 0x89: // psp_ns
4164 case 0x90: // primask_ns
4165 case 0x94: // control_ns
4167 if (!(FeatureBits
[ARM::Feature8MSecExt
]))
4168 return MCDisassembler::Fail
;
4171 // Architecturally defined as unpredictable
4172 S
= MCDisassembler::SoftFail
;
4176 if (Inst
.getOpcode() == ARM::t2MSR_M
) {
4177 unsigned Mask
= fieldFromInstruction(Val
, 10, 2);
4178 if (!(FeatureBits
[ARM::HasV7Ops
])) {
4179 // The ARMv6-M MSR bits {11-10} can be only 0b10, other values are
4182 S
= MCDisassembler::SoftFail
;
4185 // The ARMv7-M architecture stores an additional 2-bit mask value in
4186 // MSR bits {11-10}. The mask is used only with apsr, iapsr, eapsr and
4187 // xpsr, it has to be 0b10 in other cases. Bit mask{1} indicates if
4188 // the NZCVQ bits should be moved by the instruction. Bit mask{0}
4189 // indicates the move for the GE{3:0} bits, the mask{0} bit can be set
4190 // only if the processor includes the DSP extension.
4191 if (Mask
== 0 || (Mask
!= 2 && ValLow
> 3) ||
4192 (!(FeatureBits
[ARM::FeatureDSP
]) && (Mask
& 1)))
4193 S
= MCDisassembler::SoftFail
;
4199 return MCDisassembler::Fail
;
4201 Inst
.addOperand(MCOperand::createImm(Val
));
4205 static DecodeStatus
DecodeBankedReg(MCInst
&Inst
, unsigned Val
,
4206 uint64_t Address
, const void *Decoder
) {
4207 unsigned R
= fieldFromInstruction(Val
, 5, 1);
4208 unsigned SysM
= fieldFromInstruction(Val
, 0, 5);
4210 // The table of encodings for these banked registers comes from B9.2.3 of the
4211 // ARM ARM. There are patterns, but nothing regular enough to make this logic
4212 // neater. So by fiat, these values are UNPREDICTABLE:
4213 if (!ARMBankedReg::lookupBankedRegByEncoding((R
<< 5) | SysM
))
4214 return MCDisassembler::Fail
;
4216 Inst
.addOperand(MCOperand::createImm(Val
));
4217 return MCDisassembler::Success
;
4220 static DecodeStatus
DecodeDoubleRegLoad(MCInst
&Inst
, unsigned Insn
,
4221 uint64_t Address
, const void *Decoder
) {
4222 DecodeStatus S
= MCDisassembler::Success
;
4224 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
4225 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4226 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
4229 S
= MCDisassembler::SoftFail
;
4231 if (!Check(S
, DecodeGPRPairRegisterClass(Inst
, Rt
, Address
, Decoder
)))
4232 return MCDisassembler::Fail
;
4233 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4234 return MCDisassembler::Fail
;
4235 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
4236 return MCDisassembler::Fail
;
4241 static DecodeStatus
DecodeDoubleRegStore(MCInst
&Inst
, unsigned Insn
,
4243 const void *Decoder
) {
4244 DecodeStatus S
= MCDisassembler::Success
;
4246 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
4247 unsigned Rt
= fieldFromInstruction(Insn
, 0, 4);
4248 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4249 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
4251 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4252 return MCDisassembler::Fail
;
4254 if (Rn
== 0xF || Rd
== Rn
|| Rd
== Rt
|| Rd
== Rt
+1)
4255 S
= MCDisassembler::SoftFail
;
4257 if (!Check(S
, DecodeGPRPairRegisterClass(Inst
, Rt
, Address
, Decoder
)))
4258 return MCDisassembler::Fail
;
4259 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4260 return MCDisassembler::Fail
;
4261 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
4262 return MCDisassembler::Fail
;
4267 static DecodeStatus
DecodeLDRPreImm(MCInst
&Inst
, unsigned Insn
,
4268 uint64_t Address
, const void *Decoder
) {
4269 DecodeStatus S
= MCDisassembler::Success
;
4271 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4272 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
4273 unsigned imm
= fieldFromInstruction(Insn
, 0, 12);
4274 imm
|= fieldFromInstruction(Insn
, 16, 4) << 13;
4275 imm
|= fieldFromInstruction(Insn
, 23, 1) << 12;
4276 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
4278 if (Rn
== 0xF || Rn
== Rt
) S
= MCDisassembler::SoftFail
;
4280 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
4281 return MCDisassembler::Fail
;
4282 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4283 return MCDisassembler::Fail
;
4284 if (!Check(S
, DecodeAddrModeImm12Operand(Inst
, imm
, Address
, Decoder
)))
4285 return MCDisassembler::Fail
;
4286 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
4287 return MCDisassembler::Fail
;
4292 static DecodeStatus
DecodeLDRPreReg(MCInst
&Inst
, unsigned Insn
,
4293 uint64_t Address
, const void *Decoder
) {
4294 DecodeStatus S
= MCDisassembler::Success
;
4296 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4297 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
4298 unsigned imm
= fieldFromInstruction(Insn
, 0, 12);
4299 imm
|= fieldFromInstruction(Insn
, 16, 4) << 13;
4300 imm
|= fieldFromInstruction(Insn
, 23, 1) << 12;
4301 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
4302 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
4304 if (Rn
== 0xF || Rn
== Rt
) S
= MCDisassembler::SoftFail
;
4305 if (Rm
== 0xF) S
= MCDisassembler::SoftFail
;
4307 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
4308 return MCDisassembler::Fail
;
4309 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4310 return MCDisassembler::Fail
;
4311 if (!Check(S
, DecodeSORegMemOperand(Inst
, imm
, Address
, Decoder
)))
4312 return MCDisassembler::Fail
;
4313 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
4314 return MCDisassembler::Fail
;
4319 static DecodeStatus
DecodeSTRPreImm(MCInst
&Inst
, unsigned Insn
,
4320 uint64_t Address
, const void *Decoder
) {
4321 DecodeStatus S
= MCDisassembler::Success
;
4323 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4324 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
4325 unsigned imm
= fieldFromInstruction(Insn
, 0, 12);
4326 imm
|= fieldFromInstruction(Insn
, 16, 4) << 13;
4327 imm
|= fieldFromInstruction(Insn
, 23, 1) << 12;
4328 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
4330 if (Rn
== 0xF || Rn
== Rt
) S
= MCDisassembler::SoftFail
;
4332 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4333 return MCDisassembler::Fail
;
4334 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
4335 return MCDisassembler::Fail
;
4336 if (!Check(S
, DecodeAddrModeImm12Operand(Inst
, imm
, Address
, Decoder
)))
4337 return MCDisassembler::Fail
;
4338 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
4339 return MCDisassembler::Fail
;
4344 static DecodeStatus
DecodeSTRPreReg(MCInst
&Inst
, unsigned Insn
,
4345 uint64_t Address
, const void *Decoder
) {
4346 DecodeStatus S
= MCDisassembler::Success
;
4348 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4349 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
4350 unsigned imm
= fieldFromInstruction(Insn
, 0, 12);
4351 imm
|= fieldFromInstruction(Insn
, 16, 4) << 13;
4352 imm
|= fieldFromInstruction(Insn
, 23, 1) << 12;
4353 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
4355 if (Rn
== 0xF || Rn
== Rt
) S
= MCDisassembler::SoftFail
;
4357 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4358 return MCDisassembler::Fail
;
4359 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
4360 return MCDisassembler::Fail
;
4361 if (!Check(S
, DecodeSORegMemOperand(Inst
, imm
, Address
, Decoder
)))
4362 return MCDisassembler::Fail
;
4363 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
4364 return MCDisassembler::Fail
;
4369 static DecodeStatus
DecodeVLD1LN(MCInst
&Inst
, unsigned Insn
,
4370 uint64_t Address
, const void *Decoder
) {
4371 DecodeStatus S
= MCDisassembler::Success
;
4373 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4374 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
4375 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
4376 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
4377 unsigned size
= fieldFromInstruction(Insn
, 10, 2);
4383 return MCDisassembler::Fail
;
4385 if (fieldFromInstruction(Insn
, 4, 1))
4386 return MCDisassembler::Fail
; // UNDEFINED
4387 index
= fieldFromInstruction(Insn
, 5, 3);
4390 if (fieldFromInstruction(Insn
, 5, 1))
4391 return MCDisassembler::Fail
; // UNDEFINED
4392 index
= fieldFromInstruction(Insn
, 6, 2);
4393 if (fieldFromInstruction(Insn
, 4, 1))
4397 if (fieldFromInstruction(Insn
, 6, 1))
4398 return MCDisassembler::Fail
; // UNDEFINED
4399 index
= fieldFromInstruction(Insn
, 7, 1);
4401 switch (fieldFromInstruction(Insn
, 4, 2)) {
4407 return MCDisassembler::Fail
;
4412 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4413 return MCDisassembler::Fail
;
4414 if (Rm
!= 0xF) { // Writeback
4415 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4416 return MCDisassembler::Fail
;
4418 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4419 return MCDisassembler::Fail
;
4420 Inst
.addOperand(MCOperand::createImm(align
));
4423 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
4424 return MCDisassembler::Fail
;
4426 Inst
.addOperand(MCOperand::createReg(0));
4429 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4430 return MCDisassembler::Fail
;
4431 Inst
.addOperand(MCOperand::createImm(index
));
4436 static DecodeStatus
DecodeVST1LN(MCInst
&Inst
, unsigned Insn
,
4437 uint64_t Address
, const void *Decoder
) {
4438 DecodeStatus S
= MCDisassembler::Success
;
4440 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4441 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
4442 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
4443 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
4444 unsigned size
= fieldFromInstruction(Insn
, 10, 2);
4450 return MCDisassembler::Fail
;
4452 if (fieldFromInstruction(Insn
, 4, 1))
4453 return MCDisassembler::Fail
; // UNDEFINED
4454 index
= fieldFromInstruction(Insn
, 5, 3);
4457 if (fieldFromInstruction(Insn
, 5, 1))
4458 return MCDisassembler::Fail
; // UNDEFINED
4459 index
= fieldFromInstruction(Insn
, 6, 2);
4460 if (fieldFromInstruction(Insn
, 4, 1))
4464 if (fieldFromInstruction(Insn
, 6, 1))
4465 return MCDisassembler::Fail
; // UNDEFINED
4466 index
= fieldFromInstruction(Insn
, 7, 1);
4468 switch (fieldFromInstruction(Insn
, 4, 2)) {
4474 return MCDisassembler::Fail
;
4479 if (Rm
!= 0xF) { // Writeback
4480 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4481 return MCDisassembler::Fail
;
4483 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4484 return MCDisassembler::Fail
;
4485 Inst
.addOperand(MCOperand::createImm(align
));
4488 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
4489 return MCDisassembler::Fail
;
4491 Inst
.addOperand(MCOperand::createReg(0));
4494 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4495 return MCDisassembler::Fail
;
4496 Inst
.addOperand(MCOperand::createImm(index
));
4501 static DecodeStatus
DecodeVLD2LN(MCInst
&Inst
, unsigned Insn
,
4502 uint64_t Address
, const void *Decoder
) {
4503 DecodeStatus S
= MCDisassembler::Success
;
4505 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4506 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
4507 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
4508 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
4509 unsigned size
= fieldFromInstruction(Insn
, 10, 2);
4516 return MCDisassembler::Fail
;
4518 index
= fieldFromInstruction(Insn
, 5, 3);
4519 if (fieldFromInstruction(Insn
, 4, 1))
4523 index
= fieldFromInstruction(Insn
, 6, 2);
4524 if (fieldFromInstruction(Insn
, 4, 1))
4526 if (fieldFromInstruction(Insn
, 5, 1))
4530 if (fieldFromInstruction(Insn
, 5, 1))
4531 return MCDisassembler::Fail
; // UNDEFINED
4532 index
= fieldFromInstruction(Insn
, 7, 1);
4533 if (fieldFromInstruction(Insn
, 4, 1) != 0)
4535 if (fieldFromInstruction(Insn
, 6, 1))
4540 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4541 return MCDisassembler::Fail
;
4542 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+inc
, Address
, Decoder
)))
4543 return MCDisassembler::Fail
;
4544 if (Rm
!= 0xF) { // Writeback
4545 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4546 return MCDisassembler::Fail
;
4548 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4549 return MCDisassembler::Fail
;
4550 Inst
.addOperand(MCOperand::createImm(align
));
4553 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
4554 return MCDisassembler::Fail
;
4556 Inst
.addOperand(MCOperand::createReg(0));
4559 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4560 return MCDisassembler::Fail
;
4561 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+inc
, Address
, Decoder
)))
4562 return MCDisassembler::Fail
;
4563 Inst
.addOperand(MCOperand::createImm(index
));
4568 static DecodeStatus
DecodeVST2LN(MCInst
&Inst
, unsigned Insn
,
4569 uint64_t Address
, const void *Decoder
) {
4570 DecodeStatus S
= MCDisassembler::Success
;
4572 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4573 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
4574 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
4575 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
4576 unsigned size
= fieldFromInstruction(Insn
, 10, 2);
4583 return MCDisassembler::Fail
;
4585 index
= fieldFromInstruction(Insn
, 5, 3);
4586 if (fieldFromInstruction(Insn
, 4, 1))
4590 index
= fieldFromInstruction(Insn
, 6, 2);
4591 if (fieldFromInstruction(Insn
, 4, 1))
4593 if (fieldFromInstruction(Insn
, 5, 1))
4597 if (fieldFromInstruction(Insn
, 5, 1))
4598 return MCDisassembler::Fail
; // UNDEFINED
4599 index
= fieldFromInstruction(Insn
, 7, 1);
4600 if (fieldFromInstruction(Insn
, 4, 1) != 0)
4602 if (fieldFromInstruction(Insn
, 6, 1))
4607 if (Rm
!= 0xF) { // Writeback
4608 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4609 return MCDisassembler::Fail
;
4611 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4612 return MCDisassembler::Fail
;
4613 Inst
.addOperand(MCOperand::createImm(align
));
4616 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
4617 return MCDisassembler::Fail
;
4619 Inst
.addOperand(MCOperand::createReg(0));
4622 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4623 return MCDisassembler::Fail
;
4624 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+inc
, Address
, Decoder
)))
4625 return MCDisassembler::Fail
;
4626 Inst
.addOperand(MCOperand::createImm(index
));
4631 static DecodeStatus
DecodeVLD3LN(MCInst
&Inst
, unsigned Insn
,
4632 uint64_t Address
, const void *Decoder
) {
4633 DecodeStatus S
= MCDisassembler::Success
;
4635 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4636 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
4637 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
4638 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
4639 unsigned size
= fieldFromInstruction(Insn
, 10, 2);
4646 return MCDisassembler::Fail
;
4648 if (fieldFromInstruction(Insn
, 4, 1))
4649 return MCDisassembler::Fail
; // UNDEFINED
4650 index
= fieldFromInstruction(Insn
, 5, 3);
4653 if (fieldFromInstruction(Insn
, 4, 1))
4654 return MCDisassembler::Fail
; // UNDEFINED
4655 index
= fieldFromInstruction(Insn
, 6, 2);
4656 if (fieldFromInstruction(Insn
, 5, 1))
4660 if (fieldFromInstruction(Insn
, 4, 2))
4661 return MCDisassembler::Fail
; // UNDEFINED
4662 index
= fieldFromInstruction(Insn
, 7, 1);
4663 if (fieldFromInstruction(Insn
, 6, 1))
4668 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4669 return MCDisassembler::Fail
;
4670 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+inc
, Address
, Decoder
)))
4671 return MCDisassembler::Fail
;
4672 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+2*inc
, Address
, Decoder
)))
4673 return MCDisassembler::Fail
;
4675 if (Rm
!= 0xF) { // Writeback
4676 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4677 return MCDisassembler::Fail
;
4679 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4680 return MCDisassembler::Fail
;
4681 Inst
.addOperand(MCOperand::createImm(align
));
4684 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
4685 return MCDisassembler::Fail
;
4687 Inst
.addOperand(MCOperand::createReg(0));
4690 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4691 return MCDisassembler::Fail
;
4692 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+inc
, Address
, Decoder
)))
4693 return MCDisassembler::Fail
;
4694 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+2*inc
, Address
, Decoder
)))
4695 return MCDisassembler::Fail
;
4696 Inst
.addOperand(MCOperand::createImm(index
));
4701 static DecodeStatus
DecodeVST3LN(MCInst
&Inst
, unsigned Insn
,
4702 uint64_t Address
, const void *Decoder
) {
4703 DecodeStatus S
= MCDisassembler::Success
;
4705 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4706 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
4707 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
4708 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
4709 unsigned size
= fieldFromInstruction(Insn
, 10, 2);
4716 return MCDisassembler::Fail
;
4718 if (fieldFromInstruction(Insn
, 4, 1))
4719 return MCDisassembler::Fail
; // UNDEFINED
4720 index
= fieldFromInstruction(Insn
, 5, 3);
4723 if (fieldFromInstruction(Insn
, 4, 1))
4724 return MCDisassembler::Fail
; // UNDEFINED
4725 index
= fieldFromInstruction(Insn
, 6, 2);
4726 if (fieldFromInstruction(Insn
, 5, 1))
4730 if (fieldFromInstruction(Insn
, 4, 2))
4731 return MCDisassembler::Fail
; // UNDEFINED
4732 index
= fieldFromInstruction(Insn
, 7, 1);
4733 if (fieldFromInstruction(Insn
, 6, 1))
4738 if (Rm
!= 0xF) { // Writeback
4739 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4740 return MCDisassembler::Fail
;
4742 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4743 return MCDisassembler::Fail
;
4744 Inst
.addOperand(MCOperand::createImm(align
));
4747 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
4748 return MCDisassembler::Fail
;
4750 Inst
.addOperand(MCOperand::createReg(0));
4753 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4754 return MCDisassembler::Fail
;
4755 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+inc
, Address
, Decoder
)))
4756 return MCDisassembler::Fail
;
4757 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+2*inc
, Address
, Decoder
)))
4758 return MCDisassembler::Fail
;
4759 Inst
.addOperand(MCOperand::createImm(index
));
4764 static DecodeStatus
DecodeVLD4LN(MCInst
&Inst
, unsigned Insn
,
4765 uint64_t Address
, const void *Decoder
) {
4766 DecodeStatus S
= MCDisassembler::Success
;
4768 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4769 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
4770 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
4771 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
4772 unsigned size
= fieldFromInstruction(Insn
, 10, 2);
4779 return MCDisassembler::Fail
;
4781 if (fieldFromInstruction(Insn
, 4, 1))
4783 index
= fieldFromInstruction(Insn
, 5, 3);
4786 if (fieldFromInstruction(Insn
, 4, 1))
4788 index
= fieldFromInstruction(Insn
, 6, 2);
4789 if (fieldFromInstruction(Insn
, 5, 1))
4793 switch (fieldFromInstruction(Insn
, 4, 2)) {
4797 return MCDisassembler::Fail
;
4799 align
= 4 << fieldFromInstruction(Insn
, 4, 2); break;
4802 index
= fieldFromInstruction(Insn
, 7, 1);
4803 if (fieldFromInstruction(Insn
, 6, 1))
4808 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4809 return MCDisassembler::Fail
;
4810 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+inc
, Address
, Decoder
)))
4811 return MCDisassembler::Fail
;
4812 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+2*inc
, Address
, Decoder
)))
4813 return MCDisassembler::Fail
;
4814 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+3*inc
, Address
, Decoder
)))
4815 return MCDisassembler::Fail
;
4817 if (Rm
!= 0xF) { // Writeback
4818 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4819 return MCDisassembler::Fail
;
4821 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4822 return MCDisassembler::Fail
;
4823 Inst
.addOperand(MCOperand::createImm(align
));
4826 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
4827 return MCDisassembler::Fail
;
4829 Inst
.addOperand(MCOperand::createReg(0));
4832 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4833 return MCDisassembler::Fail
;
4834 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+inc
, Address
, Decoder
)))
4835 return MCDisassembler::Fail
;
4836 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+2*inc
, Address
, Decoder
)))
4837 return MCDisassembler::Fail
;
4838 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+3*inc
, Address
, Decoder
)))
4839 return MCDisassembler::Fail
;
4840 Inst
.addOperand(MCOperand::createImm(index
));
4845 static DecodeStatus
DecodeVST4LN(MCInst
&Inst
, unsigned Insn
,
4846 uint64_t Address
, const void *Decoder
) {
4847 DecodeStatus S
= MCDisassembler::Success
;
4849 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4850 unsigned Rm
= fieldFromInstruction(Insn
, 0, 4);
4851 unsigned Rd
= fieldFromInstruction(Insn
, 12, 4);
4852 Rd
|= fieldFromInstruction(Insn
, 22, 1) << 4;
4853 unsigned size
= fieldFromInstruction(Insn
, 10, 2);
4860 return MCDisassembler::Fail
;
4862 if (fieldFromInstruction(Insn
, 4, 1))
4864 index
= fieldFromInstruction(Insn
, 5, 3);
4867 if (fieldFromInstruction(Insn
, 4, 1))
4869 index
= fieldFromInstruction(Insn
, 6, 2);
4870 if (fieldFromInstruction(Insn
, 5, 1))
4874 switch (fieldFromInstruction(Insn
, 4, 2)) {
4878 return MCDisassembler::Fail
;
4880 align
= 4 << fieldFromInstruction(Insn
, 4, 2); break;
4883 index
= fieldFromInstruction(Insn
, 7, 1);
4884 if (fieldFromInstruction(Insn
, 6, 1))
4889 if (Rm
!= 0xF) { // Writeback
4890 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4891 return MCDisassembler::Fail
;
4893 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
4894 return MCDisassembler::Fail
;
4895 Inst
.addOperand(MCOperand::createImm(align
));
4898 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
4899 return MCDisassembler::Fail
;
4901 Inst
.addOperand(MCOperand::createReg(0));
4904 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
, Address
, Decoder
)))
4905 return MCDisassembler::Fail
;
4906 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+inc
, Address
, Decoder
)))
4907 return MCDisassembler::Fail
;
4908 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+2*inc
, Address
, Decoder
)))
4909 return MCDisassembler::Fail
;
4910 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Rd
+3*inc
, Address
, Decoder
)))
4911 return MCDisassembler::Fail
;
4912 Inst
.addOperand(MCOperand::createImm(index
));
4917 static DecodeStatus
DecodeVMOVSRR(MCInst
&Inst
, unsigned Insn
,
4918 uint64_t Address
, const void *Decoder
) {
4919 DecodeStatus S
= MCDisassembler::Success
;
4920 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
4921 unsigned Rt2
= fieldFromInstruction(Insn
, 16, 4);
4922 unsigned Rm
= fieldFromInstruction(Insn
, 5, 1);
4923 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
4924 Rm
|= fieldFromInstruction(Insn
, 0, 4) << 1;
4926 if (Rt
== 0xF || Rt2
== 0xF || Rm
== 0x1F)
4927 S
= MCDisassembler::SoftFail
;
4929 if (!Check(S
, DecodeSPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
4930 return MCDisassembler::Fail
;
4931 if (!Check(S
, DecodeSPRRegisterClass(Inst
, Rm
+1, Address
, Decoder
)))
4932 return MCDisassembler::Fail
;
4933 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
4934 return MCDisassembler::Fail
;
4935 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt2
, Address
, Decoder
)))
4936 return MCDisassembler::Fail
;
4937 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
4938 return MCDisassembler::Fail
;
4943 static DecodeStatus
DecodeVMOVRRS(MCInst
&Inst
, unsigned Insn
,
4944 uint64_t Address
, const void *Decoder
) {
4945 DecodeStatus S
= MCDisassembler::Success
;
4946 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
4947 unsigned Rt2
= fieldFromInstruction(Insn
, 16, 4);
4948 unsigned Rm
= fieldFromInstruction(Insn
, 5, 1);
4949 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
4950 Rm
|= fieldFromInstruction(Insn
, 0, 4) << 1;
4952 if (Rt
== 0xF || Rt2
== 0xF || Rm
== 0x1F)
4953 S
= MCDisassembler::SoftFail
;
4955 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
4956 return MCDisassembler::Fail
;
4957 if (!Check(S
, DecodeGPRRegisterClass(Inst
, Rt2
, Address
, Decoder
)))
4958 return MCDisassembler::Fail
;
4959 if (!Check(S
, DecodeSPRRegisterClass(Inst
, Rm
, Address
, Decoder
)))
4960 return MCDisassembler::Fail
;
4961 if (!Check(S
, DecodeSPRRegisterClass(Inst
, Rm
+1, Address
, Decoder
)))
4962 return MCDisassembler::Fail
;
4963 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
4964 return MCDisassembler::Fail
;
4969 static DecodeStatus
DecodeIT(MCInst
&Inst
, unsigned Insn
,
4970 uint64_t Address
, const void *Decoder
) {
4971 DecodeStatus S
= MCDisassembler::Success
;
4972 unsigned pred
= fieldFromInstruction(Insn
, 4, 4);
4973 unsigned mask
= fieldFromInstruction(Insn
, 0, 4);
4977 S
= MCDisassembler::SoftFail
;
4981 return MCDisassembler::Fail
;
4983 Inst
.addOperand(MCOperand::createImm(pred
));
4984 Inst
.addOperand(MCOperand::createImm(mask
));
4989 DecodeT2LDRDPreInstruction(MCInst
&Inst
, unsigned Insn
,
4990 uint64_t Address
, const void *Decoder
) {
4991 DecodeStatus S
= MCDisassembler::Success
;
4993 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
4994 unsigned Rt2
= fieldFromInstruction(Insn
, 8, 4);
4995 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
4996 unsigned addr
= fieldFromInstruction(Insn
, 0, 8);
4997 unsigned W
= fieldFromInstruction(Insn
, 21, 1);
4998 unsigned U
= fieldFromInstruction(Insn
, 23, 1);
4999 unsigned P
= fieldFromInstruction(Insn
, 24, 1);
5000 bool writeback
= (W
== 1) | (P
== 0);
5002 addr
|= (U
<< 8) | (Rn
<< 9);
5004 if (writeback
&& (Rn
== Rt
|| Rn
== Rt2
))
5005 Check(S
, MCDisassembler::SoftFail
);
5007 Check(S
, MCDisassembler::SoftFail
);
5010 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
5011 return MCDisassembler::Fail
;
5013 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rt2
, Address
, Decoder
)))
5014 return MCDisassembler::Fail
;
5015 // Writeback operand
5016 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
5017 return MCDisassembler::Fail
;
5019 if (!Check(S
, DecodeT2AddrModeImm8s4(Inst
, addr
, Address
, Decoder
)))
5020 return MCDisassembler::Fail
;
5026 DecodeT2STRDPreInstruction(MCInst
&Inst
, unsigned Insn
,
5027 uint64_t Address
, const void *Decoder
) {
5028 DecodeStatus S
= MCDisassembler::Success
;
5030 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
5031 unsigned Rt2
= fieldFromInstruction(Insn
, 8, 4);
5032 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
5033 unsigned addr
= fieldFromInstruction(Insn
, 0, 8);
5034 unsigned W
= fieldFromInstruction(Insn
, 21, 1);
5035 unsigned U
= fieldFromInstruction(Insn
, 23, 1);
5036 unsigned P
= fieldFromInstruction(Insn
, 24, 1);
5037 bool writeback
= (W
== 1) | (P
== 0);
5039 addr
|= (U
<< 8) | (Rn
<< 9);
5041 if (writeback
&& (Rn
== Rt
|| Rn
== Rt2
))
5042 Check(S
, MCDisassembler::SoftFail
);
5044 // Writeback operand
5045 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rn
, Address
, Decoder
)))
5046 return MCDisassembler::Fail
;
5048 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rt
, Address
, Decoder
)))
5049 return MCDisassembler::Fail
;
5051 if (!Check(S
, DecoderGPRRegisterClass(Inst
, Rt2
, Address
, Decoder
)))
5052 return MCDisassembler::Fail
;
5054 if (!Check(S
, DecodeT2AddrModeImm8s4(Inst
, addr
, Address
, Decoder
)))
5055 return MCDisassembler::Fail
;
5060 static DecodeStatus
DecodeT2Adr(MCInst
&Inst
, uint32_t Insn
,
5061 uint64_t Address
, const void *Decoder
) {
5062 unsigned sign1
= fieldFromInstruction(Insn
, 21, 1);
5063 unsigned sign2
= fieldFromInstruction(Insn
, 23, 1);
5064 if (sign1
!= sign2
) return MCDisassembler::Fail
;
5066 unsigned Val
= fieldFromInstruction(Insn
, 0, 8);
5067 Val
|= fieldFromInstruction(Insn
, 12, 3) << 8;
5068 Val
|= fieldFromInstruction(Insn
, 26, 1) << 11;
5070 Inst
.addOperand(MCOperand::createImm(SignExtend32
<13>(Val
)));
5072 return MCDisassembler::Success
;
5075 static DecodeStatus
DecodeT2ShifterImmOperand(MCInst
&Inst
, uint32_t Val
,
5077 const void *Decoder
) {
5078 DecodeStatus S
= MCDisassembler::Success
;
5080 // Shift of "asr #32" is not allowed in Thumb2 mode.
5081 if (Val
== 0x20) S
= MCDisassembler::Fail
;
5082 Inst
.addOperand(MCOperand::createImm(Val
));
5086 static DecodeStatus
DecodeSwap(MCInst
&Inst
, unsigned Insn
,
5087 uint64_t Address
, const void *Decoder
) {
5088 unsigned Rt
= fieldFromInstruction(Insn
, 12, 4);
5089 unsigned Rt2
= fieldFromInstruction(Insn
, 0, 4);
5090 unsigned Rn
= fieldFromInstruction(Insn
, 16, 4);
5091 unsigned pred
= fieldFromInstruction(Insn
, 28, 4);
5094 return DecodeCPSInstruction(Inst
, Insn
, Address
, Decoder
);
5096 DecodeStatus S
= MCDisassembler::Success
;
5098 if (Rt
== Rn
|| Rn
== Rt2
)
5099 S
= MCDisassembler::SoftFail
;
5101 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rt
, Address
, Decoder
)))
5102 return MCDisassembler::Fail
;
5103 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rt2
, Address
, Decoder
)))
5104 return MCDisassembler::Fail
;
5105 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rn
, Address
, Decoder
)))
5106 return MCDisassembler::Fail
;
5107 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
5108 return MCDisassembler::Fail
;
5113 static DecodeStatus
DecodeVCVTD(MCInst
&Inst
, unsigned Insn
,
5114 uint64_t Address
, const void *Decoder
) {
5115 const FeatureBitset
&featureBits
=
5116 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
5117 bool hasFullFP16
= featureBits
[ARM::FeatureFullFP16
];
5119 unsigned Vd
= (fieldFromInstruction(Insn
, 12, 4) << 0);
5120 Vd
|= (fieldFromInstruction(Insn
, 22, 1) << 4);
5121 unsigned Vm
= (fieldFromInstruction(Insn
, 0, 4) << 0);
5122 Vm
|= (fieldFromInstruction(Insn
, 5, 1) << 4);
5123 unsigned imm
= fieldFromInstruction(Insn
, 16, 6);
5124 unsigned cmode
= fieldFromInstruction(Insn
, 8, 4);
5125 unsigned op
= fieldFromInstruction(Insn
, 5, 1);
5127 DecodeStatus S
= MCDisassembler::Success
;
5129 // If the top 3 bits of imm are clear, this is a VMOV (immediate)
5130 if (!(imm
& 0x38)) {
5132 if (op
== 1) return MCDisassembler::Fail
;
5133 Inst
.setOpcode(ARM::VMOVv2f32
);
5138 Inst
.setOpcode(ARM::VMOVv1i64
);
5140 Inst
.setOpcode(ARM::VMOVv8i8
);
5145 Inst
.setOpcode(ARM::VMVNv2i32
);
5147 Inst
.setOpcode(ARM::VMOVv2i32
);
5152 Inst
.setOpcode(ARM::VMVNv2i32
);
5154 Inst
.setOpcode(ARM::VMOVv2i32
);
5158 return DecodeNEONModImmInstruction(Inst
, Insn
, Address
, Decoder
);
5161 if (!(imm
& 0x20)) return MCDisassembler::Fail
;
5163 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Vd
, Address
, Decoder
)))
5164 return MCDisassembler::Fail
;
5165 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Vm
, Address
, Decoder
)))
5166 return MCDisassembler::Fail
;
5167 Inst
.addOperand(MCOperand::createImm(64 - imm
));
5172 static DecodeStatus
DecodeVCVTQ(MCInst
&Inst
, unsigned Insn
,
5173 uint64_t Address
, const void *Decoder
) {
5174 const FeatureBitset
&featureBits
=
5175 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
5176 bool hasFullFP16
= featureBits
[ARM::FeatureFullFP16
];
5178 unsigned Vd
= (fieldFromInstruction(Insn
, 12, 4) << 0);
5179 Vd
|= (fieldFromInstruction(Insn
, 22, 1) << 4);
5180 unsigned Vm
= (fieldFromInstruction(Insn
, 0, 4) << 0);
5181 Vm
|= (fieldFromInstruction(Insn
, 5, 1) << 4);
5182 unsigned imm
= fieldFromInstruction(Insn
, 16, 6);
5183 unsigned cmode
= fieldFromInstruction(Insn
, 8, 4);
5184 unsigned op
= fieldFromInstruction(Insn
, 5, 1);
5186 DecodeStatus S
= MCDisassembler::Success
;
5188 // If the top 3 bits of imm are clear, this is a VMOV (immediate)
5189 if (!(imm
& 0x38)) {
5191 if (op
== 1) return MCDisassembler::Fail
;
5192 Inst
.setOpcode(ARM::VMOVv4f32
);
5197 Inst
.setOpcode(ARM::VMOVv2i64
);
5199 Inst
.setOpcode(ARM::VMOVv16i8
);
5204 Inst
.setOpcode(ARM::VMVNv4i32
);
5206 Inst
.setOpcode(ARM::VMOVv4i32
);
5211 Inst
.setOpcode(ARM::VMVNv4i32
);
5213 Inst
.setOpcode(ARM::VMOVv4i32
);
5217 return DecodeNEONModImmInstruction(Inst
, Insn
, Address
, Decoder
);
5220 if (!(imm
& 0x20)) return MCDisassembler::Fail
;
5222 if (!Check(S
, DecodeQPRRegisterClass(Inst
, Vd
, Address
, Decoder
)))
5223 return MCDisassembler::Fail
;
5224 if (!Check(S
, DecodeQPRRegisterClass(Inst
, Vm
, Address
, Decoder
)))
5225 return MCDisassembler::Fail
;
5226 Inst
.addOperand(MCOperand::createImm(64 - imm
));
5231 static DecodeStatus
DecodeNEONComplexLane64Instruction(MCInst
&Inst
,
5234 const void *Decoder
) {
5235 unsigned Vd
= (fieldFromInstruction(Insn
, 12, 4) << 0);
5236 Vd
|= (fieldFromInstruction(Insn
, 22, 1) << 4);
5237 unsigned Vn
= (fieldFromInstruction(Insn
, 16, 4) << 0);
5238 Vn
|= (fieldFromInstruction(Insn
, 7, 1) << 4);
5239 unsigned Vm
= (fieldFromInstruction(Insn
, 0, 4) << 0);
5240 Vm
|= (fieldFromInstruction(Insn
, 5, 1) << 4);
5241 unsigned q
= (fieldFromInstruction(Insn
, 6, 1) << 0);
5242 unsigned rotate
= (fieldFromInstruction(Insn
, 20, 2) << 0);
5244 DecodeStatus S
= MCDisassembler::Success
;
5246 auto DestRegDecoder
= q
? DecodeQPRRegisterClass
: DecodeDPRRegisterClass
;
5248 if (!Check(S
, DestRegDecoder(Inst
, Vd
, Address
, Decoder
)))
5249 return MCDisassembler::Fail
;
5250 if (!Check(S
, DestRegDecoder(Inst
, Vd
, Address
, Decoder
)))
5251 return MCDisassembler::Fail
;
5252 if (!Check(S
, DestRegDecoder(Inst
, Vn
, Address
, Decoder
)))
5253 return MCDisassembler::Fail
;
5254 if (!Check(S
, DecodeDPRRegisterClass(Inst
, Vm
, Address
, Decoder
)))
5255 return MCDisassembler::Fail
;
5256 // The lane index does not have any bits in the encoding, because it can only
5258 Inst
.addOperand(MCOperand::createImm(0));
5259 Inst
.addOperand(MCOperand::createImm(rotate
));
5264 static DecodeStatus
DecodeLDR(MCInst
&Inst
, unsigned Val
,
5265 uint64_t Address
, const void *Decoder
) {
5266 DecodeStatus S
= MCDisassembler::Success
;
5268 unsigned Rn
= fieldFromInstruction(Val
, 16, 4);
5269 unsigned Rt
= fieldFromInstruction(Val
, 12, 4);
5270 unsigned Rm
= fieldFromInstruction(Val
, 0, 4);
5271 Rm
|= (fieldFromInstruction(Val
, 23, 1) << 4);
5272 unsigned Cond
= fieldFromInstruction(Val
, 28, 4);
5274 if (fieldFromInstruction(Val
, 8, 4) != 0 || Rn
== Rt
)
5275 S
= MCDisassembler::SoftFail
;
5277 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rt
, Address
, Decoder
)))
5278 return MCDisassembler::Fail
;
5279 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rn
, Address
, Decoder
)))
5280 return MCDisassembler::Fail
;
5281 if (!Check(S
, DecodeAddrMode7Operand(Inst
, Rn
, Address
, Decoder
)))
5282 return MCDisassembler::Fail
;
5283 if (!Check(S
, DecodePostIdxReg(Inst
, Rm
, Address
, Decoder
)))
5284 return MCDisassembler::Fail
;
5285 if (!Check(S
, DecodePredicateOperand(Inst
, Cond
, Address
, Decoder
)))
5286 return MCDisassembler::Fail
;
5291 static DecodeStatus
DecoderForMRRC2AndMCRR2(MCInst
&Inst
, unsigned Val
,
5292 uint64_t Address
, const void *Decoder
) {
5293 DecodeStatus S
= MCDisassembler::Success
;
5295 unsigned CRm
= fieldFromInstruction(Val
, 0, 4);
5296 unsigned opc1
= fieldFromInstruction(Val
, 4, 4);
5297 unsigned cop
= fieldFromInstruction(Val
, 8, 4);
5298 unsigned Rt
= fieldFromInstruction(Val
, 12, 4);
5299 unsigned Rt2
= fieldFromInstruction(Val
, 16, 4);
5301 if ((cop
& ~0x1) == 0xa)
5302 return MCDisassembler::Fail
;
5305 S
= MCDisassembler::SoftFail
;
5307 // We have to check if the instruction is MRRC2
5308 // or MCRR2 when constructing the operands for
5309 // Inst. Reason is because MRRC2 stores to two
5310 // registers so it's tablegen desc has has two
5311 // outputs whereas MCRR doesn't store to any
5312 // registers so all of it's operands are listed
5313 // as inputs, therefore the operand order for
5314 // MRRC2 needs to be [Rt, Rt2, cop, opc1, CRm]
5315 // and MCRR2 operand order is [cop, opc1, Rt, Rt2, CRm]
5317 if (Inst
.getOpcode() == ARM::MRRC2
) {
5318 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rt
, Address
, Decoder
)))
5319 return MCDisassembler::Fail
;
5320 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rt2
, Address
, Decoder
)))
5321 return MCDisassembler::Fail
;
5323 Inst
.addOperand(MCOperand::createImm(cop
));
5324 Inst
.addOperand(MCOperand::createImm(opc1
));
5325 if (Inst
.getOpcode() == ARM::MCRR2
) {
5326 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rt
, Address
, Decoder
)))
5327 return MCDisassembler::Fail
;
5328 if (!Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rt2
, Address
, Decoder
)))
5329 return MCDisassembler::Fail
;
5331 Inst
.addOperand(MCOperand::createImm(CRm
));
5336 static DecodeStatus
DecodeForVMRSandVMSR(MCInst
&Inst
, unsigned Val
,
5338 const void *Decoder
) {
5339 const FeatureBitset
&featureBits
=
5340 ((const MCDisassembler
*)Decoder
)->getSubtargetInfo().getFeatureBits();
5341 DecodeStatus S
= MCDisassembler::Success
;
5343 unsigned Rt
= fieldFromInstruction(Val
, 12, 4);
5345 if (featureBits
[ARM::ModeThumb
] && !featureBits
[ARM::HasV8Ops
]) {
5346 if (Rt
== 13 || Rt
== 15)
5347 S
= MCDisassembler::SoftFail
;
5348 Check(S
, DecodeGPRRegisterClass(Inst
, Rt
, Address
, Decoder
));
5350 Check(S
, DecodeGPRnopcRegisterClass(Inst
, Rt
, Address
, Decoder
));
5352 if (featureBits
[ARM::ModeThumb
]) {
5353 Inst
.addOperand(MCOperand::createImm(ARMCC::AL
));
5354 Inst
.addOperand(MCOperand::createReg(0));
5356 unsigned pred
= fieldFromInstruction(Val
, 28, 4);
5357 if (!Check(S
, DecodePredicateOperand(Inst
, pred
, Address
, Decoder
)))
5358 return MCDisassembler::Fail
;