Coverage Report

Created: 2025-11-11 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonenext/arch/RISCV/RISCVInstPrinter.c
Line
Count
Source
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
static void fixDetailOfEffectiveAddr(MCInst *MI)
56
9.72k
{
57
  // Operands for load and store instructions in RISCV vary widely
58
9.72k
  unsigned id = MI->flat_insn->id;
59
9.72k
  unsigned reg = 0;
60
9.72k
  int64_t imm = 0;
61
9.72k
  uint8_t access = 0;
62
63
9.72k
  switch (id) {
64
0
  case RISCV_INS_C_FLD:
65
0
  case RISCV_INS_C_LW:
66
0
  case RISCV_INS_C_FLW:
67
0
  case RISCV_INS_C_LD:
68
0
  case RISCV_INS_C_FSD:
69
0
  case RISCV_INS_C_SW:
70
0
  case RISCV_INS_C_FSW:
71
0
  case RISCV_INS_C_SD:
72
0
  case RISCV_INS_C_FLDSP:
73
0
  case RISCV_INS_C_LWSP:
74
0
  case RISCV_INS_C_FLWSP:
75
0
  case RISCV_INS_C_LDSP:
76
0
  case RISCV_INS_C_FSDSP:
77
0
  case RISCV_INS_C_SWSP:
78
0
  case RISCV_INS_C_FSWSP:
79
0
  case RISCV_INS_C_SDSP:
80
122
  case RISCV_INS_FLW:
81
458
  case RISCV_INS_FSW:
82
673
  case RISCV_INS_FLD:
83
699
  case RISCV_INS_FSD:
84
1.42k
  case RISCV_INS_LB:
85
1.53k
  case RISCV_INS_LBU:
86
1.81k
  case RISCV_INS_LD:
87
1.89k
  case RISCV_INS_LH:
88
2.04k
  case RISCV_INS_LHU:
89
2.30k
  case RISCV_INS_LW:
90
2.42k
  case RISCV_INS_LWU:
91
2.64k
  case RISCV_INS_SB:
92
2.80k
  case RISCV_INS_SD:
93
2.90k
  case RISCV_INS_SH:
94
3.78k
  case RISCV_INS_SW: {
95
3.78k
    CS_ASSERT(3 == MI->flat_insn->detail->riscv.op_count);
96
3.78k
    CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -3)->type);
97
3.78k
    CS_ASSERT(RISCV_OP_IMM == RISCV_get_detail_op(MI, -2)->type);
98
3.78k
    CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -1)->type);
99
100
3.78k
    imm = RISCV_get_detail_op(MI, -2)->imm;
101
3.78k
    reg = RISCV_get_detail_op(MI, -1)->reg;
102
3.78k
    access = RISCV_get_detail_op(MI, -1)->access;
103
104
3.78k
    RISCV_get_detail_op(MI, -2)->type = RISCV_OP_MEM;
105
3.78k
    RISCV_get_detail_op(MI, -2)->mem.base = reg;
106
3.78k
    RISCV_get_detail_op(MI, -2)->mem.disp = imm;
107
3.78k
    RISCV_get_detail_op(MI, -2)->access = access;
108
109
3.78k
    RISCV_dec_op_count(MI);
110
111
3.78k
    break;
112
2.90k
  }
113
11
  case RISCV_INS_LR_W:
114
29
  case RISCV_INS_LR_W_AQ:
115
330
  case RISCV_INS_LR_W_AQ_RL:
116
379
  case RISCV_INS_LR_W_RL:
117
385
  case RISCV_INS_LR_D:
118
395
  case RISCV_INS_LR_D_AQ:
119
548
  case RISCV_INS_LR_D_AQ_RL:
120
637
  case RISCV_INS_LR_D_RL: {
121
637
    CS_ASSERT(2 == MI->flat_insn->detail->riscv.op_count);
122
637
    CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -1)->type);
123
637
    CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -2)->type);
124
125
637
    reg = RISCV_get_detail_op(MI, -1)->reg;
126
127
637
    RISCV_get_detail_op(MI, -1)->type = RISCV_OP_MEM;
128
637
    RISCV_get_detail_op(MI, -1)->mem.base = reg;
