Coverage Report

Created: 2025-10-12 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonev5/arch/AArch64/AArch64InstPrinter.c
Line
Count
Source
1
//==-- AArch64InstPrinter.cpp - Convert AArch64 MCInst to assembly syntax --==//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This class prints an AArch64 MCInst to a .s file.
11
//
12
//===----------------------------------------------------------------------===//
13
14
/* Capstone Disassembly Engine */
15
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2016 */
16
17
#ifdef CAPSTONE_HAS_ARM64
18
19
#include <capstone/platform.h>
20
#include <stdio.h>
21
#include <stdlib.h>
22
23
#include "AArch64InstPrinter.h"
24
#include "AArch64Disassembler.h"
25
#include "AArch64BaseInfo.h"
26
#include "../../utils.h"
27
#include "../../MCInst.h"
28
#include "../../SStream.h"
29
#include "../../MCRegisterInfo.h"
30
#include "../../MathExtras.h"
31
32
#include "AArch64Mapping.h"
33
#include "AArch64AddressingModes.h"
34
35
#define GET_REGINFO_ENUM
36
#include "AArch64GenRegisterInfo.inc"
37
38
#define GET_INSTRINFO_ENUM
39
#include "AArch64GenInstrInfo.inc"
40
41
#include "AArch64GenSubtargetInfo.inc"
42
43
44
static const char *getRegisterName(unsigned RegNo, unsigned AltIdx);
45
static void printOperand(MCInst *MI, unsigned OpNum, SStream *O);
46
static bool printSysAlias(MCInst *MI, SStream *O);
47
static char *printAliasInstr(MCInst *MI, SStream *OS, MCRegisterInfo *MRI);
48
static void printInstruction(MCInst *MI, SStream *O);
49
static void printShifter(MCInst *MI, unsigned OpNum, SStream *O);
50
static void printCustomAliasOperand(MCInst *MI, uint64_t Address, unsigned OpIdx,
51
    unsigned PrintMethodIdx, SStream *OS);
52
53
54
static cs_ac_type get_op_access(cs_struct *h, unsigned int id, unsigned int index)
55
836k
{
56
836k
#ifndef CAPSTONE_DIET
57
836k
  const uint8_t *arr = AArch64_get_op_access(h, id);
58
59
836k
  if (arr[index] == CS_AC_IGNORE)
60
0
    return 0;
61
62
836k
  return arr[index];
63
#else
64
  return 0;
65
#endif
66
836k
}
67
68
static void op_addImm(MCInst *MI, int v)
69
2.40k
{
70
2.40k
  if (MI->csh->detail) {
71
2.40k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
72
2.40k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = v;
73
2.40k
    MI->flat_insn->detail->arm64.op_count++;
74
2.40k
  }
75
2.40k
}
76
77
static void set_sme_index(MCInst *MI, bool status)
78
11.0k
{
79
  // Doing SME Index operand
80
11.0k
  MI->csh->doing_SME_Index = status;
81
82
11.0k
  if (MI->csh->detail != CS_OPT_ON)
83
0
    return;
84
85
11.0k
  if (status) {
86
6.82k
    unsigned prevOpNum = MI->flat_insn->detail->arm64.op_count - 1; 
87
6.82k
    unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, prevOpNum));
88
    // Replace previous SME register operand with an OP_SME_INDEX operand
89
6.82k
    MI->flat_insn->detail->arm64.operands[prevOpNum].type = ARM64_OP_SME_INDEX;
90
6.82k
    MI->flat_insn->detail->arm64.operands[prevOpNum].sme_index.reg = Reg;
91
6.82k
    MI->flat_insn->detail->arm64.operands[prevOpNum].sme_index.base = ARM64_REG_INVALID;
92
6.82k
    MI->flat_insn->detail->arm64.operands[prevOpNum].sme_index.disp = 0;
93
6.82k
  }
94
11.0k
}
95
96
static void set_mem_access(MCInst *MI, bool status)
97
284k
{
98
  // If status == false, check if this is meant for SME_index
99
284k
  if(!status && MI->csh->doing_SME_Index) {
100
2.63k
    MI->csh->doing_SME_Index = status;
101
2.63k
    return;
102
2.63k
  }
103
104
  // Doing Memory Operation
105
281k
  MI->csh->doing_mem = status;
106
107
108
281k
  if (MI->csh->detail != CS_OPT_ON)
109
0
    return;
110
111
281k
  if (status) {
112
140k
#ifndef CAPSTONE_DIET
113
140k
    uint8_t access;
114
140k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
115
140k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
116
140k
    MI->ac_idx++;
117
140k
#endif
118
140k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_MEM;
119
140k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.base = ARM64_REG_INVALID;
120
140k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.index = ARM64_REG_INVALID;
121
140k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = 0;
122
140k
  } else {
123
    // done, create the next operand slot
124
140k
    MI->flat_insn->detail->arm64.op_count++;
125
140k
  }
126
281k
}
127
128
void AArch64_printInst(MCInst *MI, SStream *O, void *Info)
129
293k
{
130
  // Check for special encodings and print the canonical alias instead.
131
293k
  unsigned Opcode = MCInst_getOpcode(MI);
132
293k
  int LSB, Width;
133
293k
  char *mnem;
134
135
  // printf(">>> opcode = %u\n", MCInst_getOpcode(MI));
136
137
293k
  if (Opcode == AArch64_SYSxt && printSysAlias(MI, O))
138
1.49k
    return;
139
140
  // SBFM/UBFM should print to a nicer aliased form if possible.
141
291k
  if (Opcode == AArch64_SBFMXri || Opcode == AArch64_SBFMWri ||
142
289k
      Opcode == AArch64_UBFMXri || Opcode == AArch64_UBFMWri) {
143
2.55k
    bool IsSigned = (Opcode == AArch64_SBFMXri || Opcode == AArch64_SBFMWri);
144
2.55k
    bool Is64Bit = (Opcode == AArch64_SBFMXri || Opcode == AArch64_UBFMXri);
145
146
2.55k
    MCOperand *Op0 = MCInst_getOperand(MI, 0);
147
2.55k
    MCOperand *Op1 = MCInst_getOperand(MI, 1);
148
2.55k
    MCOperand *Op2 = MCInst_getOperand(MI, 2);
149
2.55k
    MCOperand *Op3 = MCInst_getOperand(MI, 3);
150
151
2.55k
    if (MCOperand_isImm(Op2) && MCOperand_getImm(Op2) == 0 && MCOperand_isImm(Op3)) {
152
1.50k
      const char *AsmMnemonic = NULL;
153
154
1.50k
      switch (MCOperand_getImm(Op3)) {
155
212
        default:
156
212
          break;
157
158
441
        case 7:
159
441
          if (IsSigned)
160
286
            AsmMnemonic = "sxtb";
161
155
          else if (!Is64Bit)
162
60
            AsmMnemonic = "uxtb";
163
441
          break;
164
165
413
        case 15:
166
413
          if (IsSigned)
167
270
            AsmMnemonic = "sxth";
168
143
          else if (!Is64Bit)
169
71
            AsmMnemonic = "uxth";
170
413
          break;
171
172
437
        case 31:
173
          // *xtw is only valid for signed 64-bit operations.
174
437
          if (Is64Bit && IsSigned)
175
324
            AsmMnemonic = "sxtw";
176
437
          break;
177
1.50k
      }
178
179
1.50k
      if (AsmMnemonic) {
180
1.01k
        SStream_concat(O, "%s\t%s, %s", AsmMnemonic,
181
1.01k
            getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName),
182
1.01k
            getRegisterName(getWRegFromXReg(MCOperand_getReg(Op1)), AArch64_NoRegAltName));
183
184
1.01k
        if (MI->csh->detail) {
185
1.01k
#ifndef CAPSTONE_DIET
186
1.01k
          uint8_t access;
187
1.01k
          access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
188
1.01k
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
189
1.01k
          MI->ac_idx++;
190
1.01k
#endif
191
1.01k
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
192
1.01k
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0);
193
1.01k
          MI->flat_insn->detail->arm64.op_count++;
194
1.01k
#ifndef CAPSTONE_DIET
195
1.01k
          access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
196
1.01k
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
197
1.01k
          MI->ac_idx++;
198
1.01k
#endif
199
1.01k
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
200
1.01k
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = getWRegFromXReg(MCOperand_getReg(Op1));
201
1.01k
          MI->flat_insn->detail->arm64.op_count++;
202
1.01k
        }
203
204
1.01k
        MCInst_setOpcodePub(MI, AArch64_map_insn(AsmMnemonic));
205
206
1.01k
        return;
207
1.01k
      }
208
1.50k
    }
209
210
    // All immediate shifts are aliases, implemented using the Bitfield
211
    // instruction. In all cases the immediate shift amount shift must be in
212
    // the range 0 to (reg.size -1).
213
1.53k
    if (MCOperand_isImm(Op2) && MCOperand_isImm(Op3)) {
214
1.53k
      const char *AsmMnemonic = NULL;
215
1.53k
      int shift = 0;
216
1.53k
      int immr = (int)MCOperand_getImm(Op2);
217
1.53k
      int imms = (int)MCOperand_getImm(Op3);
218
219
1.53k
      if (Opcode == AArch64_UBFMWri && imms != 0x1F && ((imms + 1) == immr)) {
220
23
        AsmMnemonic = "lsl";
221
23
        shift = 31 - imms;
222
1.51k
      } else if (Opcode == AArch64_UBFMXri && imms != 0x3f &&
223
351
          ((imms + 1 == immr))) {
224
68
        AsmMnemonic = "lsl";
225
68
        shift = 63 - imms;
226
1.44k
      } else if (Opcode == AArch64_UBFMWri && imms == 0x1f) {
227
307
        AsmMnemonic = "lsr";
228
307
        shift = immr;
229
1.14k
      } else if (Opcode == AArch64_UBFMXri && imms == 0x3f) {
230
35
        AsmMnemonic = "lsr";
231
35
        shift = immr;
232
1.10k
      } else if (Opcode == AArch64_SBFMWri && imms == 0x1f) {
233
8
        AsmMnemonic = "asr";
234
8
        shift = immr;
235
1.09k
      } else if (Opcode == AArch64_SBFMXri && imms == 0x3f) {
236
72
        AsmMnemonic = "asr";
237
72
        shift = immr;
238
72
      }
239
240
1.53k
      if (AsmMnemonic) {
241
513
        SStream_concat(O, "%s\t%s, %s, ", AsmMnemonic,
242
513
            getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName),
243
513
            getRegisterName(MCOperand_getReg(Op1), AArch64_NoRegAltName));
244
245
513
        printInt32Bang(O, shift);
246
247
513
        MCInst_setOpcodePub(MI, AArch64_map_insn(AsmMnemonic));
248
249
513
        if (MI->csh->detail) {
250
513
#ifndef CAPSTONE_DIET
251
513
          uint8_t access;
252
513
          access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
253
513
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
254
513
          MI->ac_idx++;
255
513
#endif
256
513
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
257
513
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0);
258
513
          MI->flat_insn->detail->arm64.op_count++;
259
513
#ifndef CAPSTONE_DIET
260
513
          access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
261
513
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
262
513
          MI->ac_idx++;
263
513
#endif
264
513
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
265
513
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op1);
266
513
          MI->flat_insn->detail->arm64.op_count++;
267
513
#ifndef CAPSTONE_DIET
268
513
          access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
269
513
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
270
513
          MI->ac_idx++;
271
513
#endif
272
513
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
273
513
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = shift;
274
513
          MI->flat_insn->detail->arm64.op_count++;
275
513
        }
276
277
513
        return;
278
513
      }
279
1.53k
    }
280
281
    // SBFIZ/UBFIZ aliases
282
1.02k
    if (MCOperand_getImm(Op2) > MCOperand_getImm(Op3)) {
283
589
      SStream_concat(O, "%s\t%s, %s, ", (IsSigned ? "sbfiz" : "ubfiz"),
284
589
          getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName),
285
589
          getRegisterName(MCOperand_getReg(Op1), AArch64_NoRegAltName));
286
287
589
      printInt32Bang(O, (int)((Is64Bit ? 64 : 32) - MCOperand_getImm(Op2)));
288
289
589
      SStream_concat0(O, ", ");
290
291
589
      printInt32Bang(O, (int)MCOperand_getImm(Op3) + 1);
292
293
589
      MCInst_setOpcodePub(MI, AArch64_map_insn(IsSigned ? "sbfiz" : "ubfiz"));
294
295
589
      if (MI->csh->detail) {
296
589
#ifndef CAPSTONE_DIET
297
589
        uint8_t access;
298
589
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
299
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
300
589
        MI->ac_idx++;
301
589
#endif
302
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
303
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0);
304
589
        MI->flat_insn->detail->arm64.op_count++;
305
589
#ifndef CAPSTONE_DIET
306
589
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
307
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
308
589
        MI->ac_idx++;
309
589
#endif
310
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
311
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op1);
312
589
        MI->flat_insn->detail->arm64.op_count++;
313
589
#ifndef CAPSTONE_DIET
314
589
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
315
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
316
589
        MI->ac_idx++;
317
589
#endif
318
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
319
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (Is64Bit ? 64 : 32) - (int)MCOperand_getImm(Op2);
320
589
        MI->flat_insn->detail->arm64.op_count++;
321
589
#ifndef CAPSTONE_DIET
322
589
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
323
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
324
589
        MI->ac_idx++;
325
589
#endif
326
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
327
589
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op3) + 1;
328
589
        MI->flat_insn->detail->arm64.op_count++;
329
589
      }
330
331
589
      return;
332
589
    }
333
334
    // Otherwise SBFX/UBFX is the preferred form
335
437
    SStream_concat(O, "%s\t%s, %s, ", (IsSigned ? "sbfx" : "ubfx"),
336
437
        getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName),
337
437
        getRegisterName(MCOperand_getReg(Op1), AArch64_NoRegAltName));
338
339
437
    printInt32Bang(O, (int)MCOperand_getImm(Op2));
340
437
    SStream_concat0(O, ", ");
341
437
    printInt32Bang(O, (int)MCOperand_getImm(Op3) - (int)MCOperand_getImm(Op2) + 1);
342
343
437
    MCInst_setOpcodePub(MI, AArch64_map_insn(IsSigned ? "sbfx" : "ubfx"));
344
345
437
    if (MI->csh->detail) {
346
437
#ifndef CAPSTONE_DIET
347
437
      uint8_t access;
348
437
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
349
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
350
437
      MI->ac_idx++;
351
437
#endif
352
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
353
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0);
354
437
      MI->flat_insn->detail->arm64.op_count++;
355
437
#ifndef CAPSTONE_DIET
356
437
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
357
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
358
437
      MI->ac_idx++;
359
437
#endif
360
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
361
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op1);
362
437
      MI->flat_insn->detail->arm64.op_count++;
363
437
#ifndef CAPSTONE_DIET
364
437
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
365
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
366
437
      MI->ac_idx++;
367
437
#endif
368
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
369
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op2);
370
437
      MI->flat_insn->detail->arm64.op_count++;
371
437
#ifndef CAPSTONE_DIET
372
437
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
373
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
374
437
      MI->ac_idx++;
375
437
#endif
376
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
377
437
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op3) - MCOperand_getImm(Op2) + 1;
378
437
      MI->flat_insn->detail->arm64.op_count++;
379
437
    }
380
381
437
    return;
382
1.02k
  }
383
384
288k
  if (Opcode == AArch64_BFMXri || Opcode == AArch64_BFMWri) {
385
869
    MCOperand *Op0 = MCInst_getOperand(MI, 0); // Op1 == Op0
386
869
    MCOperand *Op2 = MCInst_getOperand(MI, 2);
387
869
    int ImmR = (int)MCOperand_getImm(MCInst_getOperand(MI, 3));
388
869
    int ImmS = (int)MCOperand_getImm(MCInst_getOperand(MI, 4));
389
390
869
    if ((MCOperand_getReg(Op2) == AArch64_WZR || MCOperand_getReg(Op2) == AArch64_XZR) &&
391
143
        (ImmR == 0 || ImmS < ImmR)) {
392
      // BFC takes precedence over its entire range, sligtly differently to BFI.
393
120
      int BitWidth = Opcode == AArch64_BFMXri ? 64 : 32;
394
120
      int LSB = (BitWidth - ImmR) % BitWidth;
395
120
      int Width = ImmS + 1;
396
397
120
      SStream_concat(O, "bfc\t%s, ",
398
120
          getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName));
399
400
120
      printInt32Bang(O, LSB);
401
120
      SStream_concat0(O, ", ");
402
120
      printInt32Bang(O, Width);
403
120
      MCInst_setOpcodePub(MI, AArch64_map_insn("bfc"));
404
405
120
      if (MI->csh->detail) {
406
120
#ifndef CAPSTONE_DIET
407
120
        uint8_t access;
408
120
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
409
120
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
410
120
        MI->ac_idx++;
411
120
#endif
412
120
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
413
120
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0);
414
120
        MI->flat_insn->detail->arm64.op_count++;
415
416
120
#ifndef CAPSTONE_DIET
417
120
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
418
120
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
419
120
        MI->ac_idx++;
420
120
#endif
421
120
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
422
120
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = LSB;
423
120
        MI->flat_insn->detail->arm64.op_count++;
424
120
#ifndef CAPSTONE_DIET
425
120
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
426
120
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
427
120
        MI->ac_idx++;
428
120
#endif
429
120
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
430
120
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Width;
431
120
        MI->flat_insn->detail->arm64.op_count++;
432
120
      }
