Coverage Report

Created: 2026-01-10 06:34

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