Coverage Report

Created: 2025-11-16 06:38

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