433
434
120
      return;
435
749
    } else if (ImmS < ImmR) {
436
      // BFI alias
437
361
      int BitWidth = Opcode == AArch64_BFMXri ? 64 : 32;
438
361
      LSB = (BitWidth - ImmR) % BitWidth;
439
361
      Width = ImmS + 1;
440
441
361
      SStream_concat(O, "bfi\t%s, %s, ",
442
361
          getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName),
443
361
          getRegisterName(MCOperand_getReg(Op2), AArch64_NoRegAltName));
444
445
361
      printInt32Bang(O, LSB);
446
361
      SStream_concat0(O, ", ");
447
361
      printInt32Bang(O, Width);
448
449
361
      MCInst_setOpcodePub(MI, AArch64_map_insn("bfi"));
450
451
361
      if (MI->csh->detail) {
452
361
#ifndef CAPSTONE_DIET
453
361
        uint8_t access;
454
361
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
455
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
456
361
        MI->ac_idx++;
457
361
#endif
458
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
459
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0);
460
361
        MI->flat_insn->detail->arm64.op_count++;
461
361
#ifndef CAPSTONE_DIET
462
361
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
463
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
464
361
        MI->ac_idx++;
465
361
#endif
466
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
467
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op2);
468
361
        MI->flat_insn->detail->arm64.op_count++;
469
361
#ifndef CAPSTONE_DIET
470
361
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
471
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
472
361
        MI->ac_idx++;
473
361
#endif
474
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
475
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = LSB;
476
361
        MI->flat_insn->detail->arm64.op_count++;
477
361
#ifndef CAPSTONE_DIET
478
361
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
479
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
480
361
        MI->ac_idx++;
481
361
#endif
482
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
483
361
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Width;
484
361
        MI->flat_insn->detail->arm64.op_count++;
485
361
      }
486
487
361
      return;
488
361
    }
489
490
388
    LSB = ImmR;
491
388
    Width = ImmS - ImmR + 1;
492
    // Otherwise BFXIL the preferred form
493
388
    SStream_concat(O, "bfxil\t%s, %s, ",
494
388
        getRegisterName(MCOperand_getReg(Op0), AArch64_NoRegAltName),
495
388
        getRegisterName(MCOperand_getReg(Op2), AArch64_NoRegAltName));
496
497
388
    printInt32Bang(O, LSB);
498
388
    SStream_concat0(O, ", ");
499
388
    printInt32Bang(O, Width);
500
501
388
    MCInst_setOpcodePub(MI, AArch64_map_insn("bfxil"));
502
503
388
    if (MI->csh->detail) {
504
388
#ifndef CAPSTONE_DIET
505
388
      uint8_t access;
506
388
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
507
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
508
388
      MI->ac_idx++;
509
388
#endif
510
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
511
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op0);
512
388
      MI->flat_insn->detail->arm64.op_count++;
513
388
#ifndef CAPSTONE_DIET
514
388
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
515
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
516
388
      MI->ac_idx++;
517
388
#endif
518
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
519
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(Op2);
520
388
      MI->flat_insn->detail->arm64.op_count++;
521
388
#ifndef CAPSTONE_DIET
522
388
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
523
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
524
388
      MI->ac_idx++;
525
388
#endif
526
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
527
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = LSB;
528
388
      MI->flat_insn->detail->arm64.op_count++;
529
388
#ifndef CAPSTONE_DIET
530
388
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
531
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
532
388
      MI->ac_idx++;
533
388
#endif
534
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
535
388
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Width;
536
388
      MI->flat_insn->detail->arm64.op_count++;
537
388
    }
538
539
388
    return;
540
869
  }
541
542
  // MOVZ, MOVN and "ORR wzr, #imm" instructions are aliases for MOV, but their
543
  // domains overlap so they need to be prioritized. The chain is "MOVZ lsl #0 >
544
  // MOVZ lsl #N > MOVN lsl #0 > MOVN lsl #N > ORR". The highest instruction
545
  // that can represent the move is the MOV alias, and the rest get printed
546
  // normally.
547
288k
  if ((Opcode == AArch64_MOVZXi || Opcode == AArch64_MOVZWi) &&
548
639
      MCOperand_isImm(MCInst_getOperand(MI, 1)) && MCOperand_isImm(MCInst_getOperand(MI, 2))) {
549
639
    int RegWidth = Opcode == AArch64_MOVZXi ? 64 : 32;
550
639
    int Shift = MCOperand_getImm(MCInst_getOperand(MI, 2));
551
639
    uint64_t Value = (uint64_t)MCOperand_getImm(MCInst_getOperand(MI, 1)) << Shift;
552
553
639
    if (isMOVZMovAlias(Value, Shift,
554
639
          Opcode == AArch64_MOVZXi ? 64 : 32)) {
555
621
      SStream_concat(O, "mov\t%s, ", getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, 0)), AArch64_NoRegAltName));
556
557
621
      printInt64Bang(O, SignExtend64(Value, RegWidth));
558
559
621
      if (MI->csh->detail) {
560
621
#ifndef CAPSTONE_DIET
561
621
        uint8_t access;
562
621
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
563
621
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
564
621
        MI->ac_idx++;
565
621
#endif
566
621
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
567
621
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 0));
568
621
        MI->flat_insn->detail->arm64.op_count++;
569
570
621
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
571
621
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = SignExtend64(Value, RegWidth);
572
621
        MI->flat_insn->detail->arm64.op_count++;
573
621
      }
574
575
621
      MCInst_setOpcodePub(MI, AArch64_map_insn("mov"));
576
577
621
      return;
578
621
    }
579
639
  }
580
581
287k
  if ((Opcode == AArch64_MOVNXi || Opcode == AArch64_MOVNWi) &&
582
853
      MCOperand_isImm(MCInst_getOperand(MI, 1)) && MCOperand_isImm(MCInst_getOperand(MI, 2))) {
583
853
    int RegWidth = Opcode == AArch64_MOVNXi ? 64 : 32;
584
853
    int Shift = MCOperand_getImm(MCInst_getOperand(MI, 2));
585
853
    uint64_t Value = ~((uint64_t)MCOperand_getImm(MCInst_getOperand(MI, 1)) << Shift);
586
587
853
    if (RegWidth == 32)
588
169
      Value = Value & 0xffffffff;
589
590
853
    if (AArch64_AM_isMOVNMovAlias(Value, Shift, RegWidth)) {
591
773
      SStream_concat(O, "mov\t%s, ", getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, 0)), AArch64_NoRegAltName));
592
593
773
      printInt64Bang(O, SignExtend64(Value, RegWidth));
594
595
773
      if (MI->csh->detail) {
596
773
#ifndef CAPSTONE_DIET
597
773
        uint8_t access;
598
773
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
599
773
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
600
773
        MI->ac_idx++;
601
773
#endif
602
773
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
603
773
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 0));
604
773
        MI->flat_insn->detail->arm64.op_count++;
605
606
773
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
607
773
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = SignExtend64(Value, RegWidth);
608
773
        MI->flat_insn->detail->arm64.op_count++;
609
773
      }
610
611
773
      MCInst_setOpcodePub(MI, AArch64_map_insn("mov"));
612
613
773
      return;
614
773
    }
615
853
  }
616
617
286k
  if ((Opcode == AArch64_ORRXri || Opcode == AArch64_ORRWri) &&
618
1.47k
      (MCOperand_getReg(MCInst_getOperand(MI, 1)) == AArch64_XZR ||
619
1.25k
       MCOperand_getReg(MCInst_getOperand(MI, 1)) == AArch64_WZR) &&
620
590
      MCOperand_isImm(MCInst_getOperand(MI, 2))) {
621
590
    int RegWidth = Opcode == AArch64_ORRXri ? 64 : 32;
622
590
    uint64_t Value = AArch64_AM_decodeLogicalImmediate(
623
590
        MCOperand_getImm(MCInst_getOperand(MI, 2)), RegWidth);
624
590
    SStream_concat(O, "mov\t%s, ", getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, 0)), AArch64_NoRegAltName));
625
626
590
    printInt64Bang(O, SignExtend64(Value, RegWidth));
627
628
590
    if (MI->csh->detail) {
629
590
#ifndef CAPSTONE_DIET
630
590
      uint8_t access;
631
590
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
632
590
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
633
590
      MI->ac_idx++;
634
590
#endif
635
590
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
636
590
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 0));
637
590
      MI->flat_insn->detail->arm64.op_count++;
638
639
590
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
640
590
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = SignExtend64(Value, RegWidth);
641
590
      MI->flat_insn->detail->arm64.op_count++;
642
590
    }
643
644
590
    MCInst_setOpcodePub(MI, AArch64_map_insn("mov"));
645
646
590
    return;
647
590
  }
648
649
  // Instruction TSB is specified as a one operand instruction, but 'csync' is
650
  // not encoded, so for printing it is treated as a special case here:
651
286k
  if (Opcode == AArch64_TSB) {
652
120
    SStream_concat0(O, "tsb\tcsync");
653
120
    MCInst_setOpcodePub(MI, AArch64_map_insn("tsb"));
654
120
    return;
655
120
  }
656
657
285k
  MI->MRI = Info;
658
659
285k
  mnem = printAliasInstr(MI, O, (MCRegisterInfo *)Info);
660
285k
  if (mnem) {
661
39.6k
    MCInst_setOpcodePub(MI, AArch64_map_insn(mnem));
662
39.6k
    cs_mem_free(mnem);
663
664
39.6k
    switch(MCInst_getOpcode(MI)) {
665
22.4k
      default: break;
666
22.4k
      case AArch64_LD1i8_POST:
667
456
        arm64_op_addImm(MI, 1);
668
456
        break;
669
122
      case AArch64_LD1i16_POST:
670
122
        arm64_op_addImm(MI, 2);
671
122
        break;
672
1.42k
      case AArch64_LD1i32_POST:
673
1.42k
        arm64_op_addImm(MI, 4);
674
1.42k
        break;
675
38
      case AArch64_LD1Onev1d_POST:
676
304
      case AArch64_LD1Onev2s_POST:
677
467
      case AArch64_LD1Onev4h_POST:
678
673
      case AArch64_LD1Onev8b_POST:
679
920
      case AArch64_LD1i64_POST:
680
920
        arm64_op_addImm(MI, 8);
681
920
        break;
682
35
      case AArch64_LD1Onev16b_POST:
683
108
      case AArch64_LD1Onev2d_POST:
684
222
      case AArch64_LD1Onev4s_POST:
685
289
      case AArch64_LD1Onev8h_POST:
686
357
      case AArch64_LD1Twov1d_POST:
687
428
      case AArch64_LD1Twov2s_POST:
688
464
      case AArch64_LD1Twov4h_POST:
689
1.10k
      case AArch64_LD1Twov8b_POST:
690
1.10k
        arm64_op_addImm(MI, 16);
691
1.10k
        break;
692
80
      case AArch64_LD1Threev1d_POST:
693
227
      case AArch64_LD1Threev2s_POST:
694
322
      case AArch64_LD1Threev4h_POST:
695
429
      case AArch64_LD1Threev8b_POST:
696
429
        arm64_op_addImm(MI, 24);
697
429
        break;
698
169
      case AArch64_LD1Fourv1d_POST:
699
218
      case AArch64_LD1Fourv2s_POST:
700
287
      case AArch64_LD1Fourv4h_POST:
701
335
      case AArch64_LD1Fourv8b_POST:
702
358
      case AArch64_LD1Twov16b_POST:
703
592
      case AArch64_LD1Twov2d_POST:
704
695
      case AArch64_LD1Twov4s_POST:
705
705
      case AArch64_LD1Twov8h_POST:
706
705
        arm64_op_addImm(MI, 32);
707
705
        break;
708
435
      case AArch64_LD1Threev16b_POST:
709
592
      case AArch64_LD1Threev2d_POST:
710
1.19k
      case AArch64_LD1Threev4s_POST:
711
1.77k
      case AArch64_LD1Threev8h_POST:
712
1.77k
         arm64_op_addImm(MI, 48);
713
1.77k
         break;
714
81
      case AArch64_LD1Fourv16b_POST:
715
302
      case AArch64_LD1Fourv2d_POST:
716
1.07k
      case AArch64_LD1Fourv4s_POST:
717
1.54k
      case AArch64_LD1Fourv8h_POST:
718
1.54k
        arm64_op_addImm(MI, 64);
719
1.54k
        break;
720
71
      case AArch64_UMOVvi64:
721
71
        arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_1D);
722
71
        break;
723
34
      case AArch64_UMOVvi32:
724
34
        arm64_op_addVectorArrSpecifier(MI, ARM64_VAS_1S);
725
34
        break;
726
66
      case AArch64_INSvi8gpr:
727
146
      case AArch64_DUP_ZI_B:
728
208
      case AArch64_CPY_ZPmI_B:
729
358
      case AArch64_CPY_ZPzI_B:
730
395
      case AArch64_CPY_ZPmV_B:
731
508
      case AArch64_CPY_ZPmR_B:
732
561
      case AArch64_DUP_ZR_B:
733
561
        if (MI->csh->detail) {
734
561
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1B;
735
561
        }
736
561
        break;
737
43
      case AArch64_INSvi16gpr:
738
96
      case AArch64_DUP_ZI_H:
739
253
      case AArch64_CPY_ZPmI_H:
740
297
      case AArch64_CPY_ZPzI_H:
741
469
      case AArch64_CPY_ZPmV_H:
742
535
      case AArch64_CPY_ZPmR_H:
743
1.22k
      case AArch64_DUP_ZR_H:
744
1.24k
      case AArch64_FCPY_ZPmI_H:
745
1.45k
      case AArch64_FDUP_ZI_H:
746
1.45k
        if (MI->csh->detail) {
747
1.45k
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1H;
748
1.45k
        }
749
1.45k
        break;
750
90
      case AArch64_INSvi32gpr:
751
168
      case AArch64_DUP_ZI_S:
752
413
      case AArch64_CPY_ZPmI_S:
753
516
      case AArch64_CPY_ZPzI_S:
754
597
      case AArch64_CPY_ZPmV_S:
755
635
      case AArch64_CPY_ZPmR_S:
756
947
      case AArch64_DUP_ZR_S:
757
988
      case AArch64_FCPY_ZPmI_S:
758
1.02k
      case AArch64_FDUP_ZI_S:
759
1.02k
        if (MI->csh->detail) {
760
1.02k
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1S;
761
1.02k
        }
762
1.02k
        break;
763
65
      case AArch64_INSvi64gpr:
764
106
      case AArch64_DUP_ZI_D:
765
345
      case AArch64_CPY_ZPmI_D:
766
923
      case AArch64_CPY_ZPzI_D:
767
998
      case AArch64_CPY_ZPmV_D:
768
1.05k
      case AArch64_CPY_ZPmR_D:
769
1.22k
      case AArch64_DUP_ZR_D:
770
1.58k
      case AArch64_FCPY_ZPmI_D:
771
1.88k
      case AArch64_FDUP_ZI_D:
772
1.88k
        if (MI->csh->detail) {
773
1.88k
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1D;
774
1.88k
        }
775
1.88k
        break;
776
106
      case AArch64_INSvi8lane:
777
185
      case AArch64_ORR_PPzPP:
778
591
      case AArch64_ORRS_PPzPP:
779
591
        if (MI->csh->detail) {
780
591
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1B;
781
591
          MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1B;
782
591
        }
783
591
        break;
784
86
      case AArch64_INSvi16lane:
785
86
        if (MI->csh->detail) {
786
86
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1H;
787
86
          MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1H;
788
86
        }
789
86
         break;
790
54
      case AArch64_INSvi32lane:
791
54
        if (MI->csh->detail) {
792
54
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1S;
793
54
          MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1S;
794
54
        }
795
54
        break;
796
238
      case AArch64_INSvi64lane:
797
257
      case AArch64_ORR_ZZZ:
798
257
        if (MI->csh->detail) {
799
257
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1D;
800
257
          MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1D;
801
257
        }
802
257
        break;
803
746
      case AArch64_ORRv16i8:
804
780
      case AArch64_NOTv16i8:
805
780
        if (MI->csh->detail) {
806
780
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_16B;
807
780
          MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_16B;
808
780
        }
809
780
        break;
810
37
      case AArch64_ORRv8i8:
811
71
      case AArch64_NOTv8i8:
812
71
        if (MI->csh->detail) {
813
71
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_8B;
814
71
          MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_8B;
815
71
        }
816
71
        break;
817
37
      case AArch64_AND_PPzPP:
818
138
      case AArch64_ANDS_PPzPP:
819
156
      case AArch64_EOR_PPzPP:
820
177
      case AArch64_EORS_PPzPP:
821
382
      case AArch64_SEL_PPPP:
822
595
      case AArch64_SEL_ZPZZ_B:
823
595
        if (MI->csh->detail) {
824
595
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1B;
825
595
          MI->flat_insn->detail->arm64.operands[2].vas = ARM64_VAS_1B;
826
595
        }
827
595
        break;
828
39
      case AArch64_SEL_ZPZZ_D:
829
39
        if (MI->csh->detail) {
830
39
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1D;
831
39
          MI->flat_insn->detail->arm64.operands[2].vas = ARM64_VAS_1D;
832
39
        }
833
39
        break;
834
12
      case AArch64_SEL_ZPZZ_H:
835
12
        if (MI->csh->detail) {
836
12
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1H;
837
12
          MI->flat_insn->detail->arm64.operands[2].vas = ARM64_VAS_1H;
838
12
        }
839
12
        break;
840
40
      case AArch64_SEL_ZPZZ_S:
841
40
        if (MI->csh->detail) {
842
40
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1S;
843
40
          MI->flat_insn->detail->arm64.operands[2].vas = ARM64_VAS_1S;
844
40
        }
845
40
        break;
846
276
      case AArch64_DUP_ZZI_B:
847
276
        if (MI->csh->detail) {
848
276
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1B;
849
276
          if (MI->flat_insn->detail->arm64.op_count == 1) {
850
0
            arm64_op_addReg(MI, ARM64_REG_B0 + MCOperand_getReg(MCInst_getOperand(MI, 1)) - ARM64_REG_Z0);
851
276
          } else {
852
276
            MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1B;
853
276
          }
854
276
        }
855
276
        break;
856
648
      case AArch64_DUP_ZZI_D:
857
648
        if (MI->csh->detail) {
858
648
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1D;
859
648
          if (MI->flat_insn->detail->arm64.op_count == 1) {
860
0
            arm64_op_addReg(MI, ARM64_REG_D0 + MCOperand_getReg(MCInst_getOperand(MI, 1)) - ARM64_REG_Z0);
861
648
          } else {
862
648
            MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1D;
863
648
          }
864
648
        }
865
648
        break;
866
75
      case AArch64_DUP_ZZI_H:
867
75
        if (MI->csh->detail) {
868
75
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1H;
869
75
          if (MI->flat_insn->detail->arm64.op_count == 1) {
870
0
            arm64_op_addReg(MI, ARM64_REG_H0 + MCOperand_getReg(MCInst_getOperand(MI, 1)) - ARM64_REG_Z0);
871
75
          } else {
872
75
            MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1H;
873
75
          }
874
75
        }
875
75
        break;
876
37
      case AArch64_DUP_ZZI_Q:
877
37
        if (MI->csh->detail) {
878
37
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1Q;
879
37
          if (MI->flat_insn->detail->arm64.op_count == 1) {
880
0
            arm64_op_addReg(MI, ARM64_REG_Q0 + MCOperand_getReg(MCInst_getOperand(MI, 1)) - ARM64_REG_Z0);
881
37
          } else {
882
37
            MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1Q;
883
37
          }
884
37
         }
885
37
         break;
886
122
      case AArch64_DUP_ZZI_S:
887
122
        if (MI->csh->detail) {
888
122
          MI->flat_insn->detail->arm64.operands[0].vas = ARM64_VAS_1S;
889
122
          if (MI->flat_insn->detail->arm64.op_count == 1) {
890
0
            arm64_op_addReg(MI, ARM64_REG_S0 + MCOperand_getReg(MCInst_getOperand(MI, 1)) - ARM64_REG_Z0);
891
122
          } else {
892
122
             MI->flat_insn->detail->arm64.operands[1].vas = ARM64_VAS_1S;
893
122
          }
894
122
        }
895
122
        break;
896
      // Hacky detail filling of SMSTART and SMSTOP alias'
897
35
      case AArch64_MSRpstatesvcrImm1:{
898
35
        if(MI->csh->detail){
899
35
          MI->flat_insn->detail->arm64.op_count = 2;
900
35
#ifndef CAPSTONE_DIET
901
35
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
902
35
          MI->ac_idx++;
903
35
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
904
35
          MI->ac_idx++;
905
35
#endif
906
35
          MI->flat_insn->detail->arm64.operands[0].type = ARM64_OP_SVCR;
907
35
          MI->flat_insn->detail->arm64.operands[0].sys = (unsigned)ARM64_SYSREG_SVCR;
908
35
          MI->flat_insn->detail->arm64.operands[0].svcr = lookupSVCRByEncoding(MCOperand_getImm(MCInst_getOperand(MI, 0)))->Encoding;
909
35
          MI->flat_insn->detail->arm64.operands[1].type = ARM64_OP_IMM;
910
35
          MI->flat_insn->detail->arm64.operands[1].imm = MCOperand_getImm(MCInst_getOperand(MI, 1));
911
35
        }
912
35
        break;
913
382
      }
914
39.6k
    }
