Coverage Report

Created: 2024-09-08 06:22

/src/capstonenext/arch/RISCV/RISCVInstPrinter.c
Line
Count
Source (jump to first uncovered line)
1
//===-- RISCVInstPrinter.cpp - Convert RISCV MCInst to asm 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 RISCV MCInst to a .s file.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifdef CAPSTONE_HAS_RISCV
15
16
#include <stdio.h>    // DEBUG
17
#include <stdlib.h>
18
#include <string.h>
19
#include <capstone/platform.h>
20
21
#include "RISCVInstPrinter.h"
22
#include "RISCVBaseInfo.h"
23
#include "../../MCInst.h"
24
#include "../../SStream.h"
25
#include "../../MCRegisterInfo.h"
26
#include "../../utils.h"
27
#include "../../Mapping.h"
28
#include "RISCVMapping.h"
29
30
//#include "RISCVDisassembler.h"
31
32
#define GET_REGINFO_ENUM
33
#define GET_REGINFO_MC_DESC
34
#include "RISCVGenRegisterInfo.inc"
35
#define GET_INSTRINFO_ENUM
36
#include "RISCVGenInstrInfo.inc"
37
38
// Autogenerated by tblgen.
39
static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI);
40
static bool printAliasInstr(MCInst *MI, SStream *OS, void *info);
41
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);
42
static void printFenceArg(MCInst *MI, unsigned OpNo, SStream *O);
43
static void printCSRSystemRegister(MCInst*, unsigned, SStream *);
44
static void printFRMArg(MCInst *MI, unsigned OpNo, SStream *O);
45
static void printCustomAliasOperand( MCInst *, unsigned, unsigned, SStream *);
46
/// getRegisterName - This method is automatically generated by tblgen
47
/// from the register set description.  This returns the assembler name
48
/// for the specified register.
49
static const char *getRegisterName(unsigned RegNo, unsigned AltIdx);
50
51
// Include the auto-generated portion of the assembly writer.
52
#define PRINT_ALIAS_INSTR
53
#include "RISCVGenAsmWriter.inc"
54
55
56
static void fixDetailOfEffectiveAddr(MCInst *MI)
57
9.99k
{
58
  // Operands for load and store instructions in RISCV vary widely
59
9.99k
  unsigned id = MI->flat_insn->id;
60
9.99k
  unsigned reg = 0;
61
9.99k
  int64_t imm = 0;
62
9.99k
    uint8_t access = 0;
63
  
64
9.99k
  switch (id) {
65
0
    case RISCV_INS_C_FLD:
66
0
    case RISCV_INS_C_LW:
67
0
    case RISCV_INS_C_FLW:
68
0
    case RISCV_INS_C_LD:
69
0
    case RISCV_INS_C_FSD:
70
0
    case RISCV_INS_C_SW:
71
0
    case RISCV_INS_C_FSW:
72
0
    case RISCV_INS_C_SD:
73
0
    case RISCV_INS_C_FLDSP:
74
0
    case RISCV_INS_C_LWSP:
75
0
    case RISCV_INS_C_FLWSP:
76
0
    case RISCV_INS_C_LDSP:
77
0
    case RISCV_INS_C_FSDSP:
78
0
    case RISCV_INS_C_SWSP:
79
0
    case RISCV_INS_C_FSWSP:
80
0
    case RISCV_INS_C_SDSP:
81
35
    case RISCV_INS_FLW:
82
418
    case RISCV_INS_FSW:
83
479
    case RISCV_INS_FLD:
84
714
    case RISCV_INS_FSD:
85
999
    case RISCV_INS_LB:
86
1.08k
    case RISCV_INS_LBU:
87
1.18k
    case RISCV_INS_LD:
88
1.20k
    case RISCV_INS_LH:
89
1.29k
    case RISCV_INS_LHU:
90
1.84k
    case RISCV_INS_LW:
91
1.86k
    case RISCV_INS_LWU:
92
2.36k
    case RISCV_INS_SB:
93
3.32k
    case RISCV_INS_SD:
94
3.77k
    case RISCV_INS_SH:
95
4.67k
    case RISCV_INS_SW: {
96
4.67k
      CS_ASSERT(3 == MI->flat_insn->detail->riscv.op_count);
97
4.67k
      CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -3)->type);
98
4.67k
      CS_ASSERT(RISCV_OP_IMM == RISCV_get_detail_op(MI, -2)->type);
99
4.67k
      CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -1)->type);
