Coverage Report

Created: 2024-08-21 06:24

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