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
165k
{
238
165k
  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
165k
  if (/*NoAliases ||*/ !printAliasInstr(MI, O, info))
248
119k
    printInstruction(MI, O, MRI);
249
  //printAnnotation(O, Annot);
250
  // fix load/store type insttuction
251
165k
  if (MI->csh->detail_opt &&
252
165k
      MI->flat_insn->detail->riscv.need_effective_addr)
253
11.2k
    fixDetailOfEffectiveAddr(MI);
254
255
165k
  return;
256
165k
}
257
258
static void printRegName(SStream *OS, unsigned RegNo)
259
292k
{
260
292k
  SStream_concat0(OS, getRegisterName(RegNo, RISCV_ABIRegAltName));
261
292k
}
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
91.5k
{
303
91.5k
  switch (CsrNo) {
304
  /*
305
   * From RISC-V Privileged Architecture Version 1.10.
306
   * In the same order as Table 2.5.
307
   */
308
245
  case 0x0000:
309
245
    return "ustatus";
310
147
  case 0x0004:
311
147
    return "uie";
312
44
  case 0x0005:
313
44
    return "utvec";
314
315
99
  case 0x0040:
316
99
    return "uscratch";
317
383
  case 0x0041:
318
383
    return "uepc";
319
621
  case 0x0042:
320
621
    return "ucause";
321
193
  case 0x0043:
322
193
    return "utval";
323
62
  case 0x0044:
324
62
    return "uip";
325
326
851
  case 0x0001:
327
851
    return "fflags";
328
698
  case 0x0002:
329
698
    return "frm";
330
375
  case 0x0003:
331
375
    return "fcsr";
332
333
848
  case 0x0c00:
334
848
    return "cycle";
335
1.09k
  case 0x0c01:
336
1.09k
    return "time";
337
298
  case 0x0c02:
338
298
    return "instret";
339
120
  case 0x0c03:
340
120
    return "hpmcounter3";
341
885
  case 0x0c04:
342
885
    return "hpmcounter4";
343
391
  case 0x0c05:
344
391
    return "hpmcounter5";
345
408
  case 0x0c06:
346
408
    return "hpmcounter6";
347
961
  case 0x0c07:
348
961
    return "hpmcounter7";
349
744
  case 0x0c08:
350
744
    return "hpmcounter8";
351
570
  case 0x0c09:
352
570
    return "hpmcounter9";
353
504
  case 0x0c0a:
354
504
    return "hpmcounter10";
355
442
  case 0x0c0b:
356
442
    return "hpmcounter11";
357
390
  case 0x0c0c:
358
390
    return "hpmcounter12";
359
465
  case 0x0c0d:
360
465
    return "hpmcounter13";
361
258
  case 0x0c0e:
362
258
    return "hpmcounter14";
363
916
  case 0x0c0f:
364
916
    return "hpmcounter15";
365
511
  case 0x0c10:
366
511
    return "hpmcounter16";
367
230
  case 0x0c11:
368
230
    return "hpmcounter17";
369
307
  case 0x0c12:
370
307
    return "hpmcounter18";
371
52
  case 0x0c13:
372
52
    return "hpmcounter19";
373
475
  case 0x0c14:
374
475
    return "hpmcounter20";
375
136
  case 0x0c15:
376
136
    return "hpmcounter21";
377
215
  case 0x0c16:
378
215
    return "hpmcounter22";
379
752
  case 0x0c17:
380
752
    return "hpmcounter23";
381
382
  case 0x0c18:
382
382
    return "hpmcounter24";
383
882
  case 0x0c19:
384
882
    return "hpmcounter25";
385
176
  case 0x0c1a:
386
176
    return "hpmcounter26";
387
645
  case 0x0c1b:
388
645
    return "hpmcounter27";
389
474
  case 0x0c1c:
390
474
    return "hpmcounter28";
391
182
  case 0x0c1d:
392
182
    return "hpmcounter29";
393
1.06k
  case 0x0c1e:
394
1.06k
    return "hpmcounter30";
395
316
  case 0x0c1f:
396
316
    return "hpmcounter31";
397
473
  case 0x0c80:
398
473
    return "cycleh";
399
221
  case 0x0c81:
400
221
    return "timeh";
401
772
  case 0x0c82:
402
772
    return "instreth";
403
488
  case 0x0c83:
404
488
    return "hpmcounter3h";
405
135
  case 0x0c84:
406
135
    return "hpmcounter4h";
407
135
  case 0x0c85:
408
135
    return "hpmcounter5h";
409
770
  case 0x0c86:
410
770
    return "hpmcounter6h";
411
698
  case 0x0c87:
412
698
    return "hpmcounter7h";
413
285
  case 0x0c88:
414
285
    return "hpmcounter8h";
415
69
  case 0x0c89:
416
69
    return "hpmcounter9h";
417
287
  case 0x0c8a:
418
287
    return "hpmcounter10h";
419
152
  case 0x0c8b:
420
152
    return "hpmcounter11h";
421
211
  case 0x0c8c:
422
211
    return "hpmcounter12h";
423
294
  case 0x0c8d:
424
294
    return "hpmcounter13h";
425
150
  case 0x0c8e:
426
150
    return "hpmcounter14h";
427
304
  case 0x0c8f:
428
304
    return "hpmcounter15h";
429
356
  case 0x0c90:
430
356
    return "hpmcounter16h";
431
289
  case 0x0c91:
432
289
    return "hpmcounter17h";
433
738
  case 0x0c92:
434
738
    return "hpmcounter18h";
435
181
  case 0x0c93:
436
181
    return "hpmcounter19h";
437
137
  case 0x0c94:
438
137
    return "hpmcounter20h";
439
250
  case 0x0c95:
440
250
    return "hpmcounter21h";
441
386
  case 0x0c96:
442
386
    return "hpmcounter22h";
443
181
  case 0x0c97:
444
181
    return "hpmcounter23h";
445
167
  case 0x0c98:
446
167
    return "hpmcounter24h";
447
349
  case 0x0c99:
448
349
    return "hpmcounter25h";
449
64
  case 0x0c9a:
450
64
    return "hpmcounter26h";
451
406
  case 0x0c9b:
452
406
    return "hpmcounter27h";
453
924
  case 0x0c9c:
454
924
    return "hpmcounter28h";
455
598
  case 0x0c9d:
456
598
    return "hpmcounter29h";
457
465
  case 0x0c9e:
458
465
    return "hpmcounter30h";
459
1.34k
  case 0x0c9f:
460
1.34k
    return "hpmcounter31h";
461
462
209
  case 0x0100:
463
209
    return "sstatus";
464
338
  case 0x0102:
465
338
    return "sedeleg";
466
809
  case 0x0103:
467
809
    return "sideleg";
468
289
  case 0x0104:
469
289
    return "sie";
470
919
  case 0x0105:
471
919
    return "stvec";
472
537
  case 0x0106:
473
537
    return "scounteren";
474
475
181
  case 0x0140:
476
181
    return "sscratch";
477
206
  case 0x0141:
478
206
    return "sepc";
479
154
  case 0x0142:
480
154
    return "scause";
481
160
  case 0x0143:
482
160
    return "stval";
483
418
  case 0x0144:
484
418
    return "sip";
485
486
138
  case 0x0180:
487
138
    return "satp";
488
489
104
  case 0x0f11:
490
104
    return "mvendorid";
491
70
  case 0x0f12:
492
70
    return "marchid";
493
375
  case 0x0f13:
494
375
    return "mimpid";
495
137
  case 0x0f14:
496
137
    return "mhartid";
497
498
145
  case 0x0300:
499
145
    return "mstatus";
500
179
  case 0x0301:
501
179
    return "misa";
502
550
  case 0x0302:
503
550
    return "medeleg";
504
151
  case 0x0303:
505
151
    return "mideleg";
506
525
  case 0x0304:
507
525
    return "mie";
508
613
  case 0x0305:
509
613
    return "mtvec";
510
107
  case 0x0306:
511
107
    return "mcounteren";
512
513
136
  case 0x0340:
514
136
    return "mscratch";
515
171
  case 0x0341:
516
171
    return "mepc";
517
251
  case 0x0342:
518
251
    return "mcause";
519
94
  case 0x0343:
520
94
    return "mtval";
521
284
  case 0x0344:
522
284
    return "mip";
523
524
139
  case 0x03a0:
525
139
    return "pmpcfg0";
526
91
  case 0x03a1:
527
91
    return "pmpcfg1";
528
523
  case 0x03a2:
529
523
    return "pmpcfg2";
530
249
  case 0x03a3:
531
249
    return "pmpcfg3";
532
523
  case 0x03b0:
533
523
    return "pmpaddr0";
534
273
  case 0x03b1:
535
273
    return "pmpaddr1";
536
804
  case 0x03b2:
537
804
    return "pmpaddr2";
538
408
  case 0x03b3:
539
408
    return "pmpaddr3";
540
150
  case 0x03b4:
541
150
    return "pmpaddr4";
542
413
  case 0x03b5:
543
413
    return "pmpaddr5";
544
203
  case 0x03b6:
545
203
    return "pmpaddr6";
546
99
  case 0x03b7:
547
99
    return "pmpaddr7";
548
145
  case 0x03b8:
549
145
    return "pmpaddr8";
550
263
  case 0x03b9:
551
263
    return "pmpaddr9";
552
134
  case 0x03ba:
553
134
    return "pmpaddr10";
554
94
  case 0x03bb:
555
94
    return "pmpaddr11";
556
330
  case 0x03bc:
557
330
    return "pmpaddr12";
558
92
  case 0x03bd:
559
92
    return "pmpaddr13";
560
685
  case 0x03be:
561
685
    return "pmpaddr14";
562
354
  case 0x03bf:
563
354
    return "pmpaddr15";
564
565
288
  case 0x0b00:
566
288
    return "mcycle";
567
266
  case 0x0b02:
568
266
    return "minstret";
569
102
  case 0x0b03:
570
102
    return "mhpmcounter3";
571
276
  case 0x0b04:
572
276
    return "mhpmcounter4";
573
804
  case 0x0b05:
574
804
    return "mhpmcounter5";
575
127
  case 0x0b06:
576
127
    return "mhpmcounter6";
577
71
  case 0x0b07:
578
71
    return "mhpmcounter7";
579
170
  case 0x0b08:
580
170
    return "mhpmcounter8";
581
109
  case 0x0b09:
582
109
    return "mhpmcounter9";
583
70
  case 0x0b0a:
584
70
    return "mhpmcounter10";
585
158
  case 0x0b0b:
586
158
    return "mhpmcounter11";
587
203
  case 0x0b0c:
588
203
    return "mhpmcounter12";
589
249
  case 0x0b0d:
590
249
    return "mhpmcounter13";
591
114
  case 0x0b0e:
592
114
    return "mhpmcounter14";
593
53
  case 0x0b0f:
594
53
    return "mhpmcounter15";
595
458
  case 0x0b10:
596
458
    return "mhpmcounter16";
597
146
  case 0x0b11:
598
146
    return "mhpmcounter17";
599
238
  case 0x0b12:
600
238
    return "mhpmcounter18";
601
416
  case 0x0b13:
602
416
    return "mhpmcounter19";
603
263
  case 0x0b14:
604
263
    return "mhpmcounter20";
605
427
  case 0x0b15:
606
427
    return "mhpmcounter21";
607
214
  case 0x0b16:
608
214
    return "mhpmcounter22";
609
115
  case 0x0b17:
610
115
    return "mhpmcounter23";
611
111
  case 0x0b18:
612
111
    return "mhpmcounter24";
613
285
  case 0x0b19:
614
285
    return "mhpmcounter25";
615
243
  case 0x0b1a:
616
243
    return "mhpmcounter26";
617
110
  case 0x0b1b:
618
110
    return "mhpmcounter27";
619
536
  case 0x0b1c:
620
536
    return "mhpmcounter28";
621
137
  case 0x0b1d:
622
137
    return "mhpmcounter29";
623
291
  case 0x0b1e:
624
291
    return "mhpmcounter30";
625
292
  case 0x0b1f:
626
292
    return "mhpmcounter31";
627
384
  case 0x0b80:
628
384
    return "mcycleh";
629
392
  case 0x0b82:
630
392
    return "minstreth";
631
275
  case 0x0b83:
632
275
    return "mhpmcounter3h";
633
257
  case 0x0b84:
634
257
    return "mhpmcounter4h";
635
131
  case 0x0b85:
636
131
    return "mhpmcounter5h";
637
58
  case 0x0b86:
638
58
    return "mhpmcounter6h";
639
102
  case 0x0b87:
640
102
    return "mhpmcounter7h";
641
44
  case 0x0b88:
642
44
    return "mhpmcounter8h";
643
60
  case 0x0b89:
644
60
    return "mhpmcounter9h";
645
106
  case 0x0b8a:
646
106
    return "mhpmcounter10h";
647
1.71k
  case 0x0b8b:
648
1.71k
    return "mhpmcounter11h";
649
131
  case 0x0b8c:
650
131
    return "mhpmcounter12h";
651
76
  case 0x0b8d:
652
76
    return "mhpmcounter13h";
653
232
  case 0x0b8e:
654
232
    return "mhpmcounter14h";
655
181
  case 0x0b8f:
656
181
    return "mhpmcounter15h";
657
639
  case 0x0b90:
658
639
    return "mhpmcounter16h";
659
140
  case 0x0b91:
660
140
    return "mhpmcounter17h";
661
571
  case 0x0b92:
662
571
    return "mhpmcounter18h";
663
699
  case 0x0b93:
664
699
    return "mhpmcounter19h";
665
66
  case 0x0b94:
666
66
    return "mhpmcounter20h";
667
487
  case 0x0b95:
668
487
    return "mhpmcounter21h";
669
670
  case 0x0b96:
670
670
    return "mhpmcounter22h";
671
68
  case 0x0b97:
672
68
    return "mhpmcounter23h";
673
377
  case 0x0b98:
674
377
    return "mhpmcounter24h";
675
434
  case 0x0b99:
676
434
    return "mhpmcounter25h";
677
214
  case 0x0b9a:
678
214
    return "mhpmcounter26h";
679
328
  case 0x0b9b:
680
328
    return "mhpmcounter27h";
681
359
  case 0x0b9c:
682
359
    return "mhpmcounter28h";
683
772
  case 0x0b9d:
684
772
    return "mhpmcounter29h";
685
100
  case 0x0b9e:
686
100
    return "mhpmcounter30h";
687
233
  case 0x0b9f:
688
233
    return "mhpmcounter31h";
689
690
99
  case 0x0323:
691
99
    return "mhpmevent3";
692
109
  case 0x0324:
693
109
    return "mhpmevent4";
694
516
  case 0x0325:
695
516
    return "mhpmevent5";
696
122
  case 0x0326:
697
122
    return "mhpmevent6";
698
150
  case 0x0327:
699
150
    return "mhpmevent7";
700
1.08k
  case 0x0328:
701
1.08k
    return "mhpmevent8";
702
127
  case 0x0329:
703
127
    return "mhpmevent9";
704
166
  case 0x032a:
705
166
    return "mhpmevent10";
706
363
  case 0x032b:
707
363
    return "mhpmevent11";
708
138
  case 0x032c:
709
138
    return "mhpmevent12";
710
904
  case 0x032d:
711
904
    return "mhpmevent13";
712
392
  case 0x032e:
713
392
    return "mhpmevent14";
714
145
  case 0x032f:
715
145
    return "mhpmevent15";
716
192
  case 0x0330:
717
192
    return "mhpmevent16";
718
249
  case 0x0331:
719
249
    return "mhpmevent17";
720
861
  case 0x0332:
721
861
    return "mhpmevent18";
722
169
  case 0x0333:
723
169
    return "mhpmevent19";
724
580
  case 0x0334:
725
580
    return "mhpmevent20";
726
533
  case 0x0335:
727
533
    return "mhpmevent21";
728
226
  case 0x0336:
729
226
    return "mhpmevent22";
730
231
  case 0x0337:
731
231
    return "mhpmevent23";
732
148
  case 0x0338:
733
148
    return "mhpmevent24";
734
622
  case 0x0339:
735
622
    return "mhpmevent25";
736
185
  case 0x033a:
737
185
    return "mhpmevent26";
738
217
  case 0x033b:
739
217
    return "mhpmevent27";
740
320
  case 0x033c:
741
320
    return "mhpmevent28";
742
622
  case 0x033d:
743
622
    return "mhpmevent29";
744
385
  case 0x033e:
745
385
    return "mhpmevent30";
746
391
  case 0x033f:
747
391
    return "mhpmevent31";
748
749
362
  case 0x07a0:
750
362
    return "tselect";
751
325
  case 0x07a1:
752
325
    return "tdata1";
753
336
  case 0x07a2:
754
336
    return "tdata2";
755
740
  case 0x07a3:
756
740
    return "tdata3";
757
758
113
  case 0x07b0:
759
113
    return "dcsr";
760
132
  case 0x07b1:
761
132
    return "dpc";
762
340
  case 0x07b2:
763
340
    return "dscratch";
764
91.5k
  }
765
15.0k
  return NULL;
766
91.5k
}
767
768
static void printCSRSystemRegister(MCInst *MI, unsigned OpNo,
769
           //const MCSubtargetInfo &STI,
770
           SStream *O)