100
101
4.67k
      imm = RISCV_get_detail_op(MI, -2)->imm;
102
4.67k
      reg = RISCV_get_detail_op(MI, -1)->reg;
103
4.67k
      access = RISCV_get_detail_op(MI, -1)->access;
104
105
4.67k
      RISCV_get_detail_op(MI, -2)->type = RISCV_OP_MEM;
106
4.67k
      RISCV_get_detail_op(MI, -2)->mem.base = reg;
107
4.67k
      RISCV_get_detail_op(MI, -2)->mem.disp = imm;
108
4.67k
      RISCV_get_detail_op(MI, -2)->access = access;
109
110
4.67k
      RISCV_dec_op_count(MI);
111
112
4.67k
      break;
113
3.77k
    }
114
54
    case RISCV_INS_LR_W:
115
102
    case RISCV_INS_LR_W_AQ:
116
126
    case RISCV_INS_LR_W_AQ_RL:
117
136
    case RISCV_INS_LR_W_RL:
118
253
    case RISCV_INS_LR_D:
119
265
    case RISCV_INS_LR_D_AQ:
120
275
    case RISCV_INS_LR_D_AQ_RL:
121
293
    case RISCV_INS_LR_D_RL: {
122
293
      CS_ASSERT(2 == MI->flat_insn->detail->riscv.op_count);
123
293
      CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -1)->type);
124
293
      CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -2)->type);
125
126
293
      reg = RISCV_get_detail_op(MI, -1)->reg;
127
128
293
      RISCV_get_detail_op(MI, -1)->type = RISCV_OP_MEM;
129
293
      RISCV_get_detail_op(MI, -1)->mem.base = reg;
130
293
      RISCV_get_detail_op(MI, -1)->mem.disp = 0;
131
132
293
      break;
133
275
    }
134
21
    case RISCV_INS_SC_W:
135
32
    case RISCV_INS_SC_W_AQ:
136
50
    case RISCV_INS_SC_W_AQ_RL:
137
133
    case RISCV_INS_SC_W_RL:
138
143
    case RISCV_INS_SC_D:
139
158
    case RISCV_INS_SC_D_AQ:
140
298
    case RISCV_INS_SC_D_AQ_RL:
141
332
    case RISCV_INS_SC_D_RL:
142
392
    case RISCV_INS_AMOADD_D:
143
402
    case RISCV_INS_AMOADD_D_AQ:
144
413
    case RISCV_INS_AMOADD_D_AQ_RL:
145
418
    case RISCV_INS_AMOADD_D_RL:
146
730
    case RISCV_INS_AMOADD_W:
147
747
    case RISCV_INS_AMOADD_W_AQ:
148
843
    case RISCV_INS_AMOADD_W_AQ_RL:
149
847
    case RISCV_INS_AMOADD_W_RL:
150
869
    case RISCV_INS_AMOAND_D:
151
1.02k
    case RISCV_INS_AMOAND_D_AQ:
152
1.03k
    case RISCV_INS_AMOAND_D_AQ_RL:
153
1.04k
    case RISCV_INS_AMOAND_D_RL:
154
1.06k
    case RISCV_INS_AMOAND_W:
155
1.09k
    case RISCV_INS_AMOAND_W_AQ:
156
1.10k
    case RISCV_INS_AMOAND_W_AQ_RL:
157
1.11k
    case RISCV_INS_AMOAND_W_RL:
158
1.36k
    case RISCV_INS_AMOMAXU_D:
159
1.37k
    case RISCV_INS_AMOMAXU_D_AQ:
