Coverage Report

Created: 2025-11-09 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonenext/arch/ARM/ARMInstPrinter.c
Line
Count
Source
1
/* Capstone Disassembly Engine, http://www.capstone-engine.org */
2
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */
3
/*    Rot127 <unisono@quyllur.org> 2022-2023 */
4
/* Automatically translated source file from LLVM. */
5
6
/* LLVM-commit: <commit> */
7
/* LLVM-tag: <tag> */
8
9
/* Only small edits allowed. */
10
/* For multiple similar edits, please create a Patch for the translator. */
11
12
/* Capstone's C++ file translator: */
13
/* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */
14
15
//===-- ARMInstPrinter.cpp - Convert ARM MCInst to assembly syntax --------===//
16
//
17
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
18
// See https://llvm.org/LICENSE.txt for license information.
19
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
20
//
21
//===----------------------------------------------------------------------===//
22
//
23
// This class prints an ARM MCInst to a .s file.
24
//
25
//===----------------------------------------------------------------------===//
26
27
#include <capstone/arm.h>
28
29
#include <capstone/platform.h>
30
31
#include "../../Mapping.h"
32
#include "../../MCInst.h"
33
#include "../../MCInstPrinter.h"
34
#include "../../MCRegisterInfo.h"
35
#include "../../SStream.h"
36
37
#include "ARMAddressingModes.h"
38
#include "ARMBaseInfo.h"
39
#include "ARMDisassemblerExtension.h"
40
#include "ARMInstPrinter.h"
41
#include "ARMLinkage.h"
42
#include "ARMMapping.h"
43
44
#define GET_BANKEDREG_IMPL
45
#include "ARMGenSystemRegister.inc"
46
47
14.1k
#define CONCAT(a, b) CONCAT_(a, b)
48
14.1k
#define CONCAT_(a, b) a##_##b
49
50
#define DEBUG_TYPE "asm-printer"
51
52
// Static function declarations. These are functions which have the same identifiers
53
// over all architectures. Therefor they need to be static.
54
#ifndef CAPSTONE_DIET
55
static void printCustomAliasOperand(MCInst *MI, uint64_t Address,
56
            unsigned OpIdx, unsigned PrintMethodIdx,
57
            SStream *O);
58
#endif
59
static const char *getRegisterName(unsigned RegNo, unsigned AltIdx);
60
61
/// translateShiftImm - Convert shift immediate from 0-31 to 1-32 for printing.
62
///
63
/// getSORegOffset returns an integer from 0-31, representing '32' as 0.
64
unsigned translateShiftImm(unsigned imm)
65
8.52k
{
66
  // lsr #32 and asr #32 exist, but should be encoded as a 0.
67
8.52k
  CS_ASSERT((imm & ~0x1f) == 0 && "Invalid shift encoding");
68
69
8.52k
  if (imm == 0)
70
564
    return 32;
71
7.96k
  return imm;
72
8.52k
}
73
74
/// Prints the shift value with an immediate value.
75
static inline void printRegImmShift(MCInst *MI, SStream *O,
76
            ARM_AM_ShiftOpc ShOpc, unsigned ShImm,
77
            bool UseMarkup)
78
3.23k
{
79
3.23k
  add_cs_detail(MI, ARM_OP_GROUP_RegImmShift, ShOpc, ShImm);
80
3.23k
  if (ShOpc == ARM_AM_no_shift || (ShOpc == ARM_AM_lsl && !ShImm))
81
162
    return;
82
3.07k
  SStream_concat0(O, ", ");
83
84
3.07k
  CS_ASSERT(!(ShOpc == ARM_AM_ror && !ShImm) && "Cannot have ror #0");
85
3.07k
  SStream_concat0(O, ARM_AM_getShiftOpcStr(ShOpc));
86
87
3.07k
  if (ShOpc != ARM_AM_rrx) {
88
2.69k
    SStream_concat0(O, " ");
89
2.69k
    if (getUseMarkup())
90
0
      SStream_concat0(O, "<imm:");
91
2.69k
    SStream_concat(O, "%s%d", "#", translateShiftImm(ShImm));
92
2.69k
    if (getUseMarkup())
93
0
      SStream_concat0(O, ">");
94
2.69k
  }
95
3.07k
}
96
97
static void printPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
98
139k
{
99
139k
  add_cs_detail(MI, ARM_OP_GROUP_PredicateOperand, OpNum);
100
139k
  ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(
101
139k
    MCInst_getOperand(MI, (OpNum)));
102
  // Handle the undefined 15 CC value here for printing so we don't abort().
103
139k
  if ((unsigned)CC == 15)
104
364
    SStream_concat0(O, "<und>");
105
138k
  else if (CC != ARMCC_AL)
106
22.3k
    SStream_concat0(O, ARMCondCodeToString(CC));
107
139k
}
108
109
static void printRegName(SStream *OS, unsigned RegNo)
110
1.87M
{
111
1.87M
  SStream_concat(OS, "%s%s", markup("<reg:"),
112
1.87M
           getRegisterName(RegNo, ARM_NoRegAltName));
113
1.87M
  SStream_concat0(OS, markup(">"));
114
1.87M
}
115
116
static inline void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
117
262k
{
118
262k
  add_cs_detail(MI, ARM_OP_GROUP_Operand, OpNo);
119
262k
  MCOperand *Op = MCInst_getOperand(MI, (OpNo));
120
262k
  if (MCOperand_isReg(Op)) {
121
214k
    unsigned Reg = MCOperand_getReg(Op);
122
214k
    printRegName(O, Reg);
123
214k
  } else if (MCOperand_isImm(Op)) {
124
47.5k
    SStream_concat(O, "%s", markup("<imm:"));
125
47.5k
    SStream_concat1(O, '#');
126
47.5k
    printInt64(O, MCOperand_getImm(Op));
127
47.5k
    SStream_concat0(O, markup(">"));
128
47.5k
  } else {
129
0
    CS_ASSERT_RET(0 && "Expressions are not supported.");
130
0
  }
131
262k
}
132
133
static inline void printRegisterList(MCInst *MI, unsigned OpNum, SStream *O)
134
6.33k
{
135
6.33k
  add_cs_detail(MI, ARM_OP_GROUP_RegisterList, OpNum);
136
6.33k
  if (MCInst_getOpcode(MI) != ARM_t2CLRM) {
137
6.33k
  }
138
139
6.33k
  SStream_concat0(O, "{");
140
44.1k
  for (unsigned i = OpNum, e = MCInst_getNumOperands(MI); i != e; ++i) {
141
37.8k
    if (i != OpNum)
142
31.4k
      SStream_concat0(O, ", ");
143
37.8k
    printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (i))));
144
37.8k
  }
145
6.33k
  SStream_concat0(O, "}");
146
6.33k
}
147
148
static inline void printSBitModifierOperand(MCInst *MI, unsigned OpNum,
149
              SStream *O)
150
41.6k
{
151
41.6k
  add_cs_detail(MI, ARM_OP_GROUP_SBitModifierOperand, OpNum);
152
41.6k
  if (MCOperand_getReg(MCInst_getOperand(MI, (OpNum)))) {
153
38.1k
    SStream_concat0(O, "s");
154
38.1k
  }
155
41.6k
}
156
157
static inline void printOperandAddr(MCInst *MI, uint64_t Address,
158
            unsigned OpNum, SStream *O)
159
8.79k
{
160
8.79k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
161
8.79k
  if (!MCOperand_isImm(Op) || !MI->csh->PrintBranchImmAsAddress ||
162
8.79k
      getUseMarkup()) {
163
0
    printOperand(MI, OpNum, O);
164
0
    return;
165
0
  }
166
8.79k
  int64_t Imm = MCOperand_getImm(Op);
167
  // For ARM instructions the PC offset is 8 bytes, for Thumb instructions it
168
  // is 4 bytes.
169
8.79k
  uint64_t Offset = ARM_getFeatureBits(MI->csh->mode, ARM_ModeThumb) ? 4 :
170
8.79k
                       8;
171
172
  // A Thumb instruction BLX(i) can be 16-bit aligned while targets Arm code
173
  // which is 32-bit aligned. The target address for the case is calculated as
174
  //   targetAddress = Align(PC,4) + imm32;
175
  // where
176
  //   Align(x, y) = y * (x DIV y);
177
8.79k
  if (MCInst_getOpcode(MI) == ARM_tBLXi)
178
18
    Address &= ~0x3;
179
180
8.79k
  uint64_t Target = Address + Imm + Offset;
181
182
8.79k
  Target &= 0xffffffff;
183
8.79k
  ARM_set_detail_op_imm(MI, OpNum, ARM_OP_IMM, Target);
184
8.79k
  printUInt64(O, Target);
185
8.79k
}
186
187
static inline void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNum,
188
               SStream *O)
189
3.13k
{
190
3.13k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbLdrLabelOperand, OpNum);
191
3.13k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
192
3.13k
  if (MCOperand_isExpr(MO1)) {
193
    // MO1.getExpr()->print(O, &MAI);
194
0
    return;
195
0
  }
196
197
3.13k
  SStream_concat(O, "%s", markup("<mem:"));
198
3.13k
  SStream_concat0(O, "[pc, ");
199
200
3.13k
  int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
201
202
  // Special value for #-0. All others are normal.
203
3.13k
  if (OffImm == INT32_MIN)
204
113
    OffImm = 0;
205
3.13k
  SStream_concat(O, "%s", markup("<imm:"));
206
3.13k
  printInt32Bang(O, OffImm);
207
3.13k
  SStream_concat0(O, markup(">"));
208
3.13k
  SStream_concat(O, "%s", "]");
209
3.13k
  SStream_concat0(O, markup(">"));
210
3.13k
}
211
212
// so_reg is a 4-operand unit corresponding to register forms of the A5.1
213
// "Addressing Mode 1 - Data-processing operands" forms.  This includes:
214
//    REG 0   0           - e.g. R5
215
//    REG REG 0,SH_OPC    - e.g. R5, ROR R3
216
//    REG 0   IMM,SH_OPC  - e.g. R5, LSL #3
217
static inline void printSORegRegOperand(MCInst *MI, unsigned OpNum, SStream *O)
218
997
{
219
997
  add_cs_detail(MI, ARM_OP_GROUP_SORegRegOperand, OpNum);
220
997
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
221
997
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
222
997
  MCOperand *MO3 = MCInst_getOperand(MI, (OpNum + 2));
223
224
997
  printRegName(O, MCOperand_getReg(MO1));
225
226
  // Print the shift opc.
227
997
  ARM_AM_ShiftOpc ShOpc = ARM_AM_getSORegShOp(MCOperand_getImm(MO3));
228
997
  SStream_concat(O, "%s", ", ");
229
997
  SStream_concat0(O, ARM_AM_getShiftOpcStr(ShOpc));
230
997
  if (ShOpc == ARM_AM_rrx)
231
0
    return;
232
233
997
  SStream_concat0(O, " ");
234
235
997
  printRegName(O, MCOperand_getReg(MO2));
236
997
}
237
238
static inline void printSORegImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
239
1.24k
{
240
1.24k
  add_cs_detail(MI, ARM_OP_GROUP_SORegImmOperand, OpNum);
241
1.24k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
242
1.24k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
243
244
1.24k
  printRegName(O, MCOperand_getReg(MO1));
245
246
  // Print the shift opc.
247
1.24k
  printRegImmShift(MI, O, ARM_AM_getSORegShOp(MCOperand_getImm(MO2)),
248
1.24k
       ARM_AM_getSORegOffset(MCOperand_getImm(MO2)),
249
1.24k
       getUseMarkup());
250
1.24k
}
251
252
//===--------------------------------------------------------------------===//
253
// Addressing Mode #2
254
//===--------------------------------------------------------------------===//
255
256
static inline void printAM2PreOrOffsetIndexOp(MCInst *MI, unsigned Op,
257
                SStream *O)
