Coverage Report

Created: 2025-11-24 06:12

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