771
91.5k
{
772
91.5k
  unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, OpNo));
773
91.5k
  const char *Name = getCSRSystemRegisterName(Imm);
774
775
91.5k
  if (Name) {
776
76.5k
    SStream_concat0(O, Name);
777
76.5k
  } else {
778
15.0k
    SStream_concat(O, "%u", Imm);
779
15.0k
  }
780
91.5k
}
781
782
static void printFenceArg(MCInst *MI, unsigned OpNo, SStream *O)
783
1.76k
{
784
1.76k
  unsigned FenceArg = MCOperand_getImm(MCInst_getOperand(MI, OpNo));
785
  //CS_ASSERT (((FenceArg >> 4) == 0) && "Invalid immediate in printFenceArg");
786
787
1.76k
  if ((FenceArg & RISCVFenceField_I) != 0)
788
897
    SStream_concat0(O, "i");
789
1.76k
  if ((FenceArg & RISCVFenceField_O) != 0)
790
689
    SStream_concat0(O, "o");
791
1.76k
  if ((FenceArg & RISCVFenceField_R) != 0)
792
883
    SStream_concat0(O, "r");
793
1.76k
  if ((FenceArg & RISCVFenceField_W) != 0)
794
847
    SStream_concat0(O, "w");
795
1.76k
  if (FenceArg == 0)
796
427
    SStream_concat0(O, "unknown");
797
1.76k
}
798
799
static void printFRMArg(MCInst *MI, unsigned OpNo, SStream *O)
800
17.5k
{
801
17.5k
  enum RoundingMode FRMArg = (enum RoundingMode)MCOperand_getImm(
802
17.5k
    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
17.5k
  SStream_concat0(O, roundingModeToString(FRMArg));
809
17.5k
}
810
811
#endif // CAPSTONE_HAS_RISCV