258
878
{
259
878
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
260
878
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
261
878
  MCOperand *MO3 = MCInst_getOperand(MI, (Op + 2));
262
263
878
  SStream_concat(O, "%s", markup("<mem:"));
264
878
  SStream_concat0(O, "[");
265
878
  printRegName(O, MCOperand_getReg(MO1));
266
267
878
  if (!MCOperand_getReg(MO2)) {
268
0
    if (ARM_AM_getAM2Offset(
269
0
          MCOperand_getImm(MO3))) { // Don't print +0.
270
0
      SStream_concat(
271
0
        O, "%s%s%s", ", ", markup("<imm:"), "#",
272
0
        ARM_AM_getAddrOpcStr(
273
0
          ARM_AM_getAM2Op(MCOperand_getImm(MO3))),
274
0
        ARM_AM_getAM2Offset(MCOperand_getImm(MO3)));
275
0
      SStream_concat0(O, markup(">"));
276
0
    }
277
0
    SStream_concat(O, "%s", "]");
278
0
    SStream_concat0(O, markup(">"));
279
0
    return;
280
0
  }
281
282
878
  SStream_concat0(O, ", ");
283
878
  SStream_concat0(O, ARM_AM_getAddrOpcStr(
284
878
           ARM_AM_getAM2Op(MCOperand_getImm(MO3))));
285
878
  printRegName(O, MCOperand_getReg(MO2));
286
287
878
  printRegImmShift(MI, O, ARM_AM_getAM2ShiftOpc(MCOperand_getImm(MO3)),
288
878
       ARM_AM_getAM2Offset(MCOperand_getImm(MO3)),
289
878
       getUseMarkup());
290
878
  SStream_concat(O, "%s", "]");
291
878
  SStream_concat0(O, markup(">"));
292
878
}
293
294
static inline void printAddrModeTBB(MCInst *MI, unsigned Op, SStream *O)
295
141
{
296
141
  add_cs_detail(MI, ARM_OP_GROUP_AddrModeTBB, Op);
297
141
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
298
141
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
299
141
  SStream_concat(O, "%s", markup("<mem:"));
300
141
  SStream_concat0(O, "[");
301
141
  printRegName(O, MCOperand_getReg(MO1));
302
141
  SStream_concat0(O, ", ");
303
141
  printRegName(O, MCOperand_getReg(MO2));
304
141
  SStream_concat(O, "%s", "]");
305
141
  SStream_concat0(O, markup(">"));
306
141
}
307
308
static inline void printAddrModeTBH(MCInst *MI, unsigned Op, SStream *O)
309
404
{
310
404
  add_cs_detail(MI, ARM_OP_GROUP_AddrModeTBH, Op);
311
404
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
312
404
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
313
404
  SStream_concat(O, "%s", markup("<mem:"));
314
404
  SStream_concat0(O, "[");
315
404
  printRegName(O, MCOperand_getReg(MO1));
316
404
  SStream_concat0(O, ", ");
317
404
  printRegName(O, MCOperand_getReg(MO2));
318
404
  SStream_concat(O, "%s%s%s%s%s", ", lsl ", markup("<imm:"), "#1",
319
404
           markup(">"), "]");
320
404
  SStream_concat0(O, markup(">"));
321
404
}
322
323
static inline void printAddrMode2Operand(MCInst *MI, unsigned Op, SStream *O)
324
7.52k
{
325
7.52k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode2Operand, Op);
326
7.52k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
327
328
7.52k
  if (!MCOperand_isReg(
329
7.52k
        MO1)) { // FIXME: This is for CP entries, but isn't right.
330
0
    printOperand(MI, Op, O);
331
0
    return;
332
0
  }
333
334
7.52k
  printAM2PreOrOffsetIndexOp(MI, Op, O);
335
7.52k
}
336
337
static inline void printAddrMode2OffsetOperand(MCInst *MI, unsigned OpNum,
338
                 SStream *O)
339
1.15k
{
340
1.15k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode2OffsetOperand, OpNum);
341
1.15k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
342
1.15k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
343
344
1.15k
  if (!MCOperand_getReg(MO1)) {
345
473
    unsigned ImmOffs = ARM_AM_getAM2Offset(MCOperand_getImm(MO2));
346
473
    SStream_concat(O, "%s", markup("<imm:"));
347
473
    SStream_concat1(O, '#');
348
473
    SStream_concat(O, "%s",
349
473
             ARM_AM_getAddrOpcStr(
350
473
               ARM_AM_getAM2Op(MCOperand_getImm(MO2))));
351
473
    printUInt32(O, ImmOffs);
352
473
    SStream_concat0(O, markup(">"));
353
473
    return;
354
473
  }
355
356
683
  SStream_concat0(O, ARM_AM_getAddrOpcStr(
357
683
           ARM_AM_getAM2Op(MCOperand_getImm(MO2))));
358
683
  printRegName(O, MCOperand_getReg(MO1));
359
360
683
  printRegImmShift(MI, O, ARM_AM_getAM2ShiftOpc(MCOperand_getImm(MO2)),
361
683
       ARM_AM_getAM2Offset(MCOperand_getImm(MO2)),
362
683
       getUseMarkup());
363
683
}
364
365
//===--------------------------------------------------------------------===//
366
// Addressing Mode #3
367
//===--------------------------------------------------------------------===//
368
369
static inline void printAM3PreOrOffsetIndexOp(MCInst *MI, unsigned Op,
370
                SStream *O, bool AlwaysPrintImm0)
371
727
{
372
727
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
373
727
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
374
727
  MCOperand *MO3 = MCInst_getOperand(MI, (Op + 2));
375
376
727
  SStream_concat(O, "%s", markup("<mem:"));
377
727
  SStream_concat0(O, "[");
378
379
727
  printRegName(O, MCOperand_getReg(MO1));
380
381
727
  if (MCOperand_getReg(MO2)) {
382
311
    SStream_concat(O, "%s", ", ");
383
311
    SStream_concat0(O, ARM_AM_getAddrOpcStr(ARM_AM_getAM3Op(
384
311
             MCOperand_getImm(MO3))));
385
311
    printRegName(O, MCOperand_getReg(MO2));
386
311
    SStream_concat1(O, ']');
387
311
    SStream_concat0(O, markup(">"));
388
311
    return;
389
311
  }
390
391
  // If the op is sub we have to print the immediate even if it is 0
392
416
  unsigned ImmOffs = ARM_AM_getAM3Offset(MCOperand_getImm(MO3));
393
416
  ARM_AM_AddrOpc op = ARM_AM_getAM3Op(MCOperand_getImm(MO3));
394
395
416
  if (AlwaysPrintImm0 || ImmOffs || (op == ARM_AM_sub)) {
396
411
    SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), "#",
397
411
             ARM_AM_getAddrOpcStr(op));
398
411
    printUInt32(O, ImmOffs);
399
411
    SStream_concat0(O, markup(">"));
400
411
  }
401
416
  SStream_concat1(O, ']');
402
416
  SStream_concat0(O, markup(">"));
403
416
}
404
405
#define DEFINE_printAddrMode3Operand(AlwaysPrintImm0) \
406
  static inline void CONCAT(printAddrMode3Operand, AlwaysPrintImm0)( \
407
    MCInst * MI, unsigned Op, SStream *O) \
408
727
  { \
409
727
    add_cs_detail(MI, \
410
727
            CONCAT(ARM_OP_GROUP_AddrMode3Operand, \
411
727
             AlwaysPrintImm0), \
412
727
            Op, AlwaysPrintImm0); \
413
727
    MCOperand *MO1 = MCInst_getOperand(MI, (Op)); \
414
727
    if (!MCOperand_isReg(MO1)) { \
415
0
      printOperand(MI, Op, O); \
416
0
      return; \
417
0
    } \
418
727
\
419
727
    printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0); \
420
727
  }
ARMInstPrinter.c:printAddrMode3Operand_0
Line
Count
Source
408
622
  { \
409
622
    add_cs_detail(MI, \
410
622
            CONCAT(ARM_OP_GROUP_AddrMode3Operand, \
411
622
             AlwaysPrintImm0), \
412
622
            Op, AlwaysPrintImm0); \
413
622
    MCOperand *MO1 = MCInst_getOperand(MI, (Op)); \
414
622
    if (!MCOperand_isReg(MO1)) { \
415
0
      printOperand(MI, Op, O); \
416
0
      return; \
417
0
    } \
418
622
\
419
622
    printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0); \
420
622
  }
ARMInstPrinter.c:printAddrMode3Operand_1
Line
Count
Source
408
105
  { \
409
105
    add_cs_detail(MI, \
410
105
            CONCAT(ARM_OP_GROUP_AddrMode3Operand, \
411
105
             AlwaysPrintImm0), \
412
105
            Op, AlwaysPrintImm0); \
413
105
    MCOperand *MO1 = MCInst_getOperand(MI, (Op)); \
414
105
    if (!MCOperand_isReg(MO1)) { \
415
0
      printOperand(MI, Op, O); \
416
0
      return; \
417
0
    } \
418
105
\
419
105
    printAM3PreOrOffsetIndexOp(MI, Op, O, AlwaysPrintImm0); \
420
105
  }
421
DEFINE_printAddrMode3Operand(false);
422
DEFINE_printAddrMode3Operand(true);
423
424
static inline void printAddrMode3OffsetOperand(MCInst *MI, unsigned OpNum,
425
                 SStream *O)
426
1.05k
{
427
1.05k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode3OffsetOperand, OpNum);
428
1.05k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
429
1.05k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
430
431
1.05k
  if (MCOperand_getReg(MO1)) {
432
642
    SStream_concat0(O, ARM_AM_getAddrOpcStr(ARM_AM_getAM3Op(
433
642
             MCOperand_getImm(MO2))));
434
642
    printRegName(O, MCOperand_getReg(MO1));
435
642
    return;
436
642
  }
437
438
413
  unsigned ImmOffs = ARM_AM_getAM3Offset(MCOperand_getImm(MO2));
439
413
  SStream_concat(O, "%s", markup("<imm:"));
440
413
  SStream_concat1(O, '#');
441
413
  SStream_concat(
442
413
    O, "%s",
443
413
    ARM_AM_getAddrOpcStr(ARM_AM_getAM3Op(MCOperand_getImm(MO2))));
444
413
  printUInt32(O, ImmOffs);
445
413
  SStream_concat0(O, markup(">"));
446
413
}
447
448
static inline void printPostIdxImm8Operand(MCInst *MI, unsigned OpNum,
449
             SStream *O)
450
107
{
451
107
  add_cs_detail(MI, ARM_OP_GROUP_PostIdxImm8Operand, OpNum);
452
107
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
453
107
  unsigned Imm = MCOperand_getImm(MO);
454
107
  SStream_concat(O, "%s", markup("<imm:"));
455
107
  SStream_concat1(O, '#');
456
107
  SStream_concat(O, "%s", ((Imm & 256) ? "" : "-"));
457
107
  printUInt32(O, (Imm & 0xff));
458
107
  SStream_concat0(O, markup(">"));
459
107
}
460
461
static inline void printPostIdxRegOperand(MCInst *MI, unsigned OpNum,
462
            SStream *O)
463
949
{
464
949
  add_cs_detail(MI, ARM_OP_GROUP_PostIdxRegOperand, OpNum);
465
949
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
466
949
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
467
468
949
  SStream_concat0(O, (MCOperand_getImm(MO2) ? "" : "-"));
469
949
  printRegName(O, MCOperand_getReg(MO1));
470
949
}
471
472
static inline void printPostIdxImm8s4Operand(MCInst *MI, unsigned OpNum,
473
               SStream *O)
474
1.02k
{
475
1.02k
  add_cs_detail(MI, ARM_OP_GROUP_PostIdxImm8s4Operand, OpNum);
476
1.02k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
477
1.02k
  unsigned Imm = MCOperand_getImm(MO);
478
1.02k
  SStream_concat(O, "%s", markup("<imm:"));
479
1.02k
  SStream_concat1(O, '#');
480
1.02k
  SStream_concat(O, "%s", ((Imm & 256) ? "" : "-"));
481
1.02k
  printUInt32(O, (Imm & 0xff) << 2);
482
1.02k
  SStream_concat0(O, markup(">"));
483
1.02k
}
484
485
#define DEFINE_printMveAddrModeRQOperand(shift) \
486
  static inline void CONCAT(printMveAddrModeRQOperand, shift)( \
487
    MCInst * MI, unsigned OpNum, SStream *O) \
488
34
  { \
489
34
    add_cs_detail( \
490
34
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
34
      OpNum, shift); \
492
34
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
34
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
34
\
495
34
    SStream_concat(O, "%s", markup("<mem:")); \
496
34
    SStream_concat0(O, "["); \
497
34
    printRegName(O, MCOperand_getReg(MO1)); \
498
34
    SStream_concat0(O, ", "); \
499
34
    printRegName(O, MCOperand_getReg(MO2)); \
500
34
\
501
34
    if (shift > 0) \
502
34
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
2
           getUseMarkup()); \
504
34
\
505
34
    SStream_concat(O, "%s", "]"); \
506
34
    SStream_concat0(O, markup(">")); \
507
34
  }
ARMInstPrinter.c:printMveAddrModeRQOperand_0
Line
Count
Source
488
32
  { \
489
32
    add_cs_detail( \
490
32
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
32
      OpNum, shift); \
492
32
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
32
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
32
\
495
32
    SStream_concat(O, "%s", markup("<mem:")); \
496
32
    SStream_concat0(O, "["); \
497
32
    printRegName(O, MCOperand_getReg(MO1)); \
498
32
    SStream_concat0(O, ", "); \
499
32
    printRegName(O, MCOperand_getReg(MO2)); \
500
32
\
501
32
    if (shift > 0) \
502
32
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
0
           getUseMarkup()); \
504
32
\
505
32
    SStream_concat(O, "%s", "]"); \
506
32
    SStream_concat0(O, markup(">")); \
507
32
  }
