1 //===- AArch64Disassembler.cpp - Disassembler for AArch64 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 // This file contains the functions necessary to decode AArch64 instruction
11 // bitpatterns into MCInsts (with the help of TableGenerated information from
12 // the instruction definitions).
14 //===----------------------------------------------------------------------===//
16 #define DEBUG_TYPE "arm-disassembler"
19 #include "AArch64RegisterInfo.h"
20 #include "AArch64Subtarget.h"
21 #include "Utils/AArch64BaseInfo.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCInstrDesc.h"
24 #include "llvm/MC/MCExpr.h"
25 #include "llvm/MC/MCContext.h"
26 #include "llvm/MC/MCDisassembler.h"
27 #include "llvm/MC/MCFixedLenDisassembler.h"
28 #include "llvm/Support/Debug.h"
29 #include "llvm/Support/MemoryObject.h"
30 #include "llvm/Support/ErrorHandling.h"
31 #include "llvm/Support/TargetRegistry.h"
32 #include "llvm/Support/raw_ostream.h"
36 typedef MCDisassembler::DecodeStatus DecodeStatus;
39 /// AArch64 disassembler for all AArch64 platforms.
40 class AArch64Disassembler : public MCDisassembler {
41 const MCRegisterInfo *RegInfo;
43 /// Initializes the disassembler.
45 AArch64Disassembler(const MCSubtargetInfo &STI, const MCRegisterInfo *Info)
46 : MCDisassembler(STI), RegInfo(Info) {
49 ~AArch64Disassembler() {
52 /// See MCDisassembler.
53 DecodeStatus getInstruction(MCInst &instr,
55 const MemoryObject ®ion,
58 raw_ostream &cStream) const;
60 const MCRegisterInfo *getRegInfo() const { return RegInfo; }
65 // Forward-declarations used in the auto-generated files.
66 static DecodeStatus DecodeGPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
67 uint64_t Address, const void *Decoder);
69 DecodeGPR64xspRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
70 uint64_t Address, const void *Decoder);
72 static DecodeStatus DecodeGPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
73 uint64_t Address, const void *Decoder);
75 DecodeGPR32wspRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
76 uint64_t Address, const void *Decoder);
78 static DecodeStatus DecodeFPR8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
79 uint64_t Address, const void *Decoder);
80 static DecodeStatus DecodeFPR16RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
81 uint64_t Address, const void *Decoder);
82 static DecodeStatus DecodeFPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
83 uint64_t Address, const void *Decoder);
84 static DecodeStatus DecodeFPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
85 uint64_t Address, const void *Decoder);
86 static DecodeStatus DecodeFPR128RegisterClass(llvm::MCInst &Inst,
87 unsigned RegNo, uint64_t Address,
89 static DecodeStatus DecodeVPR128RegisterClass(llvm::MCInst &Inst,
90 unsigned RegNo, uint64_t Address,
93 static DecodeStatus DecodeAddrRegExtendOperand(llvm::MCInst &Inst,
99 static DecodeStatus DecodeBitfield32ImmOperand(llvm::MCInst &Inst,
102 const void *Decoder);
104 static DecodeStatus DecodeCVT32FixedPosOperand(llvm::MCInst &Inst,
107 const void *Decoder);
109 template<int RegWidth>
110 static DecodeStatus DecodeMoveWideImmOperand(llvm::MCInst &Inst,
113 const void *Decoder);
115 template<int RegWidth>
116 static DecodeStatus DecodeLogicalImmOperand(llvm::MCInst &Inst,
119 const void *Decoder);
121 static DecodeStatus DecodeRegExtendOperand(llvm::MCInst &Inst,
122 unsigned ShiftAmount,
124 const void *Decoder);
126 static DecodeStatus Decode32BitShiftOperand(llvm::MCInst &Inst,
127 unsigned ShiftAmount,
129 const void *Decoder);
130 static DecodeStatus DecodeBitfieldInstruction(llvm::MCInst &Inst, unsigned Insn,
132 const void *Decoder);
134 static DecodeStatus DecodeFMOVLaneInstruction(llvm::MCInst &Inst, unsigned Insn,
136 const void *Decoder);
138 static DecodeStatus DecodeLDSTPairInstruction(llvm::MCInst &Inst,
141 const void *Decoder);
143 static DecodeStatus DecodeLoadPairExclusiveInstruction(llvm::MCInst &Inst,
146 const void *Decoder);
148 template<typename SomeNamedImmMapper>
149 static DecodeStatus DecodeNamedImmOperand(llvm::MCInst &Inst,
152 const void *Decoder);
155 DecodeSysRegOperand(const A64SysReg::SysRegMapper &InstMapper,
156 llvm::MCInst &Inst, unsigned Val,
157 uint64_t Address, const void *Decoder);
159 static DecodeStatus DecodeMRSOperand(llvm::MCInst &Inst,
162 const void *Decoder);
164 static DecodeStatus DecodeMSROperand(llvm::MCInst &Inst,
167 const void *Decoder);
170 static DecodeStatus DecodeSingleIndexedInstruction(llvm::MCInst &Inst,
173 const void *Decoder);
176 static bool Check(DecodeStatus &Out, DecodeStatus In);
178 #include "AArch64GenDisassemblerTables.inc"
179 #include "AArch64GenInstrInfo.inc"
181 static bool Check(DecodeStatus &Out, DecodeStatus In) {
183 case MCDisassembler::Success:
184 // Out stays the same.
186 case MCDisassembler::SoftFail:
189 case MCDisassembler::Fail:
193 llvm_unreachable("Invalid DecodeStatus!");
196 DecodeStatus AArch64Disassembler::getInstruction(MCInst &MI, uint64_t &Size,
197 const MemoryObject &Region,
200 raw_ostream &cs) const {
205 // We want to read exactly 4 bytes of data.
206 if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
208 return MCDisassembler::Fail;
211 // Encoded as a small-endian 32-bit word in the stream.
212 uint32_t insn = (bytes[3] << 24) |
217 // Calling the auto-generated decoder function.
218 DecodeStatus result = decodeInstruction(DecoderTableA6432, MI, insn, Address,
220 if (result != MCDisassembler::Fail) {
227 return MCDisassembler::Fail;
230 static unsigned getReg(const void *D, unsigned RC, unsigned RegNo) {
231 const AArch64Disassembler *Dis = static_cast<const AArch64Disassembler*>(D);
232 return Dis->getRegInfo()->getRegClass(RC).getRegister(RegNo);
235 static DecodeStatus DecodeGPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
236 uint64_t Address, const void *Decoder) {
238 return MCDisassembler::Fail;
240 uint16_t Register = getReg(Decoder, AArch64::GPR64RegClassID, RegNo);
241 Inst.addOperand(MCOperand::CreateReg(Register));
242 return MCDisassembler::Success;
246 DecodeGPR64xspRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
247 uint64_t Address, const void *Decoder) {
249 return MCDisassembler::Fail;
251 uint16_t Register = getReg(Decoder, AArch64::GPR64xspRegClassID, RegNo);
252 Inst.addOperand(MCOperand::CreateReg(Register));
253 return MCDisassembler::Success;
256 static DecodeStatus DecodeGPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
258 const void *Decoder) {
260 return MCDisassembler::Fail;
262 uint16_t Register = getReg(Decoder, AArch64::GPR32RegClassID, RegNo);
263 Inst.addOperand(MCOperand::CreateReg(Register));
264 return MCDisassembler::Success;
268 DecodeGPR32wspRegisterClass(llvm::MCInst &Inst, unsigned RegNo,
269 uint64_t Address, const void *Decoder) {
271 return MCDisassembler::Fail;
273 uint16_t Register = getReg(Decoder, AArch64::GPR32wspRegClassID, RegNo);
274 Inst.addOperand(MCOperand::CreateReg(Register));
275 return MCDisassembler::Success;
279 DecodeFPR8RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
280 uint64_t Address, const void *Decoder) {
282 return MCDisassembler::Fail;
284 uint16_t Register = getReg(Decoder, AArch64::FPR8RegClassID, RegNo);
285 Inst.addOperand(MCOperand::CreateReg(Register));
286 return MCDisassembler::Success;
290 DecodeFPR16RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
291 uint64_t Address, const void *Decoder) {
293 return MCDisassembler::Fail;
295 uint16_t Register = getReg(Decoder, AArch64::FPR16RegClassID, RegNo);
296 Inst.addOperand(MCOperand::CreateReg(Register));
297 return MCDisassembler::Success;
302 DecodeFPR32RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
303 uint64_t Address, const void *Decoder) {
305 return MCDisassembler::Fail;
307 uint16_t Register = getReg(Decoder, AArch64::FPR32RegClassID, RegNo);
308 Inst.addOperand(MCOperand::CreateReg(Register));
309 return MCDisassembler::Success;
313 DecodeFPR64RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
314 uint64_t Address, const void *Decoder) {
316 return MCDisassembler::Fail;
318 uint16_t Register = getReg(Decoder, AArch64::FPR64RegClassID, RegNo);
319 Inst.addOperand(MCOperand::CreateReg(Register));
320 return MCDisassembler::Success;
325 DecodeFPR128RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
326 uint64_t Address, const void *Decoder) {
328 return MCDisassembler::Fail;
330 uint16_t Register = getReg(Decoder, AArch64::FPR128RegClassID, RegNo);
331 Inst.addOperand(MCOperand::CreateReg(Register));
332 return MCDisassembler::Success;
336 DecodeVPR128RegisterClass(llvm::MCInst &Inst, unsigned RegNo,
337 uint64_t Address, const void *Decoder) {
339 return MCDisassembler::Fail;
341 uint16_t Register = getReg(Decoder, AArch64::VPR128RegClassID, RegNo);
342 Inst.addOperand(MCOperand::CreateReg(Register));
343 return MCDisassembler::Success;
346 static DecodeStatus DecodeAddrRegExtendOperand(llvm::MCInst &Inst,
349 const void *Decoder) {
350 // Option{1} must be 1. OptionHiS is made up of {Option{2}, Option{1},
351 // S}. Hence we want to check bit 1.
352 if (!(OptionHiS & 2))
353 return MCDisassembler::Fail;
355 Inst.addOperand(MCOperand::CreateImm(OptionHiS));
356 return MCDisassembler::Success;
359 static DecodeStatus DecodeBitfield32ImmOperand(llvm::MCInst &Inst,
362 const void *Decoder) {
363 // In the 32-bit variant, bit 6 must be zero. I.e. the immediate must be
366 return MCDisassembler::Fail;
368 Inst.addOperand(MCOperand::CreateImm(Imm6Bits));
369 return MCDisassembler::Success;
372 static DecodeStatus DecodeCVT32FixedPosOperand(llvm::MCInst &Inst,
375 const void *Decoder) {
376 // 1 <= Imm <= 32. Encoded as 64 - Imm so: 63 >= Encoded >= 32.
378 return MCDisassembler::Fail;
380 Inst.addOperand(MCOperand::CreateImm(Imm6Bits));
381 return MCDisassembler::Success;
385 template<int RegWidth>
386 static DecodeStatus DecodeMoveWideImmOperand(llvm::MCInst &Inst,
389 const void *Decoder) {
390 unsigned Imm16 = FullImm & 0xffff;
391 unsigned Shift = FullImm >> 16;
393 if (RegWidth == 32 && Shift > 1) return MCDisassembler::Fail;
395 Inst.addOperand(MCOperand::CreateImm(Imm16));
396 Inst.addOperand(MCOperand::CreateImm(Shift));
397 return MCDisassembler::Success;
400 template<int RegWidth>
401 static DecodeStatus DecodeLogicalImmOperand(llvm::MCInst &Inst,
404 const void *Decoder) {
406 if (!A64Imms::isLogicalImmBits(RegWidth, Bits, Imm))
407 return MCDisassembler::Fail;
409 Inst.addOperand(MCOperand::CreateImm(Bits));
410 return MCDisassembler::Success;
414 static DecodeStatus DecodeRegExtendOperand(llvm::MCInst &Inst,
415 unsigned ShiftAmount,
417 const void *Decoder) {
418 // Only values 0-4 are valid for this 3-bit field
420 return MCDisassembler::Fail;
422 Inst.addOperand(MCOperand::CreateImm(ShiftAmount));
423 return MCDisassembler::Success;
426 static DecodeStatus Decode32BitShiftOperand(llvm::MCInst &Inst,
427 unsigned ShiftAmount,
429 const void *Decoder) {
430 // Only values below 32 are valid for a 32-bit register
431 if (ShiftAmount > 31)
432 return MCDisassembler::Fail;
434 Inst.addOperand(MCOperand::CreateImm(ShiftAmount));
435 return MCDisassembler::Success;
438 static DecodeStatus DecodeBitfieldInstruction(llvm::MCInst &Inst, unsigned Insn,
440 const void *Decoder) {
441 unsigned Rd = fieldFromInstruction(Insn, 0, 5);
442 unsigned Rn = fieldFromInstruction(Insn, 5, 5);
443 unsigned ImmS = fieldFromInstruction(Insn, 10, 6);
444 unsigned ImmR = fieldFromInstruction(Insn, 16, 6);
445 unsigned SF = fieldFromInstruction(Insn, 31, 1);
447 // Undef for 0b11 just in case it occurs. Don't want the compiler to optimise
448 // out assertions that it thinks should never be hit.
449 enum OpcTypes { SBFM = 0, BFM, UBFM, Undef } Opc;
450 Opc = (OpcTypes)fieldFromInstruction(Insn, 29, 2);
453 // ImmR and ImmS must be between 0 and 31 for 32-bit instructions.
454 if (ImmR > 31 || ImmS > 31)
455 return MCDisassembler::Fail;
459 DecodeGPR64RegisterClass(Inst, Rd, Address, Decoder);
460 // BFM MCInsts use Rd as a source too.
461 if (Opc == BFM) DecodeGPR64RegisterClass(Inst, Rd, Address, Decoder);
462 DecodeGPR64RegisterClass(Inst, Rn, Address, Decoder);
464 DecodeGPR32RegisterClass(Inst, Rd, Address, Decoder);
465 // BFM MCInsts use Rd as a source too.
466 if (Opc == BFM) DecodeGPR32RegisterClass(Inst, Rd, Address, Decoder);
467 DecodeGPR32RegisterClass(Inst, Rn, Address, Decoder);
470 // ASR and LSR have more specific patterns so they won't get here:
471 assert(!(ImmS == 31 && !SF && Opc != BFM)
472 && "shift should have used auto decode");
473 assert(!(ImmS == 63 && SF && Opc != BFM)
474 && "shift should have used auto decode");
476 // Extension instructions similarly:
477 if (Opc == SBFM && ImmR == 0) {
478 assert((ImmS != 7 && ImmS != 15) && "extension got here");
479 assert((ImmS != 31 || SF == 0) && "extension got here");
480 } else if (Opc == UBFM && ImmR == 0) {
481 assert((SF != 0 || (ImmS != 7 && ImmS != 15)) && "extension got here");
485 // It might be a LSL instruction, which actually takes the shift amount
486 // itself as an MCInst operand.
487 if (SF && (ImmS + 1) % 64 == ImmR) {
488 Inst.setOpcode(AArch64::LSLxxi);
489 Inst.addOperand(MCOperand::CreateImm(63 - ImmS));
490 return MCDisassembler::Success;
491 } else if (!SF && (ImmS + 1) % 32 == ImmR) {
492 Inst.setOpcode(AArch64::LSLwwi);
493 Inst.addOperand(MCOperand::CreateImm(31 - ImmS));
494 return MCDisassembler::Success;
498 // Otherwise it's definitely either an extract or an insert depending on which
499 // of ImmR or ImmS is larger.
500 unsigned ExtractOp, InsertOp;
502 default: llvm_unreachable("unexpected instruction trying to decode bitfield");
504 ExtractOp = SF ? AArch64::SBFXxxii : AArch64::SBFXwwii;
505 InsertOp = SF ? AArch64::SBFIZxxii : AArch64::SBFIZwwii;
508 ExtractOp = SF ? AArch64::BFXILxxii : AArch64::BFXILwwii;
509 InsertOp = SF ? AArch64::BFIxxii : AArch64::BFIwwii;
512 ExtractOp = SF ? AArch64::UBFXxxii : AArch64::UBFXwwii;
513 InsertOp = SF ? AArch64::UBFIZxxii : AArch64::UBFIZwwii;
517 // Otherwise it's a boring insert or extract
518 Inst.addOperand(MCOperand::CreateImm(ImmR));
519 Inst.addOperand(MCOperand::CreateImm(ImmS));
523 Inst.setOpcode(InsertOp);
525 Inst.setOpcode(ExtractOp);
527 return MCDisassembler::Success;
530 static DecodeStatus DecodeFMOVLaneInstruction(llvm::MCInst &Inst, unsigned Insn,
532 const void *Decoder) {
533 // This decoder exists to add the dummy Lane operand to the MCInst, which must
534 // be 1 in assembly but has no other real manifestation.
535 unsigned Rd = fieldFromInstruction(Insn, 0, 5);
536 unsigned Rn = fieldFromInstruction(Insn, 5, 5);
537 unsigned IsToVec = fieldFromInstruction(Insn, 16, 1);
540 DecodeVPR128RegisterClass(Inst, Rd, Address, Decoder);
541 DecodeGPR64RegisterClass(Inst, Rn, Address, Decoder);
543 DecodeGPR64RegisterClass(Inst, Rd, Address, Decoder);
544 DecodeVPR128RegisterClass(Inst, Rn, Address, Decoder);
548 Inst.addOperand(MCOperand::CreateImm(1));
550 return MCDisassembler::Success;
554 static DecodeStatus DecodeLDSTPairInstruction(llvm::MCInst &Inst,
557 const void *Decoder) {
558 DecodeStatus Result = MCDisassembler::Success;
559 unsigned Rt = fieldFromInstruction(Insn, 0, 5);
560 unsigned Rn = fieldFromInstruction(Insn, 5, 5);
561 unsigned Rt2 = fieldFromInstruction(Insn, 10, 5);
562 unsigned SImm7 = fieldFromInstruction(Insn, 15, 7);
563 unsigned L = fieldFromInstruction(Insn, 22, 1);
564 unsigned V = fieldFromInstruction(Insn, 26, 1);
565 unsigned Opc = fieldFromInstruction(Insn, 30, 2);
567 // Not an official name, but it turns out that bit 23 distinguishes indexed
568 // from non-indexed operations.
569 unsigned Indexed = fieldFromInstruction(Insn, 23, 1);
571 if (Indexed && L == 0) {
572 // The MCInst for an indexed store has an out operand and 4 ins:
573 // Rn_wb, Rt, Rt2, Rn, Imm
574 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
577 // You shouldn't load to the same register twice in an instruction...
579 Result = MCDisassembler::SoftFail;
581 // ... or do any operation that writes-back to a transfer register. But note
582 // that "stp xzr, xzr, [sp], #4" is fine because xzr and sp are different.
583 if (Indexed && V == 0 && Rn != 31 && (Rt == Rn || Rt2 == Rn))
584 Result = MCDisassembler::SoftFail;
586 // Exactly how we decode the MCInst's registers depends on the Opc and V
587 // fields of the instruction. These also obviously determine the size of the
588 // operation so we can fill in that information while we're at it.
590 // The instruction operates on the FP/SIMD registers
592 default: return MCDisassembler::Fail;
594 DecodeFPR32RegisterClass(Inst, Rt, Address, Decoder);
595 DecodeFPR32RegisterClass(Inst, Rt2, Address, Decoder);
598 DecodeFPR64RegisterClass(Inst, Rt, Address, Decoder);
599 DecodeFPR64RegisterClass(Inst, Rt2, Address, Decoder);
602 DecodeFPR128RegisterClass(Inst, Rt, Address, Decoder);
603 DecodeFPR128RegisterClass(Inst, Rt2, Address, Decoder);
608 default: return MCDisassembler::Fail;
610 DecodeGPR32RegisterClass(Inst, Rt, Address, Decoder);
611 DecodeGPR32RegisterClass(Inst, Rt2, Address, Decoder);
614 assert(L && "unexpected \"store signed\" attempt");
615 DecodeGPR64RegisterClass(Inst, Rt, Address, Decoder);
616 DecodeGPR64RegisterClass(Inst, Rt2, Address, Decoder);
619 DecodeGPR64RegisterClass(Inst, Rt, Address, Decoder);
620 DecodeGPR64RegisterClass(Inst, Rt2, Address, Decoder);
625 if (Indexed && L == 1) {
626 // The MCInst for an indexed load has 3 out operands and an 3 ins:
627 // Rt, Rt2, Rn_wb, Rt2, Rn, Imm
628 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
632 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
633 Inst.addOperand(MCOperand::CreateImm(SImm7));
638 static DecodeStatus DecodeLoadPairExclusiveInstruction(llvm::MCInst &Inst,
641 const void *Decoder) {
642 unsigned Rt = fieldFromInstruction(Val, 0, 5);
643 unsigned Rn = fieldFromInstruction(Val, 5, 5);
644 unsigned Rt2 = fieldFromInstruction(Val, 10, 5);
645 unsigned MemSize = fieldFromInstruction(Val, 30, 2);
647 DecodeStatus S = MCDisassembler::Success;
648 if (Rt == Rt2) S = MCDisassembler::SoftFail;
652 if (!Check(S, DecodeGPR32RegisterClass(Inst, Rt, Address, Decoder)))
653 return MCDisassembler::Fail;
654 if (!Check(S, DecodeGPR32RegisterClass(Inst, Rt2, Address, Decoder)))
655 return MCDisassembler::Fail;
658 if (!Check(S, DecodeGPR64RegisterClass(Inst, Rt, Address, Decoder)))
659 return MCDisassembler::Fail;
660 if (!Check(S, DecodeGPR64RegisterClass(Inst, Rt2, Address, Decoder)))
661 return MCDisassembler::Fail;
664 llvm_unreachable("Invalid MemSize in DecodeLoadPairExclusiveInstruction");
667 if (!Check(S, DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder)))
668 return MCDisassembler::Fail;
673 template<typename SomeNamedImmMapper>
674 static DecodeStatus DecodeNamedImmOperand(llvm::MCInst &Inst,
677 const void *Decoder) {
678 SomeNamedImmMapper Mapper;
680 Mapper.toString(Val, ValidNamed);
681 if (ValidNamed || Mapper.validImm(Val)) {
682 Inst.addOperand(MCOperand::CreateImm(Val));
683 return MCDisassembler::Success;
686 return MCDisassembler::Fail;
689 static DecodeStatus DecodeSysRegOperand(const A64SysReg::SysRegMapper &Mapper,
693 const void *Decoder) {
695 Mapper.toString(Val, ValidNamed);
697 Inst.addOperand(MCOperand::CreateImm(Val));
699 return ValidNamed ? MCDisassembler::Success : MCDisassembler::Fail;
702 static DecodeStatus DecodeMRSOperand(llvm::MCInst &Inst,
705 const void *Decoder) {
706 return DecodeSysRegOperand(A64SysReg::MRSMapper(), Inst, Val, Address,
710 static DecodeStatus DecodeMSROperand(llvm::MCInst &Inst,
713 const void *Decoder) {
714 return DecodeSysRegOperand(A64SysReg::MSRMapper(), Inst, Val, Address,
718 static DecodeStatus DecodeSingleIndexedInstruction(llvm::MCInst &Inst,
721 const void *Decoder) {
722 unsigned Rt = fieldFromInstruction(Insn, 0, 5);
723 unsigned Rn = fieldFromInstruction(Insn, 5, 5);
724 unsigned Imm9 = fieldFromInstruction(Insn, 12, 9);
726 unsigned Opc = fieldFromInstruction(Insn, 22, 2);
727 unsigned V = fieldFromInstruction(Insn, 26, 1);
728 unsigned Size = fieldFromInstruction(Insn, 30, 2);
730 if (Opc == 0 || (V == 1 && Opc == 2)) {
731 // It's a store, the MCInst gets: Rn_wb, Rt, Rn, Imm
732 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
735 if (V == 0 && (Opc == 2 || Size == 3)) {
736 DecodeGPR64RegisterClass(Inst, Rt, Address, Decoder);
738 DecodeGPR32RegisterClass(Inst, Rt, Address, Decoder);
739 } else if (V == 1 && (Opc & 2)) {
740 DecodeFPR128RegisterClass(Inst, Rt, Address, Decoder);
744 DecodeFPR8RegisterClass(Inst, Rt, Address, Decoder);
747 DecodeFPR16RegisterClass(Inst, Rt, Address, Decoder);
750 DecodeFPR32RegisterClass(Inst, Rt, Address, Decoder);
753 DecodeFPR64RegisterClass(Inst, Rt, Address, Decoder);
758 if (Opc != 0 && (V != 1 || Opc != 2)) {
759 // It's a load, the MCInst gets: Rt, Rn_wb, Rn, Imm
760 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
763 DecodeGPR64xspRegisterClass(Inst, Rn, Address, Decoder);
765 Inst.addOperand(MCOperand::CreateImm(Imm9));
767 // N.b. The official documentation says undpredictable if Rt == Rn, but this
768 // takes place at the architectural rather than encoding level:
770 // "STR xzr, [sp], #4" is perfectly valid.
771 if (V == 0 && Rt == Rn && Rn != 31)
772 return MCDisassembler::SoftFail;
774 return MCDisassembler::Success;
777 static MCDisassembler *createAArch64Disassembler(const Target &T,
778 const MCSubtargetInfo &STI) {
779 return new AArch64Disassembler(STI, T.createMCRegInfo(""));
782 extern "C" void LLVMInitializeAArch64Disassembler() {
783 TargetRegistry::RegisterMCDisassembler(TheAArch64Target,
784 createAArch64Disassembler);