915
246k
  } else {
916
246k
    printInstruction(MI, O);
917
246k
  }
918
285k
}
919
920
static bool printSysAlias(MCInst *MI, SStream *O)
921
3.61k
{
922
  // unsigned Opcode = MCInst_getOpcode(MI);
923
  //assert(Opcode == AArch64_SYSxt && "Invalid opcode for SYS alias!");
924
925
3.61k
  const char *Ins;
926
3.61k
  uint16_t Encoding;
927
3.61k
  bool NeedsReg;
928
3.61k
  char Name[64];
929
3.61k
  MCOperand *Op1 = MCInst_getOperand(MI, 0);
930
3.61k
  MCOperand *Cn = MCInst_getOperand(MI, 1);
931
3.61k
  MCOperand *Cm = MCInst_getOperand(MI, 2);
932
3.61k
  MCOperand *Op2 = MCInst_getOperand(MI, 3);
933
934
3.61k
  unsigned Op1Val = (unsigned)MCOperand_getImm(Op1);
935
3.61k
  unsigned CnVal = (unsigned)MCOperand_getImm(Cn);
936
3.61k
  unsigned CmVal = (unsigned)MCOperand_getImm(Cm);
937
3.61k
  unsigned Op2Val = (unsigned)MCOperand_getImm(Op2);
938
939
3.61k
  Encoding = Op2Val;
940
3.61k
  Encoding |= CmVal << 3;
941
3.61k
  Encoding |= CnVal << 7;
942
3.61k
  Encoding |= Op1Val << 11;
943
944
3.61k
  if (CnVal == 7) {
945
3.04k
    switch (CmVal) {
946
56
      default:
947
56
        return false;
948
949
      // IC aliases
950
746
      case 1: case 5: {
951
746
        const IC *IC = lookupICByEncoding(Encoding);
952
        // if (!IC || !IC->haveFeatures(STI.getFeatureBits()))
953
746
        if (!IC)
954
350
          return false;
955
956
396
        NeedsReg = IC->NeedsReg;
957
396
        Ins = "ic";
958
396
        strncpy(Name, IC->Name, sizeof(Name) - 1);
959
396
      }
960
0
      break;
961
962
      // DC aliases
963
1.59k
      case 4: case 6: case 10: case 11: case 12: case 14: {
964
1.59k
        const DC *DC = lookupDCByEncoding(Encoding);
965
        // if (!DC || !DC->haveFeatures(STI.getFeatureBits()))
966
1.59k
        if (!DC)
967
1.22k
          return false;
968
969
375
        NeedsReg = true;
970
375
        Ins = "dc";
971
375
        strncpy(Name, DC->Name, sizeof(Name) - 1);
972
375
      }
973
0
      break;
974
975
      // AT aliases
976
647
      case 8: case 9: {
977
647
        const AT *AT = lookupATByEncoding(Encoding);
978
        // if (!AT || !AT->haveFeatures(STI.getFeatureBits()))
979
647
        if (!AT)
980
38
          return false;
981
982
609
        NeedsReg = true;
983
609
        Ins = "at";
984
609
        strncpy(Name, AT->Name, sizeof(Name) - 1);
985
609
      }
986
0
      break;
987
3.04k
    }
988
3.04k
  } else if (CnVal == 8) {
989
    // TLBI aliases
990
294
    const TLBI *TLBI = lookupTLBIByEncoding(Encoding);
991
    // if (!TLBI || !TLBI->haveFeatures(STI.getFeatureBits()))
992
294
    if (!TLBI)
993
176
      return false;
994
995
118
    NeedsReg = TLBI->NeedsReg;
996
118
    Ins = "tlbi";
997
118
    strncpy(Name, TLBI->Name, sizeof(Name) - 1);
998
118
  } else
999
278
    return false;
1000
1001
1.49k
  SStream_concat(O, "%s\t%s", Ins, Name);
1002
1003
1.49k
  if (NeedsReg) {
1004
1.08k
    SStream_concat(O, ", %s", getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, 4)), AArch64_NoRegAltName));
1005
1.08k
  }
1006
1007
1.49k
  MCInst_setOpcodePub(MI, AArch64_map_insn(Ins));
1008
1009
1.49k
  if (MI->csh->detail) {
1010
#if 0
1011
#ifndef CAPSTONE_DIET
1012
    uint8_t access;
1013
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1014
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1015
    MI->ac_idx++;
1016
#endif
1017
#endif
1018
1.49k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS;
1019
1.49k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = AArch64_map_sys_op(Name);
1020
1.49k
    MI->flat_insn->detail->arm64.op_count++;
1021
1022
1.49k
    if (NeedsReg) {
1023
1.08k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
1024
1.08k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, 4));
1025
1.08k
      MI->flat_insn->detail->arm64.op_count++;
1026
1.08k
    }
1027
1.49k
  }
1028
1029
1.49k
  return true;
1030
3.61k
}
1031
1032
static void printOperand(MCInst *MI, unsigned OpNum, SStream *O)
1033
399k
{
1034
399k
  MCOperand *Op = MCInst_getOperand(MI, OpNum);
1035
1036
399k
  if (MCOperand_isReg(Op)) {
1037
347k
    unsigned Reg = MCOperand_getReg(Op);
1038
1039
347k
    SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName));
1040
1041
347k
    if (MI->csh->detail) {
1042
347k
      if (MI->csh->doing_mem) {
1043
156k
        if (MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.base == ARM64_REG_INVALID) {
1044
139k
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.base = Reg;
1045
139k
        }
1046
17.2k
        else if (MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.index == ARM64_REG_INVALID) {
1047
17.2k
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.index = Reg;
1048
17.2k
        }
1049
190k
      } else if (MI->csh->doing_SME_Index) {
1050
        // Access op_count-1 as We want to add info to previous operand, not create a new one
1051
6.82k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count-1].sme_index.base = Reg;
1052
183k
      } else {
1053
183k
#ifndef CAPSTONE_DIET
1054
183k
        uint8_t access;
1055
1056
183k
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1057
183k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1058
183k
        MI->ac_idx++;
1059
183k
#endif
1060
183k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
1061
183k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg;
1062
183k
        MI->flat_insn->detail->arm64.op_count++;
1063
183k
      }
1064
347k
    }
1065
347k
  } else if (MCOperand_isImm(Op)) {
1066
52.2k
    int64_t imm = MCOperand_getImm(Op);
1067
1068
52.2k
    if (MI->Opcode == AArch64_ADR) {
1069
4.13k
      imm += MI->address;
1070
4.13k
      printUInt64Bang(O, imm);
1071
48.1k
    } else {
1072
48.1k
      if (MI->csh->doing_mem) {
1073
14.9k
        if (MI->csh->imm_unsigned) {
1074
0
          printUInt64Bang(O, imm);
1075
14.9k
        } else {
1076
14.9k
          printInt64Bang(O, imm);
1077
14.9k
        }
1078
14.9k
      } else
1079
33.1k
        printUInt64Bang(O, imm);
1080
48.1k
    }
1081
1082
52.2k
    if (MI->csh->detail) {
1083
52.2k
      if (MI->csh->doing_mem) {
1084
14.9k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = (int32_t)imm;
1085
37.2k
      } else if (MI->csh->doing_SME_Index) {
1086
        // Access op_count-1 as We want to add info to previous operand, not create a new one
1087
0
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count-1].sme_index.disp = (int32_t)imm; 
1088
37.2k
      } else {
1089
37.2k
#ifndef CAPSTONE_DIET
1090
37.2k
        uint8_t access;
1091
1092
37.2k
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1093
37.2k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1094
37.2k
#endif
1095
37.2k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1096
37.2k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = imm;
1097
37.2k
        MI->flat_insn->detail->arm64.op_count++;
1098
37.2k
      }
1099
52.2k
    }
1100
52.2k
  }
1101
399k
}
1102
1103
static void printImm(MCInst *MI, unsigned OpNum, SStream *O)
1104
4.17k
{
1105
4.17k
  MCOperand *Op = MCInst_getOperand(MI, OpNum);
1106
4.17k
  printUInt64Bang(O, MCOperand_getImm(Op));
1107
1108
4.17k
  if (MI->csh->detail) {
1109
4.17k
#ifndef CAPSTONE_DIET
1110
4.17k
    uint8_t access;
1111
4.17k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1112
4.17k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1113
4.17k
    MI->ac_idx++;
1114
4.17k
#endif
1115
4.17k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1116
4.17k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op);
1117
4.17k
    MI->flat_insn->detail->arm64.op_count++;
1118
4.17k
  }
1119
4.17k
}
1120
1121
static void printImmHex(MCInst *MI, unsigned OpNum, SStream *O)
1122
94
{
1123
94
  MCOperand *Op = MCInst_getOperand(MI, OpNum);
1124
94
  printUInt64Bang(O, MCOperand_getImm(Op));
1125
1126
94
  if (MI->csh->detail) {
1127
94
#ifndef CAPSTONE_DIET
1128
94
    uint8_t access;
1129
94
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1130
94
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1131
94
    MI->ac_idx++;
1132
94
#endif
1133
94
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1134
94
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op);
1135
94
    MI->flat_insn->detail->arm64.op_count++;
1136
94
  }
1137
94
}
1138
1139
747
static void printSImm(MCInst *MI, unsigned OpNo, SStream *O, int Size) {
1140
747
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
1141
747
  if (Size == 8)
1142
282
  printInt64Bang(O, (signed char) MCOperand_getImm(Op));
1143
465
  else if (Size == 16)
1144
465
  printInt64Bang(O, (signed short) MCOperand_getImm(Op));
1145
0
  else
1146
0
    printInt64Bang(O, MCOperand_getImm(Op));
1147
1148
747
  if (MI->csh->detail) {
1149
747
#ifndef CAPSTONE_DIET
1150
747
    uint8_t access;
1151
747
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1152
747
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1153
747
    MI->ac_idx++;
1154
747
#endif
1155
747
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1156
747
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op);
1157
747
    MI->flat_insn->detail->arm64.op_count++;
1158
747
  }
1159
747
}
1160
1161
static void printPostIncOperand(MCInst *MI, unsigned OpNum, SStream *O,
1162
    unsigned Imm)
1163
25.8k
{
1164
25.8k
  MCOperand *Op = MCInst_getOperand(MI, OpNum);
1165
1166
25.8k
  if (MCOperand_isReg(Op)) {
1167
25.8k
    unsigned Reg = MCOperand_getReg(Op);
1168
25.8k
    if (Reg == AArch64_XZR) {
1169
0
      printInt32Bang(O, Imm);
1170
1171
0
      if (MI->csh->detail) {
1172
0
#ifndef CAPSTONE_DIET
1173
0
        uint8_t access;
1174
1175
0
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1176
0
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1177
0
        MI->ac_idx++;
1178
0
#endif
1179
0
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1180
0
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Imm;
1181
0
        MI->flat_insn->detail->arm64.op_count++;
1182
0
      }
1183
25.8k
    } else {
1184
25.8k
      SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName));
1185
1186
25.8k
      if (MI->csh->detail) {
1187
25.8k
#ifndef CAPSTONE_DIET
1188
25.8k
        uint8_t access;
1189
1190
25.8k
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1191
25.8k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1192
25.8k
        MI->ac_idx++;
1193
25.8k
#endif
1194
25.8k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
1195
25.8k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg;
1196
25.8k
        MI->flat_insn->detail->arm64.op_count++;
1197
25.8k
      }
1198
25.8k
    }