Unexecuted instantiation: ARMInstPrinter.c:printMveAddrModeRQOperand_3
Unexecuted instantiation: ARMInstPrinter.c:printMveAddrModeRQOperand_1
ARMInstPrinter.c:printMveAddrModeRQOperand_2
Line
Count
Source
488
2
  { \
489
2
    add_cs_detail( \
490
2
      MI, CONCAT(ARM_OP_GROUP_MveAddrModeRQOperand, shift), \
491
2
      OpNum, shift); \
492
2
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
493
2
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
494
2
\
495
2
    SStream_concat(O, "%s", markup("<mem:")); \
496
2
    SStream_concat0(O, "["); \
497
2
    printRegName(O, MCOperand_getReg(MO1)); \
498
2
    SStream_concat0(O, ", "); \
499
2
    printRegName(O, MCOperand_getReg(MO2)); \
500
2
\
501
2
    if (shift > 0) \
502
2
      printRegImmShift(MI, O, ARM_AM_uxtw, shift, \
503
2
           getUseMarkup()); \
504
2
\
505
2
    SStream_concat(O, "%s", "]"); \
506
2
    SStream_concat0(O, markup(">")); \
507
2
  }
508
DEFINE_printMveAddrModeRQOperand(0);
509
DEFINE_printMveAddrModeRQOperand(3);
510
DEFINE_printMveAddrModeRQOperand(1);
511
DEFINE_printMveAddrModeRQOperand(2);
512
513
#define DEFINE_printAddrMode5Operand(AlwaysPrintImm0) \
514
  static inline void CONCAT(printAddrMode5Operand, AlwaysPrintImm0)( \
515
    MCInst * MI, unsigned OpNum, SStream *O) \
516
2.06k
  { \
517
2.06k
    add_cs_detail(MI, \
518
2.06k
            CONCAT(ARM_OP_GROUP_AddrMode5Operand, \
519
2.06k
             AlwaysPrintImm0), \
520
2.06k
            OpNum, AlwaysPrintImm0); \
521
2.06k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
522
2.06k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
523
2.06k
\
524
2.06k
    SStream_concat(O, "%s", markup("<mem:")); \
525
2.06k
    SStream_concat0(O, "["); \
526
2.06k
    printRegName(O, MCOperand_getReg(MO1)); \
527
2.06k
\
528
2.06k
    unsigned ImmOffs = ARM_AM_getAM5Offset(MCOperand_getImm(MO2)); \
529
2.06k
    ARM_AM_AddrOpc Op = ARM_AM_getAM5Op(MCOperand_getImm(MO2)); \
530
2.06k
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
531
2.05k
      SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), \
532
2.05k
               "#", ARM_AM_getAddrOpcStr(Op)); \
533
2.05k
      printUInt32(O, ImmOffs * 4); \
534
2.05k
      SStream_concat0(O, markup(">")); \
535
2.05k
    } \
536
2.06k
    SStream_concat(O, "%s", "]"); \
537
2.06k
    SStream_concat0(O, markup(">")); \
538
2.06k
  }
ARMInstPrinter.c:printAddrMode5Operand_0
Line
Count
Source
516
1.10k
  { \
517
1.10k
    add_cs_detail(MI, \
518
1.10k
            CONCAT(ARM_OP_GROUP_AddrMode5Operand, \
519
1.10k
             AlwaysPrintImm0), \
520
1.10k
            OpNum, AlwaysPrintImm0); \
521
1.10k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
522
1.10k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
523
1.10k
\
524
1.10k
    SStream_concat(O, "%s", markup("<mem:")); \
525
1.10k
    SStream_concat0(O, "["); \
526
1.10k
    printRegName(O, MCOperand_getReg(MO1)); \
527
1.10k
\
528
1.10k
    unsigned ImmOffs = ARM_AM_getAM5Offset(MCOperand_getImm(MO2)); \
529
1.10k
    ARM_AM_AddrOpc Op = ARM_AM_getAM5Op(MCOperand_getImm(MO2)); \
530
1.10k
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
531
1.08k
      SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), \
532
1.08k
               "#", ARM_AM_getAddrOpcStr(Op)); \
533
1.08k
      printUInt32(O, ImmOffs * 4); \
534
1.08k
      SStream_concat0(O, markup(">")); \
535
1.08k
    } \
536
1.10k
    SStream_concat(O, "%s", "]"); \
537
1.10k
    SStream_concat0(O, markup(">")); \
538
1.10k
  }
ARMInstPrinter.c:printAddrMode5Operand_1
Line
Count
Source
516
966
  { \
517
966
    add_cs_detail(MI, \
518
966
            CONCAT(ARM_OP_GROUP_AddrMode5Operand, \
519
966
             AlwaysPrintImm0), \
520
966
            OpNum, AlwaysPrintImm0); \
521
966
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
522
966
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
523
966
\
524
966
    SStream_concat(O, "%s", markup("<mem:")); \
525
966
    SStream_concat0(O, "["); \
526
966
    printRegName(O, MCOperand_getReg(MO1)); \
527
966
\
528
966
    unsigned ImmOffs = ARM_AM_getAM5Offset(MCOperand_getImm(MO2)); \
529
966
    ARM_AM_AddrOpc Op = ARM_AM_getAM5Op(MCOperand_getImm(MO2)); \
530
966
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
531
966
      SStream_concat(O, "%s%s%s%s", ", ", markup("<imm:"), \
532
966
               "#", ARM_AM_getAddrOpcStr(Op)); \
533
966
      printUInt32(O, ImmOffs * 4); \
534
966
      SStream_concat0(O, markup(">")); \
535
966
    } \
536
966
    SStream_concat(O, "%s", "]"); \
537
966
    SStream_concat0(O, markup(">")); \
538
966
  }
539
DEFINE_printAddrMode5Operand(false);
540
DEFINE_printAddrMode5Operand(true);
541
542
#define DEFINE_printAddrMode5FP16Operand(AlwaysPrintImm0) \
543
  static inline void CONCAT(printAddrMode5FP16Operand, AlwaysPrintImm0)( \
544
    MCInst * MI, unsigned OpNum, SStream *O) \
545
15
  { \
546
15
    add_cs_detail(MI, \
547
15
            CONCAT(ARM_OP_GROUP_AddrMode5FP16Operand, \
548
15
             AlwaysPrintImm0), \
549
15
            OpNum, AlwaysPrintImm0); \
550
15
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
551
15
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
552
15
\
553
15
    if (!MCOperand_isReg(MO1)) { \
554
0
      printOperand(MI, OpNum, O); \
555
0
      return; \
556
0
    } \
557
15
\
558
15
    SStream_concat(O, "%s", markup("<mem:")); \
559
15
    SStream_concat0(O, "["); \
560
15
    printRegName(O, MCOperand_getReg(MO1)); \
561
15
\
562
15
    unsigned ImmOffs = \
563
15
      ARM_AM_getAM5FP16Offset(MCOperand_getImm(MO2)); \
564
15
    unsigned Op = ARM_AM_getAM5FP16Op(MCOperand_getImm(MO2)); \
565
15
    if (AlwaysPrintImm0 || ImmOffs || Op == ARM_AM_sub) { \
566
15
      SStream_concat( \
567
15
        O, "%s%s%s%s", ", ", markup("<imm:"), "#", \
568
15
        ARM_AM_getAddrOpcStr(ARM_AM_getAM5FP16Op( \
569
15
          MCOperand_getImm(MO2)))); \
570
15
      printUInt32(O, ImmOffs * 2); \
571
15
      SStream_concat0(O, markup(">")); \
572
15
    } \
573
15
    SStream_concat(O, "%s", "]"); \
574
15
    SStream_concat0(O, markup(">")); \
575
15
  }
576
DEFINE_printAddrMode5FP16Operand(false);
577
578
static inline void printAddrMode6Operand(MCInst *MI, unsigned OpNum, SStream *O)
579
9.34k
{
580
9.34k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode6Operand, OpNum);
581
9.34k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
582
9.34k
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
583
584
9.34k
  SStream_concat(O, "%s", markup("<mem:"));
585
9.34k
  SStream_concat0(O, "[");
586
9.34k
  printRegName(O, MCOperand_getReg(MO1));
587
9.34k
  if (MCOperand_getImm(MO2)) {
588
4.09k
    SStream_concat(O, "%s", ":");
589
4.09k
    printInt64(O, ((uint32_t)MCOperand_getImm(MO2)) << 3);
590
4.09k
  }
591
9.34k
  SStream_concat(O, "%s", "]");
592
9.34k
  SStream_concat0(O, markup(">"));
593
9.34k
}
594
595
static inline void printAddrMode7Operand(MCInst *MI, unsigned OpNum, SStream *O)
596
6.73k
{
597
6.73k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode7Operand, OpNum);
598
6.73k
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
599
6.73k
  SStream_concat(O, "%s", markup("<mem:"));
600
6.73k
  SStream_concat0(O, "[");
601
6.73k
  printRegName(O, MCOperand_getReg(MO1));
602
6.73k
  SStream_concat(O, "%s", "]");
603
6.73k
  SStream_concat0(O, markup(">"));
604
6.73k
}
605
606
static inline void printAddrMode6OffsetOperand(MCInst *MI, unsigned OpNum,
607
                 SStream *O)
608
3.82k
{
609
3.82k
  add_cs_detail(MI, ARM_OP_GROUP_AddrMode6OffsetOperand, OpNum);
610
3.82k
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
611
3.82k
  if (MCOperand_getReg(MO) == 0)
612
608
    SStream_concat0(O, "!");
613
3.22k
  else {
614
3.22k
    SStream_concat0(O, ", ");
615
3.22k
    printRegName(O, MCOperand_getReg(MO));
616
3.22k
  }
617
3.82k
}
618
619
static inline void printBitfieldInvMaskImmOperand(MCInst *MI, unsigned OpNum,
620
              SStream *O)
621
164
{
622
164
  add_cs_detail(MI, ARM_OP_GROUP_BitfieldInvMaskImmOperand, OpNum);
623
164
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
624
164
  uint32_t v = ~MCOperand_getImm(MO);
625
164
  int32_t lsb = CountTrailingZeros_32(v);
626
164
  int32_t width = (32 - countLeadingZeros(v)) - lsb;
627
628
164
  SStream_concat(O, "%s", markup("<imm:"));
629
164
  SStream_concat1(O, '#');
630
164
  printInt32(O, lsb);
631
164
  SStream_concat(O, "%s%s%s", markup(">"), ", ", markup("<imm:"));
632
164
  printInt32Bang(O, width);
633
164
  SStream_concat0(O, markup(">"));
634
164
}
635
636
static inline void printMemBOption(MCInst *MI, unsigned OpNum, SStream *O)
637
534
{
638
534
  add_cs_detail(MI, ARM_OP_GROUP_MemBOption, OpNum);
639
534
  unsigned val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
640
534
  SStream_concat0(O, ARM_MB_MemBOptToString(
641
534
           val, ARM_getFeatureBits(MI->csh->mode,
642
534
                 ARM_HasV8Ops)));
643
534
}
644
645
static inline void printInstSyncBOption(MCInst *MI, unsigned OpNum, SStream *O)
646
2.26k
{
647
2.26k
  add_cs_detail(MI, ARM_OP_GROUP_InstSyncBOption, OpNum);
648
2.26k
  unsigned val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
649
2.26k
  SStream_concat0(O, ARM_ISB_InstSyncBOptToString(val));
650
2.26k
}
651
652
static inline void printTraceSyncBOption(MCInst *MI, unsigned OpNum, SStream *O)
653
0
{
654
0
  add_cs_detail(MI, ARM_OP_GROUP_TraceSyncBOption, OpNum);
655
0
  unsigned val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
656
0
  SStream_concat0(O, ARM_TSB_TraceSyncBOptToString(val));
657
0
}
658
659
static inline void printShiftImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
660
251
{
661
251
  add_cs_detail(MI, ARM_OP_GROUP_ShiftImmOperand, OpNum);
662
251
  unsigned ShiftOp = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
663
251
  bool isASR = (ShiftOp & (1 << 5)) != 0;
664
251
  unsigned Amt = ShiftOp & 0x1f;
665
251
  if (isASR) {
666
203
    SStream_concat(O, "%s%s%s", ", asr ", markup("<imm:"), "#");
667
203
    printUInt32(O, Amt == 0 ? 32 : Amt);
668
203
    SStream_concat0(O, markup(">"));
669
203
  } else if (Amt) {
670
20
    SStream_concat(O, "%s%s%s", ", lsl ", markup("<imm:"), "#");
671
20
    printUInt32(O, Amt);
672
20
    SStream_concat0(O, markup(">"));
673
20
  }
674
251
}
675
676
static inline void printPKHLSLShiftImm(MCInst *MI, unsigned OpNum, SStream *O)
677
189
{
678
189
  add_cs_detail(MI, ARM_OP_GROUP_PKHLSLShiftImm, OpNum);
679
189
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
680
189
  if (Imm == 0)
681
161
    return;
682
683
28
  SStream_concat(O, "%s%s%s", ", lsl ", markup("<imm:"), "#");
684
28
  printUInt32(O, Imm);
685
28
  SStream_concat0(O, markup(">"));
686
28
}
687
688
static inline void printPKHASRShiftImm(MCInst *MI, unsigned OpNum, SStream *O)
689
11
{
690
11
  add_cs_detail(MI, ARM_OP_GROUP_PKHASRShiftImm, OpNum);
691
11
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
692
  // A shift amount of 32 is encoded as 0.
693
11
  if (Imm == 0)
694
1
    Imm = 32;
695
696
11
  SStream_concat(O, "%s%s%s", ", asr ", markup("<imm:"), "#");
697
11
  printUInt32(O, Imm);
698
11
  SStream_concat0(O, markup(">"));
699
11
}
700
701
static inline void printGPRPairOperand(MCInst *MI, unsigned OpNum, SStream *O)
702
61
{
703
61
  add_cs_detail(MI, ARM_OP_GROUP_GPRPairOperand, OpNum);
704
61
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
705
61
  printRegName(O, MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_gsub_0));