160
1.38k
    case RISCV_INS_AMOMAXU_D_AQ_RL:
161
1.39k
    case RISCV_INS_AMOMAXU_D_RL:
162
1.40k
    case RISCV_INS_AMOMAXU_W:
163
1.42k
    case RISCV_INS_AMOMAXU_W_AQ:
164
1.43k
    case RISCV_INS_AMOMAXU_W_AQ_RL:
165
1.46k
    case RISCV_INS_AMOMAXU_W_RL:
166
1.47k
    case RISCV_INS_AMOMAX_D:
167
1.56k
    case RISCV_INS_AMOMAX_D_AQ:
168
2.66k
    case RISCV_INS_AMOMAX_D_AQ_RL:
169
2.74k
    case RISCV_INS_AMOMAX_D_RL:
170
2.76k
    case RISCV_INS_AMOMAX_W:
171
2.77k
    case RISCV_INS_AMOMAX_W_AQ:
172
2.78k
    case RISCV_INS_AMOMAX_W_AQ_RL:
173
2.80k
    case RISCV_INS_AMOMAX_W_RL:
174
2.83k
    case RISCV_INS_AMOMINU_D:
175
2.84k
    case RISCV_INS_AMOMINU_D_AQ:
176
2.86k
    case RISCV_INS_AMOMINU_D_AQ_RL:
177
3.00k
    case RISCV_INS_AMOMINU_D_RL:
178
3.05k
    case RISCV_INS_AMOMINU_W:
179
3.05k
    case RISCV_INS_AMOMINU_W_AQ:
180
3.07k
    case RISCV_INS_AMOMINU_W_AQ_RL:
181
3.11k
    case RISCV_INS_AMOMINU_W_RL:
182
3.12k
    case RISCV_INS_AMOMIN_D:
183
3.12k
    case RISCV_INS_AMOMIN_D_AQ:
184
3.13k
    case RISCV_INS_AMOMIN_D_AQ_RL:
185
3.14k
    case RISCV_INS_AMOMIN_D_RL:
186
3.18k
    case RISCV_INS_AMOMIN_W:
187
3.27k
    case RISCV_INS_AMOMIN_W_AQ:
188
3.28k
    case RISCV_INS_AMOMIN_W_AQ_RL:
189
3.30k
    case RISCV_INS_AMOMIN_W_RL:
190
4.28k
    case RISCV_INS_AMOOR_D:
191
4.34k
    case RISCV_INS_AMOOR_D_AQ:
192
4.52k
    case RISCV_INS_AMOOR_D_AQ_RL:
193
4.60k
    case RISCV_INS_AMOOR_D_RL:
194
4.63k
    case RISCV_INS_AMOOR_W:
195
4.65k
    case RISCV_INS_AMOOR_W_AQ:
196
4.69k
    case RISCV_INS_AMOOR_W_AQ_RL:
197
4.72k
    case RISCV_INS_AMOOR_W_RL:
198
4.73k
    case RISCV_INS_AMOSWAP_D:
199
4.75k
    case RISCV_INS_AMOSWAP_D_AQ:
200
4.76k
    case RISCV_INS_AMOSWAP_D_AQ_RL:
201
4.77k
    case RISCV_INS_AMOSWAP_D_RL:
202
4.78k
    case RISCV_INS_AMOSWAP_W:
203
4.79k
    case RISCV_INS_AMOSWAP_W_AQ:
204
4.84k
    case RISCV_INS_AMOSWAP_W_AQ_RL:
205
4.84k
    case RISCV_INS_AMOSWAP_W_RL:
206
4.85k
    case RISCV_INS_AMOXOR_D:
207
4.88k
    case RISCV_INS_AMOXOR_D_AQ:
208
4.88k
    case RISCV_INS_AMOXOR_D_AQ_RL:
209
4.90k
    case RISCV_INS_AMOXOR_D_RL:
210
4.92k
    case RISCV_INS_AMOXOR_W:
211
4.94k
    case RISCV_INS_AMOXOR_W_AQ:
