/src/capstonenext/arch/RISCV/RISCVBaseInfo.h
Line | Count | Source |
1 | | /* Capstone Disassembly Engine, http://www.capstone-engine.org */ |
2 | | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2022, */ |
3 | | /* Rot127 <unisono@quyllur.org> 2022-2023 */ |
4 | | /* Automatically translated source file from LLVM. */ |
5 | | |
6 | | /* LLVM-commit: <commit> */ |
7 | | /* LLVM-tag: <tag> */ |
8 | | |
9 | | /* Only small edits allowed. */ |
10 | | /* For multiple similar edits, please create a Patch for the translator. */ |
11 | | |
12 | | /* Capstone's C++ file translator: */ |
13 | | /* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */ |
14 | | |
15 | | //===-- RISCVBaseInfo.h - Top level definitions for RISC-V MC ---*- C++ -*-===// |
16 | | // |
17 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
18 | | // See https://llvm.org/LICENSE.txt for license information. |
19 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
20 | | // |
21 | | //===----------------------------------------------------------------------===// |
22 | | // |
23 | | // This file contains small standalone enum definitions for the RISC-V target |
24 | | // useful for the compiler back-end and the MC libraries. |
25 | | // |
26 | | //===----------------------------------------------------------------------===// |
27 | | #ifndef LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H |
28 | | #define LLVM_LIB_TARGET_RISCV_MCTARGETDESC_RISCVBASEINFO_H |
29 | | |
30 | | #include <stdio.h> |
31 | | #include <string.h> |
32 | | #include <stdlib.h> |
33 | | #include <capstone/platform.h> |
34 | | |
35 | | #include "../../utils.h" |
36 | | |
37 | | #define CONCAT(a, b) CONCAT_(a, b) |
38 | | #define CONCAT_(a, b) a##_##b |
39 | | |
40 | | // RISCVII - This namespace holds all of the target specific flags that |
41 | | // instruction info tracks. All definitions must match RISCVInstrFormats.td. |
42 | | // CS namespace begin: RISCVII |
43 | | |
44 | | // RISC-V Specific Machine Operand Flags |
45 | | enum { |
46 | | RISCVII_MO_None = 0, |
47 | | RISCVII_MO_CALL = 1, |
48 | | RISCVII_MO_LO = 3, |
49 | | RISCVII_MO_HI = 4, |
50 | | RISCVII_MO_PCREL_LO = 5, |
51 | | RISCVII_MO_PCREL_HI = 6, |
52 | | RISCVII_MO_GOT_HI = 7, |
53 | | RISCVII_MO_TPREL_LO = 8, |
54 | | RISCVII_MO_TPREL_HI = 9, |
55 | | RISCVII_MO_TPREL_ADD = 10, |
56 | | RISCVII_MO_TLS_GOT_HI = 11, |
57 | | RISCVII_MO_TLS_GD_HI = 12, |
58 | | RISCVII_MO_TLSDESC_HI = 13, |
59 | | RISCVII_MO_TLSDESC_LOAD_LO = 14, |
60 | | RISCVII_MO_TLSDESC_ADD_LO = 15, |
61 | | RISCVII_MO_TLSDESC_CALL = 16, |
62 | | |
63 | | // Used to differentiate between target-specific "direct" flags and "bitmask" |
64 | | // flags. A machine operand can only have one "direct" flag, but can have |
65 | | // multiple "bitmask" flags. |
66 | | RISCVII_MO_DIRECT_FLAG_MASK = 31 |
67 | | }; |
68 | | |
69 | | typedef enum OperandType { |
70 | | RISCVOp_OPERAND_FIRST_RISCV_IMM = MCOI_OPERAND_FIRST_TARGET, |
71 | | RISCVOp_OPERAND_UIMM1 = RISCVOp_OPERAND_FIRST_RISCV_IMM, |
72 | | RISCVOp_OPERAND_UIMM2, |
73 | | RISCVOp_OPERAND_UIMM2_LSB0, |
74 | | RISCVOp_OPERAND_UIMM3, |
75 | | RISCVOp_OPERAND_UIMM4, |
76 | | RISCVOp_OPERAND_UIMM5, |
77 | | RISCVOp_OPERAND_UIMM6, |
78 | | RISCVOp_OPERAND_UIMM7, |
79 | | RISCVOp_OPERAND_UIMM7_LSB00, |
80 | | RISCVOp_OPERAND_UIMM8_LSB00, |
81 | | RISCVOp_OPERAND_UIMM8, |
82 | | RISCVOp_OPERAND_UIMM8_LSB000, |
83 | | RISCVOp_OPERAND_UIMM8_GE32, |
84 | | RISCVOp_OPERAND_UIMM9_LSB000, |
85 | | RISCVOp_OPERAND_UIMM10_LSB00_NONZERO, |
86 | | RISCVOp_OPERAND_UIMM12, |
87 | | RISCVOp_OPERAND_ZERO, |
88 | | RISCVOp_OPERAND_SIMM5, |
89 | | RISCVOp_OPERAND_SIMM5_PLUS1, |
90 | | RISCVOp_OPERAND_SIMM6, |
91 | | RISCVOp_OPERAND_SIMM6_NONZERO, |
92 | | RISCVOp_OPERAND_SIMM10_LSB0000_NONZERO, |
93 | | RISCVOp_OPERAND_SIMM12, |
94 | | RISCVOp_OPERAND_SIMM12_LSB00000, |
95 | | RISCVOp_OPERAND_UIMM20, |
96 | | RISCVOp_OPERAND_UIMMLOG2XLEN, |
97 | | RISCVOp_OPERAND_UIMMLOG2XLEN_NONZERO, |
98 | | RISCVOp_OPERAND_CLUI_IMM, |
99 | | RISCVOp_OPERAND_VTYPEI10, |
100 | | RISCVOp_OPERAND_VTYPEI11, |
101 | | RISCVOp_OPERAND_RVKRNUM, |
102 | | RISCVOp_OPERAND_RVKRNUM_0_7, |
103 | | RISCVOp_OPERAND_RVKRNUM_1_10, |
104 | | RISCVOp_OPERAND_RVKRNUM_2_14, |
105 | | OPERAND_LAST_RISCV_IMM = RISCVOp_OPERAND_RVKRNUM_2_14, |
106 | | // Operand is either a register or uimm5, this is used by V extension pseudo |
107 | | // instructions to represent a value that be passed as AVL to either vsetvli |
108 | | // or vsetivli. |
109 | | RISCVOp_OPERAND_AVL, |
110 | | } RISCVOp_OperandType; |
111 | | |
112 | | // Describes the predecessor/successor bits used in the FENCE instruction. |
113 | | |
114 | | typedef enum FenceField { |
115 | | RISCVFenceField_I = 8, |
116 | | RISCVFenceField_O = 4, |
117 | | RISCVFenceField_R = 2, |
118 | | RISCVFenceField_W = 1 |
119 | | } RISCVFenceField_FenceField; |
120 | | |
121 | | // Describes the supported floating point rounding mode encodings. |
122 | | |
123 | | typedef enum RoundingMode { |
124 | | RISCVFPRndMode_RNE = 0, |
125 | | RISCVFPRndMode_RTZ = 1, |
126 | | RISCVFPRndMode_RDN = 2, |
127 | | RISCVFPRndMode_RUP = 3, |
128 | | RISCVFPRndMode_RMM = 4, |
129 | | RISCVFPRndMode_DYN = 7, |
130 | | RISCVFPRndMode_Invalid |
131 | | } RISCVFPRndMode_RoundingMode; |
132 | | |
133 | | inline static bool RISCVFPRndMode_isValidRoundingMode(unsigned Mode) |
134 | 2.35k | { |
135 | 2.35k | switch (Mode) { |
136 | 12 | default: |
137 | 12 | return false; |
138 | 198 | case RISCVFPRndMode_RNE: |
139 | 558 | case RISCVFPRndMode_RTZ: |
140 | 884 | case RISCVFPRndMode_RDN: |
141 | 1.24k | case RISCVFPRndMode_RUP: |
142 | 1.73k | case RISCVFPRndMode_RMM: |
143 | 2.34k | case RISCVFPRndMode_DYN: |
144 | 2.34k | return true; |
145 | 2.35k | } |
146 | 2.35k | } Unexecuted instantiation: RISCVModule.c:RISCVFPRndMode_isValidRoundingMode RISCVDisassembler.c:RISCVFPRndMode_isValidRoundingMode Line | Count | Source | 134 | 2.35k | { | 135 | 2.35k | switch (Mode) { | 136 | 12 | default: | 137 | 12 | return false; | 138 | 198 | case RISCVFPRndMode_RNE: | 139 | 558 | case RISCVFPRndMode_RTZ: | 140 | 884 | case RISCVFPRndMode_RDN: | 141 | 1.24k | case RISCVFPRndMode_RUP: | 142 | 1.73k | case RISCVFPRndMode_RMM: | 143 | 2.34k | case RISCVFPRndMode_DYN: | 144 | | return true; | 145 | 2.35k | } | 146 | 2.35k | } |
Unexecuted instantiation: RISCVInstPrinter.c:RISCVFPRndMode_isValidRoundingMode Unexecuted instantiation: RISCVMapping.c:RISCVFPRndMode_isValidRoundingMode Unexecuted instantiation: RISCVBaseInfo.c:RISCVFPRndMode_isValidRoundingMode |
147 | | |
148 | | inline static const char *RISCVFPRndMode_roundingModeToString(unsigned RndMode) |
149 | 1.72k | { |
150 | 1.72k | switch (RndMode) { |
151 | 0 | default: |
152 | 0 | CS_ASSERT(0 && "Unknown floating point rounding mode"); |
153 | 178 | case RISCVFPRndMode_RNE: |
154 | 178 | return "rne"; |
155 | 360 | case RISCVFPRndMode_RTZ: |
156 | 360 | return "rtz"; |
157 | 326 | case RISCVFPRndMode_RDN: |
158 | 326 | return "rdn"; |
159 | 365 | case RISCVFPRndMode_RUP: |
160 | 365 | return "rup"; |
161 | 490 | case RISCVFPRndMode_RMM: |
162 | 490 | return "rmm"; |
163 | 6 | case RISCVFPRndMode_DYN: |
164 | 6 | return "dyn"; |
165 | 1.72k | } |
166 | 1.72k | } Unexecuted instantiation: RISCVModule.c:RISCVFPRndMode_roundingModeToString Unexecuted instantiation: RISCVDisassembler.c:RISCVFPRndMode_roundingModeToString RISCVInstPrinter.c:RISCVFPRndMode_roundingModeToString Line | Count | Source | 149 | 1.72k | { | 150 | 1.72k | switch (RndMode) { | 151 | 0 | default: | 152 | 0 | CS_ASSERT(0 && "Unknown floating point rounding mode"); | 153 | 178 | case RISCVFPRndMode_RNE: | 154 | 178 | return "rne"; | 155 | 360 | case RISCVFPRndMode_RTZ: | 156 | 360 | return "rtz"; | 157 | 326 | case RISCVFPRndMode_RDN: | 158 | 326 | return "rdn"; | 159 | 365 | case RISCVFPRndMode_RUP: | 160 | 365 | return "rup"; | 161 | 490 | case RISCVFPRndMode_RMM: | 162 | 490 | return "rmm"; | 163 | 6 | case RISCVFPRndMode_DYN: | 164 | 6 | return "dyn"; | 165 | 1.72k | } | 166 | 1.72k | } |
Unexecuted instantiation: RISCVMapping.c:RISCVFPRndMode_roundingModeToString Unexecuted instantiation: RISCVBaseInfo.c:RISCVFPRndMode_roundingModeToString |
167 | | |
168 | | inline static bool RISCVVType_isTailAgnostic(unsigned VType) |
169 | 368 | { |
170 | 368 | return VType & 0x40; |
171 | 368 | } Unexecuted instantiation: RISCVModule.c:RISCVVType_isTailAgnostic Unexecuted instantiation: RISCVDisassembler.c:RISCVVType_isTailAgnostic Unexecuted instantiation: RISCVInstPrinter.c:RISCVVType_isTailAgnostic Unexecuted instantiation: RISCVMapping.c:RISCVVType_isTailAgnostic RISCVBaseInfo.c:RISCVVType_isTailAgnostic Line | Count | Source | 169 | 368 | { | 170 | 368 | return VType & 0x40; | 171 | 368 | } |
|
172 | | |
173 | | inline static bool RISCVVType_isMaskAgnostic(unsigned VType) |
174 | 368 | { |
175 | 368 | return VType & 0x80; |
176 | 368 | } Unexecuted instantiation: RISCVModule.c:RISCVVType_isMaskAgnostic Unexecuted instantiation: RISCVDisassembler.c:RISCVVType_isMaskAgnostic Unexecuted instantiation: RISCVInstPrinter.c:RISCVVType_isMaskAgnostic Unexecuted instantiation: RISCVMapping.c:RISCVVType_isMaskAgnostic RISCVBaseInfo.c:RISCVVType_isMaskAgnostic Line | Count | Source | 174 | 368 | { | 175 | 368 | return VType & 0x80; | 176 | 368 | } |
|
177 | | |
178 | | typedef enum RLISTENCODE { |
179 | | RISCVZC_RLISTENCODE_RA = 4, |
180 | | RISCVZC_RLISTENCODE_RA_S0, |
181 | | RISCVZC_RLISTENCODE_RA_S0_S1, |
182 | | RISCVZC_RLISTENCODE_RA_S0_S2, |
183 | | RISCVZC_RLISTENCODE_RA_S0_S3, |
184 | | RISCVZC_RLISTENCODE_RA_S0_S4, |
185 | | RISCVZC_RLISTENCODE_RA_S0_S5, |
186 | | RISCVZC_RLISTENCODE_RA_S0_S6, |
187 | | RISCVZC_RLISTENCODE_RA_S0_S7, |
188 | | RISCVZC_RLISTENCODE_RA_S0_S8, |
189 | | RISCVZC_RLISTENCODE_RA_S0_S9, |
190 | | // note - to include s10, s11 must also be included |
191 | | RISCVZC_RLISTENCODE_RA_S0_S11, |
192 | | RISCVZC_RLISTENCODE_INVALID_RLIST, |
193 | | } RISCVZC_RLISTENCODE; |
194 | | |
195 | | inline static unsigned RISCVZC_getStackAdjBase(unsigned RlistVal, bool IsRV64, |
196 | | bool IsEABI) |
197 | 0 | { |
198 | 0 | CS_ASSERT(RlistVal != RISCVZC_RLISTENCODE_INVALID_RLIST && |
199 | 0 | "{ra, s0-s10} is not supported, s11 must be included."); |
200 | 0 | if (IsEABI) |
201 | 0 | return 16; |
202 | 0 | if (!IsRV64) { |
203 | 0 | switch (RlistVal) { |
204 | 0 | case RISCVZC_RLISTENCODE_RA: |
205 | 0 | case RISCVZC_RLISTENCODE_RA_S0: |
206 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S1: |
207 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S2: |
208 | 0 | return 16; |
209 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S3: |
210 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S4: |
211 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S5: |
212 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S6: |
213 | 0 | return 32; |
214 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S7: |
215 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S8: |
216 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S9: |
217 | 0 | return 48; |
218 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S11: |
219 | 0 | return 64; |
220 | 0 | } |
221 | 0 | } else { |
222 | 0 | switch (RlistVal) { |
223 | 0 | case RISCVZC_RLISTENCODE_RA: |
224 | 0 | case RISCVZC_RLISTENCODE_RA_S0: |
225 | 0 | return 16; |
226 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S1: |
227 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S2: |
228 | 0 | return 32; |
229 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S3: |
230 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S4: |
231 | 0 | return 48; |
232 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S5: |
233 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S6: |
234 | 0 | return 64; |
235 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S7: |
236 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S8: |
237 | 0 | return 80; |
238 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S9: |
239 | 0 | return 96; |
240 | 0 | case RISCVZC_RLISTENCODE_RA_S0_S11: |
241 | 0 | return 112; |
242 | 0 | } |
243 | 0 | } |
244 | 0 | CS_ASSERT(0 && "Unexpected RlistVal"); |
245 | 0 | return 0; // unreachable |
246 | 0 | } Unexecuted instantiation: RISCVModule.c:RISCVZC_getStackAdjBase Unexecuted instantiation: RISCVDisassembler.c:RISCVZC_getStackAdjBase Unexecuted instantiation: RISCVInstPrinter.c:RISCVZC_getStackAdjBase Unexecuted instantiation: RISCVMapping.c:RISCVZC_getStackAdjBase Unexecuted instantiation: RISCVBaseInfo.c:RISCVZC_getStackAdjBase |
247 | | |
248 | | typedef enum VLMUL { |
249 | | RISCVII_LMUL_1 = 0, |
250 | | RISCVII_LMUL_2, |
251 | | RISCVII_LMUL_4, |
252 | | RISCVII_LMUL_8, |
253 | | RISCVII_LMUL_RESERVED, |
254 | | RISCVII_LMUL_F8, |
255 | | RISCVII_LMUL_F4, |
256 | | RISCVII_LMUL_F2 |
257 | | } RISCVII_VLMUL; |
258 | | |
259 | | inline static RISCVII_VLMUL RISCVVType_getVLMUL(unsigned VType) |
260 | 1.35k | { |
261 | 1.35k | unsigned VLMUL = VType & 0x7; |
262 | 1.35k | return (RISCVII_VLMUL)(VLMUL); |
263 | 1.35k | } Unexecuted instantiation: RISCVModule.c:RISCVVType_getVLMUL Unexecuted instantiation: RISCVDisassembler.c:RISCVVType_getVLMUL RISCVInstPrinter.c:RISCVVType_getVLMUL Line | Count | Source | 260 | 984 | { | 261 | 984 | unsigned VLMUL = VType & 0x7; | 262 | 984 | return (RISCVII_VLMUL)(VLMUL); | 263 | 984 | } |
Unexecuted instantiation: RISCVMapping.c:RISCVVType_getVLMUL RISCVBaseInfo.c:RISCVVType_getVLMUL Line | Count | Source | 260 | 368 | { | 261 | 368 | unsigned VLMUL = VType & 0x7; | 262 | 368 | return (RISCVII_VLMUL)(VLMUL); | 263 | 368 | } |
|
264 | | |
265 | | inline static unsigned RISCVVType_decodeVSEW(unsigned VSEW) |
266 | 1.10k | { |
267 | 1.10k | CS_ASSERT(VSEW < 8 && "Unexpected VSEW value"); |
268 | 1.10k | return 1 << (VSEW + 3); |
269 | 1.10k | } Unexecuted instantiation: RISCVModule.c:RISCVVType_decodeVSEW Unexecuted instantiation: RISCVDisassembler.c:RISCVVType_decodeVSEW RISCVInstPrinter.c:RISCVVType_decodeVSEW Line | Count | Source | 266 | 739 | { | 267 | 739 | CS_ASSERT(VSEW < 8 && "Unexpected VSEW value"); | 268 | 739 | return 1 << (VSEW + 3); | 269 | 739 | } |
Unexecuted instantiation: RISCVMapping.c:RISCVVType_decodeVSEW RISCVBaseInfo.c:RISCVVType_decodeVSEW Line | Count | Source | 266 | 368 | { | 267 | 368 | CS_ASSERT(VSEW < 8 && "Unexpected VSEW value"); | 268 | 368 | return 1 << (VSEW + 3); | 269 | 368 | } |
|
270 | | |
271 | | inline static unsigned RISCVVType_getSEW(unsigned VType) |
272 | 1.10k | { |
273 | 1.10k | unsigned VSEW = (VType >> 3) & 0x7; |
274 | 1.10k | return RISCVVType_decodeVSEW(VSEW); |
275 | 1.10k | } Unexecuted instantiation: RISCVModule.c:RISCVVType_getSEW Unexecuted instantiation: RISCVDisassembler.c:RISCVVType_getSEW RISCVInstPrinter.c:RISCVVType_getSEW Line | Count | Source | 272 | 739 | { | 273 | 739 | unsigned VSEW = (VType >> 3) & 0x7; | 274 | 739 | return RISCVVType_decodeVSEW(VSEW); | 275 | 739 | } |
Unexecuted instantiation: RISCVMapping.c:RISCVVType_getSEW RISCVBaseInfo.c:RISCVVType_getSEW Line | Count | Source | 272 | 368 | { | 273 | 368 | unsigned VSEW = (VType >> 3) & 0x7; | 274 | 368 | return RISCVVType_decodeVSEW(VSEW); | 275 | 368 | } |
|
276 | | |
277 | | typedef struct { |
278 | | unsigned raw_val; |
279 | | } RegVal; |
280 | | |
281 | | typedef struct SysReg { |
282 | | const char *Name; |
283 | | RegVal val1; |
284 | | const char *AltName; |
285 | | RegVal val2; |
286 | | const char *DeprecatedName; |
287 | | unsigned Encoding; |
288 | | unsigned DummyFeatureArray[1]; |
289 | | bool isRV32Only; |
290 | | } RISCV_SysReg; |
291 | | |
292 | | void printVType(unsigned VType, SStream *OS); |
293 | | |
294 | | float getFPImm(unsigned Imm); |
295 | | |
296 | | void RISCVZC_printSpimm(int64_t Spimm, SStream *OS); |
297 | | |
298 | | #endif |