706
61
  SStream_concat0(O, ", ");
707
61
  printRegName(O, MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_gsub_1));
708
61
}
709
710
static inline void printSetendOperand(MCInst *MI, unsigned OpNum, SStream *O)
711
138
{
712
138
  add_cs_detail(MI, ARM_OP_GROUP_SetendOperand, OpNum);
713
138
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
714
138
  if (MCOperand_getImm(Op))
715
137
    SStream_concat0(O, "be");
716
1
  else
717
1
    SStream_concat0(O, "le");
718
138
}
719
720
static inline void printCPSIMod(MCInst *MI, unsigned OpNum, SStream *O)
721
228
{
722
228
  add_cs_detail(MI, ARM_OP_GROUP_CPSIMod, OpNum);
723
228
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
724
228
  SStream_concat0(O, ARM_PROC_IModToString(MCOperand_getImm(Op)));
725
228
}
726
727
static inline void printCPSIFlag(MCInst *MI, unsigned OpNum, SStream *O)
728
228
{
729
228
  add_cs_detail(MI, ARM_OP_GROUP_CPSIFlag, OpNum);
730
228
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
731
228
  unsigned IFlags = MCOperand_getImm(Op);
732
912
  for (int i = 2; i >= 0; --i)
733
684
    if (IFlags & (1 << i))
734
401
      SStream_concat0(O, ARM_PROC_IFlagsToString(1 << i));
735
736
228
  if (IFlags == 0)
737
38
    SStream_concat0(O, "none");
738
228
}
739
740
static inline void printMSRMaskOperand(MCInst *MI, unsigned OpNum, SStream *O)
741
1.57k
{
742
1.57k
  add_cs_detail(MI, ARM_OP_GROUP_MSRMaskOperand, OpNum);
743
1.57k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
744
745
1.57k
  if (ARM_getFeatureBits(MI->csh->mode, ARM_FeatureMClass)) {
746
1.41k
    unsigned SYSm = MCOperand_getImm(Op) & 0xFFF; // 12-bit SYSm
747
1.41k
    unsigned Opcode = MCInst_getOpcode(MI);
748
749
    // For writes, handle extended mask bits if the DSP extension is
750
    // present.
751
1.41k
    if (Opcode == ARM_t2MSR_M &&
752
1.27k
        ARM_getFeatureBits(MI->csh->mode, ARM_FeatureDSP)) {
753
1.27k
      const ARMSysReg_MClassSysReg *TheReg =
754
1.27k
        ARMSysReg_lookupMClassSysRegBy12bitSYSmValue(
755
1.27k
          SYSm);
756
1.27k
      if (TheReg && MClassSysReg_isInRequiredFeatures(
757
451
                TheReg, ARM_FeatureDSP)) {
758
40
        SStream_concat0(O, TheReg->Name);
759
40
        return;
760
40
      }
761
1.27k
    }
762
763
    // Handle the basic 8-bit mask.
764
1.37k
    SYSm &= 0xff;
765
1.37k
    if (Opcode == ARM_t2MSR_M &&
766
1.23k
        ARM_getFeatureBits(MI->csh->mode, ARM_HasV7Ops)) {
767
      // ARMv7-M deprecates using MSR APSR without a _<bits> qualifier as
768
      // an alias for MSR APSR_nzcvq.
769
1.23k
      const ARMSysReg_MClassSysReg *TheReg =
770
1.23k
        ARMSysReg_lookupMClassSysRegAPSRNonDeprecated(
771
1.23k
          SYSm);
772
1.23k
      if (TheReg) {
773
12
        SStream_concat0(O, TheReg->Name);
774
12
        return;
775
12
      }
776
1.23k
    }
777
778
1.35k
    const ARMSysReg_MClassSysReg *TheReg =
779
1.35k
      ARMSysReg_lookupMClassSysRegBy8bitSYSmValue(SYSm);
780
1.35k
    if (TheReg) {
781
1.24k
      SStream_concat0(O, TheReg->Name);
782
1.24k
      return;
783
1.24k
    }
784
785
115
    printUInt32(O, SYSm);
786
787
115
    return;
788
1.35k
  }
789
790
  // As special cases, CPSR_f, CPSR_s and CPSR_fs prefer printing as
791
  // APSR_nzcvq, APSR_g and APSRnzcvqg, respectively.
792
165
  unsigned SpecRegRBit = MCOperand_getImm(Op) >> 4;
793
165
  unsigned Mask = MCOperand_getImm(Op) & 0xf;
794
795
165
  if (!SpecRegRBit && (Mask == 8 || Mask == 4 || Mask == 12)) {
796
9
    SStream_concat0(O, "apsr_");
797
9
    switch (Mask) {
798
0
    default:
799
0
      CS_ASSERT_RET(0 && "Unexpected mask value!");
800
1
    case 4:
801
1
      SStream_concat0(O, "g");
802
1
      return;
803
1
    case 8:
804
1
      SStream_concat0(O, "nzcvq");
805
1
      return;
806
7
    case 12:
807
7
      SStream_concat0(O, "nzcvqg");
808
7
      return;
809
9
    }
810
9
  }
811
812
156
  if (SpecRegRBit)
813
148
    SStream_concat0(O, "spsr");
814
8
  else
815
8
    SStream_concat0(O, "cpsr");
816
817
156
  if (Mask) {
818
27
    SStream_concat0(O, "_");
819
820
27
    if (Mask & 8)
821
22
      SStream_concat0(O, "f");
822
823
27
    if (Mask & 4)
824
15
      SStream_concat0(O, "s");
825
826
27
    if (Mask & 2)
827
15
      SStream_concat0(O, "x");
828
829
27
    if (Mask & 1)
830
21
      SStream_concat0(O, "c");
831
27
  }
832
156
}
833
834
static inline void printBankedRegOperand(MCInst *MI, unsigned OpNum, SStream *O)
835
921
{
836
921
  add_cs_detail(MI, ARM_OP_GROUP_BankedRegOperand, OpNum);
837
921
  uint32_t Banked = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
838
921
  const ARMBankedReg_BankedReg *TheReg =
839
921
    ARMBankedReg_lookupBankedRegByEncoding(Banked);
840
841
921
  const char *Name = TheReg->Name;
842
843
  // uint32_t isSPSR = (Banked & 0x20) >> 5;
844
  // if (isSPSR)
845
  //  Name.replace(0, 4, "SPSR"); // convert 'spsr_' to 'SPSR_'
846
921
  SStream_concat0(O, Name);
847
921
}
848
849
static inline void printMandatoryPredicateOperand(MCInst *MI, unsigned OpNum,
850
              SStream *O)
851
4.50k
{
852
4.50k
  add_cs_detail(MI, ARM_OP_GROUP_MandatoryPredicateOperand, OpNum);
853
4.50k
  ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(
854
4.50k
    MCInst_getOperand(MI, (OpNum)));
855
4.50k
  SStream_concat0(O, ARMCondCodeToString(CC));
856
4.50k
}
857
858
static inline void
859
printMandatoryRestrictedPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
860
2.04k
{
861
2.04k
  add_cs_detail(MI, ARM_OP_GROUP_MandatoryRestrictedPredicateOperand,
862
2.04k
          OpNum);
863
2.04k
  if ((ARMCC_CondCodes)MCOperand_getImm(MCInst_getOperand(MI, (OpNum))) ==
864
2.04k
      ARMCC_HS)
865
222
    SStream_concat0(O, "cs");
866
1.81k
  else
867
1.81k
    printMandatoryPredicateOperand(MI, OpNum, O);
868
2.04k
}
869
870
static inline void
871
printMandatoryInvertedPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O)
872
94
{
873
94
  add_cs_detail(MI, ARM_OP_GROUP_MandatoryInvertedPredicateOperand,
874
94
          OpNum);
875
94
  ARMCC_CondCodes CC = (ARMCC_CondCodes)MCOperand_getImm(
876
94
    MCInst_getOperand(MI, (OpNum)));
877
94
  SStream_concat0(O, ARMCondCodeToString(ARMCC_getOppositeCondition(CC)));
878
94
}
879
880
static inline void printNoHashImmediate(MCInst *MI, unsigned OpNum, SStream *O)
881
5.87k
{
882
5.87k
  add_cs_detail(MI, ARM_OP_GROUP_NoHashImmediate, OpNum);
883
5.87k
  printInt64(O, MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
884
5.87k
}
885
886
static inline void printPImmediate(MCInst *MI, unsigned OpNum, SStream *O)
887
9.56k
{
888
9.56k
  add_cs_detail(MI, ARM_OP_GROUP_PImmediate, OpNum);
889
9.56k
  SStream_concat(O, "%s%d", "p",
890
9.56k
           MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
891
9.56k
}
892
893
static inline void printCImmediate(MCInst *MI, unsigned OpNum, SStream *O)
894
19.3k
{
895
19.3k
  add_cs_detail(MI, ARM_OP_GROUP_CImmediate, OpNum);
896
19.3k
  SStream_concat(O, "%s%d", "c",
897
19.3k
           MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
898
19.3k
}
899
900
static inline void printCoprocOptionImm(MCInst *MI, unsigned OpNum, SStream *O)
901
717
{
902
717
  add_cs_detail(MI, ARM_OP_GROUP_CoprocOptionImm, OpNum);
903
717
  SStream_concat(O, "%s", "{");
904
717
  printInt64(O, MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
905
717
  SStream_concat0(O, "}");
906
717
}
907
908
#define DEFINE_printAdrLabelOperand(scale) \
909
  static inline void CONCAT(printAdrLabelOperand, scale)( \
910
    MCInst * MI, unsigned OpNum, SStream *O) \
911
2.17k
  { \
912
2.17k
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_AdrLabelOperand, scale), \
913
2.17k
            OpNum, scale); \
914
2.17k
    MCOperand *MO = MCInst_getOperand(MI, (OpNum)); \
915
2.17k
\
916
2.17k
    if (MCOperand_isExpr(MO)) { \
917
0
      return; \
918
0
    } \
919
2.17k
\
920
2.17k
    int32_t OffImm = (uint32_t)MCOperand_getImm(MO) << scale; \
921
2.17k
\
922
2.17k
    SStream_concat0(O, markup("<imm:")); \
923
2.17k
    if (OffImm == INT32_MIN) \
924
2.17k
      SStream_concat0(O, "#-0"); \
925
2.17k
    else if (OffImm < 0) { \
926
51
      printInt32Bang(O, OffImm); \
927
2.12k
    } else { \
928
2.12k
      printInt32Bang(O, OffImm); \
929
2.12k
    } \
930
2.17k
    SStream_concat0(O, markup(">")); \
931
2.17k
  }
932
214
DEFINE_printAdrLabelOperand(0);
933
1.96k
DEFINE_printAdrLabelOperand(2);
934
935
#define DEFINE_printAdrLabelOperandAddr(scale) \
936
  static inline void CONCAT(printAdrLabelOperandAddr, scale)( \
937
    MCInst * MI, uint64_t Address, unsigned OpNum, SStream *O) \
938
1.96k
  { \
939
1.96k
    CONCAT(printAdrLabelOperand, scale)(MI, OpNum, O); \
940
1.96k
  }
941
DEFINE_printAdrLabelOperandAddr(2);
942
943
static inline void printThumbS4ImmOperand(MCInst *MI, unsigned OpNum,
944
            SStream *O)
945
2.27k
{
946
2.27k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbS4ImmOperand, OpNum);
947
2.27k
  SStream_concat(O, "%s", markup("<imm:"));
948
2.27k
  printInt64Bang(O, MCOperand_getImm(MCInst_getOperand(MI, (OpNum))) * 4);
949
2.27k
  SStream_concat0(O, markup(">"));
950
2.27k
}
951
952
static inline void printThumbSRImm(MCInst *MI, unsigned OpNum, SStream *O)
953
7.43k
{
954
7.43k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbSRImm, OpNum);
955
7.43k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
956
7.43k
  SStream_concat(O, "%s", markup("<imm:"));
957
7.43k
  printUInt32Bang(O, (Imm == 0 ? 32 : Imm));
958
7.43k
  SStream_concat0(O, markup(">"));
959
7.43k
}
960
961
static inline void printThumbITMask(MCInst *MI, unsigned OpNum, SStream *O)
962
2.61k
{
963
2.61k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbITMask, OpNum);
964
  // (3 - the number of trailing zeros) is the number of then / else.