129
637
    RISCV_get_detail_op(MI, -1)->mem.disp = 0;
130
131
637
    break;
132
548
  }
133
12
  case RISCV_INS_SC_W:
134
38
  case RISCV_INS_SC_W_AQ:
135
74
  case RISCV_INS_SC_W_AQ_RL:
136
142
  case RISCV_INS_SC_W_RL:
137
162
  case RISCV_INS_SC_D:
138
170
  case RISCV_INS_SC_D_AQ:
139
196
  case RISCV_INS_SC_D_AQ_RL:
140
273
  case RISCV_INS_SC_D_RL:
141
325
  case RISCV_INS_AMOADD_D:
142
336
  case RISCV_INS_AMOADD_D_AQ:
143
640
  case RISCV_INS_AMOADD_D_AQ_RL:
144
928
  case RISCV_INS_AMOADD_D_RL:
145
968
  case RISCV_INS_AMOADD_W:
146
983
  case RISCV_INS_AMOADD_W_AQ:
147
1.04k
  case RISCV_INS_AMOADD_W_AQ_RL:
148
1.25k
  case RISCV_INS_AMOADD_W_RL:
149
1.33k
  case RISCV_INS_AMOAND_D:
150
1.41k
  case RISCV_INS_AMOAND_D_AQ:
151
1.43k
  case RISCV_INS_AMOAND_D_AQ_RL:
152
1.55k
  case RISCV_INS_AMOAND_D_RL:
153
1.56k
  case RISCV_INS_AMOAND_W:
154
1.58k
  case RISCV_INS_AMOAND_W_AQ:
155
1.65k
  case RISCV_INS_AMOAND_W_AQ_RL:
156
1.67k
  case RISCV_INS_AMOAND_W_RL:
157
2.13k
  case RISCV_INS_AMOMAXU_D:
158
2.19k
  case RISCV_INS_AMOMAXU_D_AQ:
159
2.21k
  case RISCV_INS_AMOMAXU_D_AQ_RL:
160
2.24k
  case RISCV_INS_AMOMAXU_D_RL:
161
2.28k
  case RISCV_INS_AMOMAXU_W:
162
2.30k
  case RISCV_INS_AMOMAXU_W_AQ:
163
2.38k
  case RISCV_INS_AMOMAXU_W_AQ_RL:
164
2.45k
  case RISCV_INS_AMOMAXU_W_RL:
165
2.49k
  case RISCV_INS_AMOMAX_D:
166
2.53k
  case RISCV_INS_AMOMAX_D_AQ:
167
2.55k
  case RISCV_INS_AMOMAX_D_AQ_RL:
168
2.60k
  case RISCV_INS_AMOMAX_D_RL:
169
2.64k
  case RISCV_INS_AMOMAX_W:
170
2.67k
  case RISCV_INS_AMOMAX_W_AQ:
171
2.77k
  case RISCV_INS_AMOMAX_W_AQ_RL:
172
2.84k
  case RISCV_INS_AMOMAX_W_RL:
173
2.91k
  case RISCV_INS_AMOMINU_D:
174
2.93k
  case RISCV_INS_AMOMINU_D_AQ:
175
2.95k
  case RISCV_INS_AMOMINU_D_AQ_RL:
176
3.03k
  case RISCV_INS_AMOMINU_D_RL:
177
3.06k
  case RISCV_INS_AMOMINU_W:
178
3.17k
  case RISCV_INS_AMOMINU_W_AQ:
179
3.23k
  case RISCV_INS_AMOMINU_W_AQ_RL:
180
3.25k
  case RISCV_INS_AMOMINU_W_RL:
181
3.87k
  case RISCV_INS_AMOMIN_D:
182
4.01k
  case RISCV_INS_AMOMIN_D_AQ:
183
4.04k
  case RISCV_INS_AMOMIN_D_AQ_RL:
184
4.08k
  case RISCV_INS_AMOMIN_D_RL:
185
4.09k
  case RISCV_INS_AMOMIN_W:
186
4.11k
  case RISCV_INS_AMOMIN_W_AQ:
187
4.15k
  case RISCV_INS_AMOMIN_W_AQ_RL:
188
4.19k
  case RISCV_INS_AMOMIN_W_RL:
189
4.20k
  case RISCV_INS_AMOOR_D:
190
4.21k
  case RISCV_INS_AMOOR_D_AQ:
191
4.29k
  case RISCV_INS_AMOOR_D_AQ_RL:
192
4.36k
  case RISCV_INS_AMOOR_D_RL:
193
4.41k
  case RISCV_INS_AMOOR_W:
194
4.44k
  case RISCV_INS_AMOOR_W_AQ:
195
4.46k
  case RISCV_INS_AMOOR_W_AQ_RL:
196
4.52k
  case RISCV_INS_AMOOR_W_RL:
197
4.55k
  case RISCV_INS_AMOSWAP_D:
198
4.57k
  case RISCV_INS_AMOSWAP_D_AQ:
199
4.65k
  case RISCV_INS_AMOSWAP_D_AQ_RL:
200
4.69k
  case RISCV_INS_AMOSWAP_D_RL:
201
4.70k
  case RISCV_INS_AMOSWAP_W:
202
4.74k
  case RISCV_INS_AMOSWAP_W_AQ:
203
4.76k
  case RISCV_INS_AMOSWAP_W_AQ_RL:
204
4.80k
  case RISCV_INS_AMOSWAP_W_RL:
205
4.84k
  case RISCV_INS_AMOXOR_D:
206
4.88k
  case RISCV_INS_AMOXOR_D_AQ:
207
4.93k
  case RISCV_INS_AMOXOR_D_AQ_RL:
208
4.97k
  case RISCV_INS_AMOXOR_D_RL:
209
4.98k
  case RISCV_INS_AMOXOR_W:
210
4.99k
  case RISCV_INS_AMOXOR_W_AQ:
211
5.04k
  case RISCV_INS_AMOXOR_W_AQ_RL:
212
5.30k
  case RISCV_INS_AMOXOR_W_RL: {
213
5.30k
    CS_ASSERT(3 == MI->flat_insn->detail->riscv.op_count);
214
5.30k
    CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -3)->type);
215
5.30k
    CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -2)->type);
216
5.30k
    CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -1)->type);
217
218
5.30k
    reg = RISCV_get_detail_op(MI, -1)->reg;
219
220
5.30k
    RISCV_get_detail_op(MI, -1)->type = RISCV_OP_MEM;
221
5.30k
    RISCV_get_detail_op(MI, -1)->mem.base = reg;
222
5.30k
    RISCV_get_detail_op(MI, -1)->mem.disp = 0;
223
224
5.30k
    break;
225
5.04k
  }
226
0
  default: {
227
0
    CS_ASSERT(0 && "id is not a RISC-V memory instruction");
228
0
    break;
229
5.04k
  }
230
9.72k
  }
231
9.72k
  return;