1199
25.8k
  }
1200
  //llvm_unreachable("unknown operand kind in printPostIncOperand64");
1201
25.8k
}
1202
1203
static void printVRegOperand(MCInst *MI, unsigned OpNum, SStream *O)
1204
53.4k
{
1205
53.4k
  MCOperand *Op = MCInst_getOperand(MI, OpNum);
1206
  //assert(Op.isReg() && "Non-register vreg operand!");
1207
53.4k
  unsigned Reg = MCOperand_getReg(Op);
1208
1209
53.4k
  SStream_concat0(O, getRegisterName(Reg, AArch64_vreg));
1210
1211
53.4k
  if (MI->csh->detail) {
1212
53.4k
#ifndef CAPSTONE_DIET
1213
53.4k
    uint8_t access;
1214
53.4k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1215
53.4k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1216
53.4k
    MI->ac_idx++;
1217
53.4k
#endif
1218
53.4k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
1219
53.4k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = AArch64_map_vregister(Reg);
1220
53.4k
    MI->flat_insn->detail->arm64.op_count++;
1221
53.4k
  }
1222
53.4k
}
1223
1224
static void printSysCROperand(MCInst *MI, unsigned OpNum, SStream *O)
1225
4.36k
{
1226
4.36k
  MCOperand *Op = MCInst_getOperand(MI, OpNum);
1227
  //assert(Op.isImm() && "System instruction C[nm] operands must be immediates!");
1228
4.36k
  SStream_concat(O, "c%u", MCOperand_getImm(Op));
1229
1230
4.36k
  if (MI->csh->detail) {
1231
4.36k
#ifndef CAPSTONE_DIET
1232
4.36k
    uint8_t access;
1233
1234
4.36k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1235
4.36k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1236
4.36k
    MI->ac_idx++;
1237
4.36k
#endif
1238
4.36k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_CIMM;
1239
4.36k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = MCOperand_getImm(Op);
1240
4.36k
    MI->flat_insn->detail->arm64.op_count++;
1241
4.36k
  }
1242
4.36k
}
1243
1244
static void printAddSubImm(MCInst *MI, unsigned OpNum, SStream *O)
1245
3.45k
{
1246
3.45k
  MCOperand *MO = MCInst_getOperand(MI, OpNum);
1247
3.45k
  if (MCOperand_isImm(MO)) {
1248
3.45k
    unsigned Val = (MCOperand_getImm(MO) & 0xfff);
1249
    //assert(Val == MO.getImm() && "Add/sub immediate out of range!");
1250
3.45k
    unsigned Shift = AArch64_AM_getShiftValue((int)MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1)));
1251
1252
3.45k
    printInt32Bang(O, Val);
1253
1254
3.45k
    if (MI->csh->detail) {
1255
3.45k
#ifndef CAPSTONE_DIET
1256
3.45k
      uint8_t access;
1257
1258
3.45k
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1259
3.45k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1260
3.45k
      MI->ac_idx++;
1261
3.45k
#endif
1262
3.45k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1263
3.45k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val;
1264
3.45k
      MI->flat_insn->detail->arm64.op_count++;
1265
3.45k
    }
1266
1267
3.45k
    if (Shift != 0)
1268
1.34k
      printShifter(MI, OpNum + 1, O);
1269
3.45k
  }
1270
3.45k
}
1271
1272
static void printLogicalImm32(MCInst *MI, unsigned OpNum, SStream *O)
1273
3.81k
{
1274
3.81k
  int64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1275
1276
3.81k
  Val = AArch64_AM_decodeLogicalImmediate(Val, 32);
1277
3.81k
  printUInt32Bang(O, (int)Val);
1278
1279
3.81k
  if (MI->csh->detail) {
1280
3.81k
#ifndef CAPSTONE_DIET
1281
3.81k
    uint8_t access;
1282
1283
3.81k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1284
3.81k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1285
3.81k
    MI->ac_idx++;
1286
3.81k
#endif
1287
3.81k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1288
3.81k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val;
1289
3.81k
    MI->flat_insn->detail->arm64.op_count++;
1290
3.81k
  }
1291
3.81k
}
1292
1293
static void printLogicalImm64(MCInst *MI, unsigned OpNum, SStream *O)
1294
2.10k
{
1295
2.10k
  int64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1296
2.10k
  Val = AArch64_AM_decodeLogicalImmediate(Val, 64);
1297
1298
2.10k
  switch(MI->flat_insn->id) {
1299
1.04k
    default:
1300
1.04k
      printInt64Bang(O, Val);
1301
1.04k
      break;
1302
1303
256
    case ARM64_INS_ORR:
1304
758
    case ARM64_INS_AND:
1305
1.05k
    case ARM64_INS_EOR:
1306
1.05k
    case ARM64_INS_TST:
1307
      // do not print number in negative form
1308
1.05k
      if (Val >= 0 && Val <= HEX_THRESHOLD)
1309
50
        SStream_concat(O, "#%u", (int)Val);
1310
1.00k
      else
1311
1.00k
        SStream_concat(O, "#0x%"PRIx64, Val);
1312
1.05k
      break;
1313
2.10k
  }
1314
1315
2.10k
  if (MI->csh->detail) {
1316
2.10k
#ifndef CAPSTONE_DIET
1317
2.10k
    uint8_t access;
1318
1319
2.10k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1320
2.10k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1321
2.10k
    MI->ac_idx++;
1322
2.10k
#endif
1323
2.10k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1324
2.10k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int64_t)Val;
1325
2.10k
    MI->flat_insn->detail->arm64.op_count++;
1326
2.10k
  }
1327
2.10k
}
1328
1329
static void printShifter(MCInst *MI, unsigned OpNum, SStream *O)
1330
12.7k
{
1331
12.7k
  unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1332
1333
  // LSL #0 should not be printed.
1334
12.7k
  if (AArch64_AM_getShiftType(Val) == AArch64_AM_LSL &&
1335
6.47k
      AArch64_AM_getShiftValue(Val) == 0)
1336
929
    return;
1337
1338
11.7k
  SStream_concat(O, ", %s ", AArch64_AM_getShiftExtendName(AArch64_AM_getShiftType(Val)));
1339
11.7k
  printInt32BangDec(O, AArch64_AM_getShiftValue(Val));
1340
1341
11.7k
  if (MI->csh->detail) {
1342
11.7k
    arm64_shifter shifter = ARM64_SFT_INVALID;
1343
1344
11.7k
    switch(AArch64_AM_getShiftType(Val)) {
1345
0
      default:  // never reach
1346
5.54k
      case AArch64_AM_LSL:
1347
5.54k
        shifter = ARM64_SFT_LSL;
1348
5.54k
        break;
1349
1350
3.13k
      case AArch64_AM_LSR:
1351
3.13k
        shifter = ARM64_SFT_LSR;
1352
3.13k
        break;
1353
1354
1.38k
      case AArch64_AM_ASR:
1355
1.38k
        shifter = ARM64_SFT_ASR;
1356
1.38k
        break;
1357
1358
1.45k
      case AArch64_AM_ROR:
1359
1.45k
        shifter = ARM64_SFT_ROR;
1360
1.45k
        break;
1361
1362
284
      case AArch64_AM_MSL:
1363
284
        shifter = ARM64_SFT_MSL;
1364
284
        break;
1365
11.7k
    }
1366
1367
11.7k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.type = shifter;
1368
11.7k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.value = AArch64_AM_getShiftValue(Val);
1369
11.7k
  }
1370
11.7k
}
1371
1372
static void printShiftedRegister(MCInst *MI, unsigned OpNum, SStream *O)
1373
8.37k
{
1374
8.37k
  SStream_concat0(O, getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, OpNum)), AArch64_NoRegAltName));
1375
1376
8.37k
  if (MI->csh->detail) {
1377
8.37k
#ifndef CAPSTONE_DIET
1378
8.37k
    uint8_t access;
1379
8.37k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1380
8.37k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1381
8.37k
    MI->ac_idx++;
1382
8.37k
#endif
1383
8.37k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
1384
8.37k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
1385
8.37k
    MI->flat_insn->detail->arm64.op_count++;
1386
8.37k
  }
1387
1388
8.37k
  printShifter(MI, OpNum + 1, O);
1389
8.37k
}
1390
1391
static void printArithExtend(MCInst *MI, unsigned OpNum, SStream *O)
1392
3.58k
{
1393
3.58k
  unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1394
3.58k
  AArch64_AM_ShiftExtendType ExtType = AArch64_AM_getArithExtendType(Val);
1395
3.58k
  unsigned ShiftVal = AArch64_AM_getArithShiftValue(Val);
1396
1397
  // If the destination or first source register operand is [W]SP, print
1398
  // UXTW/UXTX as LSL, and if the shift amount is also zero, print nothing at
1399
  // all.
1400
3.58k
  if (ExtType == AArch64_AM_UXTW || ExtType == AArch64_AM_UXTX) {
1401
1.88k
    unsigned Dest = MCOperand_getReg(MCInst_getOperand(MI, 0));
1402
1.88k
    unsigned Src1 = MCOperand_getReg(MCInst_getOperand(MI, 1));
1403
1404
1.88k
    if (((Dest == AArch64_SP || Src1 == AArch64_SP) &&
1405
520
          ExtType == AArch64_AM_UXTX) ||
1406
1.68k
        ((Dest == AArch64_WSP || Src1 == AArch64_WSP) &&
1407
659
         ExtType == AArch64_AM_UXTW)) {
1408
262
      if (ShiftVal != 0) {
1409
262
        SStream_concat0(O, ", lsl ");
1410
262
        printInt32Bang(O, ShiftVal);
1411
1412
262
        if (MI->csh->detail) {
1413
262
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.type = ARM64_SFT_LSL;
1414
262
          MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.value = ShiftVal;
1415
262
        }
1416
262
      }
1417
1418
262
      return;
1419
262
    }
1420
1.88k
  }
1421
1422
3.32k
  SStream_concat(O, ", %s", AArch64_AM_getShiftExtendName(ExtType));
1423
1424
3.32k
  if (MI->csh->detail) {
1425
3.32k
    arm64_extender ext = ARM64_EXT_INVALID;
1426
3.32k
    switch(ExtType) {
1427
0
      default:  // never reach
1428
1429
277
      case AArch64_AM_UXTB:
1430
277
        ext = ARM64_EXT_UXTB;
1431
277
        break;
1432
1433
409
      case AArch64_AM_UXTH:
1434
409
        ext = ARM64_EXT_UXTH;
1435
409
        break;
1436
1437
493
      case AArch64_AM_UXTW:
1438
493
        ext = ARM64_EXT_UXTW;
1439
493
        break;
1440
1441
1.13k
      case AArch64_AM_UXTX:
1442
1.13k
        ext = ARM64_EXT_UXTX;
1443
1.13k
        break;
1444
1445
470
      case AArch64_AM_SXTB:
1446
470
        ext = ARM64_EXT_SXTB;
1447
470
        break;
1448
1449
217
      case AArch64_AM_SXTH:
1450
217
        ext = ARM64_EXT_SXTH;
1451
217
        break;
1452
1453
84
      case AArch64_AM_SXTW:
1454
84
        ext = ARM64_EXT_SXTW;
1455
84
        break;
1456
1457
244
      case AArch64_AM_SXTX:
1458
244
        ext = ARM64_EXT_SXTX;
1459
244
        break;
1460
3.32k
    }
1461
1462
3.32k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].ext = ext;
1463
3.32k
  }
1464
1465
3.32k
  if (ShiftVal != 0) {
1466
3.12k
    SStream_concat0(O, " ");
1467
3.12k
    printInt32Bang(O, ShiftVal);
1468
1469
3.12k
    if (MI->csh->detail) {
1470
3.12k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.type = ARM64_SFT_LSL;
1471
3.12k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].shift.value = ShiftVal;
1472
3.12k
    }
1473
3.12k
  }
1474
3.32k
}
1475
1476
static void printExtendedRegister(MCInst *MI, unsigned OpNum, SStream *O)
1477
2.49k
{
1478
2.49k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
1479
1480
2.49k
  SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName));
1481
1482
2.49k
  if (MI->csh->detail) {
1483
2.49k
#ifndef CAPSTONE_DIET
1484
2.49k
    uint8_t access;
1485
2.49k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1486
2.49k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1487
2.49k
    MI->ac_idx++;
1488
2.49k
#endif
1489
2.49k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
1490
2.49k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg;
1491
2.49k
    MI->flat_insn->detail->arm64.op_count++;
1492
2.49k
  }
1493
1494
2.49k
  printArithExtend(MI, OpNum + 1, O);
1495
2.49k
}
1496
1497
static void printMemExtendImpl(MCInst *MI, bool SignExtend, bool DoShift, unsigned Width,
1498
             char SrcRegKind, SStream *O)
1499
17.2k
{
1500
  // sxtw, sxtx, uxtw or lsl (== uxtx)
1501
17.2k
  bool IsLSL = !SignExtend && SrcRegKind == 'x';
1502
17.2k
  if (IsLSL) {
1503
6.00k
    SStream_concat0(O, "lsl");
1504
1505
6.00k
    if (MI->csh->detail) {
1506
6.00k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].shift.type = ARM64_SFT_LSL;
1507
6.00k
    }
1508
11.2k
  } else {
1509
11.2k
    SStream_concat(O, "%cxt%c", (SignExtend ? 's' : 'u'), SrcRegKind);
1510
1511
11.2k
    if (MI->csh->detail) {
1512
11.2k
      if (!SignExtend) {
1513
4.73k
        switch(SrcRegKind) {
1514
0
          default: break;
1515
0
          case 'b':
1516
0
               MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_UXTB;
1517
0
               break;
1518
0
          case 'h':
1519
0
               MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_UXTH;
1520
0
               break;
1521
4.73k
          case 'w':
1522
4.73k
               MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_UXTW;
1523
4.73k
               break;
1524
4.73k
        }
1525
6.46k
      } else {
1526
6.46k
          switch(SrcRegKind) {
1527
0
            default: break;
1528
0
            case 'b':
1529
0
              MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_SXTB;
1530
0
              break;
1531
0
            case 'h':
1532
0
              MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_SXTH;
1533
0
              break;
1534
5.44k
            case 'w':
1535
5.44k
              MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_SXTW;
1536
5.44k
              break;
1537
1.02k
            case 'x':
1538
1.02k
              MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].ext = ARM64_EXT_SXTX;
1539
1.02k
              break;
1540
6.46k
          }
1541
6.46k
      }
1542
11.2k
    }
1543
11.2k
  }
1544
1545
17.2k
  if (DoShift || IsLSL) {
1546
13.0k
    SStream_concat(O, " #%u", Log2_32(Width / 8));
1547
1548
13.0k
    if (MI->csh->detail) {
1549
13.0k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].shift.type = ARM64_SFT_LSL;
1550
13.0k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].shift.value = Log2_32(Width / 8);
1551
13.0k
    }
1552
13.0k
  }
1553
17.2k
}
1554
1555
static void printMemExtend(MCInst *MI, unsigned OpNum, SStream *O, char SrcRegKind, unsigned Width)
1556
3.18k
{
1557
3.18k
  unsigned SignExtend = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1558
3.18k
  unsigned DoShift = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1));
1559
1560
3.18k
  printMemExtendImpl(MI, SignExtend, DoShift, Width, SrcRegKind, O);
1561
3.18k
}
1562
1563
static void printRegWithShiftExtend(MCInst *MI, unsigned OpNum, SStream *O,
1564
            bool SignExtend, int ExtWidth,
1565
            char SrcRegKind, char Suffix)