965
2.61k
  unsigned Mask = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
966
2.61k
  unsigned NumTZ = CountTrailingZeros_32(Mask);
967
968
10.0k
  for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
969
7.45k
    if ((Mask >> Pos) & 1)
970
1.68k
      SStream_concat0(O, "e");
971
972
5.77k
    else
973
5.77k
      SStream_concat0(O, "t");
974
7.45k
  }
975
2.61k
}
976
977
static inline void printThumbAddrModeRROperand(MCInst *MI, unsigned Op,
978
                 SStream *O)
979
4.87k
{
980
4.87k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeRROperand, Op);
981
4.87k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
982
4.87k
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
983
984
4.87k
  if (!MCOperand_isReg(
985
4.87k
        MO1)) { // FIXME: This is for CP entries, but isn't right.
986
0
    printOperand(MI, Op, O);
987
0
    return;
988
0
  }
989
990
4.87k
  SStream_concat(O, "%s", markup("<mem:"));
991
4.87k
  SStream_concat0(O, "[");
992
4.87k
  printRegName(O, MCOperand_getReg(MO1));
993
4.87k
  unsigned RegNum = MCOperand_getReg(MO2);
994
4.87k
  if (RegNum) {
995
4.87k
    SStream_concat0(O, ", ");
996
4.87k
    printRegName(O, RegNum);
997
4.87k
  }
998
4.87k
  SStream_concat(O, "%s", "]");
999
4.87k
  SStream_concat0(O, markup(">"));
1000
4.87k
}
1001
1002
static inline void printThumbAddrModeImm5SOperand(MCInst *MI, unsigned Op,
1003
              SStream *O, unsigned Scale)
1004
22.4k
{
1005
22.4k
  MCOperand *MO1 = MCInst_getOperand(MI, (Op));
1006
22.4k
  MCOperand *MO2 = MCInst_getOperand(MI, (Op + 1));
1007
1008
22.4k
  if (!MCOperand_isReg(
1009
22.4k
        MO1)) { // FIXME: This is for CP entries, but isn't right.
1010
0
    printOperand(MI, Op, O);
1011
0
    return;
1012
0
  }
1013
1014
22.4k
  SStream_concat(O, "%s", markup("<mem:"));
1015
22.4k
  SStream_concat0(O, "[");
1016
22.4k
  printRegName(O, MCOperand_getReg(MO1));
1017
22.4k
  unsigned ImmOffs = MCOperand_getImm(MO2);
1018
22.4k
  if (ImmOffs) {
1019
21.1k
    SStream_concat(O, "%s%s", ", ", markup("<imm:"));
1020
21.1k
    printUInt32Bang(O, ImmOffs * Scale);
1021
21.1k
    SStream_concat0(O, markup(">"));
1022
21.1k
  }
1023
22.4k
  SStream_concat(O, "%s", "]");
1024
22.4k
  SStream_concat0(O, markup(">"));
1025
22.4k
}
1026
1027
static inline void printThumbAddrModeImm5S1Operand(MCInst *MI, unsigned Op,
1028
               SStream *O)
1029
26.3k
{
1030
26.3k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeImm5S1Operand, Op);
1031
26.3k
  printThumbAddrModeImm5SOperand(MI, Op, O, 1);
1032
26.3k
}
1033
1034
static inline void printThumbAddrModeImm5S2Operand(MCInst *MI, unsigned Op,
1035
               SStream *O)
1036
29.9k
{
1037
29.9k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeImm5S2Operand, Op);
1038
29.9k
  printThumbAddrModeImm5SOperand(MI, Op, O, 2);
1039
29.9k
}
1040
1041
static inline void printThumbAddrModeImm5S4Operand(MCInst *MI, unsigned Op,
1042
               SStream *O)
1043
36.1k
{
1044
36.1k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeImm5S4Operand, Op);
1045
36.1k
  printThumbAddrModeImm5SOperand(MI, Op, O, 4);
1046
36.1k
}
1047
1048
static inline void printThumbAddrModeSPOperand(MCInst *MI, unsigned Op,
1049
                 SStream *O)
1050
18.4k
{
1051
18.4k
  add_cs_detail(MI, ARM_OP_GROUP_ThumbAddrModeSPOperand, Op);
1052
18.4k
  printThumbAddrModeImm5SOperand(MI, Op, O, 4);
1053
18.4k
}
1054
1055
// Constant shifts t2_so_reg is a 2-operand unit corresponding to the Thumb2
1056
// register with shift forms.
1057
// REG 0   0           - e.g. R5
1058
// REG IMM, SH_OPC     - e.g. R5, LSL #3
1059
static inline void printT2SOOperand(MCInst *MI, unsigned OpNum, SStream *O)
1060
429
{
1061
429
  add_cs_detail(MI, ARM_OP_GROUP_T2SOOperand, OpNum);
1062
429
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1063
429
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
1064
1065
429
  unsigned Reg = MCOperand_getReg(MO1);
1066
429
  printRegName(O, Reg);
1067
1068
  // Print the shift opc.
1069
1070
429
  printRegImmShift(MI, O, ARM_AM_getSORegShOp(MCOperand_getImm(MO2)),
1071
429
       ARM_AM_getSORegOffset(MCOperand_getImm(MO2)),
1072
429
       getUseMarkup());
1073
429
}
1074
1075
#define DEFINE_printAddrModeImm12Operand(AlwaysPrintImm0) \
1076
  static inline void CONCAT(printAddrModeImm12Operand, AlwaysPrintImm0)( \
1077
    MCInst * MI, unsigned OpNum, SStream *O) \
1078
1.63k
  { \
1079
1.63k
    add_cs_detail(MI, \
1080
1.63k
            CONCAT(ARM_OP_GROUP_AddrModeImm12Operand, \
1081
1.63k
             AlwaysPrintImm0), \
1082
1.63k
            OpNum, AlwaysPrintImm0); \
1083
1.63k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1084
1.63k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1085
1.63k
\
1086
1.63k
    if (!MCOperand_isReg(MO1)) { \
1087
0
      printOperand(MI, OpNum, O); \
1088
0
      return; \
1089
0
    } \
1090
1.63k
\
1091
1.63k
    SStream_concat(O, "%s", markup("<mem:")); \
1092
1.63k
    SStream_concat0(O, "["); \
1093
1.63k
    printRegName(O, MCOperand_getReg(MO1)); \
1094
1.63k
\
1095
1.63k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1096
1.63k
    bool isSub = OffImm < 0; \
1097
1.63k
\
1098
1.63k
    if (OffImm == INT32_MIN) \
1099
1.63k
      OffImm = 0; \
1100
1.63k
    if (isSub) { \
1101
813
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1102
813
      printInt32Bang(O, OffImm); \
1103
813
      SStream_concat0(O, markup(">")); \
1104
817
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1105
790
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1106
790
      printInt32Bang(O, OffImm); \
1107
790
      SStream_concat0(O, markup(">")); \
1108
790
    } \
1109
1.63k
    SStream_concat(O, "%s", "]"); \
1110
1.63k
    SStream_concat0(O, markup(">")); \
1111
1.63k
  }
1112
1.16k
DEFINE_printAddrModeImm12Operand(false);
1113
462
DEFINE_printAddrModeImm12Operand(true);
1114
1115
#define DEFINE_printT2AddrModeImm8Operand(AlwaysPrintImm0) \
1116
  static inline void CONCAT(printT2AddrModeImm8Operand, \
1117
          AlwaysPrintImm0)(MCInst * MI, \
1118
               unsigned OpNum, SStream *O) \
1119
3.15k
  { \
1120
3.15k
    add_cs_detail(MI, \
1121
3.15k
            CONCAT(ARM_OP_GROUP_T2AddrModeImm8Operand, \
1122
3.15k
             AlwaysPrintImm0), \
1123
3.15k
            OpNum, AlwaysPrintImm0); \
1124
3.15k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1125
3.15k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1126
3.15k
\
1127
3.15k
    SStream_concat(O, "%s", markup("<mem:")); \
1128
3.15k
    SStream_concat0(O, "["); \
1129
3.15k
    printRegName(O, MCOperand_getReg(MO1)); \
1130
3.15k
\
1131
3.15k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1132
3.15k
    bool isSub = OffImm < 0; \
1133
3.15k
\
1134
3.15k
    if (OffImm == INT32_MIN) \
1135
3.15k
      OffImm = 0; \
1136
3.15k
    if (isSub) { \
1137
2.22k
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1138
2.22k
      printInt32Bang(O, OffImm); \
1139
2.22k
      SStream_concat0(O, markup(">")); \
1140
2.22k
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1141
826
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1142
826
      printInt32Bang(O, OffImm); \
1143
826
      SStream_concat0(O, markup(">")); \
1144
826
    } \
1145
3.15k
    SStream_concat(O, "%s", "]"); \
1146
3.15k
    SStream_concat0(O, markup(">")); \
1147
3.15k
  }
1148
1.69k
DEFINE_printT2AddrModeImm8Operand(true);
1149
1.45k
DEFINE_printT2AddrModeImm8Operand(false);
1150
1151
#define DEFINE_printT2AddrModeImm8s4Operand(AlwaysPrintImm0) \
1152
  static inline void CONCAT(printT2AddrModeImm8s4Operand, \
1153
          AlwaysPrintImm0)(MCInst * MI, \
1154
               unsigned OpNum, SStream *O) \
1155
1.64k
  { \
1156
1.64k
    add_cs_detail(MI, \
1157
1.64k
            CONCAT(ARM_OP_GROUP_T2AddrModeImm8s4Operand, \
1158
1.64k
             AlwaysPrintImm0), \
1159
1.64k
            OpNum, AlwaysPrintImm0); \
1160
1.64k
    MCOperand *MO1 = MCInst_getOperand(MI, (OpNum)); \
1161
1.64k
    MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1)); \
1162
1.64k
\
1163
1.64k
    if (!MCOperand_isReg(MO1)) { \
1164
0
      printOperand(MI, OpNum, O); \
1165
0
      return; \
1166
0
    } \
1167
1.64k
\
1168
1.64k
    SStream_concat(O, "%s", markup("<mem:")); \
1169
1.64k
    SStream_concat0(O, "["); \
1170
1.64k
    printRegName(O, MCOperand_getReg(MO1)); \
1171
1.64k
\
1172
1.64k
    int32_t OffImm = (int32_t)MCOperand_getImm(MO2); \
1173
1.64k
    bool isSub = OffImm < 0; \
1174
1.64k
\
1175
1.64k
    if (OffImm == INT32_MIN) \
1176
1.64k
      OffImm = 0; \
1177
1.64k
    if (isSub) { \
1178
798
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1179
798
      printInt32Bang(O, OffImm); \
1180
798
      SStream_concat0(O, markup(">")); \
1181
851
    } else if (AlwaysPrintImm0 || OffImm > 0) { \
1182
818
      SStream_concat(O, "%s%s", ", ", markup("<imm:")); \
1183
818
      printInt32Bang(O, OffImm); \
1184
818
      SStream_concat0(O, markup(">")); \
1185
818
    } \
1186
1.64k
    SStream_concat(O, "%s", "]"); \
1187
1.64k
    SStream_concat0(O, markup(">")); \
1188
1.64k
  }
1189
1190
269
DEFINE_printT2AddrModeImm8s4Operand(false);
1191
1.38k
DEFINE_printT2AddrModeImm8s4Operand(true);
1192
1193
static inline void printT2AddrModeImm0_1020s4Operand(MCInst *MI, unsigned OpNum,
1194
                 SStream *O)
1195
56
{
1196
56
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeImm0_1020s4Operand, OpNum);
1197
56
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1198
56
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
1199
1200
56
  SStream_concat(O, "%s", markup("<mem:"));
1201
56
  SStream_concat0(O, "[");
1202
56
  printRegName(O, MCOperand_getReg(MO1));
1203
56
  if (MCOperand_getImm(MO2)) {
1204
20
    SStream_concat(O, "%s%s", ", ", markup("<imm:"));
1205
20
    printInt64Bang(O, (int32_t)(MCOperand_getImm(MO2) * 4));
1206
20
    SStream_concat0(O, markup(">"));
1207
20
  }
1208
56
  SStream_concat(O, "%s", "]");
1209
56
  SStream_concat0(O, markup(">"));
1210
56
}
1211
1212
static inline void printT2AddrModeImm8OffsetOperand(MCInst *MI, unsigned OpNum,
1213
                SStream *O)
1214
805
{
1215
805
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeImm8OffsetOperand, OpNum);
1216
805
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1217
805
  int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
1218
805
  SStream_concat(O, "%s", ", ");
1219
805
  SStream_concat0(O, markup("<imm:"));
1220
805
  if (OffImm == INT32_MIN)
1221
67
    SStream_concat0(O, "#-0");