232
9.72k
}
233
234
//void RISCVInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
235
//                                 StringRef Annot, const MCSubtargetInfo &STI)
236
void RISCV_printInst(MCInst *MI, SStream *O, void *info)
237
69.5k
{
238
69.5k
  MCRegisterInfo *MRI = (MCRegisterInfo *)info;
239
  //bool Res = false;
240
  //MCInst *NewMI = MI;
241
  // TODO: RISCV compressd instructions.
242
  //MCInst UncompressedMI;
243
  //if (!NoAliases)
244
  //Res = uncompressInst(UncompressedMI, *MI, MRI, STI);
245
  //if (Res)
246
  //NewMI = const_cast<MCInst *>(&UncompressedMI);
247
69.5k
  if (/*NoAliases ||*/ !printAliasInstr(MI, O, info))
248
54.0k
    printInstruction(MI, O, MRI);
249
  //printAnnotation(O, Annot);
250
  // fix load/store type insttuction
251
69.5k
  if (MI->csh->detail_opt &&
252
69.5k
      MI->flat_insn->detail->riscv.need_effective_addr)
253
9.72k
    fixDetailOfEffectiveAddr(MI);
254
255
69.5k
  return;
256
69.5k
}
257
258
static void printRegName(SStream *OS, unsigned RegNo)
259
122k
{
260
122k
  SStream_concat0(OS, getRegisterName(RegNo, RISCV_ABIRegAltName));
261
122k
}
262
263
/**
264
void RISCVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
265
                                    raw_ostream &O, const char *Modifier) 
266
*/
267
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
268
148k
{
269
148k
  unsigned reg;
270
148k
  int64_t Imm = 0;
271
272
148k
  RISCV_add_cs_detail(MI, OpNo);
273
274
148k
  MCOperand *MO = MCInst_getOperand(MI, OpNo);
275
276
148k
  if (MCOperand_isReg(MO)) {
277
122k
    reg = MCOperand_getReg(MO);
278
122k
    printRegName(O, reg);
279
122k
  } else {
280
25.5k
    CS_ASSERT(MCOperand_isImm(MO) &&
281
25.5k
        "Unknown operand kind in printOperand");
282
25.5k
    Imm = MCOperand_getImm(MO);
283
25.5k
    if (Imm >= 0) {
284
23.0k
      if (Imm > HEX_THRESHOLD)
285
14.4k
        SStream_concat(O, "0x%" PRIx64, Imm);
286
8.54k
      else
287
8.54k
        SStream_concat(O, "%" PRIu64, Imm);
288
23.0k
    } else {
289
2.57k
      if (Imm < -HEX_THRESHOLD)
290
2.53k
        SStream_concat(O, "-0x%" PRIx64, -Imm);
291
42
      else
292
42
        SStream_concat(O, "-%" PRIu64, -Imm);
293
2.57k
    }
294
25.5k
  }
295
296
  //CS_ASSERT(MO.isExpr() && "Unknown operand kind in printOperand");
297
298
148k
  return;
299
148k
}
300
301
static const char *getCSRSystemRegisterName(unsigned CsrNo)
302
37.9k
{
303
37.9k
  switch (CsrNo) {
304
  /*
305
   * From RISC-V Privileged Architecture Version 1.10.
306
   * In the same order as Table 2.5.
307
   */
308
171
  case 0x0000:
309
171
    return "ustatus";
310
76
  case 0x0004:
311
76
    return "uie";
312
90
  case 0x0005:
313
90
    return "utvec";
314
315
34
  case 0x0040:
316
34
    return "uscratch";
317
60
  case 0x0041:
318
60
    return "uepc";
319
79
  case 0x0042:
320
79
    return "ucause";
321
69
  case 0x0043:
322
69
    return "utval";
323
35
  case 0x0044:
324
35
    return "uip";
325
326
75
  case 0x0001:
327
75
    return "fflags";
328
166
  case 0x0002:
329
166
    return "frm";
330
112
  case 0x0003:
331
112
    return "fcsr";
332
333
489
  case 0x0c00:
334
489
    return "cycle";
335
911
  case 0x0c01:
336
911
    return "time";
337
125
  case 0x0c02:
338
125
    return "instret";
339
25
  case 0x0c03:
340
25
    return "hpmcounter3";
341
35
  case 0x0c04:
342
35
    return "hpmcounter4";
343
109
  case 0x0c05:
344
109
    return "hpmcounter5";
345
208
  case 0x0c06:
346
208
    return "hpmcounter6";
347
98
  case 0x0c07:
348
98
    return "hpmcounter7";
349
136
  case 0x0c08:
350
136
    return "hpmcounter8";
351
462
  case 0x0c09:
352
462
    return "hpmcounter9";
353
77
  case 0x0c0a:
354
77
    return "hpmcounter10";
355
145
  case 0x0c0b:
356
145
    return "hpmcounter11";
357
374
  case 0x0c0c:
358
374
    return "hpmcounter12";
359
387
  case 0x0c0d:
360
387
    return "hpmcounter13";
361
178
  case 0x0c0e:
362
178
    return "hpmcounter14";
363
48
  case 0x0c0f:
364
48
    return "hpmcounter15";
365
169
  case 0x0c10:
366
169
    return "hpmcounter16";
367
41
  case 0x0c11:
368
41
    return "hpmcounter17";
369
65
  case 0x0c12:
370
65
    return "hpmcounter18";
371
25
  case 0x0c13:
372
25
    return "hpmcounter19";
373
557
  case 0x0c14:
374
557
    return "hpmcounter20";
375
92
  case 0x0c15:
376
92
    return "hpmcounter21";
377
208
  case 0x0c16:
378
208
    return "hpmcounter22";
379
105
  case 0x0c17:
380
105
    return "hpmcounter23";
381
89
  case 0x0c18:
382
89
    return "hpmcounter24";
383
979
  case 0x0c19:
384
979
    return "hpmcounter25";
385
39
  case 0x0c1a:
386
39
    return "hpmcounter26";
387
80
  case 0x0c1b:
388
80
    return "hpmcounter27";
389
102
  case 0x0c1c:
390
102
    return "hpmcounter28";
391
37
  case 0x0c1d:
392
37
    return "hpmcounter29";
393
44
  case 0x0c1e:
394
44
    return "hpmcounter30";
395
13
  case 0x0c1f:
396
13
    return "hpmcounter31";
397
42
  case 0x0c80:
398
42
    return "cycleh";
399
22
  case 0x0c81:
400
22
    return "timeh";
401
92
  case 0x0c82:
402
92
    return "instreth";
403
20
  case 0x0c83:
404
20
    return "hpmcounter3h";
405
187
  case 0x0c84:
406
187
    return "hpmcounter4h";
407
72
  case 0x0c85:
408
72
    return "hpmcounter5h";
409
118
  case 0x0c86:
410
118
    return "hpmcounter6h";
411
130
  case 0x0c87:
412
130
    return "hpmcounter7h";
413
10
  case 0x0c88:
414
10
    return "hpmcounter8h";
415
25
  case 0x0c89:
416
25
    return "hpmcounter9h";
417
315
  case 0x0c8a:
418
315
    return "hpmcounter10h";
419
74
  case 0x0c8b:
420
74
    return "hpmcounter11h";
421
341
  case 0x0c8c:
422
341
    return "hpmcounter12h";
423
47
  case 0x0c8d:
424
47
    return "hpmcounter13h";
425
95
  case 0x0c8e:
426
95
    return "hpmcounter14h";
427
75
  case 0x0c8f:
428
75
    return "hpmcounter15h";
429
472
  case 0x0c90:
430
472
    return "hpmcounter16h";
431
61
  case 0x0c91:
432
61
    return "hpmcounter17h";
433
113
  case 0x0c92:
434
113
    return "hpmcounter18h";
435
201
  case 0x0c93:
436
201
    return "hpmcounter19h";
437
138
  case 0x0c94:
438
138
    return "hpmcounter20h";
439
194
  case 0x0c95:
440
194
    return "hpmcounter21h";
441
55
  case 0x0c96:
442
55
    return "hpmcounter22h";
443
24
  case 0x0c97:
444
24
    return "hpmcounter23h";
445
71
  case 0x0c98:
446
71
    return "hpmcounter24h";
447
22
  case 0x0c99:
448
22
    return "hpmcounter25h";
449
16
  case 0x0c9a:
450
16
    return "hpmcounter26h";
451
88
  case 0x0c9b:
452
88
    return "hpmcounter27h";
453
529
  case 0x0c9c:
454
529
    return "hpmcounter28h";
455
226
  case 0x0c9d:
456
226
    return "hpmcounter29h";
457
70
  case 0x0c9e:
458
70
    return "hpmcounter30h";
459
152
  case 0x0c9f:
460
152
    return "hpmcounter31h";
461
462
132
  case 0x0100:
463
132
    return "sstatus";
464
45
  case 0x0102:
465
45
    return "sedeleg";
466
260
  case 0x0103:
467
260
    return "sideleg";
468
126
  case 0x0104:
469
126
    return "sie";
470
27
  case 0x0105:
471
27
    return "stvec";
472
48
  case 0x0106:
473
48
    return "scounteren";
474
475
27
  case 0x0140:
476
27
    return "sscratch";
477
102
  case 0x0141:
478
102
    return "sepc";
479
72
  case 0x0142:
480
72
    return "scause";
481
60
  case 0x0143:
482
60
    return "stval";
483
100
  case 0x0144:
484
100
    return "sip";
485
486
297
  case 0x0180:
487
297
    return "satp";
488
489
18
  case 0x0f11:
490
18
    return "mvendorid";
491
26
  case 0x0f12:
492
26
    return "marchid";
493
34
  case 0x0f13:
494
34
    return "mimpid";
495
13
  case 0x0f14:
496
13
    return "mhartid";
497
498
50
  case 0x0300:
499
50
    return "mstatus";
500
28
  case 0x0301:
501
28
    return "misa";
502
42
  case 0x0302:
503
42
    return "medeleg";
504
44
  case 0x0303:
505
44
    return "mideleg";
506
20
  case 0x0304:
507
20
    return "mie";
508
312
  case 0x0305:
509
312
    return "mtvec";
510
34
  case 0x0306:
511
34
    return "mcounteren";
512
513
203
  case 0x0340:
514
203
    return "mscratch";
515
1.08k
  case 0x0341:
516
1.08k
    return "mepc";
517
19
  case 0x0342:
518
19
    return "mcause";
519
155
  case 0x0343:
520
155
    return "mtval";
521
42
  case 0x0344:
522
42
    return "mip";
523
524
230
  case 0x03a0:
525
230
    return "pmpcfg0";
526
206
  case 0x03a1:
527
206
    return "pmpcfg1";
528
122
  case 0x03a2:
529
122
    return "pmpcfg2";
530
64
  case 0x03a3:
531
64
    return "pmpcfg3";
532
633
  case 0x03b0:
533
633
    return "pmpaddr0";
534
370
  case 0x03b1:
535
370
    return "pmpaddr1";
536
124
  case 0x03b2:
537
124
    return "pmpaddr2";
538
69
  case 0x03b3:
539
69
    return "pmpaddr3";
540
27
  case 0x03b4:
541
27
    return "pmpaddr4";
542
79
  case 0x03b5:
543
79
    return "pmpaddr5";
544
19
  case 0x03b6:
545
19
    return "pmpaddr6";
546
457
  case 0x03b7:
547
457
    return "pmpaddr7";
548
35
  case 0x03b8:
549
35
    return "pmpaddr8";
550
42
  case 0x03b9:
551
42
    return "pmpaddr9";
552
32
  case 0x03ba:
553
32
    return "pmpaddr10";
554
682
  case 0x03bb:
555
682
    return "pmpaddr11";
556
11
  case 0x03bc:
557
11
    return "pmpaddr12";
558
79
  case 0x03bd:
559
79
    return "pmpaddr13";
560
240
  case 0x03be:
561
240
    return "pmpaddr14";
562
428
  case 0x03bf:
563
428
    return "pmpaddr15";
564
565
121
  case 0x0b00:
566
121
    return "mcycle";
567
73
  case 0x0b02:
568
73
    return "minstret";
569
83
  case 0x0b03:
570
83
    return "mhpmcounter3";
571
230
  case 0x0b04:
572
230
    return "mhpmcounter4";
573
493
  case 0x0b05:
574
493
    return "mhpmcounter5";
575
20
  case 0x0b06:
576
20
    return "mhpmcounter6";
577
43
  case 0x0b07:
578
43
    return "mhpmcounter7";
579
18
  case 0x0b08:
580
18
    return "mhpmcounter8";
581
60
  case 0x0b09:
582
60
    return "mhpmcounter9";
583
18
  case 0x0b0a:
584
18
    return "mhpmcounter10";
585
29
  case 0x0b0b:
586
29
    return "mhpmcounter11";
587
75
  case 0x0b0c:
588
75
    return "mhpmcounter12";
589
142
  case 0x0b0d:
590
142
    return "mhpmcounter13";
591
131
  case 0x0b0e:
592
131
    return "mhpmcounter14";
593
92
  case 0x0b0f:
594
92
    return "mhpmcounter15";
595
18
  case 0x0b10:
596
18
    return "mhpmcounter16";
597
50
  case 0x0b11:
598
50
    return "mhpmcounter17";
599
37
  case 0x0b12:
600
37
    return "mhpmcounter18";
601
96
  case 0x0b13:
602
96
    return "mhpmcounter19";
603
22
  case 0x0b14:
604
22
    return "mhpmcounter20";
605
18
  case 0x0b15:
606
18
    return "mhpmcounter21";
607
35
  case 0x0b16:
608
35
    return "mhpmcounter22";
609
36
  case 0x0b17:
610
36
    return "mhpmcounter23";
611
21
  case 0x0b18:
612
21
    return "mhpmcounter24";
613
48
  case 0x0b19:
614
48
    return "mhpmcounter25";
615
23
  case 0x0b1a:
616
23
    return "mhpmcounter26";
617
46
  case 0x0b1b:
618
46
    return "mhpmcounter27";
619
28
  case 0x0b1c:
620
28
    return "mhpmcounter28";
621
87
  case 0x0b1d:
622
87
    return "mhpmcounter29";
623
104
  case 0x0b1e:
624
104
    return "mhpmcounter30";
625
79
  case 0x0b1f:
626
79
    return "mhpmcounter31";
627
118
  case 0x0b80:
628
118
    return "mcycleh";
629
16
  case 0x0b82:
630
16
    return "minstreth";
631
22
  case 0x0b83:
632
22
    return "mhpmcounter3h";
633
74
  case 0x0b84:
634
74
    return "mhpmcounter4h";
635
34
  case 0x0b85:
636
34
    return "mhpmcounter5h";
637
27
  case 0x0b86:
638
27
    return "mhpmcounter6h";
639
69
  case 0x0b87:
640
69
    return "mhpmcounter7h";
641
26
  case 0x0b88:
642
26
    return "mhpmcounter8h";
643
47
  case 0x0b89:
644
47
    return "mhpmcounter9h";
645
70
  case 0x0b8a:
646
70
    return "mhpmcounter10h";
647
261
  case 0x0b8b:
648
261
    return "mhpmcounter11h";
649
45
  case 0x0b8c:
650
45
    return "mhpmcounter12h";
651
75
  case 0x0b8d:
652
75
    return "mhpmcounter13h";
653
77
  case 0x0b8e:
654
77
    return "mhpmcounter14h";
655
97
  case 0x0b8f:
656
97
    return "mhpmcounter15h";
657
53
  case 0x0b90:
658
53
    return "mhpmcounter16h";
659
18
  case 0x0b91:
660
18
    return "mhpmcounter17h";
661
47
  case 0x0b92:
662
47
    return "mhpmcounter18h";
663
151
  case 0x0b93:
664
151
    return "mhpmcounter19h";
665
58
  case 0x0b94:
666
58
    return "mhpmcounter20h";
667
44
  case 0x0b95:
668
44
    return "mhpmcounter21h";
669
36
  case 0x0b96:
670
36
    return "mhpmcounter22h";
671
18
  case 0x0b97:
672
18
    return "mhpmcounter23h";
673
44
  case 0x0b98:
674
44
    return "mhpmcounter24h";
675
825
  case 0x0b99:
676
825
    return "mhpmcounter25h";
677
161
  case 0x0b9a:
678
161
    return "mhpmcounter26h";
679
30
  case 0x0b9b:
680
30
    return "mhpmcounter27h";
681
636
  case 0x0b9c:
682
636
    return "mhpmcounter28h";
683
78
  case 0x0b9d:
684
78
    return "mhpmcounter29h";
685
242
  case 0x0b9e:
686
242
    return "mhpmcounter30h";
687
23
  case 0x0b9f:
688
23
    return "mhpmcounter31h";
689
690
18
  case 0x0323:
691
18
    return "mhpmevent3";
692
72
  case 0x0324:
693
72
    return "mhpmevent4";
694
197
  case 0x0325:
695
197
    return "mhpmevent5";
696
43
  case 0x0326:
697
43
    return "mhpmevent6";
698
108
  case 0x0327:
699
108
    return "mhpmevent7";
700
877
  case 0x0328:
701
877
    return "mhpmevent8";
702
13
  case 0x0329:
703
13
    return "mhpmevent9";
704
39
  case 0x032a:
705
39
    return "mhpmevent10";
706
273
  case 0x032b:
707
273
    return "mhpmevent11";
708
26
  case 0x032c:
709
26
    return "mhpmevent12";
710
143
  case 0x032d:
711
143
    return "mhpmevent13";
712
398
  case 0x032e:
713
398
    return "mhpmevent14";
714
30
  case 0x032f:
715
30
    return "mhpmevent15";
716
178
  case 0x0330:
717
178
    return "mhpmevent16";
718
130
  case 0x0331:
719
130
    return "mhpmevent17";
720
64
  case 0x0332:
721
64
    return "mhpmevent18";
722
41
  case 0x0333:
723
41
    return "mhpmevent19";
724
211
  case 0x0334:
725
211
    return "mhpmevent20";
726
123
  case 0x0335:
727
123
    return "mhpmevent21";
728
13
  case 0x0336:
729
13
    return "mhpmevent22";
730
62
  case 0x0337:
731
62
    return "mhpmevent23";
732
40
  case 0x0338:
733
40
    return "mhpmevent24";
734
25
  case 0x0339:
735
25
    return "mhpmevent25";
736
25
  case 0x033a:
737
25
    return "mhpmevent26";
738
237
  case 0x033b:
739
237
    return "mhpmevent27";
740
17
  case 0x033c:
741
17
    return "mhpmevent28";
742
234
  case 0x033d:
743
234
    return "mhpmevent29";
744
219
  case 0x033e:
745
219
    return "mhpmevent30";
746
69
  case 0x033f:
747
69
    return "mhpmevent31";
748
749
38
  case 0x07a0:
750
38
    return "tselect";
751
55
  case 0x07a1:
752
55
    return "tdata1";
753
38
  case 0x07a2:
754
38
    return "tdata2";
755
43
  case 0x07a3:
756
43
    return "tdata3";
757
758
77
  case 0x07b0:
759
77
    return "dcsr";
760
217
  case 0x07b1:
761
217
    return "dpc";
762
29
  case 0x07b2:
763
29
    return "dscratch";
764
37.9k
  }
765
8.78k
  return NULL;
766
37.9k
}
767
768
static void printCSRSystemRegister(MCInst *MI, unsigned OpNo,
769
           //const MCSubtargetInfo &STI,
770
           SStream *O)