212
4.94k
    case RISCV_INS_AMOXOR_W_AQ_RL:
213
5.03k
    case RISCV_INS_AMOXOR_W_RL: {
214
5.03k
      CS_ASSERT(3 == MI->flat_insn->detail->riscv.op_count);
215
5.03k
      CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -3)->type);
216
5.03k
      CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -2)->type);
217
5.03k
      CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -1)->type);
218
219
5.03k
      reg = RISCV_get_detail_op(MI, -1)->reg;
220
221
5.03k
      RISCV_get_detail_op(MI, -1)->type = RISCV_OP_MEM;
222
5.03k
      RISCV_get_detail_op(MI, -1)->mem.base = reg;
223
5.03k
      RISCV_get_detail_op(MI, -1)->mem.disp = 0;
224
225
5.03k
      break;
226
4.94k
    }
227
0
    default: {
228
0
      CS_ASSERT(0 && "id is not a RISC-V memory instruction");
229
0
      break;
230
4.94k
    }
231
9.99k
  }
232
9.99k
  return;
233
9.99k
}
234
235
236
//void RISCVInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
237
//                                 StringRef Annot, const MCSubtargetInfo &STI) 
238
void RISCV_printInst(MCInst *MI, SStream *O, void *info) 
239
98.7k
{
240
98.7k
    MCRegisterInfo *MRI = (MCRegisterInfo *) info;
241
    //bool Res = false;
242
    //MCInst *NewMI = MI;
243
    // TODO: RISCV compressd instructions.
244
    //MCInst UncompressedMI;
245
    //if (!NoAliases)
246
      //Res = uncompressInst(UncompressedMI, *MI, MRI, STI);
247
    //if (Res)
248
      //NewMI = const_cast<MCInst *>(&UncompressedMI);
249
98.7k
    if (/*NoAliases ||*/ !printAliasInstr(MI, O, info))
250
78.6k
        printInstruction(MI, O, MRI);
251
      //printAnnotation(O, Annot);
252
  // fix load/store type insttuction
253
98.7k
      if (MI->csh->detail_opt && 
254
98.7k
      MI->flat_insn->detail->riscv.need_effective_addr)
255
11.2k
    fixDetailOfEffectiveAddr(MI);
256
  
257
98.7k
  return;
258
98.7k
}
259
260
static void printRegName(SStream *OS, unsigned RegNo) 
261
178k
{
262
178k
    SStream_concat0(OS, getRegisterName(RegNo, RISCV_ABIRegAltName));
263
178k
}
264
265
/**
266
void RISCVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
267
                                    raw_ostream &O, const char *Modifier) 
268
*/
269
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O) 
270
157k
{
271
157k
    unsigned reg;
272
157k
    int64_t Imm = 0;
273
274
157k
    RISCV_add_cs_detail(MI, OpNo);
275
276
157k
    MCOperand *MO = MCInst_getOperand(MI, OpNo);
277
  
278
157k
    if (MCOperand_isReg(MO)) {
279
132k
        reg = MCOperand_getReg(MO);
280
132k
        printRegName(O, reg);
281
132k
    } else {
282
24.8k
    CS_ASSERT(MCOperand_isImm(MO) && "Unknown operand kind in printOperand");
283
24.8k
        Imm = MCOperand_getImm(MO);
284
24.8k
        if (Imm >= 0) {
285
21.8k
            if (Imm > HEX_THRESHOLD)
286
13.4k
              SStream_concat(O, "0x%" PRIx64, Imm);
287
8.36k
            else
288
8.36k
        SStream_concat(O, "%" PRIu64, Imm);
289
21.8k
        } else {
290
2.99k
            if (Imm < -HEX_THRESHOLD)
291
2.96k
        SStream_concat(O, "-0x%" PRIx64, -Imm);
292
27
            else
293
27
        SStream_concat(O, "-%" PRIu64, -Imm);
294
2.99k
        }
295
24.8k
      }
296
297
    //CS_ASSERT(MO.isExpr() && "Unknown operand kind in printOperand");
298
  
299
157k
  return;
300
157k
}
301
302
static const char *getCSRSystemRegisterName(unsigned CsrNo)
303
55.4k
{
304
55.4k
  switch (CsrNo) {
305
  /*
306
   * From RISC-V Privileged Architecture Version 1.10.
307
   * In the same order as Table 2.5.
308
   */
309
579
  case 0x0000: return "ustatus";
310
27
  case 0x0004: return "uie";
311
90
  case 0x0005: return "utvec";
312
313
15
  case 0x0040: return "uscratch";
314
29
  case 0x0041: return "uepc";
315
425
  case 0x0042: return "ucause";
316
94
  case 0x0043: return "utval";
317
84
  case 0x0044: return "uip";
318
319
337
  case 0x0001: return "fflags";
320
828
  case 0x0002: return "frm";
321
1.89k
  case 0x0003: return "fcsr";
322
323
139
  case 0x0c00: return "cycle";
324
1.03k
  case 0x0c01: return "time";
325
56
  case 0x0c02: return "instret";
326
318
  case 0x0c03: return "hpmcounter3";
327
222
  case 0x0c04: return "hpmcounter4";
328
80
  case 0x0c05: return "hpmcounter5";
329
241
  case 0x0c06: return "hpmcounter6";
330
131
  case 0x0c07: return "hpmcounter7";
331
306
  case 0x0c08: return "hpmcounter8";
332
133
  case 0x0c09: return "hpmcounter9";
333
373
  case 0x0c0a: return "hpmcounter10";
334
262
  case 0x0c0b: return "hpmcounter11";
335
20
  case 0x0c0c: return "hpmcounter12";
336
47
  case 0x0c0d: return "hpmcounter13";
337
35
  case 0x0c0e: return "hpmcounter14";
338
243
  case 0x0c0f: return "hpmcounter15";
339
931
  case 0x0c10: return "hpmcounter16";
340
141
  case 0x0c11: return "hpmcounter17";
341
40
  case 0x0c12: return "hpmcounter18";
342
372
  case 0x0c13: return "hpmcounter19";
343
306
  case 0x0c14: return "hpmcounter20";
344
64
  case 0x0c15: return "hpmcounter21";
345
42
  case 0x0c16: return "hpmcounter22";
346
18
  case 0x0c17: return "hpmcounter23";
347
126
  case 0x0c18: return "hpmcounter24";
348
197
  case 0x0c19: return "hpmcounter25";
349
236
  case 0x0c1a: return "hpmcounter26";
350
940
  case 0x0c1b: return "hpmcounter27";
351
179
  case 0x0c1c: return "hpmcounter28";
352
392
  case 0x0c1d: return "hpmcounter29";
353
918
  case 0x0c1e: return "hpmcounter30";
354
102
  case 0x0c1f: return "hpmcounter31";
355
275
  case 0x0c80: return "cycleh";
356
326
  case 0x0c81: return "timeh";
357
346
  case 0x0c82: return "instreth";
358
66
  case 0x0c83: return "hpmcounter3h";
359
109
  case 0x0c84: return "hpmcounter4h";
360
171
  case 0x0c85: return "hpmcounter5h";
361
70
  case 0x0c86: return "hpmcounter6h";
362
53
  case 0x0c87: return "hpmcounter7h";
363
175
  case 0x0c88: return "hpmcounter8h";
364
147
  case 0x0c89: return "hpmcounter9h";
365
428
  case 0x0c8a: return "hpmcounter10h";
366
61
  case 0x0c8b: return "hpmcounter11h";
367
135
  case 0x0c8c: return "hpmcounter12h";
368
400
  case 0x0c8d: return "hpmcounter13h";
369
56
  case 0x0c8e: return "hpmcounter14h";
370
125
  case 0x0c8f: return "hpmcounter15h";
371
588
  case 0x0c90: return "hpmcounter16h";
372
390
  case 0x0c91: return "hpmcounter17h";
373
377
  case 0x0c92: return "hpmcounter18h";
374
122
  case 0x0c93: return "hpmcounter19h";
375
374
  case 0x0c94: return "hpmcounter20h";
376
409
  case 0x0c95: return "hpmcounter21h";
377
108
  case 0x0c96: return "hpmcounter22h";
378
59
  case 0x0c97: return "hpmcounter23h";
379
20
  case 0x0c98: return "hpmcounter24h";
380
37
  case 0x0c99: return "hpmcounter25h";
381
81
  case 0x0c9a: return "hpmcounter26h";
382
98
  case 0x0c9b: return "hpmcounter27h";
383
87
  case 0x0c9c: return "hpmcounter28h";
384
434
  case 0x0c9d: return "hpmcounter29h";
385
80
  case 0x0c9e: return "hpmcounter30h";
386
274
  case 0x0c9f: return "hpmcounter31h";
387
388
96
  case 0x0100: return "sstatus";
389
736
  case 0x0102: return "sedeleg";
390
106
  case 0x0103: return "sideleg";
391
40
  case 0x0104: return "sie";
392
23
  case 0x0105: return "stvec";
393
42
  case 0x0106: return "scounteren";
394
395
55
  case 0x0140: return "sscratch";
396
294
  case 0x0141: return "sepc";
397
95
  case 0x0142: return "scause";
398
218
  case 0x0143: return "stval";
399
42
  case 0x0144: return "sip";
400
401
66
  case 0x0180: return "satp";
402
403
122
  case 0x0f11: return "mvendorid";
404
44
  case 0x0f12: return "marchid";
405
79
  case 0x0f13: return "mimpid";
406
101
  case 0x0f14: return "mhartid";
407
408
52
  case 0x0300: return "mstatus";
409
53
  case 0x0301: return "misa";
410
173
  case 0x0302: return "medeleg";
411
42
  case 0x0303: return "mideleg";
412
98
  case 0x0304: return "mie";
413
285
  case 0x0305: return "mtvec";
414
30
  case 0x0306: return "mcounteren";
415
416
290
  case 0x0340: return "mscratch";
417
782
  case 0x0341: return "mepc";
418
52
  case 0x0342: return "mcause";
419
299
  case 0x0343: return "mtval";
420
89
  case 0x0344: return "mip";
421
422
92
  case 0x03a0: return "pmpcfg0";
423
20
  case 0x03a1: return "pmpcfg1";
424
85
  case 0x03a2: return "pmpcfg2";
425
226
  case 0x03a3: return "pmpcfg3";
426
54
  case 0x03b0: return "pmpaddr0";
427
135
  case 0x03b1: return "pmpaddr1";
428
103
  case 0x03b2: return "pmpaddr2";
429
218
  case 0x03b3: return "pmpaddr3";
430
93
  case 0x03b4: return "pmpaddr4";
431
120
  case 0x03b5: return "pmpaddr5";
432
25
  case 0x03b6: return "pmpaddr6";
433
177
  case 0x03b7: return "pmpaddr7";
434
175
  case 0x03b8: return "pmpaddr8";
435
106
  case 0x03b9: return "pmpaddr9";
436
263
  case 0x03ba: return "pmpaddr10";
437
29
  case 0x03bb: return "pmpaddr11";
438
41
  case 0x03bc: return "pmpaddr12";
439
49
  case 0x03bd: return "pmpaddr13";
440
285
  case 0x03be: return "pmpaddr14";
441
66
  case 0x03bf: return "pmpaddr15";
442
443
832
  case 0x0b00: return "mcycle";
444
60
  case 0x0b02: return "minstret";
445
137
  case 0x0b03: return "mhpmcounter3";
446
494
  case 0x0b04: return "mhpmcounter4";
447
40
  case 0x0b05: return "mhpmcounter5";
448
48
  case 0x0b06: return "mhpmcounter6";
449
323
  case 0x0b07: return "mhpmcounter7";
450
65
  case 0x0b08: return "mhpmcounter8";
451
189
  case 0x0b09: return "mhpmcounter9";
452
198
  case 0x0b0a: return "mhpmcounter10";
453
52
  case 0x0b0b: return "mhpmcounter11";
454
979
  case 0x0b0c: return "mhpmcounter12";
455
210
  case 0x0b0d: return "mhpmcounter13";
456
99
  case 0x0b0e: return "mhpmcounter14";
457
199
  case 0x0b0f: return "mhpmcounter15";
458
60
  case 0x0b10: return "mhpmcounter16";
459
59
  case 0x0b11: return "mhpmcounter17";
460
235
  case 0x0b12: return "mhpmcounter18";
461
289
  case 0x0b13: return "mhpmcounter19";
462
142
  case 0x0b14: return "mhpmcounter20";
463
16
  case 0x0b15: return "mhpmcounter21";
464
171
  case 0x0b16: return "mhpmcounter22";
465
65
  case 0x0b17: return "mhpmcounter23";
466
235
  case 0x0b18: return "mhpmcounter24";
467
70
  case 0x0b19: return "mhpmcounter25";
468
140
  case 0x0b1a: return "mhpmcounter26";
469
44
  case 0x0b1b: return "mhpmcounter27";
470
1.02k
  case 0x0b1c: return "mhpmcounter28";
471
264
  case 0x0b1d: return "mhpmcounter29";
472
90
  case 0x0b1e: return "mhpmcounter30";
473
28
  case 0x0b1f: return "mhpmcounter31";
474
91
  case 0x0b80: return "mcycleh";
475
40
  case 0x0b82: return "minstreth";
476
60
  case 0x0b83: return "mhpmcounter3h";
477
148
  case 0x0b84: return "mhpmcounter4h";
478
32
  case 0x0b85: return "mhpmcounter5h";
479
193
  case 0x0b86: return "mhpmcounter6h";
480
40
  case 0x0b87: return "mhpmcounter7h";
481
187
  case 0x0b88: return "mhpmcounter8h";
482
248
  case 0x0b89: return "mhpmcounter9h";
483
33
  case 0x0b8a: return "mhpmcounter10h";
484
972
  case 0x0b8b: return "mhpmcounter11h";
485
145
  case 0x0b8c: return "mhpmcounter12h";
486
391
  case 0x0b8d: return "mhpmcounter13h";
487
301
  case 0x0b8e: return "mhpmcounter14h";
488
165
  case 0x0b8f: return "mhpmcounter15h";
489
505
  case 0x0b90: return "mhpmcounter16h";
490
386
  case 0x0b91: return "mhpmcounter17h";
491
548
  case 0x0b92: return "mhpmcounter18h";
492
126
  case 0x0b93: return "mhpmcounter19h";
493
134
  case 0x0b94: return "mhpmcounter20h";
494
136
  case 0x0b95: return "mhpmcounter21h";
495
47
  case 0x0b96: return "mhpmcounter22h";
496
169
  case 0x0b97: return "mhpmcounter23h";
497
112
  case 0x0b98: return "mhpmcounter24h";
498
75
  case 0x0b99: return "mhpmcounter25h";
499
717
  case 0x0b9a: return "mhpmcounter26h";
500
781
  case 0x0b9b: return "mhpmcounter27h";
501
301
  case 0x0b9c: return "mhpmcounter28h";
502
259
  case 0x0b9d: return "mhpmcounter29h";
503
249
  case 0x0b9e: return "mhpmcounter30h";
504
151
  case 0x0b9f: return "mhpmcounter31h";
505
506
65
  case 0x0323: return "mhpmevent3";
507
203
  case 0x0324: return "mhpmevent4";
508
114
  case 0x0325: return "mhpmevent5";
509
292
  case 0x0326: return "mhpmevent6";
510
50
  case 0x0327: return "mhpmevent7";
511
39
  case 0x0328: return "mhpmevent8";
512
76
  case 0x0329: return "mhpmevent9";
513
67
  case 0x032a: return "mhpmevent10";
514
94
  case 0x032b: return "mhpmevent11";
515
19
  case 0x032c: return "mhpmevent12";
516
87
  case 0x032d: return "mhpmevent13";
517
109
  case 0x032e: return "mhpmevent14";
518
40
  case 0x032f: return "mhpmevent15";
519
173
  case 0x0330: return "mhpmevent16";
520
125
  case 0x0331: return "mhpmevent17";
521
67
  case 0x0332: return "mhpmevent18";
522
252
  case 0x0333: return "mhpmevent19";
523
241
  case 0x0334: return "mhpmevent20";
524
129
  case 0x0335: return "mhpmevent21";
525
99
  case 0x0336: return "mhpmevent22";
526
32
  case 0x0337: return "mhpmevent23";
527
91
  case 0x0338: return "mhpmevent24";
528
23
  case 0x0339: return "mhpmevent25";
529
46
  case 0x033a: return "mhpmevent26";
530
526
  case 0x033b: return "mhpmevent27";
531
126
  case 0x033c: return "mhpmevent28";
532
165
  case 0x033d: return "mhpmevent29";
533
124
  case 0x033e: return "mhpmevent30";
534
60
  case 0x033f: return "mhpmevent31";
535
536
58
  case 0x07a0: return "tselect";
537
43
  case 0x07a1: return "tdata1";
538
32
  case 0x07a2: return "tdata2";
539
85
  case 0x07a3: return "tdata3";
540
541
145
  case 0x07b0: return "dcsr";
542
36
  case 0x07b1: return "dpc";
543
255
  case 0x07b2: return "dscratch";
544
55.4k
  }
545
10.4k
  return NULL;
546
55.4k
}
547
548
static void printCSRSystemRegister(MCInst *MI, unsigned OpNo,
549
                                   //const MCSubtargetInfo &STI,
550
                                   SStream *O) 