1566
16.1k
{
1567
16.1k
  bool DoShift;
1568
1569
16.1k
  printOperand(MI, OpNum, O);
1570
1571
16.1k
  if (Suffix == 's' || Suffix == 'd')
1572
11.1k
    SStream_concat(O, ".%c", Suffix);
1573
1574
16.1k
  DoShift = ExtWidth != 8;
1575
16.1k
  if (SignExtend || DoShift || SrcRegKind == 'w') {
1576
14.0k
    SStream_concat0(O, ", ");
1577
14.0k
    printMemExtendImpl(MI, SignExtend, DoShift, ExtWidth, SrcRegKind, O);
1578
14.0k
  }
1579
16.1k
}
1580
1581
static void printCondCode(MCInst *MI, unsigned OpNum, SStream *O)
1582
3.02k
{
1583
3.02k
  AArch64CC_CondCode CC = (AArch64CC_CondCode)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1584
3.02k
  SStream_concat0(O, getCondCodeName(CC));
1585
1586
3.02k
  if (MI->csh->detail)
1587
3.02k
    MI->flat_insn->detail->arm64.cc = (arm64_cc)(CC + 1);
1588
3.02k
}
1589
1590
static void printInverseCondCode(MCInst *MI, unsigned OpNum, SStream *O)
1591
375
{
1592
375
  AArch64CC_CondCode CC = (AArch64CC_CondCode)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1593
375
  SStream_concat0(O, getCondCodeName(getInvertedCondCode(CC)));
1594
1595
375
  if (MI->csh->detail) {
1596
375
    MI->flat_insn->detail->arm64.cc = (arm64_cc)(getInvertedCondCode(CC) + 1);
1597
375
  }
1598
375
}
1599
1600
static void printImmScale(MCInst *MI, unsigned OpNum, SStream *O, int Scale)
1601
18.6k
{
1602
18.6k
  int64_t val = Scale * MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1603
1604
18.6k
  printInt64Bang(O, val);
1605
1606
18.6k
  if (MI->csh->detail) {
1607
18.6k
    if (MI->csh->doing_mem) {
1608
15.0k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = (int32_t)val;
1609
15.0k
    } else {
1610
3.59k
#ifndef CAPSTONE_DIET
1611
3.59k
      uint8_t access;
1612
1613
3.59k
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1614
3.59k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1615
3.59k
      MI->ac_idx++;
1616
3.59k
#endif
1617
3.59k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1618
3.59k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = val;
1619
3.59k
      MI->flat_insn->detail->arm64.op_count++;
1620
3.59k
    }
1621
18.6k
  }
1622
18.6k
}
1623
1624
static void printUImm12Offset(MCInst *MI, unsigned OpNum, SStream *O, unsigned Scale)
1625
8.59k
{
1626
8.59k
  MCOperand *MO = MCInst_getOperand(MI, OpNum);
1627
1628
8.59k
  if (MCOperand_isImm(MO)) {
1629
8.59k
    int64_t val = Scale * MCOperand_getImm(MO);
1630
8.59k
    printInt64Bang(O, val);
1631
1632
8.59k
    if (MI->csh->detail) {
1633
8.59k
      if (MI->csh->doing_mem) {
1634
8.59k
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].mem.disp = (int32_t)val;
1635
8.59k
      } else {
1636
0
#ifndef CAPSTONE_DIET
1637
0
        uint8_t access;
1638
1639
0
        access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1640
0
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1641
0
        MI->ac_idx++;
1642
0
#endif
1643
0
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1644
0
        MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = (int)val;
1645
0
        MI->flat_insn->detail->arm64.op_count++;
1646
0
      }
1647
8.59k
    }
1648
8.59k
  }
1649
8.59k
}
1650
1651
#if 0
1652
static void printAMIndexedWB(MCInst *MI, unsigned OpNum, SStream *O, unsigned int Scale)
1653
{
1654
  MCOperand *MO = MCInst_getOperand(MI, OpNum + 1);
1655
1656
  SStream_concat(O, "[%s", getRegisterName(MCOperand_getReg(MCInst_getOperand(MI, OpNum)), AArch64_NoRegAltName));
1657
1658
  if (MCOperand_isImm(MO)) {
1659
    int64_t val = Scale * MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1660
    printInt64Bang(O, val);
1661
  // } else {
1662
  //   // assert(MO1.isExpr() && "Unexpected operand type!");
1663
  //   SStream_concat0(O, ", ");
1664
  //   MO1.getExpr()->print(O, &MAI);
1665
  }
1666
1667
  SStream_concat0(O, "]");
1668
}
1669
#endif
1670
1671
// IsSVEPrefetch = false
1672
static void printPrefetchOp(MCInst *MI, unsigned OpNum, SStream *O, bool IsSVEPrefetch)
1673
6.95k
{
1674
6.95k
  unsigned prfop = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1675
1676
6.95k
  if (IsSVEPrefetch) {
1677
5.34k
    const SVEPRFM *PRFM = lookupSVEPRFMByEncoding(prfop);
1678
5.34k
    if (PRFM)
1679
4.64k
      SStream_concat0(O, PRFM->Name);
1680
1681
5.34k
    return;
1682
5.34k
  } else {
1683
1.60k
    const PRFM *PRFM = lookupPRFMByEncoding(prfop);
1684
1.60k
    if (PRFM)
1685
513
      SStream_concat0(O, PRFM->Name);
1686
1687
1.60k
    return;
1688
1.60k
  }
1689
1690
  // FIXME: set OpcodePub?
1691
1692
0
  printInt32Bang(O, prfop);
1693
1694
0
  if (MI->csh->detail) {
1695
0
#ifndef CAPSTONE_DIET
1696
0
    uint8_t access;
1697
0
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1698
0
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1699
0
    MI->ac_idx++;
1700
0
#endif
1701
0
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
1702
0
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = prfop;
1703
0
    MI->flat_insn->detail->arm64.op_count++;
1704
0
  }
1705
0
}
1706
1707
static void printPSBHintOp(MCInst *MI, unsigned OpNum, SStream *O)
1708
650
{
1709
650
  MCOperand *Op = MCInst_getOperand(MI, OpNum);
1710
650
  unsigned int psbhintop = MCOperand_getImm(Op);
1711
1712
650
  const PSB *PSB = lookupPSBByEncoding(psbhintop);
1713
650
  if (PSB)
1714
650
    SStream_concat0(O, PSB->Name);
1715
0
  else
1716
0
    printUInt32Bang(O, psbhintop);
1717
650
}
1718
1719
685
static void printBTIHintOp(MCInst *MI, unsigned OpNum, SStream *O) {
1720
685
  unsigned btihintop = MCOperand_getImm(MCInst_getOperand(MI, OpNum)) ^ 32;
1721
1722
685
  const BTI *BTI = lookupBTIByEncoding(btihintop);
1723
685
  if (BTI)
1724
685
  SStream_concat0(O, BTI->Name);
1725
0
  else
1726
0
  printUInt32Bang(O, btihintop);
1727
685
}
1728
1729
static void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1730
1.76k
{
1731
1.76k
  MCOperand *MO = MCInst_getOperand(MI, OpNum);
1732
1.76k
  float FPImm = MCOperand_isFPImm(MO) ? MCOperand_getFPImm(MO) : AArch64_AM_getFPImmFloat((int)MCOperand_getImm(MO));
1733
1734
  // 8 decimal places are enough to perfectly represent permitted floats.
1735
#if defined(_KERNEL_MODE)
1736
  // Issue #681: Windows kernel does not support formatting float point
1737
  SStream_concat0(O, "#<float_point_unsupported>");
1738
#else
1739
1.76k
  SStream_concat(O, "#%.8f", FPImm);
1740
1.76k
#endif
1741
1742
1.76k
  if (MI->csh->detail) {
1743
1.76k
#ifndef CAPSTONE_DIET
1744
1.76k
    uint8_t access;
1745
1746
1.76k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1747
1.76k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1748
1.76k
    MI->ac_idx++;
1749
1.76k
#endif
1750
1.76k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_FP;
1751
1.76k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].fp = FPImm;
1752
1.76k
    MI->flat_insn->detail->arm64.op_count++;
1753
1.76k
  }
1754
1.76k
}
1755
1756
//static unsigned getNextVectorRegister(unsigned Reg, unsigned Stride = 1)
1757
static unsigned getNextVectorRegister(unsigned Reg, unsigned Stride)
1758
184k
{
1759
368k
  while (Stride--) {
1760
184k
    if (Reg >= AArch64_Q0 && Reg <= AArch64_Q30) // AArch64_Q0 .. AArch64_Q30
1761
152k
      Reg += 1;
1762
31.4k
    else if (Reg == AArch64_Q31) // Vector lists can wrap around.
1763
7.72k
      Reg = AArch64_Q0;
1764
23.6k
    else if (Reg >= AArch64_Z0 && Reg <= AArch64_Z30) // AArch64_Z0 .. AArch64_Z30
1765
23.2k
      Reg += 1;
1766
494
    else if (Reg == AArch64_Z31) // Vector lists can wrap around.
1767
494
      Reg = AArch64_Z0;
1768
184k
  }
1769
1770
184k
  return Reg;
1771
184k
}
1772
1773
static void printGPRSeqPairsClassOperand(MCInst *MI, unsigned OpNum, SStream *O, unsigned int size)
1774
5.23k
{
1775
  // static_assert(size == 64 || size == 32,
1776
  //    "Template parameter must be either 32 or 64");
1777
5.23k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
1778
5.23k
  unsigned Sube = (size == 32) ? AArch64_sube32 : AArch64_sube64;
1779
5.23k
  unsigned Subo = (size == 32) ? AArch64_subo32 : AArch64_subo64;
1780
5.23k
  unsigned Even = MCRegisterInfo_getSubReg(MI->MRI, Reg, Sube);
1781
5.23k
  unsigned Odd = MCRegisterInfo_getSubReg(MI->MRI, Reg, Subo);
1782
1783
5.23k
  SStream_concat(O, "%s, %s", getRegisterName(Even, AArch64_NoRegAltName),
1784
5.23k
      getRegisterName(Odd, AArch64_NoRegAltName));
1785
1786
5.23k
  if (MI->csh->detail) {
1787
5.23k
#ifndef CAPSTONE_DIET
1788
5.23k
    uint8_t access;
1789
1790
5.23k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1791
5.23k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1792
5.23k
    MI->ac_idx++;
1793
5.23k
#endif
1794
1795
5.23k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
1796
5.23k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Even;
1797
5.23k
    MI->flat_insn->detail->arm64.op_count++;
1798
1799
5.23k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
1800
5.23k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Odd;
1801
5.23k
    MI->flat_insn->detail->arm64.op_count++;
1802
5.23k
  }
1803
5.23k
}
1804
1805
static void printVectorList(MCInst *MI, unsigned OpNum, SStream *O,
1806
    char *LayoutSuffix, MCRegisterInfo *MRI, arm64_vas vas)
1807
76.5k
{
1808
1.14M
#define GETREGCLASS_CONTAIN0(_class, _reg) MCRegisterClass_contains(MCRegisterInfo_getRegClass(MRI, _class), _reg)
1809
76.5k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
1810
76.5k
  unsigned NumRegs = 1, FirstReg, i;
1811
1812
76.5k
  SStream_concat0(O, "{");
1813
1814
  // Work out how many registers there are in the list (if there is an actual
1815
  // list).
1816
76.5k
  if (GETREGCLASS_CONTAIN0(AArch64_DDRegClassID , Reg) ||
1817
72.8k
      GETREGCLASS_CONTAIN0(AArch64_ZPR2RegClassID, Reg) ||
1818
70.3k
      GETREGCLASS_CONTAIN0(AArch64_QQRegClassID, Reg))
1819
15.6k
    NumRegs = 2;
1820
60.8k
  else if (GETREGCLASS_CONTAIN0(AArch64_DDDRegClassID, Reg) ||
1821
58.7k
      GETREGCLASS_CONTAIN0(AArch64_ZPR3RegClassID, Reg) ||
1822
57.5k
      GETREGCLASS_CONTAIN0(AArch64_QQQRegClassID, Reg))
1823
17.9k
    NumRegs = 3;
1824
42.8k
  else if (GETREGCLASS_CONTAIN0(AArch64_DDDDRegClassID, Reg) ||
1825
40.1k
      GETREGCLASS_CONTAIN0(AArch64_ZPR4RegClassID, Reg) ||
1826
38.8k
      GETREGCLASS_CONTAIN0(AArch64_QQQQRegClassID, Reg))
1827
18.7k
    NumRegs = 4;
1828
1829
  // Now forget about the list and find out what the first register is.
1830
76.5k
  if ((FirstReg = MCRegisterInfo_getSubReg(MRI, Reg, AArch64_dsub0)))
1831
8.59k
    Reg = FirstReg;
1832
67.9k
  else if ((FirstReg = MCRegisterInfo_getSubReg(MRI, Reg, AArch64_qsub0)))
1833
38.8k
    Reg = FirstReg;
1834
29.0k
  else if ((FirstReg = MCRegisterInfo_getSubReg(MRI, Reg, AArch64_zsub0)))
1835
4.90k
    Reg = FirstReg;
1836
1837
  // If it's a D-reg, we need to promote it to the equivalent Q-reg before
1838
  // printing (otherwise getRegisterName fails).
1839
76.5k
  if (GETREGCLASS_CONTAIN0(AArch64_FPR64RegClassID, Reg)) {
1840
10.4k
    const MCRegisterClass *FPR128RC = MCRegisterInfo_getRegClass(MRI, AArch64_FPR128RegClassID);
1841
10.4k
    Reg = MCRegisterInfo_getMatchingSuperReg(MRI, Reg, AArch64_dsub, FPR128RC);
1842
10.4k
  }
1843
1844
260k
  for (i = 0; i < NumRegs; ++i, Reg = getNextVectorRegister(Reg, 1)) {
1845
184k
    bool isZReg = GETREGCLASS_CONTAIN0(AArch64_ZPRRegClassID, Reg);
1846
184k
    if (isZReg)
1847
23.6k
      SStream_concat(O, "%s%s", getRegisterName(Reg, AArch64_NoRegAltName), LayoutSuffix);
1848
160k
    else
1849
160k
      SStream_concat(O, "%s%s", getRegisterName(Reg, AArch64_vreg), LayoutSuffix);
1850
1851
184k
    if (MI->csh->detail) {
1852
184k
#ifndef CAPSTONE_DIET
1853
184k
      uint8_t access;
1854
1855
184k
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
1856
184k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
1857
184k
      MI->ac_idx++;
1858
184k
#endif
1859
184k
      unsigned regForDetail = isZReg ? Reg : AArch64_map_vregister(Reg);
1860
184k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
1861
184k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = regForDetail;
1862
184k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].vas = vas;
1863
184k
      MI->flat_insn->detail->arm64.op_count++;
1864
184k
    }
1865
1866
184k
    if (i + 1 != NumRegs)
1867
107k
      SStream_concat0(O, ", ");
1868
184k
  }
1869
1870
76.5k
  SStream_concat0(O, "}");
1871
76.5k
}
1872
1873
static void printTypedVectorList(MCInst *MI, unsigned OpNum, SStream *O, unsigned NumLanes, char LaneKind)
1874
76.5k
{
1875
76.5k
  char Suffix[32];
1876
76.5k
  arm64_vas vas = 0;
1877
1878
76.5k
  if (NumLanes) {
1879
31.1k
    cs_snprintf(Suffix, sizeof(Suffix), ".%u%c", NumLanes, LaneKind);
1880
1881
31.1k
    switch(LaneKind) {
1882
0
      default: break;
1883
9.57k
      case 'b':
1884
9.57k
        switch(NumLanes) {
1885
0
          default: break;
1886
0
          case 1:
1887
0
               vas = ARM64_VAS_1B;
1888
0
               break;
1889
0
          case 4:
1890
0
               vas = ARM64_VAS_4B;
1891
0
               break;
1892
3.02k
          case 8:
1893
3.02k
               vas = ARM64_VAS_8B;
1894
3.02k
               break;
1895
6.55k
          case 16:
1896
6.55k
               vas = ARM64_VAS_16B;
1897
6.55k
               break;
1898
9.57k
        }
1899
9.57k
        break;
1900
9.57k
      case 'h':
1901
8.41k
        switch(NumLanes) {
1902
0
          default: break;
1903
0
          case 1:
1904
0
               vas = ARM64_VAS_1H;
1905
0
               break;
1906
0
          case 2:
1907
0
               vas = ARM64_VAS_2H;
1908
0
               break;
1909
3.08k
          case 4:
1910
3.08k
               vas = ARM64_VAS_4H;
1911
3.08k
               break;
1912
5.32k
          case 8:
1913
5.32k
               vas = ARM64_VAS_8H;
1914
5.32k
               break;
1915
8.41k
        }
1916
8.41k
        break;
1917
8.41k
      case 's':
1918
7.84k
        switch(NumLanes) {
1919
0
          default: break;
1920
0
          case 1:
1921
0
               vas = ARM64_VAS_1S;
1922
0
               break;
1923
2.11k
          case 2:
1924
2.11k
               vas = ARM64_VAS_2S;
1925
2.11k
               break;
1926
5.73k
          case 4:
1927
5.73k
               vas = ARM64_VAS_4S;
1928
5.73k
               break;
1929
7.84k
        }
1930
7.84k
        break;
1931
7.84k
      case 'd':
1932
5.28k
        switch(NumLanes) {
1933
0
          default: break;
1934
2.18k
          case 1:
1935
2.18k
               vas = ARM64_VAS_1D;
1936
2.18k
               break;
1937
3.09k
          case 2:
1938
3.09k
               vas = ARM64_VAS_2D;
1939
3.09k
               break;
1940
5.28k
        }
1941
5.28k
        break;
1942
5.28k
      case 'q':
1943
0
        switch(NumLanes) {
1944
0
          default: break;
1945
0
          case 1:
1946
0
               vas = ARM64_VAS_1Q;
1947
0
               break;
1948
0
        }
1949
0
        break;
1950
31.1k
    }
1951
45.4k
  } else {
1952
45.4k
    cs_snprintf(Suffix, sizeof(Suffix), ".%c", LaneKind);
1953
1954
45.4k
    switch(LaneKind) {
1955
0
      default: break;
1956
10.1k
      case 'b':
1957
10.1k
           vas = ARM64_VAS_1B;
1958
10.1k
           break;
1959
9.38k
      case 'h':
1960
9.38k
           vas = ARM64_VAS_1H;
1961
9.38k
           break;
1962
14.5k
      case 's':
1963
14.5k
           vas = ARM64_VAS_1S;
1964
14.5k
           break;
1965
11.3k
      case 'd':
1966
11.3k
           vas = ARM64_VAS_1D;
1967
11.3k
           break;
1968
0
      case 'q':
1969
0
           vas = ARM64_VAS_1Q;
1970
0
           break;
1971
45.4k
    }
1972
45.4k
  }
1973
1974
76.5k
  printVectorList(MI, OpNum, O, Suffix, MI->MRI, vas);
1975
76.5k
}
1976
1977
static void printVectorIndex(MCInst *MI, unsigned OpNum, SStream *O)
1978
40.7k
{
1979
40.7k
  SStream_concat0(O, "[");
1980
40.7k
  printInt32(O, (int)MCOperand_getImm(MCInst_getOperand(MI, OpNum)));
1981
40.7k
  SStream_concat0(O, "]");
1982
1983
40.7k
  if (MI->csh->detail) {
1984
40.7k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count - 1].vector_index = (int)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
1985
40.7k
  }