1222
738
  else if (OffImm < 0) {
1223
188
    printInt32Bang(O, OffImm);
1224
550
  } else {
1225
550
    printInt32Bang(O, OffImm);
1226
550
  }
1227
805
  SStream_concat0(O, markup(">"));
1228
805
}
1229
1230
static inline void
1231
printT2AddrModeImm8s4OffsetOperand(MCInst *MI, unsigned OpNum, SStream *O)
1232
226
{
1233
226
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeImm8s4OffsetOperand, OpNum);
1234
226
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1235
226
  int32_t OffImm = (int32_t)MCOperand_getImm(MO1);
1236
1237
226
  SStream_concat(O, "%s", ", ");
1238
226
  SStream_concat0(O, markup("<imm:"));
1239
226
  if (OffImm == INT32_MIN)
1240
38
    SStream_concat0(O, "#-0");
1241
188
  else if (OffImm < 0) {
1242
54
    printInt32Bang(O, OffImm);
1243
134
  } else {
1244
134
    printInt32Bang(O, OffImm);
1245
134
  }
1246
226
  SStream_concat0(O, markup(">"));
1247
226
}
1248
1249
static inline void printT2AddrModeSoRegOperand(MCInst *MI, unsigned OpNum,
1250
                 SStream *O)
1251
129
{
1252
129
  add_cs_detail(MI, ARM_OP_GROUP_T2AddrModeSoRegOperand, OpNum);
1253
129
  MCOperand *MO1 = MCInst_getOperand(MI, (OpNum));
1254
129
  MCOperand *MO2 = MCInst_getOperand(MI, (OpNum + 1));
1255
129
  MCOperand *MO3 = MCInst_getOperand(MI, (OpNum + 2));
1256
1257
129
  SStream_concat(O, "%s", markup("<mem:"));
1258
129
  SStream_concat0(O, "[");
1259
129
  printRegName(O, MCOperand_getReg(MO1));
1260
1261
129
  SStream_concat0(O, ", ");
1262
129
  printRegName(O, MCOperand_getReg(MO2));
1263
1264
129
  unsigned ShAmt = MCOperand_getImm(MO3);
1265
129
  if (ShAmt) {
1266
72
    SStream_concat(O, "%s%s%s", ", lsl ", markup("<imm:"), "#");
1267
72
    printUInt32(O, ShAmt);
1268
72
    SStream_concat0(O, markup(">"));
1269
72
  }
1270
129
  SStream_concat(O, "%s", "]");
1271
129
  SStream_concat0(O, markup(">"));
1272
129
}
1273
1274
static inline void printFPImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1275
239
{
1276
239
  add_cs_detail(MI, ARM_OP_GROUP_FPImmOperand, OpNum);
1277
239
  MCOperand *MO = MCInst_getOperand(MI, (OpNum));
1278
239
  SStream_concat(O, "%s", markup("<imm:"));
1279
239
  printFloatBang(O, ARM_AM_getFPImmFloat(MCOperand_getImm(MO)));
1280
239
  SStream_concat0(O, markup(">"));
1281
239
}
1282
1283
static inline void printVMOVModImmOperand(MCInst *MI, unsigned OpNum,
1284
            SStream *O)
1285
690
{
1286
690
  add_cs_detail(MI, ARM_OP_GROUP_VMOVModImmOperand, OpNum);
1287
690
  unsigned EncodedImm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1288
690
  unsigned EltBits;
1289
690
  uint64_t Val = ARM_AM_decodeVMOVModImm(EncodedImm, &EltBits);
1290
690
  SStream_concat(O, "%s", markup("<imm:"));
1291
690
  printUInt64Bang(O, Val);
1292
690
  SStream_concat0(O, markup(">"));
1293
690
}
1294
1295
static inline void printImmPlusOneOperand(MCInst *MI, unsigned OpNum,
1296
            SStream *O)
1297
187
{
1298
187
  add_cs_detail(MI, ARM_OP_GROUP_ImmPlusOneOperand, OpNum);
1299
187
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1300
187
  SStream_concat(O, "%s", markup("<imm:"));
1301
187
  printUInt32Bang(O, Imm + 1);
1302
187
  SStream_concat0(O, markup(">"));
1303
187
}
1304
1305
static inline void printRotImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1306
752
{
1307
752
  add_cs_detail(MI, ARM_OP_GROUP_RotImmOperand, OpNum);
1308
752
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1309
752
  if (Imm == 0)
1310
17
    return;
1311
1312
735
  SStream_concat(O, "%s%s%s%d", ", ror ", markup("<imm:"), "#", 8 * Imm);
1313
735
  SStream_concat0(O, markup(">"));
1314
735
}
1315
1316
static inline void printModImmOperand(MCInst *MI, unsigned OpNum, SStream *O)
1317
1.04k
{
1318
1.04k
  add_cs_detail(MI, ARM_OP_GROUP_ModImmOperand, OpNum);
1319
1.04k
  MCOperand *Op = MCInst_getOperand(MI, (OpNum));
1320
1321
  // Support for fixups (MCFixup)
1322
1.04k
  if (MCOperand_isExpr(Op)) {
1323
0
    printOperand(MI, OpNum, O);
1324
0
    return;
1325
0
  }
1326
1327
1.04k
  unsigned Bits = MCOperand_getImm(Op) & 0xFF;
1328
1.04k
  unsigned Rot = (MCOperand_getImm(Op) & 0xF00) >> 7;
1329
1330
1.04k
  bool PrintUnsigned = false;
1331
1.04k
  switch (MCInst_getOpcode(MI)) {
1332
24
  case ARM_MOVi:
1333
    // Movs to PC should be treated unsigned
1334
24
    PrintUnsigned =
1335
24
      (MCOperand_getReg(MCInst_getOperand(MI, (OpNum - 1))) ==
1336
24
       ARM_PC);
1337
24
    break;
1338
144
  case ARM_MSRi:
1339
    // Movs to special registers should be treated unsigned
1340
144
    PrintUnsigned = true;
1341
144
    break;
1342
1.04k
  }
1343
1344
1.04k
  int32_t Rotated = ARM_AM_rotr32(Bits, Rot);
1345
1.04k
  if (ARM_AM_getSOImmVal(Rotated) == MCOperand_getImm(Op)) {
1346
    // #rot has the least possible value
1347
686
    SStream_concat(O, "%s", "#");
1348
686
    SStream_concat0(O, markup("<imm:"));
1349
686
    if (PrintUnsigned)
1350
89
      printUInt32(O, (uint32_t)(Rotated));
1351
597
    else
1352
597
      printInt32(O, Rotated);
1353
686
    SStream_concat0(O, markup(">"));
1354
686
    return;
1355
686
  }
1356
1357
  // Explicit #bits, #rot implied
1358
362
  SStream_concat(O, "%s%s%u", "#", markup("<imm:"), Bits);
1359
362
  SStream_concat(O, "%s%s%s%u", markup(">"), ", #", markup("<imm:"), Rot);
1360
362
  SStream_concat0(O, markup(">"));
1361
362
}
1362
1363
static inline void printFBits16(MCInst *MI, unsigned OpNum, SStream *O)
1364
64
{
1365
64
  add_cs_detail(MI, ARM_OP_GROUP_FBits16, OpNum);
1366
64
  SStream_concat(O, "%s%s", markup("<imm:"), "#");
1367
64
  SStream_concat(O, "%d",
1368
64
           16 - MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
1369
64
  SStream_concat0(O, markup(">"));
1370
64
}
1371
1372
static inline void printFBits32(MCInst *MI, unsigned OpNum, SStream *O)
1373
42
{
1374
42
  add_cs_detail(MI, ARM_OP_GROUP_FBits32, OpNum);
1375
42
  SStream_concat(O, "%s%s", markup("<imm:"), "#");
1376
42
  printInt64(O, 32 - MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
1377
42
  SStream_concat0(O, markup(">"));
1378
42
}
1379
1380
static inline void printVectorIndex(MCInst *MI, unsigned OpNum, SStream *O)
1381
1.04k
{
1382
1.04k
  add_cs_detail(MI, ARM_OP_GROUP_VectorIndex, OpNum);
1383
1.04k
  SStream_concat(O, "%s", "[");
1384
1.04k
  printInt64(O,
1385
1.04k
       (int32_t)MCOperand_getImm(MCInst_getOperand(MI, (OpNum))));
1386
1.04k
  SStream_concat0(O, "]");
1387
1.04k
}
1388
1389
static inline void printVectorListOne(MCInst *MI, unsigned OpNum, SStream *O)
1390
578
{
1391
578
  add_cs_detail(MI, ARM_OP_GROUP_VectorListOne, OpNum);
1392
578
  SStream_concat0(O, "{");
1393
578
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1394
578
  SStream_concat0(O, "}");
1395
578
}
1396
1397
static inline void printVectorListTwo(MCInst *MI, unsigned OpNum, SStream *O)
1398
1.09k
{
1399
1.09k
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwo, OpNum);
1400
1.09k
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1401
1.09k
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1402
1.09k
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_1);
1403
1.09k
  SStream_concat0(O, "{");
1404
1.09k
  printRegName(O, Reg0);
1405
1.09k
  SStream_concat0(O, ", ");
1406
1.09k
  printRegName(O, Reg1);
1407
1.09k
  SStream_concat0(O, "}");
1408
1.09k
}
1409
1410
static inline void printVectorListTwoSpaced(MCInst *MI, unsigned OpNum,
1411
              SStream *O)
1412
885
{
1413
885
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwoSpaced, OpNum);
1414
885
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1415
885
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1416
885
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_2);
1417
885
  SStream_concat0(O, "{");
1418
885
  printRegName(O, Reg0);
1419
885
  SStream_concat0(O, ", ");
1420
885
  printRegName(O, Reg1);
1421
885
  SStream_concat0(O, "}");
1422
885
}
1423
1424
static inline void printVectorListThree(MCInst *MI, unsigned OpNum, SStream *O)
1425
542
{
1426
542
  add_cs_detail(MI, ARM_OP_GROUP_VectorListThree, OpNum);
1427
  // Normally, it's not safe to use register enum values directly with
1428
  // addition to get the next register, but for VFP registers, the
1429
  // sort order is guaranteed because they're all of the form D<n>.
1430
542
  SStream_concat0(O, "{");
1431
542
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1432
542
  SStream_concat0(O, ", ");
1433
542
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 1);
1434
542
  SStream_concat0(O, ", ");
1435
542
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1436
542
  SStream_concat0(O, "}");
1437
542
}
1438
1439
static inline void printVectorListFour(MCInst *MI, unsigned OpNum, SStream *O)
1440
856
{
1441
856
  add_cs_detail(MI, ARM_OP_GROUP_VectorListFour, OpNum);
1442
  // Normally, it's not safe to use register enum values directly with
1443
  // addition to get the next register, but for VFP registers, the
1444
  // sort order is guaranteed because they're all of the form D<n>.
1445
856
  SStream_concat0(O, "{");
1446
856
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1447
856
  SStream_concat0(O, ", ");
1448
856
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 1);
1449
856
  SStream_concat0(O, ", ");
1450
856
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1451
856
  SStream_concat0(O, ", ");
1452
856
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 3);
1453
856
  SStream_concat0(O, "}");
1454
856
}
1455
1456
static inline void printVectorListOneAllLanes(MCInst *MI, unsigned OpNum,
1457
                SStream *O)
1458
4
{
1459
4
  add_cs_detail(MI, ARM_OP_GROUP_VectorListOneAllLanes, OpNum);
1460
4
  SStream_concat0(O, "{");
1461
4
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1462
4
  SStream_concat0(O, "[]}");
1463
4
}
1464
1465
static inline void printVectorListTwoAllLanes(MCInst *MI, unsigned OpNum,
1466
                SStream *O)
1467
400
{
1468
400
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwoAllLanes, OpNum);
1469
400
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1470
400
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1471
400
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_1);
1472
400
  SStream_concat0(O, "{");
1473
400
  printRegName(O, Reg0);
1474
400
  SStream_concat0(O, "[], ");
1475
400
  printRegName(O, Reg1);
1476
400
  SStream_concat0(O, "[]}");
1477
400
}
1478
1479
static inline void printVectorListThreeAllLanes(MCInst *MI, unsigned OpNum,
1480
            SStream *O)
1481
0
{
1482
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListThreeAllLanes, OpNum);
1483
  // Normally, it's not safe to use register enum values directly with
1484
  // addition to get the next register, but for VFP registers, the
1485
  // sort order is guaranteed because they're all of the form D<n>.
1486
0
  SStream_concat0(O, "{");
1487
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1488
0
  SStream_concat0(O, "[], ");
1489
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 1);
1490
0
  SStream_concat0(O, "[], ");
1491
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1492
0
  SStream_concat0(O, "[]}");
1493
0
}
1494
1495
static inline void printVectorListFourAllLanes(MCInst *MI, unsigned OpNum,
1496
                 SStream *O)
1497
0
{
1498
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListFourAllLanes, OpNum);
1499
  // Normally, it's not safe to use register enum values directly with