551
55.4k
{
552
55.4k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, OpNo));
553
55.4k
  const char *Name = getCSRSystemRegisterName(Imm);
554
555
55.4k
  if (Name) {
556
45.0k
    SStream_concat0(O, Name);
557
45.0k
  } else {
558
10.4k
    SStream_concat(O, "%u", Imm);
559
10.4k
  }
560
55.4k
}
561
562
static void printFenceArg(MCInst *MI, unsigned OpNo, SStream *O) 
563
1.52k
{
564
1.52k
    unsigned FenceArg = MCOperand_getImm(MCInst_getOperand(MI, OpNo));
565
    //CS_ASSERT (((FenceArg >> 4) == 0) && "Invalid immediate in printFenceArg");
566
567
1.52k
    if ((FenceArg & RISCVFenceField_I) != 0)
568
653
        SStream_concat0(O, "i");
569
1.52k
    if ((FenceArg & RISCVFenceField_O) != 0)
570
1.24k
        SStream_concat0(O, "o");
571
1.52k
  if ((FenceArg & RISCVFenceField_R) != 0)
572
1.31k
        SStream_concat0(O, "r");
573
1.52k
    if ((FenceArg & RISCVFenceField_W) != 0)
574
955
        SStream_concat0(O, "w");
575
1.52k
    if (FenceArg == 0)
576
54
        SStream_concat0(O, "unknown");
577
1.52k
}
578
579
static void printFRMArg(MCInst *MI, unsigned OpNo, SStream *O) 
580
11.8k
{
581
11.8k
    enum RoundingMode FRMArg = 
582
11.8k
        (enum RoundingMode)MCOperand_getImm(MCInst_getOperand(MI, OpNo));
583
#if 0
584
  auto FRMArg =
585
      static_cast<RISCVFPRndMode::RoundingMode>(MI->getOperand(OpNo).getImm());
586
  O << RISCVFPRndMode::roundingModeToString(FRMArg);
587
#endif
588
11.8k
    SStream_concat0(O, roundingModeToString(FRMArg));
589
11.8k
}
590
  
591
#endif        // CAPSTONE_HAS_RISCV