1986
40.7k
}
1987
1988
static void printAlignedLabel(MCInst *MI, unsigned OpNum, SStream *O)
1989
12.4k
{
1990
12.4k
  MCOperand *Op = MCInst_getOperand(MI, OpNum);
1991
1992
  // If the label has already been resolved to an immediate offset (say, when
1993
  // we're running the disassembler), just print the immediate.
1994
12.4k
  if (MCOperand_isImm(Op)) {
1995
12.4k
    uint64_t imm = (MCOperand_getImm(Op) * 4) + MI->address;
1996
12.4k
    printUInt64Bang(O, imm);
1997
1998
12.4k
    if (MI->csh->detail) {
1999
12.4k
#ifndef CAPSTONE_DIET
2000
12.4k
      uint8_t access;
2001
2002
12.4k
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2003
12.4k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2004
12.4k
      MI->ac_idx++;
2005
12.4k
#endif
2006
12.4k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
2007
12.4k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = imm;
2008
12.4k
      MI->flat_insn->detail->arm64.op_count++;
2009
12.4k
    }
2010
12.4k
  }
2011
12.4k
}
2012
2013
static void printAdrpLabel(MCInst *MI, unsigned OpNum, SStream *O)
2014
2.63k
{
2015
2.63k
  MCOperand *Op = MCInst_getOperand(MI, OpNum);
2016
2017
2.63k
  if (MCOperand_isImm(Op)) {
2018
    // ADRP sign extends a 21-bit offset, shifts it left by 12
2019
    // and adds it to the value of the PC with its bottom 12 bits cleared
2020
2.63k
    uint64_t imm = (MCOperand_getImm(Op) * 0x1000) + (MI->address & ~0xfff);
2021
2.63k
    printUInt64Bang(O, imm);
2022
2023
2.63k
    if (MI->csh->detail) {
2024
2.63k
#ifndef CAPSTONE_DIET
2025
2.63k
      uint8_t access;
2026
2027
2.63k
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2028
2.63k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2029
2.63k
      MI->ac_idx++;
2030
2.63k
#endif
2031
2.63k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
2032
2.63k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = imm;
2033
2.63k
      MI->flat_insn->detail->arm64.op_count++;
2034
2.63k
    }
2035
2.63k
  }
2036
2.63k
}
2037
2038
static void printBarrierOption(MCInst *MI, unsigned OpNum, SStream *O)
2039
185
{
2040
185
  unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2041
185
  unsigned Opcode = MCInst_getOpcode(MI);
2042
185
  const char *Name = NULL;
2043
2044
185
  if (Opcode == AArch64_ISB) {
2045
36
    const ISB *ISB = lookupISBByEncoding(Val);
2046
36
    Name = ISB ? ISB->Name : NULL;
2047
149
  } else if (Opcode == AArch64_TSB) {
2048
0
    const TSB *TSB = lookupTSBByEncoding(Val);
2049
0
    Name = TSB ? TSB->Name : NULL;
2050
149
  } else {
2051
149
    const DB *DB = lookupDBByEncoding(Val);
2052
149
    Name = DB ? DB->Name : NULL;
2053
149
  }
2054
2055
185
  if (Name) {
2056
108
    SStream_concat0(O, Name);
2057
2058
108
    if (MI->csh->detail) {
2059
108
#ifndef CAPSTONE_DIET
2060
108
      uint8_t access;
2061
2062
108
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2063
108
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2064
108
      MI->ac_idx++;
2065
108
#endif
2066
108
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_BARRIER;
2067
108
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].barrier = Val;
2068
108
      MI->flat_insn->detail->arm64.op_count++;
2069
108
    }
2070
108
  } else {
2071
77
    printUInt32Bang(O, Val);
2072
2073
77
    if (MI->csh->detail) {
2074
77
#ifndef CAPSTONE_DIET
2075
77
      uint8_t access;
2076
2077
77
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2078
77
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2079
77
      MI->ac_idx++;
2080
77
#endif
2081
77
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
2082
77
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val;
2083
77
      MI->flat_insn->detail->arm64.op_count++;
2084
77
    }
2085
77
  }
2086
185
}
2087
2088
72
static void printBarriernXSOption(MCInst *MI, unsigned OpNo, SStream *O) {
2089
72
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, OpNo));
2090
  // assert(MI->getOpcode() == AArch64::DSBnXS);
2091
2092
72
  const char *Name = NULL;
2093
72
  const DBnXS *DB = lookupDBnXSByEncoding(Val);
2094
72
  Name = DB ? DB->Name : NULL;
2095
2096
72
  if (Name) {
2097
72
    SStream_concat0(O, Name);
2098
2099
72
    if (MI->csh->detail) {
2100
72
#ifndef CAPSTONE_DIET
2101
72
      uint8_t access;
2102
2103
72
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2104
72
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2105
72
      MI->ac_idx++;
2106
72
#endif
2107
72
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_BARRIER;
2108
72
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].barrier = Val;
2109
72
      MI->flat_insn->detail->arm64.op_count++;
2110
72
    }
2111
72
  }
2112
0
  else {
2113
0
    printUInt32Bang(O, Val);
2114
2115
0
    if (MI->csh->detail) {
2116
0
#ifndef CAPSTONE_DIET
2117
0
      uint8_t access;
2118
2119
0
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2120
0
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2121
0
      MI->ac_idx++;
2122
0
#endif
2123
0
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
2124
0
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val;
2125
0
      MI->flat_insn->detail->arm64.op_count++;
2126
0
    }
2127
0
  }
2128
72
}
2129
2130
static void printMRSSystemRegister(MCInst *MI, unsigned OpNum, SStream *O)
2131
1.64k
{
2132
1.64k
  unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2133
1.64k
  const SysReg *Reg = lookupSysRegByEncoding(Val);
2134
2135
  // Horrible hack for the one register that has identical encodings but
2136
  // different names in MSR and MRS. Because of this, one of MRS and MSR is
2137
  // going to get the wrong entry
2138
1.64k
  if (Val == ARM64_SYSREG_DBGDTRRX_EL0) {
2139
365
    SStream_concat0(O, "dbgdtrrx_el0");
2140
2141
365
    if (MI->csh->detail) {
2142
365
#ifndef CAPSTONE_DIET
2143
365
      uint8_t access;
2144
2145
365
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2146
365
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2147
365
      MI->ac_idx++;
2148
365
#endif
2149
2150
365
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS;
2151
365
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Val;
2152
365
      MI->flat_insn->detail->arm64.op_count++;
2153
365
    }
2154
2155
365
    return;
2156
365
  }
2157
2158
  // Another hack for a register which has an alternative name which is not an alias,
2159
  // and is not in the Armv9-A documentation.
2160
1.27k
  if( Val == ARM64_SYSREG_VSCTLR_EL2){
2161
37
    SStream_concat0(O, "ttbr0_el2");
2162
2163
37
    if (MI->csh->detail) {
2164
37
#ifndef CAPSTONE_DIET
2165
37
      uint8_t access;
2166
2167
37
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2168
37
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2169
37
      MI->ac_idx++;
2170
37
#endif
2171
2172
37
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS;
2173
37
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Val;
2174
37
      MI->flat_insn->detail->arm64.op_count++;
2175
37
    }
2176
2177
37
    return;
2178
37
  }
2179
2180
  // if (Reg && Reg->Readable && Reg->haveFeatures(STI.getFeatureBits()))
2181
1.23k
  if (Reg && Reg->Readable) {
2182
60
    SStream_concat0(O, Reg->Name);
2183
2184
60
    if (MI->csh->detail) {
2185
60
#ifndef CAPSTONE_DIET
2186
60
      uint8_t access;
2187
2188
60
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2189
60
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2190
60
      MI->ac_idx++;
2191
60
#endif
2192
2193
60
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS;
2194
60
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Reg->Encoding;
2195
60
      MI->flat_insn->detail->arm64.op_count++;
2196
60
    }
2197
1.17k
  } else {
2198
1.17k
    char result[128];
2199
2200
1.17k
    AArch64SysReg_genericRegisterString(Val, result);
2201
1.17k
    SStream_concat0(O, result);
2202
2203
1.17k
    if (MI->csh->detail) {
2204
1.17k
#ifndef CAPSTONE_DIET
2205
1.17k
      uint8_t access;
2206
1.17k
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2207
1.17k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2208
1.17k
      MI->ac_idx++;
2209
1.17k
#endif
2210
1.17k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG_MRS;
2211
1.17k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Val;
2212
1.17k
      MI->flat_insn->detail->arm64.op_count++;
2213
1.17k
    }
2214
1.17k
  }
2215
1.23k
}
2216
2217
static void printMSRSystemRegister(MCInst *MI, unsigned OpNum, SStream *O)
2218
3.66k
{
2219
3.66k
  unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2220
3.66k
  const SysReg *Reg = lookupSysRegByEncoding(Val);
2221
2222
  // Horrible hack for the one register that has identical encodings but
2223
  // different names in MSR and MRS. Because of this, one of MRS and MSR is
2224
  // going to get the wrong entry
2225
3.66k
  if (Val == ARM64_SYSREG_DBGDTRTX_EL0) {
2226
6
    SStream_concat0(O, "dbgdtrtx_el0");
2227
2228
6
    if (MI->csh->detail) {
2229
6
#ifndef CAPSTONE_DIET
2230
6
      uint8_t access;
2231
2232
6
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2233
6
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2234
6
      MI->ac_idx++;
2235
6
#endif
2236
2237
6
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS;
2238
6
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Val;
2239
6
      MI->flat_insn->detail->arm64.op_count++;
2240
6
    }
2241
2242
6
    return;
2243
6
  }
2244
2245
  // Another hack for a register which has an alternative name which is not an alias,
2246
  // and is not in the Armv9-A documentation.
2247
3.65k
  if( Val == ARM64_SYSREG_VSCTLR_EL2){
2248
292
    SStream_concat0(O, "ttbr0_el2");
2249
2250
292
    if (MI->csh->detail) {
2251
292
#ifndef CAPSTONE_DIET
2252
292
      uint8_t access;
2253
2254
292
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2255
292
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2256
292
      MI->ac_idx++;
2257
292
#endif
2258
2259
292
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS;
2260
292
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Val;
2261
292
      MI->flat_insn->detail->arm64.op_count++;
2262
292
    }
2263
2264
292
    return;
2265
292
  }
2266
2267
  // if (Reg && Reg->Writeable && Reg->haveFeatures(STI.getFeatureBits()))
2268
3.36k
  if (Reg && Reg->Writeable) {
2269
175
    SStream_concat0(O, Reg->Name);
2270
2271
175
    if (MI->csh->detail) {
2272
175
#ifndef CAPSTONE_DIET
2273
175
      uint8_t access;
2274
2275
175
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2276
175
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2277
175
      MI->ac_idx++;
2278
175
#endif
2279
2280
175
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SYS;
2281
175
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = Reg->Encoding;
2282
175
      MI->flat_insn->detail->arm64.op_count++;
2283
175
    }
2284
3.18k
  } else {
2285
3.18k
    char result[128];
2286
2287
3.18k
    AArch64SysReg_genericRegisterString(Val, result);
2288
3.18k
    SStream_concat0(O, result);
2289
2290
3.18k
    if (MI->csh->detail) {
2291
3.18k
#ifndef CAPSTONE_DIET
2292
3.18k
      uint8_t access;
2293
3.18k
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2294
3.18k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2295
3.18k
      MI->ac_idx++;
2296
3.18k
#endif
2297
3.18k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG_MRS;
2298
3.18k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Val;
2299
3.18k
      MI->flat_insn->detail->arm64.op_count++;
2300
3.18k
    }
2301
3.18k
  }
2302
3.36k
}
2303
2304
static void printSystemPStateField(MCInst *MI, unsigned OpNum, SStream *O)
2305
431
{
2306
431
  unsigned Val = (unsigned)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2307
2308
431
  const PState *PState = lookupPStateByEncoding(Val);
2309
2310
431
  if (PState) {
2311
431
    SStream_concat0(O, PState->Name);
2312
2313
431
    if (MI->csh->detail) {
2314
431
#ifndef CAPSTONE_DIET
2315
431
      uint8_t access;
2316
431
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2317
431
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2318
431
      MI->ac_idx++;
2319
431
#endif
2320
431
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_PSTATE;
2321
431
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].pstate = Val;
2322
431
      MI->flat_insn->detail->arm64.op_count++;
2323
431
    }
2324
431
  } else {
2325
0
    printUInt32Bang(O, Val);
2326
2327
0
    if (MI->csh->detail) {
2328
0
#ifndef CAPSTONE_DIET
2329
0
      unsigned char access;
2330
2331
0
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2332
0
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2333
0
      MI->ac_idx++;
2334
0
#endif
2335
2336
0
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
2337
0
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val;
2338
0
      MI->flat_insn->detail->arm64.op_count++;
2339
0
    }
2340
0
  }
2341
431
}
2342
2343
static void printSIMDType10Operand(MCInst *MI, unsigned OpNum, SStream *O)
2344
1.21k
{
2345
1.21k
  uint8_t RawVal = (uint8_t)MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2346
1.21k
  uint64_t Val = AArch64_AM_decodeAdvSIMDModImmType10(RawVal);
2347
2348
1.21k
  SStream_concat(O, "#%#016llx", Val);
2349
2350
1.21k
  if (MI->csh->detail) {
2351
1.21k
#ifndef CAPSTONE_DIET
2352
1.21k
    unsigned char access;
2353
2354
1.21k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2355
1.21k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2356
1.21k
    MI->ac_idx++;
2357
1.21k
#endif
2358
1.21k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_IMM;
2359
1.21k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].imm = Val;
2360
1.21k
    MI->flat_insn->detail->arm64.op_count++;
2361
1.21k
  }
2362
1.21k
}
2363
2364
static void printComplexRotationOp(MCInst *MI, unsigned OpNum, SStream *O, int64_t Angle, int64_t Remainder)
2365
2.33k
{
2366
2.33k
  unsigned int Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2367
2.33k
  printInt64Bang(O, (Val * Angle) + Remainder);
2368
2.33k
  op_addImm(MI, (Val * Angle) + Remainder);
2369
2.33k
}
2370
2371
static void printSVCROp(MCInst *MI, unsigned OpNum, SStream *O)
2372
0
{
2373
0
  MCOperand *MO = MCInst_getOperand(MI, OpNum);
2374
    // assert(MCOperand_isImm(MO) && "Unexpected operand type!");
2375
0
    unsigned svcrop = MCOperand_getImm(MO);
2376
0
  const SVCR *svcr = lookupSVCRByEncoding(svcrop);
2377
    // assert(svcr && "Unexpected SVCR operand!");
2378
0
  SStream_concat0(O, svcr->Name);
2379
2380
0
  if (MI->csh->detail) {
2381
0
#ifndef CAPSTONE_DIET
2382
0
    uint8_t access;
2383
2384
0
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2385
0
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2386
0
    MI->ac_idx++;
2387
0
#endif
2388
2389
0
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_SVCR;
2390
0
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].sys = (unsigned)ARM64_SYSREG_SVCR;
2391
0
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].svcr = svcr->Encoding;
2392
0
    MI->flat_insn->detail->arm64.op_count++;