771
37.9k
{
772
37.9k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, OpNo));
773
37.9k
  const char *Name = getCSRSystemRegisterName(Imm);
774
775
37.9k
  if (Name) {
776
29.2k
    SStream_concat0(O, Name);
777
29.2k
  } else {
778
8.78k
    SStream_concat(O, "%u", Imm);
779
8.78k
  }
780
37.9k
}
781
782
static void printFenceArg(MCInst *MI, unsigned OpNo, SStream *O)
783
1.45k
{
784
1.45k
  unsigned FenceArg = MCOperand_getImm(MCInst_getOperand(MI, OpNo));
785
  //CS_ASSERT (((FenceArg >> 4) == 0) && "Invalid immediate in printFenceArg");
786
787
1.45k
  if ((FenceArg & RISCVFenceField_I) != 0)
788
732
    SStream_concat0(O, "i");
789
1.45k
  if ((FenceArg & RISCVFenceField_O) != 0)
790
387
    SStream_concat0(O, "o");
791
1.45k
  if ((FenceArg & RISCVFenceField_R) != 0)
792
737
    SStream_concat0(O, "r");
793
1.45k
  if ((FenceArg & RISCVFenceField_W) != 0)
794
690
    SStream_concat0(O, "w");
795
1.45k
  if (FenceArg == 0)
796
361
    SStream_concat0(O, "unknown");
797
1.45k
}
798
799
static void printFRMArg(MCInst *MI, unsigned OpNo, SStream *O)
800
6.77k
{
801
6.77k
  enum RoundingMode FRMArg = (enum RoundingMode)MCOperand_getImm(
802
6.77k
    MCInst_getOperand(MI, OpNo));
803
#if 0
804
  auto FRMArg =
805
      static_cast<RISCVFPRndMode::RoundingMode>(MI->getOperand(OpNo).getImm());
806
  O << RISCVFPRndMode::roundingModeToString(FRMArg);
807
#endif
808
6.77k
  SStream_concat0(O, roundingModeToString(FRMArg));
809
6.77k
}
810
811
#endif // CAPSTONE_HAS_RISCV