Coverage Report

Created: 2025-07-01 07:03

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