1500
  // addition to get the next register, but for VFP registers, the
1501
  // sort order is guaranteed because they're all of the form D<n>.
1502
0
  SStream_concat0(O, "{");
1503
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1504
0
  SStream_concat0(O, "[], ");
1505
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 1);
1506
0
  SStream_concat0(O, "[], ");
1507
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1508
0
  SStream_concat0(O, "[], ");
1509
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 3);
1510
0
  SStream_concat0(O, "[]}");
1511
0
}
1512
1513
static inline void printVectorListTwoSpacedAllLanes(MCInst *MI, unsigned OpNum,
1514
                SStream *O)
1515
181
{
1516
181
  add_cs_detail(MI, ARM_OP_GROUP_VectorListTwoSpacedAllLanes, OpNum);
1517
181
  unsigned Reg = MCOperand_getReg(MCInst_getOperand(MI, (OpNum)));
1518
181
  unsigned Reg0 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_0);
1519
181
  unsigned Reg1 = MCRegisterInfo_getSubReg(MI->MRI, Reg, ARM_dsub_2);
1520
181
  SStream_concat0(O, "{");
1521
181
  printRegName(O, Reg0);
1522
181
  SStream_concat0(O, "[], ");
1523
181
  printRegName(O, Reg1);
1524
181
  SStream_concat0(O, "[]}");
1525
181
}
1526
1527
static inline void
1528
printVectorListThreeSpacedAllLanes(MCInst *MI, unsigned OpNum, SStream *O)
1529
0
{
1530
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListThreeSpacedAllLanes, OpNum);
1531
  // Normally, it's not safe to use register enum values directly with
1532
  // addition to get the next register, but for VFP registers, the
1533
  // sort order is guaranteed because they're all of the form D<n>.
1534
0
  SStream_concat0(O, "{");
1535
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1536
0
  SStream_concat0(O, "[], ");
1537
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1538
0
  SStream_concat0(O, "[], ");
1539
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 4);
1540
0
  SStream_concat0(O, "[]}");
1541
0
}
1542
1543
static inline void printVectorListFourSpacedAllLanes(MCInst *MI, unsigned OpNum,
1544
                 SStream *O)
1545
0
{
1546
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListFourSpacedAllLanes, OpNum);
1547
  // Normally, it's not safe to use register enum values directly with
1548
  // addition to get the next register, but for VFP registers, the
1549
  // sort order is guaranteed because they're all of the form D<n>.
1550
0
  SStream_concat0(O, "{");
1551
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1552
0
  SStream_concat0(O, "[], ");
1553
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1554
0
  SStream_concat0(O, "[], ");
1555
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 4);
1556
0
  SStream_concat0(O, "[], ");
1557
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 6);
1558
0
  SStream_concat0(O, "[]}");
1559
0
}
1560
1561
static inline void printVectorListThreeSpaced(MCInst *MI, unsigned OpNum,
1562
                SStream *O)
1563
0
{
1564
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListThreeSpaced, OpNum);
1565
  // Normally, it's not safe to use register enum values directly with
1566
  // addition to get the next register, but for VFP registers, the
1567
  // sort order is guaranteed because they're all of the form D<n>.
1568
0
  SStream_concat0(O, "{");
1569
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1570
0
  SStream_concat0(O, ", ");
1571
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1572
0
  SStream_concat0(O, ", ");
1573
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 4);
1574
0
  SStream_concat0(O, "}");
1575
0
}
1576
1577
static inline void printVectorListFourSpaced(MCInst *MI, unsigned OpNum,
1578
               SStream *O)
1579
0
{
1580
0
  add_cs_detail(MI, ARM_OP_GROUP_VectorListFourSpaced, OpNum);
1581
  // Normally, it's not safe to use register enum values directly with
1582
  // addition to get the next register, but for VFP registers, the
1583
  // sort order is guaranteed because they're all of the form D<n>.
1584
0
  SStream_concat0(O, "{");
1585
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))));
1586
0
  SStream_concat0(O, ", ");
1587
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 2);
1588
0
  SStream_concat0(O, ", ");
1589
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 4);
1590
0
  SStream_concat0(O, ", ");
1591
0
  printRegName(O, MCOperand_getReg(MCInst_getOperand(MI, (OpNum))) + 6);
1592
0
  SStream_concat0(O, "}");
1593
0
}
1594
1595
#define DEFINE_printMVEVectorList(NumRegs) \
1596
  static inline void CONCAT(printMVEVectorList, NumRegs)( \
1597
    MCInst * MI, unsigned OpNum, SStream *O) \
1598
450
  { \
1599
450
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_MVEVectorList, NumRegs), \
1600
450
            OpNum, NumRegs); \
1601
450
    unsigned Reg = \
1602
450
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1603
450
    const char *Prefix = "{"; \
1604
1.58k
    for (unsigned i = 0; i < NumRegs; i++) { \
1605
1.13k
      SStream_concat0(O, Prefix); \
1606
1.13k
      printRegName( \
1607
1.13k
        O, MCRegisterInfo_getSubReg(MI->MRI, Reg, \
1608
1.13k
                  ARM_qsub_0 + i)); \
1609
1.13k
      Prefix = ", "; \
1610
1.13k
    } \
1611
450
    SStream_concat0(O, "}"); \
1612
450
  }
ARMInstPrinter.c:printMVEVectorList_2
Line
Count
Source
1598
333
  { \
1599
333
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_MVEVectorList, NumRegs), \
1600
333
            OpNum, NumRegs); \
1601
333
    unsigned Reg = \
1602
333
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1603
333
    const char *Prefix = "{"; \
1604
999
    for (unsigned i = 0; i < NumRegs; i++) { \
1605
666
      SStream_concat0(O, Prefix); \
1606
666
      printRegName( \
1607
666
        O, MCRegisterInfo_getSubReg(MI->MRI, Reg, \
1608
666
                  ARM_qsub_0 + i)); \
1609
666
      Prefix = ", "; \
1610
666
    } \
1611
333
    SStream_concat0(O, "}"); \
1612
333
  }
ARMInstPrinter.c:printMVEVectorList_4
Line
Count
Source
1598
117
  { \
1599
117
    add_cs_detail(MI, CONCAT(ARM_OP_GROUP_MVEVectorList, NumRegs), \
1600
117
            OpNum, NumRegs); \
1601
117
    unsigned Reg = \
1602
117
      MCOperand_getReg(MCInst_getOperand(MI, (OpNum))); \
1603
117
    const char *Prefix = "{"; \
1604
585
    for (unsigned i = 0; i < NumRegs; i++) { \
1605
468
      SStream_concat0(O, Prefix); \
1606
468
      printRegName( \
1607
468
        O, MCRegisterInfo_getSubReg(MI->MRI, Reg, \
1608
468
                  ARM_qsub_0 + i)); \
1609
468
      Prefix = ", "; \
1610
468
    } \
1611
117
    SStream_concat0(O, "}"); \
1612
117
  }
1613
DEFINE_printMVEVectorList(2) DEFINE_printMVEVectorList(4)
1614
1615
#define DEFINE_printComplexRotationOp(Angle, Remainder) \
1616
  static inline void CONCAT(printComplexRotationOp, \
1617
          CONCAT(Angle, Remainder))( \
1618
    MCInst * MI, unsigned OpNo, SStream *O) \
1619
304
  { \
1620
304
    add_cs_detail( \
1621
304
      MI, \
1622
304
      CONCAT(CONCAT(ARM_OP_GROUP_ComplexRotationOp, Angle), \
1623
304
             Remainder), \
1624
304
      OpNo, Angle, Remainder); \
1625
304
    unsigned Val = \
1626
304
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
1627
304
    SStream_concat(O, "#%d", (Val * Angle) + Remainder); \
1628
304
  }
ARMInstPrinter.c:printComplexRotationOp_90_0
Line
Count
Source
1619
103
  { \
1620
103
    add_cs_detail( \
1621
103
      MI, \
1622
103
      CONCAT(CONCAT(ARM_OP_GROUP_ComplexRotationOp, Angle), \
1623
103
             Remainder), \
1624
103
      OpNo, Angle, Remainder); \
1625
103
    unsigned Val = \
1626
103
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
1627
103
    SStream_concat(O, "#%d", (Val * Angle) + Remainder); \
1628
103
  }
ARMInstPrinter.c:printComplexRotationOp_180_90
Line
Count
Source
1619
201
  { \
1620
201
    add_cs_detail( \
1621
201
      MI, \
1622
201
      CONCAT(CONCAT(ARM_OP_GROUP_ComplexRotationOp, Angle), \
1623
201
             Remainder), \
1624
201
      OpNo, Angle, Remainder); \
1625
201
    unsigned Val = \
1626
201
      MCOperand_getImm(MCInst_getOperand(MI, (OpNo))); \
1627
201
    SStream_concat(O, "#%d", (Val * Angle) + Remainder); \
1628
201
  }
1629
  DEFINE_printComplexRotationOp(90, 0) DEFINE_printComplexRotationOp(180,
1630
                     90)
1631
1632
    static inline void printVPTPredicateOperand(MCInst *MI,
1633
                  unsigned OpNum,
1634
                  SStream *O)
1635
7.67k
{
1636
7.67k
  add_cs_detail(MI, ARM_OP_GROUP_VPTPredicateOperand, OpNum);
1637
7.67k
  ARMVCC_VPTCodes CC = (ARMVCC_VPTCodes)MCOperand_getImm(
1638
7.67k
    MCInst_getOperand(MI, (OpNum)));
1639
7.67k
  if (CC != ARMVCC_None)
1640
507
    SStream_concat0(O, ARMVPTPredToString(CC));
1641
7.67k
}
1642
1643
static inline void printVPTMask(MCInst *MI, unsigned OpNum, SStream *O)
1644
1.15k
{
1645
1.15k
  add_cs_detail(MI, ARM_OP_GROUP_VPTMask, OpNum);
1646
  // (3 - the number of trailing zeroes) is the number of them / else.
1647
1.15k
  unsigned Mask = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1648
1.15k
  unsigned NumTZ = CountTrailingZeros_32(Mask);
1649
1650
3.79k
  for (unsigned Pos = 3, e = NumTZ; Pos > e; --Pos) {
1651
2.64k
    bool T = ((Mask >> Pos) & 1) == 0;
1652
2.64k
    if (T)
1653
1.76k
      SStream_concat0(O, "t");
1654
1655
885
    else
1656
885
      SStream_concat0(O, "e");
1657
2.64k
  }
1658
1.15k
}
1659
1660
static inline void printMveSaturateOp(MCInst *MI, unsigned OpNum, SStream *O)
1661
0
{
1662
0
  add_cs_detail(MI, ARM_OP_GROUP_MveSaturateOp, OpNum);
1663
0
  uint32_t Val = MCOperand_getImm(MCInst_getOperand(MI, (OpNum)));
1664
1665
0
  printUInt32Bang(O, (Val == 1 ? 48 : 64));
1666
0
}
1667
1668
#define PRINT_ALIAS_INSTR
1669
#include "ARMGenAsmWriter.inc"
1670
1671
static void printInst(MCInst *MI, SStream *O, void *info)
1672
164k
{
1673
164k
  bool isAlias = false;
1674
164k
  bool useAliasDetails = map_use_alias_details(MI);
1675
164k
  map_set_fill_detail_ops(MI, useAliasDetails);
1676
164k
  unsigned Opcode = MCInst_getOpcode(MI);
1677
164k
  uint64_t Address = MI->address;
1678
1679
164k
  switch (Opcode) {
1680
  // Check for MOVs and print canonical forms, instead.
1681
123
  case ARM_MOVsr: {
1682
123
    isAlias = true;
1683
123
    MCInst_setIsAlias(MI, isAlias);
1684
    // FIXME: Thumb variants?
1685
123
    MCOperand *MO3 = MCInst_getOperand(MI, (3));
1686
1687
123
    SStream_concat1(O, ' ');
1688
123
    SStream_concat0(O, ARM_AM_getShiftOpcStr(ARM_AM_getSORegShOp(
1689
123
             MCOperand_getImm(MO3))));
1690
123
    printSBitModifierOperand(MI, 6, O);
1691
123
    printPredicateOperand(MI, 4, O);
1692
1693
123
    SStream_concat0(O, " ");
1694
1695
123
    printOperand(MI, 0, O);
1696
123
    SStream_concat0(O, ", ");
1697
123
    printOperand(MI, 1, O);
1698
1699
123
    SStream_concat0(O, ", ");
1700
123
    printOperand(MI, 2, O);
1701
1702
123
    if (useAliasDetails)
1703
123
      return;
1704
0
    else
1705
0
      goto add_real_detail;
1706
123
  }
1707
1708
305
  case ARM_MOVsi: {
1709
305
    isAlias = true;
1710
305
    MCInst_setIsAlias(MI, isAlias);
1711
    // FIXME: Thumb variants?
1712
305
    MCOperand *MO2 = MCInst_getOperand(MI, (2));
1713
1714
305
    SStream_concat0(O, ARM_AM_getShiftOpcStr(ARM_AM_getSORegShOp(
1715
305
             MCOperand_getImm(MO2))));
1716
305
    printSBitModifierOperand(MI, 5, O);
1717
305
    printPredicateOperand(MI, 3, O);
1718
1719
305
    SStream_concat0(O, " ");
1720
1721
305
    printOperand(MI, 0, O);
1722
305
    SStream_concat0(O, ", ");
1723
305
    printOperand(MI, 1, O);
1724
1725
305
    if (ARM_AM_getSORegShOp(MCOperand_getImm(MO2)) == ARM_AM_rrx) {
1726
8
      if (useAliasDetails)
1727
8
        return;
1728
0
      else
1729
0
        goto add_real_detail;
1730
8
    }
1731
1732
297
    SStream_concat(O, "%s%s%s%d", ", ", markup("<imm:"), "#",
1733
297
             translateShiftImm(ARM_AM_getSORegOffset(
1734
297
               MCOperand_getImm(MO2))));
1735
297
    SStream_concat0(O, markup(">"));
1736
297
    if (useAliasDetails)
1737
297
      return;
1738
0
    else
1739
0
      goto add_real_detail;
1740
297
  }
1741
1742
  // A8.6.123 PUSH
1743
28
  case ARM_STMDB_UPD:
1744
61
  case ARM_t2STMDB_UPD:
1745
61
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP &&
1746
33
        MCInst_getNumOperands(MI) > 5) {
1747
25
      isAlias = true;
1748
25
      MCInst_setIsAlias(MI, isAlias);
1749
      // Should only print PUSH if there are at least two registers in the
1750
      // list.
1751
25
      SStream_concat0(O, "push");
1752
25
      printPredicateOperand(MI, 2, O);
1753
25
      if (Opcode == ARM_t2STMDB_UPD)
1754
22
        SStream_concat0(O, ".w");
1755
25
      SStream_concat0(O, " ");
1756
1757
25
      printRegisterList(MI, 4, O);
1758
25
      if (useAliasDetails)
1759
25
        return;
1760
0
      else
1761
0
        goto add_real_detail;
1762
25
    } else
1763
36
      break;
1764
1765
238
  case ARM_STR_PRE_IMM:
1766
238
    if (MCOperand_getReg(MCInst_getOperand(MI, (2))) == ARM_SP &&
1767
47
        MCOperand_getImm(MCInst_getOperand(MI, (3))) == -4) {
1768
0
      isAlias = true;
1769
0
      MCInst_setIsAlias(MI, isAlias);
1770
0
      SStream_concat1(O, ' ');
1771
0
      SStream_concat0(O, "push");
1772
0
      printPredicateOperand(MI, 4, O);
1773
0
      SStream_concat0(O, " {");
1774
0
      printOperand(MI, 1, O);
1775
0
      SStream_concat0(O, "}");
1776
0
      if (useAliasDetails)
1777
0
        return;
1778
0
      else
1779
0
        goto add_real_detail;
1780
0
    } else
1781
238
      break;
1782
1783
  // A8.6.122 POP
1784
271
  case ARM_LDMIA_UPD:
1785
278
  case ARM_t2LDMIA_UPD:
1786
278
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP &&
1787
5
        MCInst_getNumOperands(MI) > 5) {
1788
5
      isAlias = true;
1789
5
      MCInst_setIsAlias(MI, isAlias);
1790
      // Should only print POP if there are at least two registers in the
1791
      // list.
1792
5
      SStream_concat0(O, "pop");
1793
5
      printPredicateOperand(MI, 2, O);
1794
5
      if (Opcode == ARM_t2LDMIA_UPD)
1795
2
        SStream_concat0(O, ".w");
1796
5
      SStream_concat0(O, " ");
1797
1798
5
      printRegisterList(MI, 4, O);
1799
5
      if (useAliasDetails)
1800
5
        return;
1801
0
      else
1802
0
        goto add_real_detail;
1803
5
    } else
