Coverage Report

Created: 2026-08-14 06:51

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