Coverage Report

Created: 2025-10-10 06:20

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