1804
273
      break;
1805
1806
12
  case ARM_LDR_POST_IMM:
1807
12
    if ((MCOperand_getReg(MCInst_getOperand(MI, (2))) == ARM_SP) &&
1808
8
        ((ARM_AM_getAM2Offset(MCOperand_getImm(
1809
8
            MCInst_getOperand(MI, (4)))) == 4))) {
1810
3
      isAlias = true;
1811
3
      MCInst_setIsAlias(MI, isAlias);
1812
3
      SStream_concat0(O, "pop");
1813
3
      printPredicateOperand(MI, 5, O);
1814
3
      SStream_concat0(O, " {");
1815
3
      printOperand(MI, 0, O);
1816
3
      SStream_concat0(O, "}");
1817
3
      if (useAliasDetails)
1818
3
        return;
1819
0
      else
1820
0
        goto add_real_detail;
1821
3
    } else
1822
9
      break;
1823
180
  case ARM_t2LDR_POST:
1824
180
    if ((MCOperand_getReg(MCInst_getOperand(MI, (2))) == ARM_SP) &&
1825
136
        (Opcode == ARM_t2LDR_POST &&
1826
136
         (MCOperand_getImm(MCInst_getOperand(MI, (3))) == 4))) {
1827
134
      isAlias = true;
1828
134
      MCInst_setIsAlias(MI, isAlias);
1829
134
      SStream_concat0(O, "pop");
1830
134
      printPredicateOperand(MI, 4, O);
1831
134
      SStream_concat0(O, " {");
1832
134
      printOperand(MI, 0, O);
1833
134
      SStream_concat0(O, "}");
1834
134
      if (useAliasDetails)
1835
134
        return;
1836
0
      else
1837
0
        goto add_real_detail;
1838
134
    } else
1839
46
      break;
1840
1841
  // A8.6.355 VPUSH
1842
10
  case ARM_VSTMSDB_UPD:
1843
14
  case ARM_VSTMDDB_UPD:
1844
14
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP) {
1845
14
      isAlias = true;
1846
14
      MCInst_setIsAlias(MI, isAlias);
1847
14
      SStream_concat0(O, "vpush");
1848
14
      printPredicateOperand(MI, 2, O);
1849
14
      SStream_concat0(O, " ");
1850
1851
14
      printRegisterList(MI, 4, O);
1852
14
      if (useAliasDetails)
1853
14
        return;
1854
0
      else
1855
0
        goto add_real_detail;
1856
14
    } else
1857
0
      break;
1858
1859
  // A8.6.354 VPOP
1860
2
  case ARM_VLDMSIA_UPD:
1861
158
  case ARM_VLDMDIA_UPD:
1862
158
    if (MCOperand_getReg(MCInst_getOperand(MI, (0))) == ARM_SP) {
1863
156
      isAlias = true;
1864
156
      MCInst_setIsAlias(MI, isAlias);
1865
156
      SStream_concat1(O, ' ');
1866
156
      SStream_concat0(O, "vpop");
1867
156
      printPredicateOperand(MI, 2, O);
1868
156
      SStream_concat0(O, " ");
1869
1870
156
      printRegisterList(MI, 4, O);
1871
156
      if (useAliasDetails)
1872
156
        return;
1873
0
      else
1874
0
        goto add_real_detail;
1875
156
    } else
1876
2
      break;
1877
1878
1.77k
  case ARM_tLDMIA: {
1879
1.77k
    isAlias = true;
1880
1.77k
    MCInst_setIsAlias(MI, isAlias);
1881
1.77k
    bool Writeback = true;
1882
1.77k
    unsigned BaseReg = MCOperand_getReg(MCInst_getOperand(MI, (0)));
1883
9.47k
    for (unsigned i = 3; i < MCInst_getNumOperands(MI); ++i) {
1884
7.70k
      if (MCOperand_getReg(MCInst_getOperand(MI, (i))) ==
1885
7.70k
          BaseReg)
1886
1.07k
        Writeback = false;
1887
7.70k
    }
1888
1889
1.77k
    SStream_concat0(O, "ldm");
1890
1891
1.77k
    printPredicateOperand(MI, 1, O);
1892
1.77k
    SStream_concat0(O, " ");
1893
1894
1.77k
    printOperand(MI, 0, O);
1895
1.77k
    if (Writeback) {
1896
700
      SStream_concat0(O, "!");
1897
700
    }
1898
1.77k
    SStream_concat0(O, ", ");
1899
1.77k
    printRegisterList(MI, 3, O);
1900
1.77k
    if (useAliasDetails)
1901
1.77k
      return;
1902
0
    else
1903
0
      goto add_real_detail;
1904
1.77k
  }
1905
1906
  // Combine 2 GPRs from disassember into a GPRPair to match with instr def.
1907
  // ldrexd/strexd require even/odd GPR pair. To enforce this constraint,
1908
  // a single GPRPair reg operand is used in the .td file to replace the two
1909
  // GPRs. However, when decoding them, the two GRPs cannot be automatically
1910
  // expressed as a GPRPair, so we have to manually merge them.
1911
  // FIXME: We would really like to be able to tablegen'erate this.
1912
1
  case ARM_LDREXD:
1913
51
  case ARM_STREXD:
1914
60
  case ARM_LDAEXD:
1915
61
  case ARM_STLEXD: {
1916
61
    const MCRegisterClass *MRC =
1917
61
      MCRegisterInfo_getRegClass(MI->MRI, ARM_GPRRegClassID);
1918
61
    bool isStore = Opcode == ARM_STREXD || Opcode == ARM_STLEXD;
1919
61
    unsigned Reg = MCOperand_getReg(
1920
61
      MCInst_getOperand(MI, isStore ? 1 : 0));
1921
1922
61
    if (MCRegisterClass_contains(MRC, Reg)) {
1923
0
      MCInst NewMI;
1924
1925
0
      MCInst_Init(&NewMI, CS_ARCH_ARM);
1926
0
      MCInst_setOpcode(&NewMI, Opcode);
1927
1928
0
      if (isStore)
1929
0
        MCInst_addOperand2(&NewMI,
1930
0
               MCInst_getOperand(MI, 0));
1931
1932
0
      MCOperand_CreateReg0(
1933
0
        &NewMI,
1934
0
        MCRegisterInfo_getMatchingSuperReg(
1935
0
          MI->MRI, Reg, ARM_gsub_0,
1936
0
          MCRegisterInfo_getRegClass(
1937
0
            MI->MRI,
1938
0
            ARM_GPRPairRegClassID)));
1939
1940
      // Copy the rest operands into NewMI.
1941
0
      for (unsigned i = isStore ? 3 : 2;
1942
0
           i < MCInst_getNumOperands(MI); ++i)
1943
0
        MCInst_addOperand2(&NewMI,
1944
0
               MCInst_getOperand(MI, i));
1945
1946
0
      printInstruction(&NewMI, Address, O);
1947
0
      return;
1948
0
    }
1949
61
    break;
1950
61
  }
1951
61
  case ARM_TSB:
1952
38
  case ARM_t2TSB:
1953
38
    isAlias = true;
1954
38
    MCInst_setIsAlias(MI, isAlias);
1955
1956
38
    SStream_concat0(O, " tsb csync");
1957
38
    if (useAliasDetails)
1958
38
      return;
1959
0
    else
1960
0
      goto add_real_detail;
1961
53
  case ARM_t2DSB:
1962
53
    isAlias = true;
1963
53
    MCInst_setIsAlias(MI, isAlias);
1964
1965
53
    switch (MCOperand_getImm(MCInst_getOperand(MI, (0)))) {
1966
13
    default:
1967
13
      if (!printAliasInstr(MI, Address, O))
1968
13
        printInstruction(MI, Address, O);
1969
13
      break;
1970
7
    case 0:
1971
7
      SStream_concat0(O, " ssbb");
1972
7
      break;
1973
33
    case 4:
1974
33
      SStream_concat0(O, " pssbb");
1975
33
      break;
1976
53
    };
1977
53
    if (useAliasDetails)
1978
53
      return;
1979
0
    else
1980
0
      goto add_real_detail;
1981
164k
  }
1982
1983
162k
  if (!isAlias)
1984
162k
    isAlias |= printAliasInstr(MI, Address, O);
1985
1986
162k
add_real_detail:
1987
162k
  MCInst_setIsAlias(MI, isAlias);
1988
162k
  if (!isAlias || !useAliasDetails) {
1989
161k
    map_set_fill_detail_ops(MI, !(isAlias && useAliasDetails));
1990
161k
    if (isAlias)
1991
0
      SStream_Close(O);
1992
161k
    printInstruction(MI, Address, O);
1993
161k
    if (isAlias)
1994
0
      SStream_Open(O);
1995
161k
  }
1996
162k
}
1997
1998
const char *ARM_LLVM_getRegisterName(unsigned RegNo, unsigned AltIdx)
1999
109k
{
2000
109k
  return getRegisterName(RegNo, AltIdx);
2001
109k
}
2002
2003
void ARM_LLVM_printInstruction(MCInst *MI, SStream *O,
2004
             void * /* MCRegisterInfo* */ info)
2005
164k
{
2006
164k
  printInst(MI, O, info);
2007
164k
}