2393
0
  }
2394
0
}
2395
2396
static void printMatrix(MCInst *MI, unsigned OpNum, SStream *O, int EltSize)
2397
232
{
2398
232
  MCOperand *RegOp = MCInst_getOperand(MI, OpNum);
2399
    // assert(MCOperand_isReg(RegOp) && "Unexpected operand type!");
2400
232
  unsigned Reg = MCOperand_getReg(RegOp);
2401
2402
232
  SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName));
2403
232
  const char *sizeStr = "";
2404
232
    switch (EltSize) {
2405
232
    case 0:
2406
232
    sizeStr = "";
2407
232
      break;
2408
0
    case 8:
2409
0
      sizeStr = ".b";
2410
0
      break;
2411
0
    case 16:
2412
0
      sizeStr = ".h";
2413
0
      break;
2414
0
    case 32:
2415
0
      sizeStr = ".s";
2416
0
      break;
2417
0
    case 64:
2418
0
      sizeStr = ".d";
2419
0
      break;
2420
0
    case 128:
2421
0
      sizeStr = ".q";
2422
0
      break;
2423
0
    default:
2424
0
    break;
2425
    //   llvm_unreachable("Unsupported element size");
2426
232
    }
2427
232
  SStream_concat0(O, sizeStr);
2428
2429
232
  if (MI->csh->detail) {
2430
232
#ifndef CAPSTONE_DIET
2431
232
    uint8_t access;
2432
2433
232
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2434
232
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2435
232
    MI->ac_idx++;
2436
232
#endif
2437
2438
232
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
2439
232
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg;
2440
232
    MI->flat_insn->detail->arm64.op_count++;
2441
232
  }
2442
232
}
2443
2444
static void printMatrixIndex(MCInst *MI, unsigned OpNum, SStream *O)
2445
6.82k
{
2446
6.82k
  int64_t imm = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2447
6.82k
  printInt64(O, imm);
2448
2449
6.82k
  if (MI->csh->detail) {
2450
6.82k
    if (MI->csh->doing_SME_Index) {
2451
      // Access op_count-1 as We want to add info to previous operand, not create a new one
2452
6.82k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count-1].sme_index.disp = imm;
2453
6.82k
    }
2454
6.82k
  }
2455
6.82k
}
2456
2457
static void printMatrixTile(MCInst *MI, unsigned OpNum, SStream *O)
2458
1.66k
{
2459
1.66k
  MCOperand *RegOp = MCInst_getOperand(MI, OpNum);
2460
    // assert(MCOperand_isReg(RegOp) && "Unexpected operand type!");
2461
1.66k
  unsigned Reg = MCOperand_getReg(RegOp);
2462
1.66k
    SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName));
2463
2464
1.66k
  if (MI->csh->detail) {
2465
1.66k
#ifndef CAPSTONE_DIET
2466
1.66k
    uint8_t access;
2467
2468
1.66k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2469
1.66k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2470
1.66k
    MI->ac_idx++;
2471
1.66k
#endif
2472
2473
1.66k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
2474
1.66k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg;
2475
1.66k
    MI->flat_insn->detail->arm64.op_count++;
2476
1.66k
  }
2477
1.66k
}
2478
2479
static void printMatrixTileVector(MCInst *MI, unsigned OpNum, SStream *O, bool IsVertical)
2480
5.97k
{
2481
5.97k
  MCOperand *RegOp = MCInst_getOperand(MI, OpNum);
2482
    // assert(MCOperand_isReg(RegOp) && "Unexpected operand type!");
2483
5.97k
  unsigned Reg = MCOperand_getReg(RegOp);
2484
5.97k
#ifndef CAPSTONE_DIET
2485
5.97k
  const char *RegName = getRegisterName(Reg, AArch64_NoRegAltName);
2486
2487
5.97k
  const size_t strLn = strlen(RegName);
2488
  // +2 for extra chars, + 1 for null char \0
2489
5.97k
  char *RegNameNew = cs_mem_malloc(sizeof(char) * (strLn + 2 + 1));
2490
5.97k
  int index = 0, i;
2491
48.3k
  for (i = 0; i < (strLn + 2); i++){
2492
42.4k
    if(RegName[i] != '.'){
2493
36.4k
      RegNameNew[index] = RegName[i];
2494
36.4k
      index++;
2495
36.4k
    }
2496
5.97k
    else{
2497
5.97k
      RegNameNew[index] = IsVertical ? 'v' : 'h';
2498
5.97k
      RegNameNew[index + 1] = '.';
2499
5.97k
      index += 2;
2500
5.97k
    }
2501
42.4k
  }
2502
5.97k
  SStream_concat0(O, RegNameNew);
2503
5.97k
#endif
2504
2505
5.97k
  if (MI->csh->detail) {
2506
5.97k
#ifndef CAPSTONE_DIET
2507
5.97k
    uint8_t access;
2508
2509
5.97k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2510
5.97k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2511
5.97k
    MI->ac_idx++;
2512
5.97k
#endif
2513
2514
5.97k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
2515
5.97k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg;
2516
5.97k
    MI->flat_insn->detail->arm64.op_count++;
2517
5.97k
  }
2518
5.97k
#ifndef CAPSTONE_DIET
2519
5.97k
  cs_mem_free(RegNameNew);
2520
5.97k
#endif
2521
5.97k
}
2522
2523
static const unsigned MatrixZADRegisterTable[] = {
2524
  AArch64_ZAD0, AArch64_ZAD1, AArch64_ZAD2, AArch64_ZAD3,
2525
  AArch64_ZAD4, AArch64_ZAD5, AArch64_ZAD6, AArch64_ZAD7
2526
};
2527
2528
595
static void printMatrixTileList(MCInst *MI, unsigned OpNum, SStream *O){
2529
595
  unsigned MaxRegs = 8;
2530
595
  unsigned RegMask = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2531
2532
595
  unsigned NumRegs = 0, I;
2533
5.35k
  for (I = 0; I < MaxRegs; ++I)
2534
4.76k
    if ((RegMask & (1 << I)) != 0)
2535
1.30k
      ++NumRegs;
2536
2537
595
  SStream_concat0(O, "{");
2538
595
  unsigned Printed = 0, J;
2539
5.35k
  for (J = 0; J < MaxRegs; ++J) {
2540
4.76k
    unsigned Reg = RegMask & (1 << J);
2541
4.76k
    if (Reg == 0)
2542
3.45k
      continue;
2543
1.30k
    SStream_concat0(O, getRegisterName(MatrixZADRegisterTable[J], AArch64_NoRegAltName));
2544
2545
1.30k
    if (MI->csh->detail) {
2546
1.30k
#ifndef CAPSTONE_DIET
2547
1.30k
      uint8_t access;
2548
2549
1.30k
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2550
1.30k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2551
1.30k
      MI->ac_idx++;
2552
1.30k
#endif
2553
2554
1.30k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
2555
1.30k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = MatrixZADRegisterTable[J];
2556
1.30k
      MI->flat_insn->detail->arm64.op_count++;
2557
1.30k
    }
2558
2559
1.30k
    if (Printed + 1 != NumRegs)
2560
710
      SStream_concat0(O, ", ");
2561
1.30k
    ++Printed;
2562
1.30k
  }
2563
595
  SStream_concat0(O, "}");
2564
595
}
2565
2566
static void printSVEPattern(MCInst *MI, unsigned OpNum, SStream *O)
2567
1.92k
{
2568
1.92k
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2569
2570
1.92k
  const SVEPREDPAT *Pat = lookupSVEPREDPATByEncoding(Val);
2571
1.92k
  if (Pat)
2572
1.19k
    SStream_concat0(O, Pat->Name);
2573
738
  else
2574
738
    printUInt32Bang(O, Val);
2575
1.92k
}
2576
2577
// default suffix = 0
2578
static void printSVERegOp(MCInst *MI, unsigned OpNum, SStream *O, char suffix)
2579
124k
{
2580
124k
  unsigned int Reg;
2581
2582
#if 0
2583
  switch (suffix) {
2584
    case 0:
2585
    case 'b':
2586
    case 'h':
2587
    case 's':
2588
    case 'd':
2589
    case 'q':
2590
      break;
2591
    default:
2592
      // llvm_unreachable("Invalid kind specifier.");
2593
  }
2594
#endif
2595
2596
124k
  Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
2597
2598
124k
  if (MI->csh->detail) {
2599
124k
#ifndef CAPSTONE_DIET
2600
124k
      uint8_t access;
2601
2602
124k
      access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2603
124k
      MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2604
124k
      MI->ac_idx++;
2605
124k
#endif
2606
124k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
2607
124k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg;
2608
124k
    MI->flat_insn->detail->arm64.op_count++;
2609
124k
  }
2610
2611
124k
  SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName));
2612
2613
124k
  if (suffix != '\0')
2614
80.2k
    SStream_concat(O, ".%c", suffix);
2615
124k
}
2616
2617
static void printImmSVE16(int16_t Val, SStream *O)
2618
765
{
2619
765
  printUInt32Bang(O, Val);
2620
765
}
2621
2622
static void printImmSVE32(int32_t Val, SStream *O)
2623
1.02k
{
2624
1.02k
  printUInt32Bang(O, Val);
2625
1.02k
}
2626
2627
static void printImmSVE64(int64_t Val, SStream *O)
2628
1.32k
{
2629
1.32k
  printUInt64Bang(O, Val);
2630
1.32k
}
2631
2632
static void printImm8OptLsl32(MCInst *MI, unsigned OpNum, SStream *O)
2633
1.10k
{
2634
1.10k
  unsigned UnscaledVal = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2635
1.10k
  unsigned Shift = MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1));
2636
1.10k
  uint32_t Val;
2637
2638
  // assert(AArch64_AM::getShiftType(Shift) == AArch64_AM::LSL &&
2639
  //  "Unexepected shift type!");
2640
2641
  // #0 lsl #8 is never pretty printed
2642
1.10k
  if ((UnscaledVal == 0) && (AArch64_AM_getShiftValue(Shift) != 0)) {
2643
83
    printUInt32Bang(O, UnscaledVal);
2644
83
    printShifter(MI, OpNum + 1, O);
2645
83
    return;
2646
83
  }
2647
2648
1.02k
  Val = UnscaledVal * (1 << AArch64_AM_getShiftValue(Shift));
2649
1.02k
  printImmSVE32(Val, O);
2650
1.02k
}
2651
2652
static void printImm8OptLsl64(MCInst *MI, unsigned OpNum, SStream *O)
2653
1.09k
{
2654
1.09k
  unsigned UnscaledVal = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2655
1.09k
  unsigned Shift = MCOperand_getImm(MCInst_getOperand(MI, OpNum + 1));
2656
1.09k
  uint64_t Val;
2657
2658
  // assert(AArch64_AM::getShiftType(Shift) == AArch64_AM::LSL &&
2659
  //  "Unexepected shift type!");
2660
2661
  // #0 lsl #8 is never pretty printed
2662
1.09k
  if ((UnscaledVal == 0) && (AArch64_AM_getShiftValue(Shift) != 0)) {
2663
195
    printUInt32Bang(O, UnscaledVal);
2664
195
    printShifter(MI, OpNum + 1, O);
2665
195
    return;
2666
195
  }
2667
2668
899
  Val = UnscaledVal * (1 << AArch64_AM_getShiftValue(Shift));
2669
899
  printImmSVE64(Val, O);
2670
899
}
2671
2672
static void printSVELogicalImm16(MCInst *MI, unsigned OpNum, SStream *O)
2673
242
{
2674
242
  uint64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2675
242
  uint64_t PrintVal = AArch64_AM_decodeLogicalImmediate(Val, 64);
2676
2677
  // Prefer the default format for 16bit values, hex otherwise.
2678
242
  printImmSVE16(PrintVal, O);
2679
242
}
2680
2681
static void printSVELogicalImm32(MCInst *MI, unsigned OpNum, SStream *O)
2682
1.19k
{
2683
1.19k
  uint64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2684
1.19k
  uint64_t PrintVal = AArch64_AM_decodeLogicalImmediate(Val, 64);
2685
2686
  // Prefer the default format for 16bit values, hex otherwise.
2687
1.19k
  if ((uint16_t)PrintVal == (uint32_t)PrintVal)
2688
523
    printImmSVE16(PrintVal, O);
2689
675
  else
2690
675
    printUInt64Bang(O, PrintVal);
2691
1.19k
}
2692
2693
static void printSVELogicalImm64(MCInst *MI, unsigned OpNum, SStream *O)
2694
424
{
2695
424
  uint64_t Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2696
424
  uint64_t PrintVal = AArch64_AM_decodeLogicalImmediate(Val, 64);
2697
2698
424
  printImmSVE64(PrintVal, O);
2699
424
}
2700
2701
static void printZPRasFPR(MCInst *MI, unsigned OpNum, SStream *O, int Width)
2702
1.96k
{
2703
1.96k
  unsigned int Base, Reg;
2704
2705
1.96k
  switch (Width) {
2706
0
    default: // llvm_unreachable("Unsupported width");
2707
319
    case 8:   Base = AArch64_B0; break;
2708
433
    case 16:  Base = AArch64_H0; break;
2709
587
    case 32:  Base = AArch64_S0; break;
2710
587
    case 64:  Base = AArch64_D0; break;
2711
36
    case 128: Base = AArch64_Q0; break;
2712
1.96k
  }
2713
2714
1.96k
  Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum)) - AArch64_Z0 + Base;
2715
2716
1.96k
  SStream_concat0(O, getRegisterName(Reg, AArch64_NoRegAltName));
2717
2718
1.96k
  if (MI->csh->detail) {
2719
1.96k
#ifndef CAPSTONE_DIET
2720
1.96k
    uint8_t access;
2721
2722
1.96k
    access = get_op_access(MI->csh, MCInst_getOpcode(MI), MI->ac_idx);
2723
1.96k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].access = access;
2724
1.96k
    MI->ac_idx++;
2725
1.96k
#endif
2726
1.96k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].type = ARM64_OP_REG;
2727
1.96k
    MI->flat_insn->detail->arm64.operands[MI->flat_insn->detail->arm64.op_count].reg = Reg;
2728
1.96k
    MI->flat_insn->detail->arm64.op_count++;
2729
1.96k
  }
