LLVM 24.0.0git
AArch64Disassembler.cpp
Go to the documentation of this file.
1//===- AArch64Disassembler.cpp - Disassembler for AArch64 -----------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9//
10//===----------------------------------------------------------------------===//
11
12#include "AArch64Disassembler.h"
18#include "llvm/MC/MCDecoder.h"
21#include "llvm/MC/MCInst.h"
22#include "llvm/MC/MCInstrDesc.h"
27#include "llvm/Support/Debug.h"
28#include <memory>
29
30using namespace llvm;
31using namespace llvm::MCD;
32
33#define DEBUG_TYPE "aarch64-disassembler"
34
35// Pull DecodeStatus and its enum values into the global namespace.
37
38template <int Bits>
39static DecodeStatus DecodeSImm(MCInst &Inst, uint64_t Imm, uint64_t Address,
40 const MCDisassembler *Decoder);
41
42#define Success MCDisassembler::Success
43#define Fail MCDisassembler::Fail
44#define SoftFail MCDisassembler::SoftFail
45
46template <unsigned RegClassID, unsigned FirstReg, unsigned NumRegsInClass>
47static DecodeStatus DecodeSimpleRegisterClass(MCInst &Inst, unsigned RegNo,
48 uint64_t Address,
49 const MCDisassembler *Decoder) {
50 if (RegNo > NumRegsInClass - 1)
51 return Fail;
52
54 getAArch64MCRegisterClass(RegClassID).getRegister(RegNo + FirstReg);
56 return Success;
57}
58
59static DecodeStatus
60DecodeGPR64x8ClassRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
61 const MCDisassembler *Decoder) {
62 if (RegNo > 22)
63 return Fail;
64 if (RegNo & 1)
65 return Fail;
66
68 getAArch64MCRegisterClass(AArch64::GPR64x8ClassRegClassID)
69 .getRegister(RegNo >> 1);
71 return Success;
72}
73
74template <unsigned RegClassID, unsigned Multiple, unsigned Min, unsigned Max>
75static DecodeStatus
76DecodeMulMinMaxRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
77 const MCDisassembler *Decoder) {
78 unsigned Reg = (RegNo * Multiple) + Min;
79 if (Reg < Min || Reg > Max || (Reg % Multiple))
80 return Fail;
81 MCRegister Register = getAArch64MCRegisterClass(RegClassID).getRegister(Reg);
83 return Success;
84}
85
86template <unsigned Min, unsigned Max>
87static DecodeStatus DecodeZPR2Mul2RegisterClass(MCInst &Inst, unsigned RegNo,
88 uint64_t Address,
89 const void *Decoder) {
90 unsigned Reg = (RegNo * 2) + Min;
91 if (Reg < Min || Reg > Max || (Reg & 1))
92 return Fail;
93
95 getAArch64MCRegisterClass(AArch64::ZPR2RegClassID).getRegister(Reg);
97 return Success;
98}
99
100static DecodeStatus DecodeZK(MCInst &Inst, unsigned RegNo, uint64_t Address,
101 const MCDisassembler *Decoder) {
102 if (RegNo > 7)
103 return Fail;
104
106 getAArch64MCRegisterClass(AArch64::ZPR_KRegClassID).getRegister(RegNo);
108 return Success;
109}
110
112 uint64_t Address,
113 const void *Decoder) {
114 if (RegNo * 4 > 28)
115 return Fail;
117 getAArch64MCRegisterClass(AArch64::ZPR4RegClassID).getRegister(RegNo * 4);
119 return Success;
120}
121
122static DecodeStatus
124 uint64_t Address,
125 const MCDisassembler *Decoder) {
126 if (RegMask > 0xFF)
127 return Fail;
128 Inst.addOperand(MCOperand::createImm(RegMask));
129 return Success;
130}
131
133 const MCDisassembler *Decoder) {
134 Inst.addOperand(MCOperand::createReg(AArch64::ZT0));
135 return Success;
136}
137
139 const MCDisassembler *Decoder) {
140 Inst.addOperand(MCOperand::createReg(AArch64::ZA));
141 return Success;
142}
143
145 const MCDisassembler *Decoder) {
146 Inst.addOperand(MCOperand::createReg(AArch64::ZAB0));
147 return Success;
148}
149
150static DecodeStatus DecodeMPR16RegisterClass(MCInst &Inst, unsigned RegNo,
151 uint64_t Address,
152 const MCDisassembler *Decoder) {
154 getAArch64MCRegisterClass(AArch64::MPR16RegClassID).getRegister(RegNo);
156 return Success;
157}
158
159static DecodeStatus DecodeMPR32RegisterClass(MCInst &Inst, unsigned RegNo,
160 uint64_t Address,
161 const MCDisassembler *Decoder) {
163 getAArch64MCRegisterClass(AArch64::MPR32RegClassID).getRegister(RegNo);
165 return Success;
166}
167
168static DecodeStatus DecodeMPR64RegisterClass(MCInst &Inst, unsigned RegNo,
169 uint64_t Address,
170 const MCDisassembler *Decoder) {
172 getAArch64MCRegisterClass(AArch64::MPR64RegClassID).getRegister(RegNo);
174 return Success;
175}
176
177static DecodeStatus DecodeMPR128RegisterClass(MCInst &Inst, unsigned RegNo,
178 uint64_t Address,
179 const MCDisassembler *Decoder) {
181 getAArch64MCRegisterClass(AArch64::MPR128RegClassID).getRegister(RegNo);
183 return Success;
184}
185
187 uint64_t Address,
188 const void *Decoder) {
189 if ((RegNo * 2) > 14)
190 return Fail;
192 getAArch64MCRegisterClass(AArch64::PPR2RegClassID).getRegister(RegNo * 2);
194 return Success;
195}
196
198 uint64_t Addr,
199 const MCDisassembler *Decoder) {
200 // scale{5} is asserted as 1 in tblgen.
201 Imm |= 0x20;
202 Inst.addOperand(MCOperand::createImm(64 - Imm));
203 return Success;
204}
205
207 uint64_t Addr,
208 const MCDisassembler *Decoder) {
209 Inst.addOperand(MCOperand::createImm(64 - Imm));
210 return Success;
211}
212
213static DecodeStatus DecodePCRelLabel16(MCInst &Inst, unsigned Imm,
214 uint64_t Addr,
215 const MCDisassembler *Decoder) {
216 // Immediate is encoded as the top 16-bits of an unsigned 18-bit negative
217 // PC-relative offset.
218 uint64_t ImmVal = Imm;
219 if (ImmVal > (1 << 16))
220 return Fail;
221 ImmVal = -ImmVal;
222 if (!Decoder->tryAddingSymbolicOperand(Inst, (ImmVal << 2), Addr,
223 /*IsBranch=*/false, 0, 0, 4))
224 Inst.addOperand(MCOperand::createImm(ImmVal));
225 return Success;
226}
227
228static DecodeStatus DecodePCRelLabel19(MCInst &Inst, unsigned Imm,
229 uint64_t Addr,
230 const MCDisassembler *Decoder) {
231 int64_t ImmVal = SignExtend64<19>(Imm);
232
233 if (!Decoder->tryAddingSymbolicOperand(
234 Inst, ImmVal * 4, Addr, Inst.getOpcode() != AArch64::LDRXl, 0, 0, 4))
235 Inst.addOperand(MCOperand::createImm(ImmVal));
236 return Success;
237}
238
239static DecodeStatus DecodePCRelLabel9(MCInst &Inst, unsigned Imm, uint64_t Addr,
240 const MCDisassembler *Decoder) {
241 int64_t ImmVal = SignExtend64<9>(Imm);
242
243 if (!Decoder->tryAddingSymbolicOperand(Inst, (ImmVal * 4), Addr,
244 /*IsBranch=*/true, 0, 0, 4))
245 Inst.addOperand(MCOperand::createImm(ImmVal));
246 return Success;
247}
248
249static DecodeStatus DecodeMemExtend(MCInst &Inst, unsigned Imm,
250 uint64_t Address,
251 const MCDisassembler *Decoder) {
252 Inst.addOperand(MCOperand::createImm((Imm >> 1) & 1));
253 Inst.addOperand(MCOperand::createImm(Imm & 1));
254 return Success;
255}
256
257static DecodeStatus DecodeMRSSystemRegister(MCInst &Inst, unsigned Imm,
258 uint64_t Address,
259 const MCDisassembler *Decoder) {
261
262 // Every system register in the encoding space is valid with the syntax
263 // S<op0>_<op1>_<Cn>_<Cm>_<op2>, so decoding system registers always succeeds.
264 return Success;
265}
266
267static DecodeStatus DecodeMSRSystemRegister(MCInst &Inst, unsigned Imm,
268 uint64_t Address,
269 const MCDisassembler *Decoder) {
271
272 return Success;
273}
274
276 uint64_t Address,
277 const MCDisassembler *Decoder) {
278 // This decoder exists to add the dummy Lane operand to the MCInst, which must
279 // be 1 in assembly but has no other real manifestation.
280 unsigned Rd = fieldFromInstruction(Insn, 0, 5);
281 unsigned Rn = fieldFromInstruction(Insn, 5, 5);
282 unsigned IsToVec = fieldFromInstruction(Insn, 16, 1);
283
284 if (IsToVec) {
286 Inst, Rd, Address, Decoder);
288 Inst, Rn, Address, Decoder);
289 } else {
291 Inst, Rd, Address, Decoder);
293 Inst, Rn, Address, Decoder);
294 }
295
296 // Add the lane
298
299 return Success;
300}
301
302static DecodeStatus DecodeVecShiftRImm(MCInst &Inst, unsigned Imm,
303 unsigned Add) {
305 return Success;
306}
307
308static DecodeStatus DecodeVecShiftLImm(MCInst &Inst, unsigned Imm,
309 unsigned Add) {
310 Inst.addOperand(MCOperand::createImm((Imm + Add) & (Add - 1)));
311 return Success;
312}
313
314static DecodeStatus DecodeVecShiftR64Imm(MCInst &Inst, unsigned Imm,
315 uint64_t Addr,
316 const MCDisassembler *Decoder) {
317 return DecodeVecShiftRImm(Inst, Imm, 64);
318}
319
321 uint64_t Addr,
322 const MCDisassembler *Decoder) {
323 return DecodeVecShiftRImm(Inst, Imm | 0x20, 64);
324}
325
326static DecodeStatus DecodeVecShiftR32Imm(MCInst &Inst, unsigned Imm,
327 uint64_t Addr,
328 const MCDisassembler *Decoder) {
329 return DecodeVecShiftRImm(Inst, Imm, 32);
330}
331
333 uint64_t Addr,
334 const MCDisassembler *Decoder) {
335 return DecodeVecShiftRImm(Inst, Imm | 0x10, 32);
336}
337
338static DecodeStatus DecodeVecShiftR16Imm(MCInst &Inst, unsigned Imm,
339 uint64_t Addr,
340 const MCDisassembler *Decoder) {
341 return DecodeVecShiftRImm(Inst, Imm, 16);
342}
343
345 uint64_t Addr,
346 const MCDisassembler *Decoder) {
347 return DecodeVecShiftRImm(Inst, Imm | 0x8, 16);
348}
349
350static DecodeStatus DecodeVecShiftR8Imm(MCInst &Inst, unsigned Imm,
351 uint64_t Addr,
352 const MCDisassembler *Decoder) {
353 return DecodeVecShiftRImm(Inst, Imm, 8);
354}
355
356static DecodeStatus DecodeVecShiftL64Imm(MCInst &Inst, unsigned Imm,
357 uint64_t Addr,
358 const MCDisassembler *Decoder) {
359 return DecodeVecShiftLImm(Inst, Imm, 64);
360}
361
362static DecodeStatus DecodeVecShiftL32Imm(MCInst &Inst, unsigned Imm,
363 uint64_t Addr,
364 const MCDisassembler *Decoder) {
365 return DecodeVecShiftLImm(Inst, Imm, 32);
366}
367
368static DecodeStatus DecodeVecShiftL16Imm(MCInst &Inst, unsigned Imm,
369 uint64_t Addr,
370 const MCDisassembler *Decoder) {
371 return DecodeVecShiftLImm(Inst, Imm, 16);
372}
373
374static DecodeStatus DecodeVecShiftL8Imm(MCInst &Inst, unsigned Imm,
375 uint64_t Addr,
376 const MCDisassembler *Decoder) {
377 return DecodeVecShiftLImm(Inst, Imm, 8);
378}
379
380static DecodeStatus
382 const MCDisassembler *Decoder) {
383 unsigned Rd = fieldFromInstruction(insn, 0, 5);
384 unsigned Rn = fieldFromInstruction(insn, 5, 5);
385 unsigned Rm = fieldFromInstruction(insn, 16, 5);
386 unsigned shiftHi = fieldFromInstruction(insn, 22, 2);
387 unsigned shiftLo = fieldFromInstruction(insn, 10, 6);
388 unsigned shift = (shiftHi << 6) | shiftLo;
389 switch (Inst.getOpcode()) {
390 default:
391 return Fail;
392 case AArch64::ADDWrs:
393 case AArch64::ADDSWrs:
394 case AArch64::SUBWrs:
395 case AArch64::SUBSWrs:
396 // if shift == '11' then ReservedValue()
397 if (shiftHi == 0x3)
398 return Fail;
399 [[fallthrough]];
400 case AArch64::ANDWrs:
401 case AArch64::ANDSWrs:
402 case AArch64::BICWrs:
403 case AArch64::BICSWrs:
404 case AArch64::ORRWrs:
405 case AArch64::ORNWrs:
406 case AArch64::EORWrs:
407 case AArch64::EONWrs: {
408 // if sf == '0' and imm6<5> == '1' then ReservedValue()
409 if (shiftLo >> 5 == 1)
410 return Fail;
412 Decoder);
414 Decoder);
416 Decoder);
417 break;
418 }
419 case AArch64::ADDXrs:
420 case AArch64::ADDSXrs:
421 case AArch64::SUBXrs:
422 case AArch64::SUBSXrs:
423 // if shift == '11' then ReservedValue()
424 if (shiftHi == 0x3)
425 return Fail;
426 [[fallthrough]];
427 case AArch64::ANDXrs:
428 case AArch64::ANDSXrs:
429 case AArch64::BICXrs:
430 case AArch64::BICSXrs:
431 case AArch64::ORRXrs:
432 case AArch64::ORNXrs:
433 case AArch64::EORXrs:
434 case AArch64::EONXrs:
436 Decoder);
438 Decoder);
440 Decoder);
441 break;
442 }
443
444 Inst.addOperand(MCOperand::createImm(shift));
445 return Success;
446}
447
449 uint64_t Addr,
450 const MCDisassembler *Decoder) {
451 unsigned Rd = fieldFromInstruction(insn, 0, 5);
452 unsigned imm = fieldFromInstruction(insn, 5, 16);
453 unsigned shift = fieldFromInstruction(insn, 21, 2);
454 shift <<= 4;
455 switch (Inst.getOpcode()) {
456 default:
457 return Fail;
458 case AArch64::MOVZWi:
459 case AArch64::MOVNWi:
460 case AArch64::MOVKWi:
461 if (shift & (1U << 5))
462 return Fail;
464 Decoder);
465 break;
466 case AArch64::MOVZXi:
467 case AArch64::MOVNXi:
468 case AArch64::MOVKXi:
470 Decoder);
471 break;
472 }
473
474 if (Inst.getOpcode() == AArch64::MOVKWi ||
475 Inst.getOpcode() == AArch64::MOVKXi)
476 Inst.addOperand(Inst.getOperand(0));
477
478 if (!Decoder->tryAddingSymbolicOperand(Inst, imm, Addr, /*IsBranch*/ false, 0,
479 0, 4))
481
482 Inst.addOperand(MCOperand::createImm(shift));
483 return Success;
484}
485
486static DecodeStatus
488 const MCDisassembler *Decoder) {
489 unsigned Rt = fieldFromInstruction(insn, 0, 5);
490 unsigned Rn = fieldFromInstruction(insn, 5, 5);
491 unsigned offset = fieldFromInstruction(insn, 10, 12);
492
493 switch (Inst.getOpcode()) {
494 default:
495 return Fail;
496 case AArch64::PRFMui:
497 // Rt is an immediate in prefetch.
499 break;
500 case AArch64::STRBBui:
501 case AArch64::LDRBBui:
502 case AArch64::LDRSBWui:
503 case AArch64::STRHHui:
504 case AArch64::LDRHHui:
505 case AArch64::LDRSHWui:
506 case AArch64::STRWui:
507 case AArch64::LDRWui:
509 Decoder);
510 break;
511 case AArch64::LDRSBXui:
512 case AArch64::LDRSHXui:
513 case AArch64::LDRSWui:
514 case AArch64::STRXui:
515 case AArch64::LDRXui:
517 Decoder);
518 break;
519 case AArch64::LDRQui:
520 case AArch64::STRQui:
522 Decoder);
523 break;
524 case AArch64::LDRDui:
525 case AArch64::STRDui:
527 Decoder);
528 break;
529 case AArch64::LDRSui:
530 case AArch64::STRSui:
532 Decoder);
533 break;
534 case AArch64::LDRHui:
535 case AArch64::STRHui:
537 Decoder);
538 break;
539 case AArch64::LDRBui:
540 case AArch64::STRBui:
542 Decoder);
543 break;
544 }
545
547 Decoder);
548 if (!Decoder->tryAddingSymbolicOperand(Inst, offset, Addr, Fail, 0, 0, 4))
549 Inst.addOperand(MCOperand::createImm(offset));
550 return Success;
551}
552
554 uint64_t Addr,
555 const MCDisassembler *Decoder) {
556 unsigned Rt = fieldFromInstruction(insn, 0, 5);
557 unsigned Rn = fieldFromInstruction(insn, 5, 5);
558 int64_t offset = SignExtend64<9>(fieldFromInstruction(insn, 12, 9));
559
560 // First operand is always the writeback to the address register, if needed.
561 switch (Inst.getOpcode()) {
562 default:
563 break;
564 case AArch64::LDRSBWpre:
565 case AArch64::LDRSHWpre:
566 case AArch64::STRBBpre:
567 case AArch64::LDRBBpre:
568 case AArch64::STRHHpre:
569 case AArch64::LDRHHpre:
570 case AArch64::STRWpre:
571 case AArch64::LDRWpre:
572 case AArch64::LDRSBWpost:
573 case AArch64::LDRSHWpost:
574 case AArch64::STRBBpost:
575 case AArch64::LDRBBpost:
576 case AArch64::STRHHpost:
577 case AArch64::LDRHHpost:
578 case AArch64::STRWpost:
579 case AArch64::LDRWpost:
580 case AArch64::LDRSBXpre:
581 case AArch64::LDRSHXpre:
582 case AArch64::STRXpre:
583 case AArch64::LDRSWpre:
584 case AArch64::LDRXpre:
585 case AArch64::LDRSBXpost:
586 case AArch64::LDRSHXpost:
587 case AArch64::STRXpost:
588 case AArch64::LDRSWpost:
589 case AArch64::LDRXpost:
590 case AArch64::LDRQpre:
591 case AArch64::STRQpre:
592 case AArch64::LDRQpost:
593 case AArch64::STRQpost:
594 case AArch64::LDRDpre:
595 case AArch64::STRDpre:
596 case AArch64::LDRDpost:
597 case AArch64::STRDpost:
598 case AArch64::LDRSpre:
599 case AArch64::STRSpre:
600 case AArch64::LDRSpost:
601 case AArch64::STRSpost:
602 case AArch64::LDRHpre:
603 case AArch64::STRHpre:
604 case AArch64::LDRHpost:
605 case AArch64::STRHpost:
606 case AArch64::LDRBpre:
607 case AArch64::STRBpre:
608 case AArch64::LDRBpost:
609 case AArch64::STRBpost:
611 Decoder);
612 break;
613 }
614
615 switch (Inst.getOpcode()) {
616 default:
617 return Fail;
618 case AArch64::PRFUMi:
619 // Rt is an immediate in prefetch.
621 break;
622 case AArch64::STURBBi:
623 case AArch64::LDURBBi:
624 case AArch64::LDURSBWi:
625 case AArch64::STURHHi:
626 case AArch64::LDURHHi:
627 case AArch64::LDURSHWi:
628 case AArch64::STURWi:
629 case AArch64::LDURWi:
630 case AArch64::LDTRSBWi:
631 case AArch64::LDTRSHWi:
632 case AArch64::STTRWi:
633 case AArch64::LDTRWi:
634 case AArch64::STTRHi:
635 case AArch64::LDTRHi:
636 case AArch64::LDTRBi:
637 case AArch64::STTRBi:
638 case AArch64::LDRSBWpre:
639 case AArch64::LDRSHWpre:
640 case AArch64::STRBBpre:
641 case AArch64::LDRBBpre:
642 case AArch64::STRHHpre:
643 case AArch64::LDRHHpre:
644 case AArch64::STRWpre:
645 case AArch64::LDRWpre:
646 case AArch64::LDRSBWpost:
647 case AArch64::LDRSHWpost:
648 case AArch64::STRBBpost:
649 case AArch64::LDRBBpost:
650 case AArch64::STRHHpost:
651 case AArch64::LDRHHpost:
652 case AArch64::STRWpost:
653 case AArch64::LDRWpost:
654 case AArch64::STLURBi:
655 case AArch64::STLURHi:
656 case AArch64::STLURWi:
657 case AArch64::LDAPURBi:
658 case AArch64::LDAPURSBWi:
659 case AArch64::LDAPURHi:
660 case AArch64::LDAPURSHWi:
661 case AArch64::LDAPURi:
663 Decoder);
664 break;
665 case AArch64::LDURSBXi:
666 case AArch64::LDURSHXi:
667 case AArch64::LDURSWi:
668 case AArch64::STURXi:
669 case AArch64::LDURXi:
670 case AArch64::LDTRSBXi:
671 case AArch64::LDTRSHXi:
672 case AArch64::LDTRSWi:
673 case AArch64::STTRXi:
674 case AArch64::LDTRXi:
675 case AArch64::LDRSBXpre:
676 case AArch64::LDRSHXpre:
677 case AArch64::STRXpre:
678 case AArch64::LDRSWpre:
679 case AArch64::LDRXpre:
680 case AArch64::LDRSBXpost:
681 case AArch64::LDRSHXpost:
682 case AArch64::STRXpost:
683 case AArch64::LDRSWpost:
684 case AArch64::LDRXpost:
685 case AArch64::LDAPURSWi:
686 case AArch64::LDAPURSHXi:
687 case AArch64::LDAPURSBXi:
688 case AArch64::STLURXi:
689 case AArch64::LDAPURXi:
691 Decoder);
692 break;
693 case AArch64::LDURQi:
694 case AArch64::STURQi:
695 case AArch64::LDRQpre:
696 case AArch64::STRQpre:
697 case AArch64::LDRQpost:
698 case AArch64::STRQpost:
700 Decoder);
701 break;
702 case AArch64::LDURDi:
703 case AArch64::STURDi:
704 case AArch64::LDRDpre:
705 case AArch64::STRDpre:
706 case AArch64::LDRDpost:
707 case AArch64::STRDpost:
709 Decoder);
710 break;
711 case AArch64::LDURSi:
712 case AArch64::STURSi:
713 case AArch64::LDRSpre:
714 case AArch64::STRSpre:
715 case AArch64::LDRSpost:
716 case AArch64::STRSpost:
718 Decoder);
719 break;
720 case AArch64::LDURHi:
721 case AArch64::STURHi:
722 case AArch64::LDRHpre:
723 case AArch64::STRHpre:
724 case AArch64::LDRHpost:
725 case AArch64::STRHpost:
727 Decoder);
728 break;
729 case AArch64::LDURBi:
730 case AArch64::STURBi:
731 case AArch64::LDRBpre:
732 case AArch64::STRBpre:
733 case AArch64::LDRBpost:
734 case AArch64::STRBpost:
736 Decoder);
737 break;
738 }
739
741 Decoder);
742 Inst.addOperand(MCOperand::createImm(offset));
743
744 bool IsLoad = fieldFromInstruction(insn, 22, 1);
745 bool IsIndexed = fieldFromInstruction(insn, 10, 2) != 0;
746 bool IsFP = fieldFromInstruction(insn, 26, 1);
747
748 // Cannot write back to a transfer register (but xzr != sp).
749 if (IsLoad && IsIndexed && !IsFP && Rn != 31 && Rt == Rn)
750 return SoftFail;
751
752 return Success;
753}
754
755static DecodeStatus
757 const MCDisassembler *Decoder) {
758 unsigned Rt = fieldFromInstruction(insn, 0, 5);
759 unsigned Rn = fieldFromInstruction(insn, 5, 5);
760 unsigned Rt2 = fieldFromInstruction(insn, 10, 5);
761 unsigned Rs = fieldFromInstruction(insn, 16, 5);
762
763 unsigned Opcode = Inst.getOpcode();
764 switch (Opcode) {
765 default:
766 return Fail;
767 case AArch64::STLXRW:
768 case AArch64::STLXRB:
769 case AArch64::STLXRH:
770 case AArch64::STXRW:
771 case AArch64::STXRB:
772 case AArch64::STXRH:
774 Decoder);
775 [[fallthrough]];
776 case AArch64::LDARW:
777 case AArch64::LDARB:
778 case AArch64::LDARH:
779 case AArch64::LDAXRW:
780 case AArch64::LDAXRB:
781 case AArch64::LDAXRH:
782 case AArch64::LDXRW:
783 case AArch64::LDXRB:
784 case AArch64::LDXRH:
785 case AArch64::STLRW:
786 case AArch64::STLRB:
787 case AArch64::STLRH:
788 case AArch64::STLLRW:
789 case AArch64::STLLRB:
790 case AArch64::STLLRH:
791 case AArch64::LDLARW:
792 case AArch64::LDLARB:
793 case AArch64::LDLARH:
795 Decoder);
796 break;
797 case AArch64::STLXRX:
798 case AArch64::STXRX:
800 Decoder);
801 [[fallthrough]];
802 case AArch64::LDARX:
803 case AArch64::LDAXRX:
804 case AArch64::LDXRX:
805 case AArch64::STLRX:
806 case AArch64::LDLARX:
807 case AArch64::STLLRX:
809 Decoder);
810 break;
811 case AArch64::STLXPW:
812 case AArch64::STXPW:
814 Decoder);
815 [[fallthrough]];
816 case AArch64::LDAXPW:
817 case AArch64::LDXPW:
819 Decoder);
821 Decoder);
822 break;
823 case AArch64::STLXPX:
824 case AArch64::STXPX:
826 Decoder);
827 [[fallthrough]];
828 case AArch64::LDAXPX:
829 case AArch64::LDXPX:
831 Decoder);
833 Decoder);
834 break;
835 }
836
838 Decoder);
839
840 // You shouldn't load to the same register twice in an instruction...
841 if ((Opcode == AArch64::LDAXPW || Opcode == AArch64::LDXPW ||
842 Opcode == AArch64::LDAXPX || Opcode == AArch64::LDXPX) &&
843 Rt == Rt2)
844 return SoftFail;
845
846 return Success;
847}
848
850 uint64_t Addr,
851 const MCDisassembler *Decoder) {
852 unsigned Rt = fieldFromInstruction(insn, 0, 5);
853 unsigned Rn = fieldFromInstruction(insn, 5, 5);
854 unsigned Rt2 = fieldFromInstruction(insn, 10, 5);
855 int64_t offset = SignExtend64<7>(fieldFromInstruction(insn, 15, 7));
856 bool IsLoad = fieldFromInstruction(insn, 22, 1);
857
858 unsigned Opcode = Inst.getOpcode();
859 bool NeedsDisjointWritebackTransfer = false;
860
861 // First operand is always writeback of base register.
862 switch (Opcode) {
863 default:
864 break;
865 case AArch64::LDPXpost:
866 case AArch64::STPXpost:
867 case AArch64::LDPSWpost:
868 case AArch64::LDPXpre:
869 case AArch64::STPXpre:
870 case AArch64::LDPSWpre:
871 case AArch64::LDPWpost:
872 case AArch64::STPWpost:
873 case AArch64::LDPWpre:
874 case AArch64::STPWpre:
875 case AArch64::LDPQpost:
876 case AArch64::STPQpost:
877 case AArch64::LDPQpre:
878 case AArch64::STPQpre:
879 case AArch64::LDPDpost:
880 case AArch64::STPDpost:
881 case AArch64::LDPDpre:
882 case AArch64::STPDpre:
883 case AArch64::LDPSpost:
884 case AArch64::STPSpost:
885 case AArch64::LDPSpre:
886 case AArch64::STPSpre:
887 case AArch64::STGPpre:
888 case AArch64::STGPpost:
889 case AArch64::LDTPpre:
890 case AArch64::LDTPpost:
891 case AArch64::LDTPQpost:
892 case AArch64::LDTPQpre:
893 case AArch64::STTPpost:
894 case AArch64::STTPpre:
895 case AArch64::STTPQpost:
896 case AArch64::STTPQpre:
898 Decoder);
899 break;
900 }
901
902 switch (Opcode) {
903 default:
904 return Fail;
905 case AArch64::LDPXpost:
906 case AArch64::STPXpost:
907 case AArch64::LDPSWpost:
908 case AArch64::LDPXpre:
909 case AArch64::STPXpre:
910 case AArch64::LDPSWpre:
911 case AArch64::STGPpre:
912 case AArch64::STGPpost:
913 case AArch64::LDTPpost:
914 case AArch64::LDTPpre:
915 case AArch64::STTPpost:
916 case AArch64::STTPpre:
917 NeedsDisjointWritebackTransfer = true;
918 [[fallthrough]];
919 case AArch64::LDNPXi:
920 case AArch64::STNPXi:
921 case AArch64::LDPXi:
922 case AArch64::STPXi:
923 case AArch64::LDPSWi:
924 case AArch64::STGPi:
925 case AArch64::LDTPi:
926 case AArch64::STTPi:
927 case AArch64::STTNPXi:
928 case AArch64::LDTNPXi:
930 Decoder);
932 Decoder);
933 break;
934 case AArch64::LDPWpost:
935 case AArch64::STPWpost:
936 case AArch64::LDPWpre:
937 case AArch64::STPWpre:
938 NeedsDisjointWritebackTransfer = true;
939 [[fallthrough]];
940 case AArch64::LDNPWi:
941 case AArch64::STNPWi:
942 case AArch64::LDPWi:
943 case AArch64::STPWi:
945 Decoder);
947 Decoder);
948 break;
949 case AArch64::LDNPQi:
950 case AArch64::STNPQi:
951 case AArch64::LDPQpost:
952 case AArch64::STPQpost:
953 case AArch64::LDPQi:
954 case AArch64::STPQi:
955 case AArch64::LDPQpre:
956 case AArch64::STPQpre:
957 case AArch64::LDTPQi:
958 case AArch64::LDTPQpost:
959 case AArch64::LDTPQpre:
960 case AArch64::LDTNPQi:
961 case AArch64::STTPQi:
962 case AArch64::STTPQpost:
963 case AArch64::STTPQpre:
964 case AArch64::STTNPQi:
966 Decoder);
968 Decoder);
969 break;
970 case AArch64::LDNPDi:
971 case AArch64::STNPDi:
972 case AArch64::LDPDpost:
973 case AArch64::STPDpost:
974 case AArch64::LDPDi:
975 case AArch64::STPDi:
976 case AArch64::LDPDpre:
977 case AArch64::STPDpre:
979 Decoder);
981 Decoder);
982 break;
983 case AArch64::LDNPSi:
984 case AArch64::STNPSi:
985 case AArch64::LDPSpost:
986 case AArch64::STPSpost:
987 case AArch64::LDPSi:
988 case AArch64::STPSi:
989 case AArch64::LDPSpre:
990 case AArch64::STPSpre:
992 Decoder);
994 Decoder);
995 break;
996 }
997
999 Decoder);
1000 Inst.addOperand(MCOperand::createImm(offset));
1001
1002 // You shouldn't load to the same register twice in an instruction...
1003 if (IsLoad && Rt == Rt2)
1004 return SoftFail;
1005
1006 // ... or do any operation that writes-back to a transfer register. But note
1007 // that "stp xzr, xzr, [sp], #4" is fine because xzr and sp are different.
1008 if (NeedsDisjointWritebackTransfer && Rn != 31 && (Rt == Rn || Rt2 == Rn))
1009 return SoftFail;
1010
1011 return Success;
1012}
1013
1015 uint64_t Addr,
1016 const MCDisassembler *Decoder) {
1017 unsigned Rt = fieldFromInstruction(insn, 0, 5);
1018 unsigned Rn = fieldFromInstruction(insn, 5, 5);
1019 uint64_t offset = fieldFromInstruction(insn, 22, 1) << 9 |
1020 fieldFromInstruction(insn, 12, 9);
1021 unsigned writeback = fieldFromInstruction(insn, 11, 1);
1022
1023 switch (Inst.getOpcode()) {
1024 default:
1025 return Fail;
1026 case AArch64::LDRAAwriteback:
1027 case AArch64::LDRABwriteback:
1029 Inst, Rn /* writeback register */, Addr, Decoder);
1030 break;
1031 case AArch64::LDRAAindexed:
1032 case AArch64::LDRABindexed:
1033 break;
1034 }
1035
1037 Decoder);
1039 Decoder);
1040 DecodeSImm<10>(Inst, offset, Addr, Decoder);
1041
1042 if (writeback && Rt == Rn && Rn != 31) {
1043 return SoftFail;
1044 }
1045
1046 return Success;
1047}
1048
1050 uint64_t Addr,
1051 const MCDisassembler *Decoder) {
1052 unsigned Rd = fieldFromInstruction(insn, 0, 5);
1053 unsigned Rn = fieldFromInstruction(insn, 5, 5);
1054 unsigned Rm = fieldFromInstruction(insn, 16, 5);
1055 unsigned extend = fieldFromInstruction(insn, 10, 6);
1056
1057 unsigned shift = extend & 0x7;
1058 if (shift > 4)
1059 return Fail;
1060
1061 switch (Inst.getOpcode()) {
1062 default:
1063 return Fail;
1064 case AArch64::ADDWrx:
1065 case AArch64::SUBWrx:
1067 Decoder);
1069 Decoder);
1071 Decoder);
1072 break;
1073 case AArch64::ADDSWrx:
1074 case AArch64::SUBSWrx:
1076 Decoder);
1078 Decoder);
1080 Decoder);
1081 break;
1082 case AArch64::ADDXrx:
1083 case AArch64::SUBXrx:
1085 Decoder);
1087 Decoder);
1089 Decoder);
1090 break;
1091 case AArch64::ADDSXrx:
1092 case AArch64::SUBSXrx:
1094 Decoder);
1096 Decoder);
1098 Decoder);
1099 break;
1100 case AArch64::ADDXrx64:
1101 case AArch64::SUBXrx64:
1103 Decoder);
1105 Decoder);
1107 Decoder);
1108 break;
1109 case AArch64::SUBSXrx64:
1110 case AArch64::ADDSXrx64:
1112 Decoder);
1114 Decoder);
1116 Decoder);
1117 break;
1118 }
1119
1120 Inst.addOperand(MCOperand::createImm(extend));
1121 return Success;
1122}
1123
1125 uint64_t Addr,
1126 const MCDisassembler *Decoder) {
1127 unsigned Rd = fieldFromInstruction(insn, 0, 5);
1128 unsigned Rn = fieldFromInstruction(insn, 5, 5);
1129 unsigned Datasize = fieldFromInstruction(insn, 31, 1);
1130 unsigned imm;
1131
1132 if (Datasize) {
1133 if (Inst.getOpcode() == AArch64::ANDSXri)
1135 Decoder);
1136 else
1138 Inst, Rd, Addr, Decoder);
1140 Decoder);
1141 imm = fieldFromInstruction(insn, 10, 13);
1143 return Fail;
1144 } else {
1145 if (Inst.getOpcode() == AArch64::ANDSWri)
1147 Decoder);
1148 else
1150 Inst, Rd, Addr, Decoder);
1152 Decoder);
1153 imm = fieldFromInstruction(insn, 10, 12);
1155 return Fail;
1156 }
1158 return Success;
1159}
1160
1162 uint64_t Addr,
1163 const MCDisassembler *Decoder) {
1164 unsigned Rd = fieldFromInstruction(insn, 0, 5);
1165 unsigned cmode = fieldFromInstruction(insn, 12, 4);
1166 unsigned imm = fieldFromInstruction(insn, 16, 3) << 5;
1167 imm |= fieldFromInstruction(insn, 5, 5);
1168
1169 if (Inst.getOpcode() == AArch64::MOVID)
1171 Decoder);
1172 else
1174 Decoder);
1175
1177
1178 switch (Inst.getOpcode()) {
1179 default:
1180 break;
1181 case AArch64::MOVIv4i16:
1182 case AArch64::MOVIv8i16:
1183 case AArch64::MVNIv4i16:
1184 case AArch64::MVNIv8i16:
1185 case AArch64::MOVIv2i32:
1186 case AArch64::MOVIv4i32:
1187 case AArch64::MVNIv2i32:
1188 case AArch64::MVNIv4i32:
1189 Inst.addOperand(MCOperand::createImm((cmode & 6) << 2));
1190 break;
1191 case AArch64::MOVIv2s_msl:
1192 case AArch64::MOVIv4s_msl:
1193 case AArch64::MVNIv2s_msl:
1194 case AArch64::MVNIv4s_msl:
1195 Inst.addOperand(MCOperand::createImm((cmode & 1) ? 0x110 : 0x108));
1196 break;
1197 }
1198
1199 return Success;
1200}
1201
1203 uint64_t Addr,
1204 const MCDisassembler *Decoder) {
1205 unsigned Rd = fieldFromInstruction(insn, 0, 5);
1206 unsigned cmode = fieldFromInstruction(insn, 12, 4);
1207 unsigned imm = fieldFromInstruction(insn, 16, 3) << 5;
1208 imm |= fieldFromInstruction(insn, 5, 5);
1209
1210 // Tied operands added twice.
1212 Decoder);
1214 Decoder);
1215
1217 Inst.addOperand(MCOperand::createImm((cmode & 6) << 2));
1218
1219 return Success;
1220}
1221
1223 uint64_t Addr,
1224 const MCDisassembler *Decoder) {
1225 unsigned Rd = fieldFromInstruction(insn, 0, 5);
1226 int64_t imm = SignExtend64<21>((fieldFromInstruction(insn, 5, 19) << 2) |
1227 fieldFromInstruction(insn, 29, 2));
1228
1230 Decoder);
1231 if (!Decoder->tryAddingSymbolicOperand(Inst, imm, Addr, Fail, 0, 0, 4))
1233
1234 return Success;
1235}
1236
1238 uint64_t Addr,
1239 const MCDisassembler *Decoder) {
1240 unsigned Rd = fieldFromInstruction(insn, 0, 5);
1241 unsigned Rn = fieldFromInstruction(insn, 5, 5);
1242 unsigned Imm = fieldFromInstruction(insn, 10, 14);
1243 unsigned S = fieldFromInstruction(insn, 29, 1);
1244 unsigned Datasize = fieldFromInstruction(insn, 31, 1);
1245
1246 unsigned ShifterVal = (Imm >> 12) & 3;
1247 unsigned ImmVal = Imm & 0xFFF;
1248
1249 if (ShifterVal != 0 && ShifterVal != 1)
1250 return Fail;
1251
1252 if (Datasize) {
1253 if (Rd == 31 && !S)
1255 Inst, Rd, Addr, Decoder);
1256 else
1258 Decoder);
1260 Decoder);
1261 } else {
1262 if (Rd == 31 && !S)
1264 Inst, Rd, Addr, Decoder);
1265 else
1267 Decoder);
1269 Decoder);
1270 }
1271
1272 if (!Decoder->tryAddingSymbolicOperand(Inst, Imm, Addr, Fail, 0, 0, 4))
1273 Inst.addOperand(MCOperand::createImm(ImmVal));
1274 Inst.addOperand(MCOperand::createImm(12 * ShifterVal));
1275 return Success;
1276}
1277
1279 uint64_t Addr,
1280 const MCDisassembler *Decoder) {
1281 int64_t imm = SignExtend64<26>(fieldFromInstruction(insn, 0, 26));
1282
1283 if (!Decoder->tryAddingSymbolicOperand(Inst, imm * 4, Addr, true, 0, 0, 4))
1285
1286 return Success;
1287}
1288
1289static bool isInvalidPState(uint64_t Op1, uint64_t Op2) {
1290 return Op1 == 0b000 && (Op2 == 0b000 || // CFINV
1291 Op2 == 0b001 || // XAFlag
1292 Op2 == 0b010); // AXFlag
1293}
1294
1295static DecodeStatus
1297 const MCDisassembler *Decoder) {
1298 uint64_t op1 = fieldFromInstruction(insn, 16, 3);
1299 uint64_t op2 = fieldFromInstruction(insn, 5, 3);
1300 uint64_t imm = fieldFromInstruction(insn, 8, 4);
1301 uint64_t pstate_field = (op1 << 3) | op2;
1302
1303 if (isInvalidPState(op1, op2))
1304 return Fail;
1305
1306 Inst.addOperand(MCOperand::createImm(pstate_field));
1308
1309 auto PState = AArch64PState::lookupPStateImm0_15ByEncoding(pstate_field);
1310 if (PState &&
1311 PState->haveFeatures(Decoder->getSubtargetInfo().getFeatureBits()))
1312 return Success;
1313 return Fail;
1314}
1315
1316static DecodeStatus
1318 const MCDisassembler *Decoder) {
1319 uint64_t op1 = fieldFromInstruction(insn, 16, 3);
1320 uint64_t op2 = fieldFromInstruction(insn, 5, 3);
1321 uint64_t crm_high = fieldFromInstruction(insn, 9, 3);
1322 uint64_t imm = fieldFromInstruction(insn, 8, 1);
1323 uint64_t pstate_field = (crm_high << 6) | (op1 << 3) | op2;
1324
1325 if (isInvalidPState(op1, op2))
1326 return Fail;
1327
1328 Inst.addOperand(MCOperand::createImm(pstate_field));
1330
1331 auto PState = AArch64PState::lookupPStateImm0_1ByEncoding(pstate_field);
1332 if (PState &&
1333 PState->haveFeatures(Decoder->getSubtargetInfo().getFeatureBits()))
1334 return Success;
1335 return Fail;
1336}
1337
1339 uint64_t Addr,
1340 const MCDisassembler *Decoder) {
1341 uint64_t Rt = fieldFromInstruction(insn, 0, 5);
1342 uint64_t bit = fieldFromInstruction(insn, 31, 1) << 5;
1343 bit |= fieldFromInstruction(insn, 19, 5);
1344 int64_t dst = SignExtend64<14>(fieldFromInstruction(insn, 5, 14));
1345
1346 if (fieldFromInstruction(insn, 31, 1) == 0)
1348 Decoder);
1349 else
1351 Decoder);
1353 if (!Decoder->tryAddingSymbolicOperand(Inst, dst * 4, Addr, true, 0, 0, 4))
1355
1356 return Success;
1357}
1358
1359static DecodeStatus
1361 unsigned RegNo, uint64_t Addr,
1362 const MCDisassembler *Decoder) {
1363 // Register number must be even (see CASP instruction)
1364 if (RegNo & 0x1)
1365 return Fail;
1366
1367 MCRegister Reg = getAArch64MCRegisterClass(RegClassID).getRegister(RegNo / 2);
1369 return Success;
1370}
1371
1372static DecodeStatus
1374 const MCDisassembler *Decoder) {
1376 Inst, AArch64::WSeqPairsClassRegClassID, RegNo, Addr, Decoder);
1377}
1378
1379static DecodeStatus
1381 const MCDisassembler *Decoder) {
1383 Inst, AArch64::XSeqPairsClassRegClassID, RegNo, Addr, Decoder);
1384}
1385
1387 uint64_t Addr,
1388 const MCDisassembler *Decoder) {
1389 unsigned op1 = fieldFromInstruction(insn, 16, 3);
1390 unsigned CRn = fieldFromInstruction(insn, 12, 4);
1391 unsigned CRm = fieldFromInstruction(insn, 8, 4);
1392 unsigned op2 = fieldFromInstruction(insn, 5, 3);
1393 unsigned Rt = fieldFromInstruction(insn, 0, 5);
1394 if (Rt != 0b11111)
1395 return Fail;
1396
1402 Decoder);
1403
1404 return Success;
1405}
1406
1407static DecodeStatus
1409 const MCDisassembler *Decoder) {
1410 unsigned Zdn = fieldFromInstruction(insn, 0, 5);
1411 unsigned imm = fieldFromInstruction(insn, 5, 13);
1413 return Fail;
1414
1415 // The same (tied) operand is added twice to the instruction.
1417 Decoder);
1418 if (Inst.getOpcode() != AArch64::DUPM_ZI)
1420 Decoder);
1422 return Success;
1423}
1424
1425static DecodeStatus DecodeZeroImm(MCInst &Inst, const MCDisassembler *Decoder) {
1427 return Success;
1428}
1429
1430template <int Bits>
1432 const MCDisassembler *Decoder) {
1433 if (Imm & ~((1LL << Bits) - 1))
1434 return Fail;
1435
1436 // Imm is a signed immediate, so sign extend it.
1437 if (Imm & (1 << (Bits - 1)))
1438 Imm |= ~((1LL << Bits) - 1);
1439
1441 return Success;
1442}
1443
1444// Decode 8-bit signed/unsigned immediate for a given element width.
1445template <int ElementWidth>
1446static DecodeStatus DecodeImm8OptLsl(MCInst &Inst, unsigned Imm, uint64_t Addr,
1447 const MCDisassembler *Decoder) {
1448 unsigned Val = (uint8_t)Imm;
1449 unsigned Shift = (Imm & 0x100) ? 8 : 0;
1450 if (ElementWidth == 8 && Shift)
1451 return Fail;
1453 Inst.addOperand(MCOperand::createImm(Shift));
1454 return Success;
1455}
1456
1457static DecodeStatus DecodeHinteUImm16(MCInst &Inst, unsigned Imm, uint64_t Addr,
1458 const MCDisassembler *Decoder) {
1459 if (Imm > 65535 ||
1460 (Imm >= 12319 && Imm <= 16383 && ((Imm - 12319) % 32) == 0))
1461 return Fail;
1462
1464 return Success;
1465}
1466
1467// Decode uimm4 ranged from 1-16.
1468static DecodeStatus DecodeSVEIncDecImm(MCInst &Inst, unsigned Imm,
1469 uint64_t Addr,
1470 const MCDisassembler *Decoder) {
1471 Inst.addOperand(MCOperand::createImm(Imm + 1));
1472 return Success;
1473}
1474
1475static DecodeStatus DecodeSVCROp(MCInst &Inst, unsigned Imm, uint64_t Address,
1476 const MCDisassembler *Decoder) {
1477 if (AArch64SVCR::lookupSVCRByEncoding(Imm)) {
1479 return Success;
1480 }
1481 return Fail;
1482}
1483
1485 uint64_t Addr,
1486 const MCDisassembler *Decoder) {
1487 unsigned Rd = fieldFromInstruction(insn, 0, 5);
1488 unsigned Rs = fieldFromInstruction(insn, 16, 5);
1489 unsigned Rn = fieldFromInstruction(insn, 5, 5);
1490
1491 // None of the registers may alias: if they do, then the instruction is not
1492 // merely unpredictable but actually entirely unallocated.
1493 if (Rd == Rs || Rs == Rn || Rd == Rn)
1494 return MCDisassembler::Fail;
1495
1496 // All three register operands are written back, so they all appear
1497 // twice in the operand list, once as outputs and once as inputs.
1499 Inst, Rd, Addr, Decoder) ||
1501 Inst, Rs, Addr, Decoder) ||
1503 Inst, Rn, Addr, Decoder) ||
1505 Inst, Rd, Addr, Decoder) ||
1507 Inst, Rs, Addr, Decoder) ||
1509 Inst, Rn, Addr, Decoder))
1510 return MCDisassembler::Fail;
1511
1513}
1514
1516 uint64_t Addr,
1517 const MCDisassembler *Decoder) {
1518 unsigned Rd = fieldFromInstruction(insn, 0, 5);
1519 unsigned Rm = fieldFromInstruction(insn, 16, 5);
1520 unsigned Rn = fieldFromInstruction(insn, 5, 5);
1521
1522 // None of the registers may alias: if they do, then the instruction is not
1523 // merely unpredictable but actually entirely unallocated.
1524 if (Rd == Rm || Rm == Rn || Rd == Rn)
1525 return MCDisassembler::Fail;
1526
1527 // Rd and Rn (not Rm) register operands are written back, so they appear
1528 // twice in the operand list, once as outputs and once as inputs.
1530 Inst, Rd, Addr, Decoder) ||
1532 Inst, Rn, Addr, Decoder) ||
1534 Inst, Rd, Addr, Decoder) ||
1536 Inst, Rn, Addr, Decoder) ||
1538 Inst, Rm, Addr, Decoder))
1539 return MCDisassembler::Fail;
1540
1542}
1543
1545 uint64_t Addr,
1546 const MCDisassembler *Decoder) {
1547 unsigned Rd = fieldFromInstruction(insn, 0, 5);
1548 unsigned Rn = fieldFromInstruction(insn, 5, 5);
1549
1550 // None of the registers may alias: if they do, then the instruction is not
1551 // merely unpredictable but actually entirely unallocated.
1552 if (Rd == Rn)
1553 return MCDisassembler::Fail;
1554
1555 // Rd and Rn register operands are written back, so they appear
1556 // twice in the operand list, once as outputs and once as inputs.
1558 Inst, Rd, Addr, Decoder) ||
1560 Inst, Rn, Addr, Decoder) ||
1562 Inst, Rd, Addr, Decoder) ||
1564 Inst, Rn, Addr, Decoder))
1565 return MCDisassembler::Fail;
1566
1568}
1569
1571 uint64_t Addr,
1572 const MCDisassembler *Decoder) {
1573 // PRFM with Rt = '11xxx' should be decoded as RPRFM.
1574 // Fail to decode and defer to fallback decoder table to decode RPRFM.
1575 unsigned Mask = 0x18;
1576 uint64_t Rt = fieldFromInstruction(insn, 0, 5);
1577 if ((Rt & Mask) == Mask)
1578 return Fail;
1579
1580 uint64_t Rn = fieldFromInstruction(insn, 5, 5);
1581 uint64_t Shift = fieldFromInstruction(insn, 12, 1);
1582 uint64_t Extend = fieldFromInstruction(insn, 15, 1);
1583 uint64_t Rm = fieldFromInstruction(insn, 16, 5);
1584
1587 Decoder);
1588
1589 switch (Inst.getOpcode()) {
1590 default:
1591 return Fail;
1592 case AArch64::PRFMroW:
1594 Decoder);
1595 break;
1596 case AArch64::PRFMroX:
1598 Decoder);
1599 break;
1600 }
1601
1602 DecodeMemExtend(Inst, (Extend << 1) | Shift, Addr, Decoder);
1603
1604 return Success;
1605}
1606
1607static DecodeStatus
1609 const MCDisassembler *Decoder) {
1610 unsigned RvBits = fieldFromInstruction(Bits, 13, 2);
1611 unsigned RnBits = fieldFromInstruction(Bits, 5, 5);
1612 unsigned Imm4Bits = fieldFromInstruction(Bits, 0, 4);
1613
1614 DecodeMPRRegisterClass(Inst, Decoder);
1616 Inst, RvBits, Addr, Decoder);
1617 Inst.addOperand(MCOperand::createImm(Imm4Bits));
1619 Addr, Decoder);
1620 // Spill and fill instructions have a single immediate used for both
1621 // the vector select offset and optional memory offset. Replicate
1622 // the decoded immediate.
1623 Inst.addOperand(MCOperand::createImm(Imm4Bits));
1624 return Success;
1625}
1626
1627#include "AArch64GenDisassemblerTables.inc"
1628#include "AArch64GenInstrInfo.inc"
1629
1631 const MCSubtargetInfo &STI,
1632 MCContext &Ctx) {
1633
1634 return new AArch64Disassembler(STI, Ctx, T.createMCInstrInfo());
1635}
1636
1638 ArrayRef<uint8_t> Bytes,
1640 raw_ostream &CS) const {
1641 CommentStream = &CS;
1642
1643 Size = 0;
1644 // We want to read exactly 4 bytes of data.
1645 if (Bytes.size() < 4)
1646 return Fail;
1647 Size = 4;
1648
1649 // Encoded as a small-endian 32-bit word in the stream.
1650 uint32_t Insn =
1651 (Bytes[3] << 24) | (Bytes[2] << 16) | (Bytes[1] << 8) | (Bytes[0] << 0);
1652
1653 const uint8_t *Tables[] = {DecoderTable32, DecoderTableFallback32};
1654
1655 for (const auto *Table : Tables) {
1656 DecodeStatus Result =
1657 decodeInstruction(Table, MI, Insn, Address, this, STI);
1658 if (Result != MCDisassembler::Fail)
1659 return Result;
1660 }
1661
1662 return MCDisassembler::Fail;
1663}
1664
1666 uint64_t Address) const {
1667 // AArch64 instructions are always 4 bytes wide, so there's no point
1668 // in skipping any smaller number of bytes if an instruction can't
1669 // be decoded.
1670 return 4;
1671}
1672
1673static MCSymbolizer *
1675 LLVMSymbolLookupCallback SymbolLookUp,
1676 void *DisInfo, MCContext *Ctx,
1677 std::unique_ptr<MCRelocationInfo> &&RelInfo) {
1678 return new AArch64ExternalSymbolizer(*Ctx, std::move(RelInfo), GetOpInfo,
1679 SymbolLookUp, DisInfo);
1680}
1681
1682extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
static DecodeStatus DecodeUnconditionalBranch(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeMPR32RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodePCRelLabel16(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeMPR8RegisterClass(MCInst &Inst, const MCDisassembler *Decoder)
static DecodeStatus DecodeSystemPStateImm0_1Instruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeMPR64RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftL64Imm(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftL32Imm(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeHinteUImm16(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static MCSymbolizer * createAArch64ExternalSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo)
static DecodeStatus DecodeCPYMemOpInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftR8Imm(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeUnsignedLdStInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeMPRRegisterClass(MCInst &Inst, const MCDisassembler *Decoder)
static DecodeStatus DecodeMulMinMaxRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeModImmTiedInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeFixedPointScaleImm64(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeSystemPStateImm0_15Instruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeModImmInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static MCDisassembler * createAArch64Disassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
static DecodeStatus DecodeGPR64x8ClassRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeThreeAddrSRegInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeSETMemGoOpInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeXSeqPairsClassRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeExclusiveLdStInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftL16Imm(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeTestAndBranch(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeZeroImm(MCInst &Inst, const MCDisassembler *Decoder)
#define SoftFail
static DecodeStatus DecodeSImm(MCInst &Inst, uint64_t Imm, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftR32ImmNarrow(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeZK(MCInst &Inst, unsigned RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeAdrInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodePPR2Mul2RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus DecodePairLdStInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftL8Imm(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeSVEIncDecImm(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeMPR16RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftRImm(MCInst &Inst, unsigned Imm, unsigned Add)
static DecodeStatus DecodeFixedPointScaleImm32(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeMoveImmInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftR64Imm(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodePCRelLabel9(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftLImm(MCInst &Inst, unsigned Imm, unsigned Add)
static DecodeStatus DecodeVecShiftR16ImmNarrow(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeSVCROp(MCInst &Inst, unsigned Imm, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeWSeqPairsClassRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftR64ImmNarrow(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeZPR4Mul4RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeSMESpillFillInstruction(MCInst &Inst, uint32_t Bits, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeLogicalImmInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
#define Fail
MCDisassembler::DecodeStatus DecodeStatus
static DecodeStatus DecodeMSRSystemRegister(MCInst &Inst, unsigned Imm, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeZPR2Mul2RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const void *Decoder)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64Disassembler()
#define Success
static DecodeStatus DecodeSETMemOpInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeSVELogicalImmInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeMemExtend(MCInst &Inst, unsigned Imm, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeSignedLdStInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeAuthLoadInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeSyspXzrInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeFMOVLaneInstruction(MCInst &Inst, unsigned Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeAddSubERegInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static bool isInvalidPState(uint64_t Op1, uint64_t Op2)
static DecodeStatus DecodeSimpleRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeMatrixTileListRegisterClass(MCInst &Inst, unsigned RegMask, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftR16Imm(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeVecShiftR32Imm(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeImm8OptLsl(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodePRFMRegInstruction(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeAddSubImmShift(MCInst &Inst, uint32_t insn, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRSeqPairsClassRegisterClass(MCInst &Inst, unsigned RegClassID, unsigned RegNo, uint64_t Addr, const MCDisassembler *Decoder)
static DecodeStatus DecodeMPR128RegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeMRSSystemRegister(MCInst &Inst, unsigned Imm, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeZTRRegisterClass(MCInst &Inst, const MCDisassembler *Decoder)
static DecodeStatus DecodePCRelLabel19(MCInst &Inst, unsigned Imm, uint64_t Addr, const MCDisassembler *Decoder)
#define LLVM_ABI
Definition Compiler.h:215
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
IRTranslator LLVM IR MI
Register Reg
#define T
MCDisassembler::DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const override
Returns the disassembly of a single instruction.
uint64_t suggestBytesToSkip(ArrayRef< uint8_t > Bytes, uint64_t Address) const override
Suggest a distance to skip in a buffer of data to find the next place to look for the start of an ins...
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
Context object for machine code objects.
Definition MCContext.h:83
Superclass for all disassemblers.
bool tryAddingSymbolicOperand(MCInst &Inst, int64_t Value, uint64_t Address, bool IsBranch, uint64_t Offset, uint64_t OpSize, uint64_t InstSize) const
const MCSubtargetInfo & getSubtargetInfo() const
const MCSubtargetInfo & STI
raw_ostream * CommentStream
DecodeStatus
Ternary decode status.
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
unsigned getOpcode() const
Definition MCInst.h:202
void addOperand(const MCOperand Op)
Definition MCInst.h:215
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:210
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:138
static MCOperand createImm(int64_t Val)
Definition MCInst.h:145
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Generic base class for all target subtargets.
const FeatureBitset & getFeatureBits() const
Symbolize and annotate disassembled instructions.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
The type for the symbol lookup function.
int(* LLVMOpInfoCallback)(void *DisInfo, uint64_t PC, uint64_t Offset, uint64_t OpSize, uint64_t InstSize, int TagType, void *TagBuf)
The type for the operand information call back function.
static bool isValidDecodeLogicalImmediate(uint64_t val, unsigned regSize)
isValidDecodeLogicalImmediate - Check to see if the logical immediate value in the form "N:immr:imms"...
std::enable_if_t< std::is_integral_v< IntType >, IntType > fieldFromInstruction(const IntType &Insn, unsigned StartBit, unsigned NumBits)
Definition MCDecoder.h:37
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheAArch64beTarget()
Target & getTheAArch64leTarget()
Target & getTheAArch64_32Target()
Target & getTheARM64_32Target()
@ Add
Sum of integers.
Target & getTheARM64Target()
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Definition MathExtras.h:573
static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn)
RegisterMCSymbolizer - Register an MCSymbolizer implementation for the given target.
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.