1 //===- AArch64Disassembler.cpp - Disassembler for AArch64/Thumb ISA -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #define DEBUG_TYPE "arm-disassembler"
13 #include "AArch64RegisterInfo.h"
14 #include "AArch64Subtarget.h"
15 #include "Utils/AArch64BaseInfo.h"
16 #include "llvm/MC/MCInst.h"
17 #include "llvm/MC/MCInstrDesc.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCDisassembler.h"
21 #include "llvm/MC/MCFixedLenDisassembler.h"
22 #include "llvm/Support/Debug.h"
23 #include "llvm/Support/MemoryObject.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Support/TargetRegistry.h"
26 #include "llvm/Support/raw_ostream.h"
30 typedef MCDisassembler::DecodeStatus DecodeStatus;
33 /// AArch64 disassembler for all AArch64 platforms.
34 class AArch64Disassembler : public MCDisassembler {
35 const MCRegisterInfo *RegInfo;
37 /// Initializes the disassembler.
39 AArch64Disassembler(const MCSubtargetInfo &STI, const MCRegisterInfo *Info)
40 : MCDisassembler(STI), RegInfo(Info) {
43 ~AArch64Disassembler() {
46 /// See MCDisassembler.
47 DecodeStatus getInstruction(MCInst &instr,
49 const MemoryObject ®ion,
52 raw_ostream &cStream) const;
54 const MCRegisterInfo *getRegInfo() const { return RegInfo; }
59 // Forward-declarations used in the auto-generated files.
60 static DecodeStatus DecodeGPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
61 uint64_t Address, const void *Decoder);
63 DecodeGPR64xspRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
64 uint64_t Address, const void *Decoder);
66 static DecodeStatus DecodeGPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
67 uint64_t Address, const void *Decoder);
69 DecodeGPR32wspRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
70 uint64_t Address, const void *Decoder);
72 static DecodeStatus DecodeFPR8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
73 uint64_t Address, const void *Decoder);
74 static DecodeStatus DecodeFPR16RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
75 uint64_t Address, const void *Decoder);
76 static DecodeStatus DecodeFPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
77 uint64_t Address, const void *Decoder);
78 static DecodeStatus DecodeFPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
79 uint64_t Address, const void *Decoder);
80 static DecodeStatus DecodeFPR128RegisterClass(llvm::MCInst &Inst,
81 unsigned RegNo, uint64_t Address,
83 static DecodeStatus DecodeVPR128RegisterClass(llvm::MCInst &Inst,
84 unsigned RegNo, uint64_t Address,
87 static DecodeStatus DecodeAddrRegExtendOperand(llvm::MCInst &Inst,
93 static DecodeStatus DecodeBitfield32ImmOperand(llvm::MCInst &Inst,
98 static DecodeStatus DecodeCVT32FixedPosOperand(llvm::MCInst &Inst,
101 const void *Decoder);
103 template<int RegWidth>
104 static DecodeStatus DecodeMoveWideImmOperand(llvm::MCInst &Inst,
107 const void *Decoder);
109 template<int RegWidth>
110 static DecodeStatus DecodeLogicalImmOperand(llvm::MCInst &Inst,
113 const void *Decoder);
115 static DecodeStatus DecodeRegExtendOperand(llvm::MCInst &Inst,
116 unsigned ShiftAmount,
118 const void *Decoder);
120 static DecodeStatus Decode32BitShiftOperand(llvm::MCInst &Inst,
121 unsigned ShiftAmount,
123 const void *Decoder);
124 static DecodeStatus DecodeBitfieldInstruction(llvm::MCInst &Inst, unsigned Insn,
126 const void *Decoder);
128 static DecodeStatus DecodeFMOVLaneInstruction(llvm::MCInst &Inst, unsigned Insn,
130 const void *Decoder);
132 static DecodeStatus DecodeLDSTPairInstruction(llvm::MCInst &Inst,
135 const void *Decoder);
137 static DecodeStatus DecodeLoadPairExclusiveInstruction(llvm::MCInst &Inst,
140 const void *Decoder);
142 template<typename SomeNamedImmMapper>
143 static DecodeStatus DecodeNamedImmOperand(llvm::MCInst &Inst,
146 const void *Decoder);
149 DecodeSysRegOperand(const A64SysReg::SysRegMapper &InstMapper,
150 llvm::MCInst &Inst, unsigned Val,
151 uint64_t Address, const void *Decoder);
153 static DecodeStatus DecodeMRSOperand(llvm::MCInst &Inst,
156 const void *Decoder);
158 static DecodeStatus DecodeMSROperand(llvm::MCInst &Inst,
161 const void *Decoder);
164 static DecodeStatus DecodeSingleIndexedInstruction(llvm::MCInst &Inst,
167 const void *Decoder);
170 static bool Check(DecodeStatus &Out, DecodeStatus In);
172 #include "AArch64GenDisassemblerTables.inc"
173 #include "AArch64GenInstrInfo.inc"
175 static bool Check(DecodeStatus &Out, DecodeStatus In) {
177 case MCDisassembler::Success:
178 // Out stays the same.
180 case MCDisassembler::SoftFail:
183 case MCDisassembler::Fail:
187 llvm_unreachable("Invalid DecodeStatus!");
190 DecodeStatus AArch64Disassembler::getInstruction(MCInst &MI, uint64_t &Size,
191 const MemoryObject &Region,
194 raw_ostream &cs) const {
199 // We want to read exactly 4 bytes of data.
200 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
202 return MCDisassembler::Fail;
205 // Encoded as a small-endian 32-bit word in the stream.
206 uint32_t insn = (bytes[3] << 24) |
211 // Calling the auto-generated decoder function.
212 DecodeStatus result = decodeInstruction(DecoderTableA6432, MI, insn, Address,
214 if (result != MCDisassembler::Fail) {
221 return MCDisassembler::Fail;
224 static unsigned getReg(const void *D, unsigned RC, unsigned RegNo) {
225 const AArch64Disassembler *Dis = static_cast<const AArch64Disassembler*>(D);
226 return Dis->getRegInfo()->getRegClass(RC).getRegister(RegNo);
229 static DecodeStatus DecodeGPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
230 uint64_t Address, const void *Decoder) {
232 return MCDisassembler::Fail;
234 uint16_t Register = getReg(Decoder, AArch64::GPR64RegClassID, RegNo);
235 Inst.addOperand(MCOperand::CreateReg(Register));
236 return MCDisassembler::Success;
240 DecodeGPR64xspRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
241 uint64_t Address, const void *Decoder) {
243 return MCDisassembler::Fail;
245 uint16_t Register = getReg(Decoder, AArch64::GPR64xspRegClassID, RegNo);
246 Inst.addOperand(MCOperand::CreateReg(Register));
247 return MCDisassembler::Success;
250 static DecodeStatus DecodeGPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
252 const void *Decoder) {
254 return MCDisassembler::Fail;
256 uint16_t Register = getReg(Decoder, AArch64::GPR32RegClassID, RegNo);
257 Inst.addOperand(MCOperand::CreateReg(Register));
258 return MCDisassembler::Success;
262 DecodeGPR32wspRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
263 uint64_t Address, const void *Decoder) {
265 return MCDisassembler::Fail;
267 uint16_t Register = getReg(Decoder, AArch64::GPR32wspRegClassID, RegNo);
268 Inst.addOperand(MCOperand::CreateReg(Register));
269 return MCDisassembler::Success;
273 DecodeFPR8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
274 uint64_t Address, const void *Decoder) {
276 return MCDisassembler::Fail;
278 uint16_t Register = getReg(Decoder, AArch64::FPR8RegClassID, RegNo);
279 Inst.addOperand(MCOperand::CreateReg(Register));
280 return MCDisassembler::Success;
284 DecodeFPR16RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
285 uint64_t Address, const void *Decoder) {
287 return MCDisassembler::Fail;
289 uint16_t Register = getReg(Decoder, AArch64::FPR16RegClassID, RegNo);
290 Inst.addOperand(MCOperand::CreateReg(Register));
291 return MCDisassembler::Success;
296 DecodeFPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
297 uint64_t Address, const void *Decoder) {
299 return MCDisassembler::Fail;
301 uint16_t Register = getReg(Decoder, AArch64::FPR32RegClassID, RegNo);
302 Inst.addOperand(MCOperand::CreateReg(Register));
303 return MCDisassembler::Success;
307 DecodeFPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
308 uint64_t Address, const void *Decoder) {
310 return MCDisassembler::Fail;
312 uint16_t Register = getReg(Decoder, AArch64::FPR64RegClassID, RegNo);
313 Inst.addOperand(MCOperand::CreateReg(Register));
314 return MCDisassembler::Success;
319 DecodeFPR128RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
320 uint64_t Address, const void *Decoder) {
322 return MCDisassembler::Fail;
324 uint16_t Register = getReg(Decoder, AArch64::FPR128RegClassID, RegNo);
325 Inst.addOperand(MCOperand::CreateReg(Register));
326 return MCDisassembler::Success;
330 DecodeVPR128RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
331 uint64_t Address, const void *Decoder) {
333 return MCDisassembler::Fail;
335 uint16_t Register = getReg(Decoder, AArch64::VPR128RegClassID, RegNo);
336 Inst.addOperand(MCOperand::CreateReg(Register));
337 return MCDisassembler::Success;
340 static DecodeStatus DecodeAddrRegExtendOperand(llvm::MCInst &Inst,
343 const void *Decoder) {
344 // Option{1} must be 1. OptionHiS is made up of {Option{2}, Option{1},
345 // S}. Hence we want to check bit 1.
346 if (!(OptionHiS & 2))
347 return MCDisassembler::Fail;
349 Inst.addOperand(MCOperand::CreateImm(OptionHiS));
350 return MCDisassembler::Success;
353 static DecodeStatus DecodeBitfield32ImmOperand(llvm::MCInst &Inst,
356 const void *Decoder) {
357 // In the 32-bit variant, bit 6 must be zero. I.e. the immediate must be
360 return MCDisassembler::Fail;
362 Inst.addOperand(MCOperand::CreateImm(Imm6Bits));
363 return MCDisassembler::Success;
366 static DecodeStatus DecodeCVT32FixedPosOperand(llvm::MCInst &Inst,
369 const void *Decoder) {
370 // 1 <= Imm <= 32. Encoded as 64 - Imm so: 63 >= Encoded >= 32.
372 return MCDisassembler::Fail;
374 Inst.addOperand(MCOperand::CreateImm(Imm6Bits));
375 return MCDisassembler::Success;
379 template<int RegWidth>
380 static DecodeStatus DecodeMoveWideImmOperand(llvm::MCInst &Inst,
383 const void *Decoder) {
384 unsigned Imm16 = FullImm & 0xffff;
385 unsigned Shift = FullImm >> 16;
387 if (RegWidth == 32 && Shift > 1) return MCDisassembler::Fail;
389 Inst.addOperand(MCOperand::CreateImm(Imm16));
390 Inst.addOperand(MCOperand::CreateImm(Shift));
391 return MCDisassembler::Success;
394 template<int RegWidth>
395 static DecodeStatus DecodeLogicalImmOperand(llvm::MCInst &Inst,
398 const void *Decoder) {
400 if (!A64Imms::isLogicalImmBits(RegWidth, Bits, Imm))
401 return MCDisassembler::Fail;
403 Inst.addOperand(MCOperand::CreateImm(Bits));
404 return MCDisassembler::Success;
408 static DecodeStatus DecodeRegExtendOperand(llvm::MCInst &Inst,
409 unsigned ShiftAmount,
411 const void *Decoder) {
412 // Only values 0-4 are valid for this 3-bit field
414 return MCDisassembler::Fail;
416 Inst.addOperand(MCOperand::CreateImm(ShiftAmount));
417 return MCDisassembler::Success;
420 static DecodeStatus Decode32BitShiftOperand(llvm::MCInst &Inst,
421 unsigned ShiftAmount,
423 const void *Decoder) {
424 // Only values below 32 are valid for a 32-bit register
425 if (ShiftAmount > 31)
426 return MCDisassembler::Fail;
428 Inst.addOperand(MCOperand::CreateImm(ShiftAmount));
429 return MCDisassembler::Success;
432 static DecodeStatus DecodeBitfieldInstruction(llvm::MCInst &Inst, unsigned Insn,
434 const void *Decoder) {
435 unsigned Rd = fieldFromInstruction(Insn, 0, 5);
436 unsigned Rn = fieldFromInstruction(Insn, 5, 5);
437 unsigned ImmS = fieldFromInstruction(Insn, 10, 6);
438 unsigned ImmR = fieldFromInstruction(Insn, 16, 6);
439 unsigned SF = fieldFromInstruction(Insn, 31, 1);
441 // Undef for 0b11 just in case it occurs. Don't want the compiler to optimise
442 // out assertions that it thinks should never be hit.
443 enum OpcTypes { SBFM = 0, BFM, UBFM, Undef } Opc;
444 Opc = (OpcTypes)fieldFromInstruction(Insn, 29, 2);
447 // ImmR and ImmS must be between 0 and 31 for 32-bit instructions.
448 if (ImmR > 31 || ImmS > 31)
449 return MCDisassembler::Fail;
453 DecodeGPR64RegisterClass(Inst, Rd, Address, Decoder);
454 // BFM MCInsts use Rd as a source too.
455 if (Opc == BFM) DecodeGPR64RegisterClass(Inst, Rd, Address, Decoder);
456 DecodeGPR64RegisterClass(Inst, Rn, Address, Decoder);
458 DecodeGPR32RegisterClass(Inst, Rd, Address, Decoder);
459 // BFM MCInsts use Rd as a source too.
460 if (Opc == BFM) DecodeGPR32RegisterClass(Inst, Rd, Address, Decoder);
461 DecodeGPR32RegisterClass(Inst, Rn, Address, Decoder);
464 // ASR and LSR have more specific patterns so they won't get here:
465 assert(!(ImmS == 31 && !SF && Opc != BFM)
466 && "shift should have used auto decode");
467 assert(!(ImmS == 63 && SF && Opc != BFM)
468 && "shift should have used auto decode");
470 // Extension instructions similarly:
471 if (Opc == SBFM && ImmR == 0) {
472 assert((ImmS != 7 && ImmS != 15) && "extension got here");
473 assert((ImmS != 31 || SF == 0) && "extension got here");
474 } else if (Opc == UBFM && ImmR == 0) {
475 assert((SF != 0 || (ImmS != 7 && ImmS != 15)) && "extension got here");
479 // It might be a LSL instruction, which actually takes the shift amount
480 // itself as an MCInst operand.
481 if (SF && (ImmS + 1) % 64 == ImmR) {
482 Inst.setOpcode(AArch64::LSLxxi);
483 Inst.addOperand(MCOperand::CreateImm(63 - ImmS));
484 return MCDisassembler::Success;
485 } else if (!SF && (ImmS + 1) % 32 == ImmR) {
486 Inst.setOpcode(AArch64::LSLwwi);
487 Inst.addOperand(MCOperand::CreateImm(31 - ImmS));
488 return MCDisassembler::Success;
492 // Otherwise it's definitely either an extract or an insert depending on which
493 // of ImmR or ImmS is larger.
494 unsigned ExtractOp, InsertOp;
496 default: llvm_unreachable("unexpected instruction trying to decode bitfield");
498 ExtractOp = SF ? AArch64::SBFXxxii : AArch64::SBFXwwii;
499 InsertOp = SF ? AArch64::SBFIZxxii : AArch64::SBFIZwwii;
502 ExtractOp = SF ? AArch64::BFXILxxii : AArch64::BFXILwwii;
503 InsertOp = SF ? AArch64::BFIxxii : AArch64::BFIwwii;
506 ExtractOp = SF ? AArch64::UBFXxxii : AArch64::UBFXwwii;
507 InsertOp = SF ? AArch64::UBFIZxxii : AArch64::UBFIZwwii;
511 // Otherwise it's a boring insert or extract
512 Inst.addOperand(MCOperand::CreateImm(ImmR));
513 Inst.addOperand(MCOperand::CreateImm(ImmS));
517 Inst.setOpcode(InsertOp);
519 Inst.setOpcode(ExtractOp);
521 return MCDisassembler::Success;
524 static DecodeStatus DecodeFMOVLaneInstruction(llvm::MCInst &Inst, unsigned Insn,
526 const void *Decoder) {
527 // This decoder exists to add the dummy Lane operand to the MCInst, which must
528 // be 1 in assembly but has no other real manifestation.
529 unsigned Rd = fieldFromInstruction(Insn, 0, 5);
530 unsigned Rn = fieldFromInstruction(Insn, 5, 5);
531 unsigned IsToVec = fieldFromInstruction(Insn, 16, 1);
534 DecodeVPR128RegisterClass(Inst, Rd, Address, Decoder);
535 DecodeGPR64RegisterClass(Inst, Rn, Address, Decoder);
537 DecodeGPR64RegisterClass(Inst, Rd, Address, Decoder);
538 DecodeVPR128RegisterClass(Inst, Rn, Address, Decoder);
542 Inst.addOperand(MCOperand::CreateImm(1));
544 return MCDisassembler::Success;
548 static DecodeStatus DecodeLDSTPairInstruction(llvm::MCInst &Inst,
551 const void *Decoder) {
552 DecodeStatus Result = MCDisassembler::Success;
553 unsigned Rt = fieldFromInstruction(Insn, 0, 5);
554 unsigned Rn = fieldFromInstruction(Insn, 5, 5);
555 unsigned Rt2 = fieldFromInstruction(Insn, 10, 5);
556 unsigned SImm7 = fieldFromInstruction(Insn, 15, 7);
557 unsigned L = fieldFromInstruction(Insn, 22, 1);
558 unsigned V = fieldFromInstruction(Insn, 26, 1);
559 unsigned Opc = fieldFromInstruction(Insn, 30, 2);
561 // Not an official name, but it turns out that bit 23 distinguishes indexed
562 // from non-indexed operations.
563 unsigned Indexed = fieldFromInstruction(Insn, 23, 1);
565 if (Indexed && L == 0) {
566 // The MCInst for an indexed store has an out operand and 4 ins:
567 // Rn_wb, Rt, Rt2, Rn, Imm
568 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
571 // You shouldn't load to the same register twice in an instruction...
573 Result = MCDisassembler::SoftFail;
575 // ... or do any operation that writes-back to a transfer register. But note
576 // that "stp xzr, xzr, [sp], #4" is fine because xzr and sp are different.
577 if (Indexed && V == 0 && Rn != 31 && (Rt == Rn || Rt2 == Rn))
578 Result = MCDisassembler::SoftFail;
580 // Exactly how we decode the MCInst's registers depends on the Opc and V
581 // fields of the instruction. These also obviously determine the size of the
582 // operation so we can fill in that information while we're at it.
584 // The instruction operates on the FP/SIMD registers
586 default: return MCDisassembler::Fail;
588 DecodeFPR32RegisterClass(Inst, Rt, Address, Decoder);
589 DecodeFPR32RegisterClass(Inst, Rt2, Address, Decoder);
592 DecodeFPR64RegisterClass(Inst, Rt, Address, Decoder);
593 DecodeFPR64RegisterClass(Inst, Rt2, Address, Decoder);
596 DecodeFPR128RegisterClass(Inst, Rt, Address, Decoder);
597 DecodeFPR128RegisterClass(Inst, Rt2, Address, Decoder);
602 default: return MCDisassembler::Fail;
604 DecodeGPR32RegisterClass(Inst, Rt, Address, Decoder);
605 DecodeGPR32RegisterClass(Inst, Rt2, Address, Decoder);
608 assert(L && "unexpected \"store signed\" attempt");
609 DecodeGPR64RegisterClass(Inst, Rt, Address, Decoder);
610 DecodeGPR64RegisterClass(Inst, Rt2, Address, Decoder);
613 DecodeGPR64RegisterClass(Inst, Rt, Address, Decoder);
614 DecodeGPR64RegisterClass(Inst, Rt2, Address, Decoder);
619 if (Indexed && L == 1) {
620 // The MCInst for an indexed load has 3 out operands and an 3 ins:
621 // Rt, Rt2, Rn_wb, Rt2, Rn, Imm
622 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
626 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
627 Inst.addOperand(MCOperand::CreateImm(SImm7));
632 static DecodeStatus DecodeLoadPairExclusiveInstruction(llvm::MCInst &Inst,
635 const void *Decoder) {
636 unsigned Rt = fieldFromInstruction(Val, 0, 5);
637 unsigned Rn = fieldFromInstruction(Val, 5, 5);
638 unsigned Rt2 = fieldFromInstruction(Val, 10, 5);
639 unsigned MemSize = fieldFromInstruction(Val, 30, 2);
641 DecodeStatus S = MCDisassembler::Success;
642 if (Rt == Rt2) S = MCDisassembler::SoftFail;
646 if (!Check(S, DecodeGPR32RegisterClass(Inst, Rt, Address, Decoder)))
647 return MCDisassembler::Fail;
648 if (!Check(S, DecodeGPR32RegisterClass(Inst, Rt2, Address, Decoder)))
649 return MCDisassembler::Fail;
652 if (!Check(S, DecodeGPR64RegisterClass(Inst, Rt, Address, Decoder)))
653 return MCDisassembler::Fail;
654 if (!Check(S, DecodeGPR64RegisterClass(Inst, Rt2, Address, Decoder)))
655 return MCDisassembler::Fail;
658 llvm_unreachable("Invalid MemSize in DecodeLoadPairExclusiveInstruction");
661 if (!Check(S, DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder)))
662 return MCDisassembler::Fail;
667 template<typename SomeNamedImmMapper>
668 static DecodeStatus DecodeNamedImmOperand(llvm::MCInst &Inst,
671 const void *Decoder) {
672 SomeNamedImmMapper Mapper;
674 Mapper.toString(Val, ValidNamed);
675 if (ValidNamed || Mapper.validImm(Val)) {
676 Inst.addOperand(MCOperand::CreateImm(Val));
677 return MCDisassembler::Success;
680 return MCDisassembler::Fail;
683 static DecodeStatus DecodeSysRegOperand(const A64SysReg::SysRegMapper &Mapper,
687 const void *Decoder) {
689 Mapper.toString(Val, ValidNamed);
691 Inst.addOperand(MCOperand::CreateImm(Val));
693 return ValidNamed ? MCDisassembler::Success : MCDisassembler::Fail;
696 static DecodeStatus DecodeMRSOperand(llvm::MCInst &Inst,
699 const void *Decoder) {
700 return DecodeSysRegOperand(A64SysReg::MRSMapper(), Inst, Val, Address,
704 static DecodeStatus DecodeMSROperand(llvm::MCInst &Inst,
707 const void *Decoder) {
708 return DecodeSysRegOperand(A64SysReg::MSRMapper(), Inst, Val, Address,
712 static DecodeStatus DecodeSingleIndexedInstruction(llvm::MCInst &Inst,
715 const void *Decoder) {
716 unsigned Rt = fieldFromInstruction(Insn, 0, 5);
717 unsigned Rn = fieldFromInstruction(Insn, 5, 5);
718 unsigned Imm9 = fieldFromInstruction(Insn, 12, 9);
720 unsigned Opc = fieldFromInstruction(Insn, 22, 2);
721 unsigned V = fieldFromInstruction(Insn, 26, 1);
722 unsigned Size = fieldFromInstruction(Insn, 30, 2);
724 if (Opc == 0 || (V == 1 && Opc == 2)) {
725 // It's a store, the MCInst gets: Rn_wb, Rt, Rn, Imm
726 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
729 if (V == 0 && (Opc == 2 || Size == 3)) {
730 DecodeGPR64RegisterClass(Inst, Rt, Address, Decoder);
732 DecodeGPR32RegisterClass(Inst, Rt, Address, Decoder);
733 } else if (V == 1 && (Opc & 2)) {
734 DecodeFPR128RegisterClass(Inst, Rt, Address, Decoder);
738 DecodeFPR8RegisterClass(Inst, Rt, Address, Decoder);
741 DecodeFPR16RegisterClass(Inst, Rt, Address, Decoder);
744 DecodeFPR32RegisterClass(Inst, Rt, Address, Decoder);
747 DecodeFPR64RegisterClass(Inst, Rt, Address, Decoder);
752 if (Opc != 0 && (V != 1 || Opc != 2)) {
753 // It's a load, the MCInst gets: Rt, Rn_wb, Rn, Imm
754 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
757 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
759 Inst.addOperand(MCOperand::CreateImm(Imm9));
761 // N.b. The official documentation says undpredictable if Rt == Rn, but this
762 // takes place at the architectural rather than encoding level:
764 // "STR xzr, [sp], #4" is perfectly valid.
765 if (V == 0 && Rt == Rn && Rn != 31)
766 return MCDisassembler::SoftFail;
768 return MCDisassembler::Success;
771 static MCDisassembler *createAArch64Disassembler(const Target &T,
772 const MCSubtargetInfo &STI) {
773 return new AArch64Disassembler(STI, T.createMCRegInfo(""));
776 extern "C" void LLVMInitializeAArch64Disassembler() {
777 TargetRegistry::RegisterMCDisassembler(TheAArch64Target,
778 createAArch64Disassembler);