Coverage Report

Created: 2026-09-01 07:20

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