2730
1.96k
}
2731
2732
static void printExactFPImm(MCInst *MI, unsigned OpNum, SStream *O, unsigned ImmIs0, unsigned ImmIs1)
2733
770
{
2734
770
  const ExactFPImm *Imm0Desc = lookupExactFPImmByEnum(ImmIs0);
2735
770
  const ExactFPImm *Imm1Desc = lookupExactFPImmByEnum(ImmIs1);
2736
770
  unsigned Val = MCOperand_getImm(MCInst_getOperand(MI, OpNum));
2737
2738
770
  SStream_concat0(O, Val ? Imm1Desc->Repr : Imm0Desc->Repr);
2739
770
}
2740
2741
static void printGPR64as32(MCInst *MI, unsigned OpNum, SStream *O)
2742
3.15k
{
2743
3.15k
  unsigned int Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
2744
2745
3.15k
  SStream_concat0(O, getRegisterName(getWRegFromXReg(Reg), AArch64_NoRegAltName));
2746
3.15k
}
2747
2748
static void printGPR64x8(MCInst *MI, unsigned OpNum, SStream *O) 
2749
659
{
2750
659
    unsigned int Reg = MCOperand_getReg(MCInst_getOperand(MI, OpNum));
2751
2752
659
    SStream_concat0(O, getRegisterName(MCRegisterInfo_getSubReg(MI->MRI, Reg, AArch64_x8sub_0), AArch64_NoRegAltName));
2753
659
}
2754
2755
#define PRINT_ALIAS_INSTR
2756
#include "AArch64GenAsmWriter.inc"
2757
#include "AArch64GenRegisterName.inc"
2758
2759
void AArch64_post_printer(csh handle, cs_insn *flat_insn, char *insn_asm, MCInst *mci)
2760
293k
{
2761
293k
  if (((cs_struct *)handle)->detail != CS_OPT_ON)
2762
0
    return;
2763
2764
293k
  if (mci->csh->detail) {
2765
293k
    unsigned opcode = MCInst_getOpcode(mci);
2766
2767
293k
    switch (opcode) {
2768
237k
      default:
2769
237k
        break;
2770
237k
      case AArch64_LD1Fourv16b_POST:
2771
545
      case AArch64_LD1Fourv1d_POST:
2772
776
      case AArch64_LD1Fourv2d_POST:
2773
844
      case AArch64_LD1Fourv2s_POST:
2774
942
      case AArch64_LD1Fourv4h_POST:
2775
1.84k
      case AArch64_LD1Fourv4s_POST:
2776
1.99k
      case AArch64_LD1Fourv8b_POST:
2777
2.50k
      case AArch64_LD1Fourv8h_POST:
2778
2.54k
      case AArch64_LD1Onev16b_POST:
2779
2.58k
      case AArch64_LD1Onev1d_POST:
2780
2.65k
      case AArch64_LD1Onev2d_POST:
2781
2.94k
      case AArch64_LD1Onev2s_POST:
2782
3.10k
      case AArch64_LD1Onev4h_POST:
2783
3.21k
      case AArch64_LD1Onev4s_POST:
2784
3.42k
      case AArch64_LD1Onev8b_POST:
2785
3.65k
      case AArch64_LD1Onev8h_POST:
2786
3.78k
      case AArch64_LD1Rv16b_POST:
2787
3.96k
      case AArch64_LD1Rv1d_POST:
2788
4.03k
      case AArch64_LD1Rv2d_POST:
2789
4.14k
      case AArch64_LD1Rv2s_POST:
2790
4.15k
      case AArch64_LD1Rv4h_POST:
2791
4.24k
      case AArch64_LD1Rv4s_POST:
2792
4.32k
      case AArch64_LD1Rv8b_POST:
2793
4.36k
      case AArch64_LD1Rv8h_POST:
2794
4.82k
      case AArch64_LD1Threev16b_POST:
2795
4.90k
      case AArch64_LD1Threev1d_POST:
2796
5.14k
      case AArch64_LD1Threev2d_POST:
2797
5.29k
      case AArch64_LD1Threev2s_POST:
2798
5.40k
      case AArch64_LD1Threev4h_POST:
2799
6.11k
      case AArch64_LD1Threev4s_POST:
2800
6.23k
      case AArch64_LD1Threev8b_POST:
2801
7.19k
      case AArch64_LD1Threev8h_POST:
2802
7.22k
      case AArch64_LD1Twov16b_POST:
2803
7.29k
      case AArch64_LD1Twov1d_POST:
2804
7.52k
      case AArch64_LD1Twov2d_POST:
2805
7.60k
      case AArch64_LD1Twov2s_POST:
2806
7.65k
      case AArch64_LD1Twov4h_POST:
2807
7.75k
      case AArch64_LD1Twov4s_POST:
2808
8.40k
      case AArch64_LD1Twov8b_POST:
2809
8.41k
      case AArch64_LD1Twov8h_POST:
2810
8.73k
      case AArch64_LD1i16_POST:
2811
11.2k
      case AArch64_LD1i32_POST:
2812
11.4k
      case AArch64_LD1i64_POST:
2813
12.2k
      case AArch64_LD1i8_POST:
2814
12.2k
      case AArch64_LD2Rv16b_POST:
2815
13.1k
      case AArch64_LD2Rv1d_POST:
2816
13.1k
      case AArch64_LD2Rv2d_POST:
2817
13.1k
      case AArch64_LD2Rv2s_POST:
2818
13.2k
      case AArch64_LD2Rv4h_POST:
2819
13.3k
      case AArch64_LD2Rv4s_POST:
2820
13.4k
      case AArch64_LD2Rv8b_POST:
2821
13.4k
      case AArch64_LD2Rv8h_POST:
2822
14.0k
      case AArch64_LD2Twov16b_POST:
2823
14.2k
      case AArch64_LD2Twov2d_POST:
2824
14.2k
      case AArch64_LD2Twov2s_POST:
2825
14.9k
      case AArch64_LD2Twov4h_POST:
2826
15.0k
      case AArch64_LD2Twov4s_POST:
2827
15.1k
      case AArch64_LD2Twov8b_POST:
2828
15.2k
      case AArch64_LD2Twov8h_POST:
2829
15.2k
      case AArch64_LD2i16_POST:
2830
15.8k
      case AArch64_LD2i32_POST:
2831
16.2k
      case AArch64_LD2i64_POST:
2832
17.1k
      case AArch64_LD2i8_POST:
2833
17.1k
      case AArch64_LD3Rv16b_POST:
2834
17.2k
      case AArch64_LD3Rv1d_POST:
2835
17.4k
      case AArch64_LD3Rv2d_POST:
2836
17.5k
      case AArch64_LD3Rv2s_POST:
2837
17.5k
      case AArch64_LD3Rv4h_POST:
2838
17.6k
      case AArch64_LD3Rv4s_POST:
2839
17.7k
      case AArch64_LD3Rv8b_POST:
2840
18.0k
      case AArch64_LD3Rv8h_POST:
2841
18.2k
      case AArch64_LD3Threev16b_POST:
2842
18.5k
      case AArch64_LD3Threev2d_POST:
2843
18.5k
      case AArch64_LD3Threev2s_POST:
2844
18.9k
      case AArch64_LD3Threev4h_POST:
2845
19.1k
      case AArch64_LD3Threev4s_POST:
2846
19.1k
      case AArch64_LD3Threev8b_POST:
2847
19.9k
      case AArch64_LD3Threev8h_POST:
2848
20.5k
      case AArch64_LD3i16_POST:
2849
21.4k
      case AArch64_LD3i32_POST:
2850
22.2k
      case AArch64_LD3i64_POST:
2851
22.5k
      case AArch64_LD3i8_POST:
2852
22.7k
      case AArch64_LD4Fourv16b_POST:
2853
22.7k
      case AArch64_LD4Fourv2d_POST:
2854
22.7k
      case AArch64_LD4Fourv2s_POST:
2855
22.8k
      case AArch64_LD4Fourv4h_POST:
2856
23.3k
      case AArch64_LD4Fourv4s_POST:
2857
23.5k
      case AArch64_LD4Fourv8b_POST:
2858
23.5k
      case AArch64_LD4Fourv8h_POST:
2859
23.6k
      case AArch64_LD4Rv16b_POST:
2860
23.7k
      case AArch64_LD4Rv1d_POST:
2861
23.8k
      case AArch64_LD4Rv2d_POST:
2862
24.5k
      case AArch64_LD4Rv2s_POST:
2863
24.6k
      case AArch64_LD4Rv4h_POST:
2864
24.7k
      case AArch64_LD4Rv4s_POST:
2865
24.7k
      case AArch64_LD4Rv8b_POST:
2866
24.9k
      case AArch64_LD4Rv8h_POST:
2867
25.3k
      case AArch64_LD4i16_POST:
2868
25.7k
      case AArch64_LD4i32_POST:
2869
25.9k
      case AArch64_LD4i64_POST:
2870
26.6k
      case AArch64_LD4i8_POST:
2871
26.9k
      case AArch64_LDRBBpost:
2872
27.0k
      case AArch64_LDRBpost:
2873
27.0k
      case AArch64_LDRDpost:
2874
27.2k
      case AArch64_LDRHHpost:
2875
27.2k
      case AArch64_LDRHpost:
2876
27.3k
      case AArch64_LDRQpost:
2877
27.4k
      case AArch64_LDPDpost:
2878
27.5k
      case AArch64_LDPQpost:
2879
27.6k
      case AArch64_LDPSWpost:
2880
27.7k
      case AArch64_LDPSpost:
2881
28.3k
      case AArch64_LDPWpost:
2882
28.3k
      case AArch64_LDPXpost:
2883
28.4k
      case AArch64_ST1Fourv16b_POST:
2884
28.4k
      case AArch64_ST1Fourv1d_POST:
2885
28.7k
      case AArch64_ST1Fourv2d_POST:
2886
28.7k
      case AArch64_ST1Fourv2s_POST:
2887
29.0k
      case AArch64_ST1Fourv4h_POST:
2888
29.2k
      case AArch64_ST1Fourv4s_POST:
2889
29.2k
      case AArch64_ST1Fourv8b_POST:
2890
30.4k
      case AArch64_ST1Fourv8h_POST:
2891
30.6k
      case AArch64_ST1Onev16b_POST:
2892
30.6k
      case AArch64_ST1Onev1d_POST:
2893
30.6k
      case AArch64_ST1Onev2d_POST:
2894
30.7k
      case AArch64_ST1Onev2s_POST:
2895
30.7k
      case AArch64_ST1Onev4h_POST:
2896
30.8k
      case AArch64_ST1Onev4s_POST:
2897
30.8k
      case AArch64_ST1Onev8b_POST:
2898
30.9k
      case AArch64_ST1Onev8h_POST:
2899
31.0k
      case AArch64_ST1Threev16b_POST:
2900
31.0k
      case AArch64_ST1Threev1d_POST:
2901
31.1k
      case AArch64_ST1Threev2d_POST:
2902
31.1k
      case AArch64_ST1Threev2s_POST:
2903
31.3k
      case AArch64_ST1Threev4h_POST:
2904
31.4k
      case AArch64_ST1Threev4s_POST:
2905
31.7k
      case AArch64_ST1Threev8b_POST:
2906
31.8k
      case AArch64_ST1Threev8h_POST:
2907
31.8k
      case AArch64_ST1Twov16b_POST:
2908
31.8k
      case AArch64_ST1Twov1d_POST:
2909
31.9k
      case AArch64_ST1Twov2d_POST:
2910
31.9k
      case AArch64_ST1Twov2s_POST:
2911
32.0k
      case AArch64_ST1Twov4h_POST:
2912
32.0k
      case AArch64_ST1Twov4s_POST:
2913
32.0k
      case AArch64_ST1Twov8b_POST:
2914
32.2k
      case AArch64_ST1Twov8h_POST:
2915
32.5k
      case AArch64_ST1i16_POST:
2916
32.6k
      case AArch64_ST1i32_POST:
2917
32.8k
      case AArch64_ST1i64_POST:
2918
33.1k
      case AArch64_ST1i8_POST:
2919
33.2k
      case AArch64_ST2GPostIndex:
2920
33.6k
      case AArch64_ST2Twov16b_POST:
2921
33.6k
      case AArch64_ST2Twov2d_POST:
2922
33.8k
      case AArch64_ST2Twov2s_POST:
2923
34.1k
      case AArch64_ST2Twov4h_POST:
2924
34.3k
      case AArch64_ST2Twov4s_POST:
2925
34.3k
      case AArch64_ST2Twov8b_POST:
2926
34.6k
      case AArch64_ST2Twov8h_POST:
2927
34.8k
      case AArch64_ST2i16_POST:
2928
34.9k
      case AArch64_ST2i32_POST:
2929
35.1k
      case AArch64_ST2i64_POST:
2930
35.5k
      case AArch64_ST2i8_POST:
2931
35.6k
      case AArch64_ST3Threev16b_POST:
2932
35.9k
      case AArch64_ST3Threev2d_POST:
2933
36.0k
      case AArch64_ST3Threev2s_POST:
2934
36.0k
      case AArch64_ST3Threev4h_POST:
2935
36.4k
      case AArch64_ST3Threev4s_POST:
2936
36.5k
      case AArch64_ST3Threev8b_POST:
2937
36.5k
      case AArch64_ST3Threev8h_POST:
2938
37.3k
      case AArch64_ST3i16_POST:
2939
37.9k
      case AArch64_ST3i32_POST:
2940
38.0k
      case AArch64_ST3i64_POST:
2941
38.9k
      case AArch64_ST3i8_POST:
2942
39.7k
      case AArch64_ST4Fourv16b_POST:
2943
39.7k
      case AArch64_ST4Fourv2d_POST:
2944
39.8k
      case AArch64_ST4Fourv2s_POST:
2945
39.9k
      case AArch64_ST4Fourv4h_POST:
2946
40.0k
      case AArch64_ST4Fourv4s_POST:
2947
40.1k
      case AArch64_ST4Fourv8b_POST:
2948
40.3k
      case AArch64_ST4Fourv8h_POST:
2949
40.9k
      case AArch64_ST4i16_POST:
2950
41.7k
      case AArch64_ST4i32_POST:
2951
41.9k
      case AArch64_ST4i64_POST:
2952
42.0k
      case AArch64_ST4i8_POST:
2953
42.2k
      case AArch64_STPDpost:
2954
42.5k
      case AArch64_STPQpost:
2955
42.7k
      case AArch64_STPSpost:
2956
43.5k
      case AArch64_STPWpost:
2957
44.0k
      case AArch64_STPXpost:
2958
44.1k
      case AArch64_STRBBpost:
2959
44.2k
      case AArch64_STRBpost:
2960
44.3k
      case AArch64_STRDpost:
2961
44.6k
      case AArch64_STRHHpost:
2962
44.7k
      case AArch64_STRHpost:
2963
45.0k
      case AArch64_STRQpost:
2964
45.1k
      case AArch64_STRSpost:
2965
45.2k
      case AArch64_STRWpost:
2966
45.2k
      case AArch64_STRXpost:
2967
45.5k
      case AArch64_STZ2GPostIndex:
2968
45.5k
      case AArch64_STZGPostIndex:
2969
45.5k
      case AArch64_STGPostIndex:
2970
45.5k
      case AArch64_STGPpost:
2971
45.6k
      case AArch64_LDRSBWpost:
2972
45.7k
      case AArch64_LDRSBXpost:
2973
45.7k
      case AArch64_LDRSHWpost:
2974
46.2k
      case AArch64_LDRSHXpost:
2975
46.3k
      case AArch64_LDRSWpost:
2976
46.4k
      case AArch64_LDRSpost:
2977
46.5k
      case AArch64_LDRWpost:
2978
46.6k
      case AArch64_LDRXpost:
2979
46.6k
        flat_insn->detail->arm64.writeback = true;
2980
46.6k
          flat_insn->detail->arm64.post_index = true;
2981
46.6k
        break;
2982
305
      case AArch64_LDRAAwriteback:
2983
1.56k
      case AArch64_LDRABwriteback:
2984
1.64k
      case AArch64_ST2GPreIndex:
2985
2.09k
      case AArch64_LDPDpre:
2986
2.14k
      case AArch64_LDPQpre:
2987
2.19k
      case AArch64_LDPSWpre:
2988
2.32k
      case AArch64_LDPSpre:
2989
2.68k
      case AArch64_LDPWpre:
2990
2.79k
      case AArch64_LDPXpre:
2991
3.06k
      case AArch64_LDRBBpre:
2992
3.18k
      case AArch64_LDRBpre:
2993
3.21k
      case AArch64_LDRDpre:
2994
3.32k
      case AArch64_LDRHHpre:
2995
3.40k
      case AArch64_LDRHpre:
2996
3.44k
      case AArch64_LDRQpre:
2997
3.60k
      case AArch64_LDRSBWpre:
2998
3.66k
      case AArch64_LDRSBXpre:
2999
4.08k
      case AArch64_LDRSHWpre:
3000
4.10k
      case AArch64_LDRSHXpre:
3001
4.16k
      case AArch64_LDRSWpre:
3002
4.24k
      case AArch64_LDRSpre:
3003
4.31k
      case AArch64_LDRWpre:
3004
4.43k
      case AArch64_LDRXpre:
3005
4.56k
      case AArch64_STGPreIndex:
3006
5.05k
      case AArch64_STPDpre:
3007
5.61k
      case AArch64_STPQpre:
3008
5.73k
      case AArch64_STPSpre:
3009
6.03k
      case AArch64_STPWpre:
3010
6.39k
      case AArch64_STPXpre:
3011
6.51k
      case AArch64_STRBBpre:
3012
6.90k
      case AArch64_STRBpre:
3013
6.94k
      case AArch64_STRDpre:
3014
7.38k
      case AArch64_STRHHpre:
3015
7.48k
      case AArch64_STRHpre:
3016
7.55k
      case AArch64_STRQpre:
3017
7.79k
      case AArch64_STRSpre:
3018
8.15k
      case AArch64_STRWpre:
3019
8.26k
      case AArch64_STRXpre:
3020
8.48k
      case AArch64_STZ2GPreIndex:
3021
8.77k
      case AArch64_STZGPreIndex:
3022
8.77k
      case AArch64_STGPpre:
3023
        flat_insn->detail->arm64.writeback = true;
3024
8.77k
        break;
3025
293k
    }
3026
293k
  }
3027
293k
}
3028
3029
#endif