/src/capstonenext/arch/RISCV/RISCVInstPrinter.c
Line | Count | Source (jump to first uncovered line) |
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 | | |
56 | | static void fixDetailOfEffectiveAddr(MCInst *MI) |
57 | 5.70k | { |
58 | | // Operands for load and store instructions in RISCV vary widely |
59 | 5.70k | unsigned id = MI->flat_insn->id; |
60 | 5.70k | unsigned reg = 0; |
61 | 5.70k | int64_t imm = 0; |
62 | 5.70k | uint8_t access = 0; |
63 | | |
64 | 5.70k | switch (id) { |
65 | 0 | case RISCV_INS_C_FLD: |
66 | 0 | case RISCV_INS_C_LW: |
67 | 0 | case RISCV_INS_C_FLW: |
68 | 0 | case RISCV_INS_C_LD: |
69 | 0 | case RISCV_INS_C_FSD: |
70 | 0 | case RISCV_INS_C_SW: |
71 | 0 | case RISCV_INS_C_FSW: |
72 | 0 | case RISCV_INS_C_SD: |
73 | 0 | case RISCV_INS_C_FLDSP: |
74 | 0 | case RISCV_INS_C_LWSP: |
75 | 0 | case RISCV_INS_C_FLWSP: |
76 | 0 | case RISCV_INS_C_LDSP: |
77 | 0 | case RISCV_INS_C_FSDSP: |
78 | 0 | case RISCV_INS_C_SWSP: |
79 | 0 | case RISCV_INS_C_FSWSP: |
80 | 0 | case RISCV_INS_C_SDSP: |
81 | 88 | case RISCV_INS_FLW: |
82 | 186 | case RISCV_INS_FSW: |
83 | 237 | case RISCV_INS_FLD: |
84 | 252 | case RISCV_INS_FSD: |
85 | 442 | case RISCV_INS_LB: |
86 | 516 | case RISCV_INS_LBU: |
87 | 537 | case RISCV_INS_LD: |
88 | 874 | case RISCV_INS_LH: |
89 | 924 | case RISCV_INS_LHU: |
90 | 980 | case RISCV_INS_LW: |
91 | 1.00k | case RISCV_INS_LWU: |
92 | 1.02k | case RISCV_INS_SB: |
93 | 1.35k | case RISCV_INS_SD: |
94 | 1.45k | case RISCV_INS_SH: |
95 | 1.79k | case RISCV_INS_SW: { |
96 | 1.79k | CS_ASSERT(3 == MI->flat_insn->detail->riscv.op_count); |
97 | 1.79k | CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -3)->type); |
98 | 1.79k | CS_ASSERT(RISCV_OP_IMM == RISCV_get_detail_op(MI, -2)->type); |
99 | 1.79k | CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -1)->type); |
100 | | |
101 | 1.79k | imm = RISCV_get_detail_op(MI, -2)->imm; |
102 | 1.79k | reg = RISCV_get_detail_op(MI, -1)->reg; |
103 | 1.79k | access = RISCV_get_detail_op(MI, -1)->access; |
104 | | |
105 | 1.79k | RISCV_get_detail_op(MI, -2)->type = RISCV_OP_MEM; |
106 | 1.79k | RISCV_get_detail_op(MI, -2)->mem.base = reg; |
107 | 1.79k | RISCV_get_detail_op(MI, -2)->mem.disp = imm; |
108 | 1.79k | RISCV_get_detail_op(MI, -2)->access = access; |
109 | | |
110 | 1.79k | RISCV_dec_op_count(MI); |
111 | | |
112 | 1.79k | break; |
113 | 1.45k | } |
114 | 22 | case RISCV_INS_LR_W: |
115 | 27 | case RISCV_INS_LR_W_AQ: |
116 | 47 | case RISCV_INS_LR_W_AQ_RL: |
117 | 50 | case RISCV_INS_LR_W_RL: |
118 | 86 | case RISCV_INS_LR_D: |
119 | 96 | case RISCV_INS_LR_D_AQ: |
120 | 246 | case RISCV_INS_LR_D_AQ_RL: |
121 | 261 | case RISCV_INS_LR_D_RL: { |
122 | 261 | CS_ASSERT(2 == MI->flat_insn->detail->riscv.op_count); |
123 | 261 | CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -1)->type); |
124 | 261 | CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -2)->type); |
125 | | |
126 | 261 | reg = RISCV_get_detail_op(MI, -1)->reg; |
127 | | |
128 | 261 | RISCV_get_detail_op(MI, -1)->type = RISCV_OP_MEM; |
129 | 261 | RISCV_get_detail_op(MI, -1)->mem.base = reg; |
130 | 261 | RISCV_get_detail_op(MI, -1)->mem.disp = 0; |
131 | | |
132 | 261 | break; |
133 | 246 | } |
134 | 176 | case RISCV_INS_SC_W: |
135 | 194 | case RISCV_INS_SC_W_AQ: |
136 | 203 | case RISCV_INS_SC_W_AQ_RL: |
137 | 210 | case RISCV_INS_SC_W_RL: |
138 | 250 | case RISCV_INS_SC_D: |
139 | 265 | case RISCV_INS_SC_D_AQ: |
140 | 301 | case RISCV_INS_SC_D_AQ_RL: |
141 | 348 | case RISCV_INS_SC_D_RL: |
142 | 357 | case RISCV_INS_AMOADD_D: |
143 | 367 | case RISCV_INS_AMOADD_D_AQ: |
144 | 664 | case RISCV_INS_AMOADD_D_AQ_RL: |
145 | 739 | case RISCV_INS_AMOADD_D_RL: |
146 | 781 | case RISCV_INS_AMOADD_W: |
147 | 791 | case RISCV_INS_AMOADD_W_AQ: |
148 | 828 | case RISCV_INS_AMOADD_W_AQ_RL: |
149 | 1.05k | case RISCV_INS_AMOADD_W_RL: |
150 | 1.06k | case RISCV_INS_AMOAND_D: |
151 | 1.09k | case RISCV_INS_AMOAND_D_AQ: |
152 | 1.12k | case RISCV_INS_AMOAND_D_AQ_RL: |
153 | 1.13k | case RISCV_INS_AMOAND_D_RL: |
154 | 1.14k | case RISCV_INS_AMOAND_W: |
155 | 1.16k | case RISCV_INS_AMOAND_W_AQ: |
156 | 1.18k | case RISCV_INS_AMOAND_W_AQ_RL: |
157 | 1.19k | case RISCV_INS_AMOAND_W_RL: |
158 | 1.21k | case RISCV_INS_AMOMAXU_D: |
159 | 1.22k | case RISCV_INS_AMOMAXU_D_AQ: |
160 | 1.24k | case RISCV_INS_AMOMAXU_D_AQ_RL: |
161 | 1.24k | case RISCV_INS_AMOMAXU_D_RL: |
162 | 1.25k | case RISCV_INS_AMOMAXU_W: |
163 | 1.26k | case RISCV_INS_AMOMAXU_W_AQ: |
164 | 1.30k | case RISCV_INS_AMOMAXU_W_AQ_RL: |
165 | 1.31k | case RISCV_INS_AMOMAXU_W_RL: |
166 | 1.31k | case RISCV_INS_AMOMAX_D: |
167 | 1.34k | case RISCV_INS_AMOMAX_D_AQ: |
168 | 1.59k | case RISCV_INS_AMOMAX_D_AQ_RL: |
169 | 1.60k | case RISCV_INS_AMOMAX_D_RL: |
170 | 1.61k | case RISCV_INS_AMOMAX_W: |
171 | 1.62k | case RISCV_INS_AMOMAX_W_AQ: |
172 | 1.63k | case RISCV_INS_AMOMAX_W_AQ_RL: |
173 | 1.66k | case RISCV_INS_AMOMAX_W_RL: |
174 | 1.76k | case RISCV_INS_AMOMINU_D: |
175 | 1.77k | case RISCV_INS_AMOMINU_D_AQ: |
176 | 1.82k | case RISCV_INS_AMOMINU_D_AQ_RL: |
177 | 1.96k | case RISCV_INS_AMOMINU_D_RL: |
178 | 2.09k | case RISCV_INS_AMOMINU_W: |
179 | 2.11k | case RISCV_INS_AMOMINU_W_AQ: |
180 | 2.17k | case RISCV_INS_AMOMINU_W_AQ_RL: |
181 | 2.19k | case RISCV_INS_AMOMINU_W_RL: |
182 | 2.28k | case RISCV_INS_AMOMIN_D: |
183 | 2.30k | case RISCV_INS_AMOMIN_D_AQ: |
184 | 2.31k | case RISCV_INS_AMOMIN_D_AQ_RL: |
185 | 2.32k | case RISCV_INS_AMOMIN_D_RL: |
186 | 2.32k | case RISCV_INS_AMOMIN_W: |
187 | 2.38k | case RISCV_INS_AMOMIN_W_AQ: |
188 | 2.39k | case RISCV_INS_AMOMIN_W_AQ_RL: |
189 | 2.43k | case RISCV_INS_AMOMIN_W_RL: |
190 | 2.53k | case RISCV_INS_AMOOR_D: |
191 | 2.64k | case RISCV_INS_AMOOR_D_AQ: |
192 | 2.85k | case RISCV_INS_AMOOR_D_AQ_RL: |
193 | 2.86k | case RISCV_INS_AMOOR_D_RL: |
194 | 2.87k | case RISCV_INS_AMOOR_W: |
195 | 2.89k | case RISCV_INS_AMOOR_W_AQ: |
196 | 3.13k | case RISCV_INS_AMOOR_W_AQ_RL: |
197 | 3.13k | case RISCV_INS_AMOOR_W_RL: |
198 | 3.14k | case RISCV_INS_AMOSWAP_D: |
199 | 3.16k | case RISCV_INS_AMOSWAP_D_AQ: |
200 | 3.22k | case RISCV_INS_AMOSWAP_D_AQ_RL: |
201 | 3.28k | case RISCV_INS_AMOSWAP_D_RL: |
202 | 3.28k | case RISCV_INS_AMOSWAP_W: |
203 | 3.29k | case RISCV_INS_AMOSWAP_W_AQ: |
204 | 3.30k | case RISCV_INS_AMOSWAP_W_AQ_RL: |
205 | 3.31k | case RISCV_INS_AMOSWAP_W_RL: |
206 | 3.33k | case RISCV_INS_AMOXOR_D: |
207 | 3.35k | case RISCV_INS_AMOXOR_D_AQ: |
208 | 3.39k | case RISCV_INS_AMOXOR_D_AQ_RL: |
209 | 3.40k | case RISCV_INS_AMOXOR_D_RL: |
210 | 3.41k | case RISCV_INS_AMOXOR_W: |
211 | 3.59k | case RISCV_INS_AMOXOR_W_AQ: |
212 | 3.60k | case RISCV_INS_AMOXOR_W_AQ_RL: |
213 | 3.64k | case RISCV_INS_AMOXOR_W_RL: { |
214 | 3.64k | CS_ASSERT(3 == MI->flat_insn->detail->riscv.op_count); |
215 | 3.64k | CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -3)->type); |
216 | 3.64k | CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -2)->type); |
217 | 3.64k | CS_ASSERT(RISCV_OP_REG == RISCV_get_detail_op(MI, -1)->type); |
218 | | |
219 | 3.64k | reg = RISCV_get_detail_op(MI, -1)->reg; |
220 | | |
221 | 3.64k | RISCV_get_detail_op(MI, -1)->type = RISCV_OP_MEM; |
222 | 3.64k | RISCV_get_detail_op(MI, -1)->mem.base = reg; |
223 | 3.64k | RISCV_get_detail_op(MI, -1)->mem.disp = 0; |
224 | | |
225 | 3.64k | break; |
226 | 3.60k | } |
227 | 0 | default: { |
228 | 0 | CS_ASSERT(0 && "id is not a RISC-V memory instruction"); |
229 | 0 | break; |
230 | 3.60k | } |
231 | 5.70k | } |
232 | 5.70k | return; |
233 | 5.70k | } |
234 | | |
235 | | |
236 | | //void RISCVInstPrinter::printInst(const MCInst *MI, raw_ostream &O, |
237 | | // StringRef Annot, const MCSubtargetInfo &STI) |
238 | | void RISCV_printInst(MCInst *MI, SStream *O, void *info) |
239 | 34.5k | { |
240 | 34.5k | MCRegisterInfo *MRI = (MCRegisterInfo *) info; |
241 | | //bool Res = false; |
242 | | //MCInst *NewMI = MI; |
243 | | // TODO: RISCV compressd instructions. |
244 | | //MCInst UncompressedMI; |
245 | | //if (!NoAliases) |
246 | | //Res = uncompressInst(UncompressedMI, *MI, MRI, STI); |
247 | | //if (Res) |
248 | | //NewMI = const_cast<MCInst *>(&UncompressedMI); |
249 | 34.5k | if (/*NoAliases ||*/ !printAliasInstr(MI, O, info)) |
250 | 27.2k | printInstruction(MI, O, MRI); |
251 | | //printAnnotation(O, Annot); |
252 | | // fix load/store type insttuction |
253 | 34.5k | if (MI->csh->detail_opt && |
254 | 34.5k | MI->flat_insn->detail->riscv.need_effective_addr) |
255 | 5.70k | fixDetailOfEffectiveAddr(MI); |
256 | | |
257 | 34.5k | return; |
258 | 34.5k | } |
259 | | |
260 | | static void printRegName(SStream *OS, unsigned RegNo) |
261 | 64.1k | { |
262 | 64.1k | SStream_concat0(OS, getRegisterName(RegNo, RISCV_ABIRegAltName)); |
263 | 64.1k | } |
264 | | |
265 | | /** |
266 | | void RISCVInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, |
267 | | raw_ostream &O, const char *Modifier) |
268 | | */ |
269 | | static void printOperand(MCInst *MI, unsigned OpNo, SStream *O) |
270 | 75.7k | { |
271 | 75.7k | unsigned reg; |
272 | 75.7k | int64_t Imm = 0; |
273 | | |
274 | 75.7k | RISCV_add_cs_detail(MI, OpNo); |
275 | | |
276 | 75.7k | MCOperand *MO = MCInst_getOperand(MI, OpNo); |
277 | | |
278 | 75.7k | if (MCOperand_isReg(MO)) { |
279 | 64.1k | reg = MCOperand_getReg(MO); |
280 | 64.1k | printRegName(O, reg); |
281 | 64.1k | } else { |
282 | 11.6k | CS_ASSERT(MCOperand_isImm(MO) && "Unknown operand kind in printOperand"); |
283 | 11.6k | Imm = MCOperand_getImm(MO); |
284 | 11.6k | if (Imm >= 0) { |
285 | 10.4k | if (Imm > HEX_THRESHOLD) |
286 | 6.44k | SStream_concat(O, "0x%" PRIx64, Imm); |
287 | 4.00k | else |
288 | 4.00k | SStream_concat(O, "%" PRIu64, Imm); |
289 | 10.4k | } else { |
290 | 1.18k | if (Imm < -HEX_THRESHOLD) |
291 | 1.14k | SStream_concat(O, "-0x%" PRIx64, -Imm); |
292 | 44 | else |
293 | 44 | SStream_concat(O, "-%" PRIu64, -Imm); |
294 | 1.18k | } |
295 | 11.6k | } |
296 | | |
297 | | //CS_ASSERT(MO.isExpr() && "Unknown operand kind in printOperand"); |
298 | | |
299 | 75.7k | return; |
300 | 75.7k | } |
301 | | |
302 | | static const char *getCSRSystemRegisterName(unsigned CsrNo) |
303 | 16.3k | { |
304 | 16.3k | switch (CsrNo) { |
305 | | /* |
306 | | * From RISC-V Privileged Architecture Version 1.10. |
307 | | * In the same order as Table 2.5. |
308 | | */ |
309 | 154 | case 0x0000: return "ustatus"; |
310 | 20 | case 0x0004: return "uie"; |
311 | 101 | case 0x0005: return "utvec"; |
312 | | |
313 | 29 | case 0x0040: return "uscratch"; |
314 | 53 | case 0x0041: return "uepc"; |
315 | 22 | case 0x0042: return "ucause"; |
316 | 16 | case 0x0043: return "utval"; |
317 | 45 | case 0x0044: return "uip"; |
318 | | |
319 | 189 | case 0x0001: return "fflags"; |
320 | 56 | case 0x0002: return "frm"; |
321 | 14 | case 0x0003: return "fcsr"; |
322 | | |
323 | 691 | case 0x0c00: return "cycle"; |
324 | 564 | case 0x0c01: return "time"; |
325 | 47 | case 0x0c02: return "instret"; |
326 | 27 | case 0x0c03: return "hpmcounter3"; |
327 | 18 | case 0x0c04: return "hpmcounter4"; |
328 | 402 | case 0x0c05: return "hpmcounter5"; |
329 | 78 | case 0x0c06: return "hpmcounter6"; |
330 | 94 | case 0x0c07: return "hpmcounter7"; |
331 | 143 | case 0x0c08: return "hpmcounter8"; |
332 | 207 | case 0x0c09: return "hpmcounter9"; |
333 | 30 | case 0x0c0a: return "hpmcounter10"; |
334 | 16 | case 0x0c0b: return "hpmcounter11"; |
335 | 24 | case 0x0c0c: return "hpmcounter12"; |
336 | 122 | case 0x0c0d: return "hpmcounter13"; |
337 | 65 | case 0x0c0e: return "hpmcounter14"; |
338 | 24 | case 0x0c0f: return "hpmcounter15"; |
339 | 40 | case 0x0c10: return "hpmcounter16"; |
340 | 84 | case 0x0c11: return "hpmcounter17"; |
341 | 42 | case 0x0c12: return "hpmcounter18"; |
342 | 56 | case 0x0c13: return "hpmcounter19"; |
343 | 59 | case 0x0c14: return "hpmcounter20"; |
344 | 18 | case 0x0c15: return "hpmcounter21"; |
345 | 15 | case 0x0c16: return "hpmcounter22"; |
346 | 55 | case 0x0c17: return "hpmcounter23"; |
347 | 296 | case 0x0c18: return "hpmcounter24"; |
348 | 47 | case 0x0c19: return "hpmcounter25"; |
349 | 29 | case 0x0c1a: return "hpmcounter26"; |
350 | 157 | case 0x0c1b: return "hpmcounter27"; |
351 | 5 | case 0x0c1c: return "hpmcounter28"; |
352 | 3 | case 0x0c1d: return "hpmcounter29"; |
353 | 90 | case 0x0c1e: return "hpmcounter30"; |
354 | 8 | case 0x0c1f: return "hpmcounter31"; |
355 | 9 | case 0x0c80: return "cycleh"; |
356 | 59 | case 0x0c81: return "timeh"; |
357 | 226 | case 0x0c82: return "instreth"; |
358 | 34 | case 0x0c83: return "hpmcounter3h"; |
359 | 22 | case 0x0c84: return "hpmcounter4h"; |
360 | 36 | case 0x0c85: return "hpmcounter5h"; |
361 | 42 | case 0x0c86: return "hpmcounter6h"; |
362 | 27 | case 0x0c87: return "hpmcounter7h"; |
363 | 63 | case 0x0c88: return "hpmcounter8h"; |
364 | 27 | case 0x0c89: return "hpmcounter9h"; |
365 | 64 | case 0x0c8a: return "hpmcounter10h"; |
366 | 27 | case 0x0c8b: return "hpmcounter11h"; |
367 | 18 | case 0x0c8c: return "hpmcounter12h"; |
368 | 56 | case 0x0c8d: return "hpmcounter13h"; |
369 | 20 | case 0x0c8e: return "hpmcounter14h"; |
370 | 6 | case 0x0c8f: return "hpmcounter15h"; |
371 | 92 | case 0x0c90: return "hpmcounter16h"; |
372 | 141 | case 0x0c91: return "hpmcounter17h"; |
373 | 43 | case 0x0c92: return "hpmcounter18h"; |
374 | 33 | case 0x0c93: return "hpmcounter19h"; |
375 | 39 | case 0x0c94: return "hpmcounter20h"; |
376 | 33 | case 0x0c95: return "hpmcounter21h"; |
377 | 119 | case 0x0c96: return "hpmcounter22h"; |
378 | 5 | case 0x0c97: return "hpmcounter23h"; |
379 | 35 | case 0x0c98: return "hpmcounter24h"; |
380 | 8 | case 0x0c99: return "hpmcounter25h"; |
381 | 168 | case 0x0c9a: return "hpmcounter26h"; |
382 | 10 | case 0x0c9b: return "hpmcounter27h"; |
383 | 4 | case 0x0c9c: return "hpmcounter28h"; |
384 | 36 | case 0x0c9d: return "hpmcounter29h"; |
385 | 19 | case 0x0c9e: return "hpmcounter30h"; |
386 | 39 | case 0x0c9f: return "hpmcounter31h"; |
387 | | |
388 | 8 | case 0x0100: return "sstatus"; |
389 | 2 | case 0x0102: return "sedeleg"; |
390 | 38 | case 0x0103: return "sideleg"; |
391 | 81 | case 0x0104: return "sie"; |
392 | 23 | case 0x0105: return "stvec"; |
393 | 14 | case 0x0106: return "scounteren"; |
394 | | |
395 | 14 | case 0x0140: return "sscratch"; |
396 | 37 | case 0x0141: return "sepc"; |
397 | 36 | case 0x0142: return "scause"; |
398 | 18 | case 0x0143: return "stval"; |
399 | 15 | case 0x0144: return "sip"; |
400 | | |
401 | 4 | case 0x0180: return "satp"; |
402 | | |
403 | 14 | case 0x0f11: return "mvendorid"; |
404 | 10 | case 0x0f12: return "marchid"; |
405 | 14 | case 0x0f13: return "mimpid"; |
406 | 30 | case 0x0f14: return "mhartid"; |
407 | | |
408 | 26 | case 0x0300: return "mstatus"; |
409 | 3 | case 0x0301: return "misa"; |
410 | 5 | case 0x0302: return "medeleg"; |
411 | 7 | case 0x0303: return "mideleg"; |
412 | 47 | case 0x0304: return "mie"; |
413 | 178 | case 0x0305: return "mtvec"; |
414 | 1 | case 0x0306: return "mcounteren"; |
415 | | |
416 | 7 | case 0x0340: return "mscratch"; |
417 | 387 | case 0x0341: return "mepc"; |
418 | 51 | case 0x0342: return "mcause"; |
419 | 83 | case 0x0343: return "mtval"; |
420 | 51 | case 0x0344: return "mip"; |
421 | | |
422 | 11 | case 0x03a0: return "pmpcfg0"; |
423 | 14 | case 0x03a1: return "pmpcfg1"; |
424 | 133 | case 0x03a2: return "pmpcfg2"; |
425 | 14 | case 0x03a3: return "pmpcfg3"; |
426 | 34 | case 0x03b0: return "pmpaddr0"; |
427 | 9 | case 0x03b1: return "pmpaddr1"; |
428 | 206 | case 0x03b2: return "pmpaddr2"; |
429 | 29 | case 0x03b3: return "pmpaddr3"; |
430 | 15 | case 0x03b4: return "pmpaddr4"; |
431 | 5 | case 0x03b5: return "pmpaddr5"; |
432 | 38 | case 0x03b6: return "pmpaddr6"; |
433 | 115 | case 0x03b7: return "pmpaddr7"; |
434 | 22 | case 0x03b8: return "pmpaddr8"; |
435 | 5 | case 0x03b9: return "pmpaddr9"; |
436 | 31 | case 0x03ba: return "pmpaddr10"; |
437 | 3 | case 0x03bb: return "pmpaddr11"; |
438 | 8 | case 0x03bc: return "pmpaddr12"; |
439 | 15 | case 0x03bd: return "pmpaddr13"; |
440 | 131 | case 0x03be: return "pmpaddr14"; |
441 | 8 | case 0x03bf: return "pmpaddr15"; |
442 | | |
443 | 421 | case 0x0b00: return "mcycle"; |
444 | 31 | case 0x0b02: return "minstret"; |
445 | 56 | case 0x0b03: return "mhpmcounter3"; |
446 | 63 | case 0x0b04: return "mhpmcounter4"; |
447 | 26 | case 0x0b05: return "mhpmcounter5"; |
448 | 6 | case 0x0b06: return "mhpmcounter6"; |
449 | 10 | case 0x0b07: return "mhpmcounter7"; |
450 | 281 | case 0x0b08: return "mhpmcounter8"; |
451 | 21 | case 0x0b09: return "mhpmcounter9"; |
452 | 186 | case 0x0b0a: return "mhpmcounter10"; |
453 | 14 | case 0x0b0b: return "mhpmcounter11"; |
454 | 146 | case 0x0b0c: return "mhpmcounter12"; |
455 | 430 | case 0x0b0d: return "mhpmcounter13"; |
456 | 83 | case 0x0b0e: return "mhpmcounter14"; |
457 | 361 | case 0x0b0f: return "mhpmcounter15"; |
458 | 20 | case 0x0b10: return "mhpmcounter16"; |
459 | 48 | case 0x0b11: return "mhpmcounter17"; |
460 | 15 | case 0x0b12: return "mhpmcounter18"; |
461 | 23 | case 0x0b13: return "mhpmcounter19"; |
462 | 10 | case 0x0b14: return "mhpmcounter20"; |
463 | 60 | case 0x0b15: return "mhpmcounter21"; |
464 | 10 | case 0x0b16: return "mhpmcounter22"; |
465 | 24 | case 0x0b17: return "mhpmcounter23"; |
466 | 5 | case 0x0b18: return "mhpmcounter24"; |
467 | 45 | case 0x0b19: return "mhpmcounter25"; |
468 | 61 | case 0x0b1a: return "mhpmcounter26"; |
469 | 111 | case 0x0b1b: return "mhpmcounter27"; |
470 | 18 | case 0x0b1c: return "mhpmcounter28"; |
471 | 9 | case 0x0b1d: return "mhpmcounter29"; |
472 | 43 | case 0x0b1e: return "mhpmcounter30"; |
473 | 90 | case 0x0b1f: return "mhpmcounter31"; |
474 | 37 | case 0x0b80: return "mcycleh"; |
475 | 15 | case 0x0b82: return "minstreth"; |
476 | 12 | case 0x0b83: return "mhpmcounter3h"; |
477 | 35 | case 0x0b84: return "mhpmcounter4h"; |
478 | 15 | case 0x0b85: return "mhpmcounter5h"; |
479 | 11 | case 0x0b86: return "mhpmcounter6h"; |
480 | 29 | case 0x0b87: return "mhpmcounter7h"; |
481 | 3 | case 0x0b88: return "mhpmcounter8h"; |
482 | 36 | case 0x0b89: return "mhpmcounter9h"; |
483 | 11 | case 0x0b8a: return "mhpmcounter10h"; |
484 | 45 | case 0x0b8b: return "mhpmcounter11h"; |
485 | 10 | case 0x0b8c: return "mhpmcounter12h"; |
486 | 18 | case 0x0b8d: return "mhpmcounter13h"; |
487 | 6 | case 0x0b8e: return "mhpmcounter14h"; |
488 | 19 | case 0x0b8f: return "mhpmcounter15h"; |
489 | 79 | case 0x0b90: return "mhpmcounter16h"; |
490 | 34 | case 0x0b91: return "mhpmcounter17h"; |
491 | 23 | case 0x0b92: return "mhpmcounter18h"; |
492 | 30 | case 0x0b93: return "mhpmcounter19h"; |
493 | 22 | case 0x0b94: return "mhpmcounter20h"; |
494 | 33 | case 0x0b95: return "mhpmcounter21h"; |
495 | 43 | case 0x0b96: return "mhpmcounter22h"; |
496 | 37 | case 0x0b97: return "mhpmcounter23h"; |
497 | 107 | case 0x0b98: return "mhpmcounter24h"; |
498 | 79 | case 0x0b99: return "mhpmcounter25h"; |
499 | 22 | case 0x0b9a: return "mhpmcounter26h"; |
500 | 73 | case 0x0b9b: return "mhpmcounter27h"; |
501 | 10 | case 0x0b9c: return "mhpmcounter28h"; |
502 | 99 | case 0x0b9d: return "mhpmcounter29h"; |
503 | 17 | case 0x0b9e: return "mhpmcounter30h"; |
504 | 9 | case 0x0b9f: return "mhpmcounter31h"; |
505 | | |
506 | 9 | case 0x0323: return "mhpmevent3"; |
507 | 57 | case 0x0324: return "mhpmevent4"; |
508 | 233 | case 0x0325: return "mhpmevent5"; |
509 | 18 | case 0x0326: return "mhpmevent6"; |
510 | 19 | case 0x0327: return "mhpmevent7"; |
511 | 22 | case 0x0328: return "mhpmevent8"; |
512 | 26 | case 0x0329: return "mhpmevent9"; |
513 | 5 | case 0x032a: return "mhpmevent10"; |
514 | 122 | case 0x032b: return "mhpmevent11"; |
515 | 8 | case 0x032c: return "mhpmevent12"; |
516 | 55 | case 0x032d: return "mhpmevent13"; |
517 | 42 | case 0x032e: return "mhpmevent14"; |
518 | 105 | case 0x032f: return "mhpmevent15"; |
519 | 8 | case 0x0330: return "mhpmevent16"; |
520 | 90 | case 0x0331: return "mhpmevent17"; |
521 | 87 | case 0x0332: return "mhpmevent18"; |
522 | 9 | case 0x0333: return "mhpmevent19"; |
523 | 55 | case 0x0334: return "mhpmevent20"; |
524 | 91 | case 0x0335: return "mhpmevent21"; |
525 | 8 | case 0x0336: return "mhpmevent22"; |
526 | 44 | case 0x0337: return "mhpmevent23"; |
527 | 38 | case 0x0338: return "mhpmevent24"; |
528 | 6 | case 0x0339: return "mhpmevent25"; |
529 | 147 | case 0x033a: return "mhpmevent26"; |
530 | 114 | case 0x033b: return "mhpmevent27"; |
531 | 6 | case 0x033c: return "mhpmevent28"; |
532 | 110 | case 0x033d: return "mhpmevent29"; |
533 | 61 | case 0x033e: return "mhpmevent30"; |
534 | 82 | case 0x033f: return "mhpmevent31"; |
535 | | |
536 | 4 | case 0x07a0: return "tselect"; |
537 | 20 | case 0x07a1: return "tdata1"; |
538 | 7 | case 0x07a2: return "tdata2"; |
539 | 8 | case 0x07a3: return "tdata3"; |
540 | | |
541 | 22 | case 0x07b0: return "dcsr"; |
542 | 25 | case 0x07b1: return "dpc"; |
543 | 21 | case 0x07b2: return "dscratch"; |
544 | 16.3k | } |
545 | 2.92k | return NULL; |
546 | 16.3k | } |
547 | | |
548 | | static void printCSRSystemRegister(MCInst *MI, unsigned OpNo, |
549 | | //const MCSubtargetInfo &STI, |
550 | | SStream *O) |
551 | 16.3k | { |
552 | 16.3k | unsigned Imm = MCOperand_getImm(MCInst_getOperand(MI, OpNo)); |
553 | 16.3k | const char *Name = getCSRSystemRegisterName(Imm); |
554 | | |
555 | 16.3k | if (Name) { |
556 | 13.3k | SStream_concat0(O, Name); |
557 | 13.3k | } else { |
558 | 2.92k | SStream_concat(O, "%u", Imm); |
559 | 2.92k | } |
560 | 16.3k | } |
561 | | |
562 | | static void printFenceArg(MCInst *MI, unsigned OpNo, SStream *O) |
563 | 1.22k | { |
564 | 1.22k | unsigned FenceArg = MCOperand_getImm(MCInst_getOperand(MI, OpNo)); |
565 | | //CS_ASSERT (((FenceArg >> 4) == 0) && "Invalid immediate in printFenceArg"); |
566 | | |
567 | 1.22k | if ((FenceArg & RISCVFenceField_I) != 0) |
568 | 618 | SStream_concat0(O, "i"); |
569 | 1.22k | if ((FenceArg & RISCVFenceField_O) != 0) |
570 | 332 | SStream_concat0(O, "o"); |
571 | 1.22k | if ((FenceArg & RISCVFenceField_R) != 0) |
572 | 624 | SStream_concat0(O, "r"); |
573 | 1.22k | if ((FenceArg & RISCVFenceField_W) != 0) |
574 | 568 | SStream_concat0(O, "w"); |
575 | 1.22k | if (FenceArg == 0) |
576 | 302 | SStream_concat0(O, "unknown"); |
577 | 1.22k | } |
578 | | |
579 | | static void printFRMArg(MCInst *MI, unsigned OpNo, SStream *O) |
580 | 3.14k | { |
581 | 3.14k | enum RoundingMode FRMArg = |
582 | 3.14k | (enum RoundingMode)MCOperand_getImm(MCInst_getOperand(MI, OpNo)); |
583 | | #if 0 |
584 | | auto FRMArg = |
585 | | static_cast<RISCVFPRndMode::RoundingMode>(MI->getOperand(OpNo).getImm()); |
586 | | O << RISCVFPRndMode::roundingModeToString(FRMArg); |
587 | | #endif |
588 | 3.14k | SStream_concat0(O, roundingModeToString(FRMArg)); |
589 | 3.14k | } |
590 | | |
591 | | #endif // CAPSTONE_HAS_RISCV |