Debian Codegraph @

arch/RISCV/RISCVDisassembler.c

raw symbols SCIP
1 //===-- RISCVDisassembler.cpp - Disassembler for RISCV --------------------===//cxx . . $ `<file>/arch/RISCV/RISCVDisassembler.c`/
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 /* Capstone Disassembly Engine */
11 /* RISC-V Backend By Rodrigo Cortes Porto <[email protected]> &
12 Shawn Chang <[email protected]>, HardenedLinux@2018 */
13
14 #ifdef CAPSTONE_HAS_RISCVcxx . . $ `<built-in>:425:9`!
15
16 #include <stdio.h> // DEBUG
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include "../../cs_priv.h"cxx . . $ `<file>/cs_priv.h`/
21 #include "../../utils.h"cxx . . $ `<file>/utils.h`/
22
23 #include "../../MCInst.h"cxx . . $ `<file>/MCInst.h`/
24 #include "../../MCInstrDesc.h"cxx . . $ `<file>/MCInstrDesc.h`/
25 #include "../../MCFixedLenDisassembler.h"cxx . . $ `<file>/MCFixedLenDisassembler.h`/
26 #include "../../MCRegisterInfo.h"cxx . . $ `<file>/MCRegisterInfo.h`/
27 #include "../../MCDisassembler.h"cxx . . $ `<file>/MCDisassembler.h`/
28 #include "../../MathExtras.h"cxx . . $ `<file>/MathExtras.h`/
29 #include "RISCVBaseInfo.h"cxx . . $ `<file>/arch/RISCV/RISCVBaseInfo.h`/
30 #include "RISCVDisassembler.h"cxx . . $ `<file>/arch/RISCV/RISCVDisassembler.h`/
31
32
33 /* Need the feature infos define in
34 RISCVGenSubtargetInfo.inc. */
35 #define GET_SUBTARGETINFO_ENUMcxx . . $ `arch/RISCV/RISCVDisassembler.c:35:9`!
36 #include "RISCVGenSubtargetInfo.inc"cxx . . $ `<file>/arch/RISCV/RISCVGenSubtargetInfo.inc`/
37
38 /* When we specify the RISCV64 mode, It means It is RV64IMAFD.
39 Similar, RISCV32 means RV32IMAFD.
40 */
41 static uint64_tcxx . . $ uint64_t# getFeatureBitscxx . . $ getFeatureBits(c104ebd7d68b2193).(int mode)
42 {
43 uint64_tcxx . . $ uint64_t# ret = RISCV_FeatureStdExtMcxx . . $ RISCV_FeatureStdExtM. | RISCV_FeatureStdExtAcxx . . $ RISCV_FeatureStdExtA. |
44 RISCV_FeatureStdExtFcxx . . $ RISCV_FeatureStdExtF. | RISCV_FeatureStdExtDcxx . . $ RISCV_FeatureStdExtD. ;
45
46 if (mode & CS_MODE_RISCV64cxx . . $ CS_MODE_RISCV64.)
47 ret |= RISCV_Feature64Bitcxx . . $ RISCV_Feature64Bit.;
48 if (mode & CS_MODE_RISCVCcxx . . $ CS_MODE_RISCVC.)
49 ret |= RISCV_FeatureStdExtCcxx . . $ RISCV_FeatureStdExtC.;
50
51 return ret;
52 }
53
54 #define GET_REGINFO_ENUMcxx . . $ `arch/RISCV/RISCVDisassembler.c:54:9`!
55 #define GET_REGINFO_MC_DESCcxx . . $ `arch/RISCV/RISCVDisassembler.c:55:9`!
56 #include "RISCVGenRegisterInfo.inc"cxx . . $ `<file>/arch/RISCV/RISCVGenRegisterInfo.inc`/
57 #define GET_INSTRINFO_ENUMcxx . . $ `arch/RISCV/RISCVDisassembler.c:57:9`!
58 #include "RISCVGenInstrInfo.inc"cxx . . $ `<file>/arch/RISCV/RISCVGenInstrInfo.inc`/
59
60 static const unsigned GPRDecoderTablecxx . . $ GPRDecoderTable.[] = {
61 RISCV_X0cxx . . $ RISCV_X0., RISCV_X1cxx . . $ RISCV_X1., RISCV_X2cxx . . $ RISCV_X2., RISCV_X3cxx . . $ RISCV_X3.,
62 RISCV_X4cxx . . $ RISCV_X4., RISCV_X5cxx . . $ RISCV_X5., RISCV_X6cxx . . $ RISCV_X6., RISCV_X7cxx . . $ RISCV_X7.,
63 RISCV_X8cxx . . $ RISCV_X8., RISCV_X9cxx . . $ RISCV_X9., RISCV_X10cxx . . $ RISCV_X10., RISCV_X11cxx . . $ RISCV_X11.,
64 RISCV_X12cxx . . $ RISCV_X12., RISCV_X13cxx . . $ RISCV_X13., RISCV_X14cxx . . $ RISCV_X14., RISCV_X15cxx . . $ RISCV_X15.,
65 RISCV_X16cxx . . $ RISCV_X16., RISCV_X17cxx . . $ RISCV_X17., RISCV_X18cxx . . $ RISCV_X18., RISCV_X19cxx . . $ RISCV_X19.,
66 RISCV_X20cxx . . $ RISCV_X20., RISCV_X21cxx . . $ RISCV_X21., RISCV_X22cxx . . $ RISCV_X22., RISCV_X23cxx . . $ RISCV_X23.,
67 RISCV_X24cxx . . $ RISCV_X24., RISCV_X25cxx . . $ RISCV_X25., RISCV_X26cxx . . $ RISCV_X26., RISCV_X27cxx . . $ RISCV_X27.,
68 RISCV_X28cxx . . $ RISCV_X28., RISCV_X29cxx . . $ RISCV_X29., RISCV_X30cxx . . $ RISCV_X30., RISCV_X31cxx . . $ RISCV_X31.
69 };
70
71 static DecodeStatuscxx . . $ DecodeStatus# DecodeGPRRegisterClasscxx . . $ DecodeGPRRegisterClass(9e81003452fc9bbc).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# RegNo,
72 uint64_tcxx . . $ uint64_t# Address, const void *Decoder)
73 {
74 unsigned Reg = 0;
75
76 if (RegNo >= ARR_SIZEcxx . . $ `utils.h:24:9`!(GPRDecoderTable))
77 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
78
79 // We must define our own mapping from RegNo to register identifier.
80 // Accessing index RegNo in the register class will work in the case that
81 // registers were added in ascending order, but not in general.
82 Reg = GPRDecoderTablecxx . . $ GPRDecoderTable.[RegNo];
83 //Inst.addOperand(MCOperand::createReg(Reg));
84 MCOperand_CreateReg0cxx . . $ MCOperand_CreateReg0(1d3fdd902ae43da2).(Inst, Reg);
85 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
86 }
87
88 static const unsigned FPR32DecoderTablecxx . . $ FPR32DecoderTable.[] = {
89 RISCV_F0_32cxx . . $ RISCV_F0_32., RISCV_F1_32cxx . . $ RISCV_F1_32., RISCV_F2_32cxx . . $ RISCV_F2_32., RISCV_F3_32cxx . . $ RISCV_F3_32.,
90 RISCV_F4_32cxx . . $ RISCV_F4_32., RISCV_F5_32cxx . . $ RISCV_F5_32., RISCV_F6_32cxx . . $ RISCV_F6_32., RISCV_F7_32cxx . . $ RISCV_F7_32.,
91 RISCV_F8_32cxx . . $ RISCV_F8_32., RISCV_F9_32cxx . . $ RISCV_F9_32., RISCV_F10_32cxx . . $ RISCV_F10_32., RISCV_F11_32cxx . . $ RISCV_F11_32.,
92 RISCV_F12_32cxx . . $ RISCV_F12_32., RISCV_F13_32cxx . . $ RISCV_F13_32., RISCV_F14_32cxx . . $ RISCV_F14_32., RISCV_F15_32cxx . . $ RISCV_F15_32.,
93 RISCV_F16_32cxx . . $ RISCV_F16_32., RISCV_F17_32cxx . . $ RISCV_F17_32., RISCV_F18_32cxx . . $ RISCV_F18_32., RISCV_F19_32cxx . . $ RISCV_F19_32.,
94 RISCV_F20_32cxx . . $ RISCV_F20_32., RISCV_F21_32cxx . . $ RISCV_F21_32., RISCV_F22_32cxx . . $ RISCV_F22_32., RISCV_F23_32cxx . . $ RISCV_F23_32.,
95 RISCV_F24_32cxx . . $ RISCV_F24_32., RISCV_F25_32cxx . . $ RISCV_F25_32., RISCV_F26_32cxx . . $ RISCV_F26_32., RISCV_F27_32cxx . . $ RISCV_F27_32.,
96 RISCV_F28_32cxx . . $ RISCV_F28_32., RISCV_F29_32cxx . . $ RISCV_F29_32., RISCV_F30_32cxx . . $ RISCV_F30_32., RISCV_F31_32cxx . . $ RISCV_F31_32.
97 };
98
99 static DecodeStatuscxx . . $ DecodeStatus# DecodeFPR32RegisterClasscxx . . $ DecodeFPR32RegisterClass(9e81003452fc9bbc).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# RegNo,
100 uint64_tcxx . . $ uint64_t# Address, const void *Decoder)
101 {
102 unsigned Reg = 0;
103
104 if (RegNo >= ARR_SIZEcxx . . $ `utils.h:24:9`!(FPR32DecoderTable))
105 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
106
107 // We must define our own mapping from RegNo to register identifier.
108 // Accessing index RegNo in the register class will work in the case that
109 // registers were added in ascending order, but not in general.
110 Reg = FPR32DecoderTablecxx . . $ FPR32DecoderTable.[RegNo];
111 MCOperand_CreateReg0cxx . . $ MCOperand_CreateReg0(1d3fdd902ae43da2).(Inst, Reg);
112 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
113 }
114
115 static DecodeStatuscxx . . $ DecodeStatus# DecodeFPR32CRegisterClasscxx . . $ DecodeFPR32CRegisterClass(9e81003452fc9bbc).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# RegNo,
116 uint64_tcxx . . $ uint64_t# Address,
117 const void *Decoder)
118 {
119 unsigned Reg = 0;
120
121 if (RegNo > 8)
122 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
123 Reg = FPR32DecoderTablecxx . . $ FPR32DecoderTable.[RegNo + 8];
124 MCOperand_CreateReg0cxx . . $ MCOperand_CreateReg0(1d3fdd902ae43da2).(Inst, Reg);
125 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
126 }
127
128 static const unsigned FPR64DecoderTablecxx . . $ FPR64DecoderTable.[] = {
129 RISCV_F0_64cxx . . $ RISCV_F0_64., RISCV_F1_64cxx . . $ RISCV_F1_64., RISCV_F2_64cxx . . $ RISCV_F2_64., RISCV_F3_64cxx . . $ RISCV_F3_64.,
130 RISCV_F4_64cxx . . $ RISCV_F4_64., RISCV_F5_64cxx . . $ RISCV_F5_64., RISCV_F6_64cxx . . $ RISCV_F6_64., RISCV_F7_64cxx . . $ RISCV_F7_64.,
131 RISCV_F8_64cxx . . $ RISCV_F8_64., RISCV_F9_64cxx . . $ RISCV_F9_64., RISCV_F10_64cxx . . $ RISCV_F10_64., RISCV_F11_64cxx . . $ RISCV_F11_64.,
132 RISCV_F12_64cxx . . $ RISCV_F12_64., RISCV_F13_64cxx . . $ RISCV_F13_64., RISCV_F14_64cxx . . $ RISCV_F14_64., RISCV_F15_64cxx . . $ RISCV_F15_64.,
133 RISCV_F16_64cxx . . $ RISCV_F16_64., RISCV_F17_64cxx . . $ RISCV_F17_64., RISCV_F18_64cxx . . $ RISCV_F18_64., RISCV_F19_64cxx . . $ RISCV_F19_64.,
134 RISCV_F20_64cxx . . $ RISCV_F20_64., RISCV_F21_64cxx . . $ RISCV_F21_64., RISCV_F22_64cxx . . $ RISCV_F22_64., RISCV_F23_64cxx . . $ RISCV_F23_64.,
135 RISCV_F24_64cxx . . $ RISCV_F24_64., RISCV_F25_64cxx . . $ RISCV_F25_64., RISCV_F26_64cxx . . $ RISCV_F26_64., RISCV_F27_64cxx . . $ RISCV_F27_64.,
136 RISCV_F28_64cxx . . $ RISCV_F28_64., RISCV_F29_64cxx . . $ RISCV_F29_64., RISCV_F30_64cxx . . $ RISCV_F30_64., RISCV_F31_64cxx . . $ RISCV_F31_64.
137 };
138
139 static DecodeStatuscxx . . $ DecodeStatus# DecodeFPR64RegisterClasscxx . . $ DecodeFPR64RegisterClass(9e81003452fc9bbc).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# RegNo,
140 uint64_tcxx . . $ uint64_t# Address, const void *Decoder)
141 {
142 unsigned Reg = 0;
143
144 if (RegNo >= ARR_SIZEcxx . . $ `utils.h:24:9`!(FPR64DecoderTable))
145 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
146
147 // We must define our own mapping from RegNo to register identifier.
148 // Accessing index RegNo in the register class will work in the case that
149 // registers were added in ascending order, but not in general.
150 Reg = FPR64DecoderTablecxx . . $ FPR64DecoderTable.[RegNo];
151 MCOperand_CreateReg0cxx . . $ MCOperand_CreateReg0(1d3fdd902ae43da2).(Inst, Reg);
152 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
153 }
154
155 static DecodeStatuscxx . . $ DecodeStatus# DecodeFPR64CRegisterClasscxx . . $ DecodeFPR64CRegisterClass(9e81003452fc9bbc).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# RegNo,
156 uint64_tcxx . . $ uint64_t# Address,
157 const void *Decoder)
158 {
159 unsigned Reg = 0;
160
161 if (RegNo > 8)
162 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
163 Reg = FPR64DecoderTablecxx . . $ FPR64DecoderTable.[RegNo + 8];
164 MCOperand_CreateReg0cxx . . $ MCOperand_CreateReg0(1d3fdd902ae43da2).(Inst, Reg);
165 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
166 }
167
168 static DecodeStatuscxx . . $ DecodeStatus# DecodeGPRNoX0RegisterClasscxx . . $ DecodeGPRNoX0RegisterClass(9e81003452fc9bbc).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# RegNo,
169 uint64_tcxx . . $ uint64_t# Address,
170 const void *Decoder)
171 {
172 if (RegNo == 0)
173 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
174 return DecodeGPRRegisterClasscxx . . $ DecodeGPRRegisterClass(9e81003452fc9bbc).(Inst, RegNo, Address, Decoder);
175 }
176
177 static DecodeStatuscxx . . $ DecodeStatus# DecodeGPRNoX0X2RegisterClasscxx . . $ DecodeGPRNoX0X2RegisterClass(9e81003452fc9bbc).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# RegNo,
178 uint64_tcxx . . $ uint64_t# Address,
179 const void *Decoder)
180 {
181 if (RegNo == 2)
182 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
183 return DecodeGPRNoX0RegisterClasscxx . . $ DecodeGPRNoX0RegisterClass(9e81003452fc9bbc).(Inst, RegNo, Address, Decoder);
184 }
185
186 static DecodeStatuscxx . . $ DecodeStatus# DecodeGPRCRegisterClasscxx . . $ DecodeGPRCRegisterClass(9e81003452fc9bbc).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# RegNo,
187 uint64_tcxx . . $ uint64_t# Address,
188 const void *Decoder)
189 {
190 unsigned Reg = 0;
191
192 if (RegNo > 8)
193 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
194
195 Reg = GPRDecoderTablecxx . . $ GPRDecoderTable.[RegNo + 8];
196 MCOperand_CreateReg0cxx . . $ MCOperand_CreateReg0(1d3fdd902ae43da2).(Inst, Reg);
197 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
198 }
199
200 // Add implied SP operand for instructions *SP compressed instructions. The SP
201 // operand isn't explicitly encoded in the instruction.
202 static void addImplySPcxx . . $ addImplySP(1552b0b633062f1f).(MCInstcxx . . $ MCInst# *Inst, int64_tcxx . . $ int64_t# Address, const void *Decoder)
203 {
204 if (MCInst_getOpcodecxx . . $ MCInst_getOpcode(66549afbf0596d6c).(Inst) == RISCV_C_LWSPcxx . . $ RISCV_C_LWSP. ||
205 MCInst_getOpcodecxx . . $ MCInst_getOpcode(66549afbf0596d6c).(Inst) == RISCV_C_SWSPcxx . . $ RISCV_C_SWSP. ||
206 MCInst_getOpcodecxx . . $ MCInst_getOpcode(66549afbf0596d6c).(Inst) == RISCV_C_LDSPcxx . . $ RISCV_C_LDSP. ||
207 MCInst_getOpcodecxx . . $ MCInst_getOpcode(66549afbf0596d6c).(Inst) == RISCV_C_SDSPcxx . . $ RISCV_C_SDSP. ||
208 MCInst_getOpcodecxx . . $ MCInst_getOpcode(66549afbf0596d6c).(Inst) == RISCV_C_FLWSPcxx . . $ RISCV_C_FLWSP. ||
209 MCInst_getOpcodecxx . . $ MCInst_getOpcode(66549afbf0596d6c).(Inst) == RISCV_C_FSWSPcxx . . $ RISCV_C_FSWSP. ||
210 MCInst_getOpcodecxx . . $ MCInst_getOpcode(66549afbf0596d6c).(Inst) == RISCV_C_FLDSPcxx . . $ RISCV_C_FLDSP. ||
211 MCInst_getOpcodecxx . . $ MCInst_getOpcode(66549afbf0596d6c).(Inst) == RISCV_C_FSDSPcxx . . $ RISCV_C_FSDSP. ||
212 MCInst_getOpcodecxx . . $ MCInst_getOpcode(66549afbf0596d6c).(Inst) == RISCV_C_ADDI4SPNcxx . . $ RISCV_C_ADDI4SPN.) {
213 DecodeGPRRegisterClasscxx . . $ DecodeGPRRegisterClass(9e81003452fc9bbc).(Inst, 2, Address, Decoder);
214 }
215
216 if (MCInst_getOpcodecxx . . $ MCInst_getOpcode(66549afbf0596d6c).(Inst) == RISCV_C_ADDI16SPcxx . . $ RISCV_C_ADDI16SP.) {
217 DecodeGPRRegisterClasscxx . . $ DecodeGPRRegisterClass(9e81003452fc9bbc).(Inst, 2, Address, Decoder);
218 DecodeGPRRegisterClasscxx . . $ DecodeGPRRegisterClass(9e81003452fc9bbc).(Inst, 2, Address, Decoder);
219 }
220 }
221
222 static DecodeStatuscxx . . $ DecodeStatus# decodeUImmOperandcxx . . $ decodeUImmOperand(56c8623f6555d519).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# Imm,
223 int64_tcxx . . $ int64_t# Address, const void *Decoder,
224 unsigned N)
225 {
226 //CS_ASSERT(isUInt<N>(Imm) && "Invalid immediate");
227 addImplySPcxx . . $ addImplySP(1552b0b633062f1f).(Inst, Address, Decoder);
228 //Inst.addOperand(MCOperand::createImm(Imm));
229 MCOperand_CreateImm0cxx . . $ MCOperand_CreateImm0(c25c894236a70359).(Inst, Imm);
230 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
231 }
232
233 static DecodeStatuscxx . . $ DecodeStatus# decodeUImmNonZeroOperandcxx . . $ decodeUImmNonZeroOperand(56c8623f6555d519).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# Imm,
234 int64_tcxx . . $ int64_t# Address,
235 const void *Decoder,
236 unsigned N)
237 {
238 if (Imm == 0)
239 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
240 return decodeUImmOperandcxx . . $ decodeUImmOperand(56c8623f6555d519).(Inst, Imm, Address, Decoder, N);
241 }
242
243 static DecodeStatuscxx . . $ DecodeStatus# decodeSImmOperandcxx . . $ decodeSImmOperand(56c8623f6555d519).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# Imm,
244 int64_tcxx . . $ int64_t# Address, const void *Decoder,
245 unsigned N)
246 {
247 //CS_ASSERT(isUInt<N>(Imm) && "Invalid immediate");
248 addImplySPcxx . . $ addImplySP(1552b0b633062f1f).(Inst, Address, Decoder);
249 // Sign-extend the number in the bottom N bits of Imm
250 //Inst.addOperand(MCOperand::createImm(SignExtend64<N>(Imm)));
251 MCOperand_CreateImm0cxx . . $ MCOperand_CreateImm0(c25c894236a70359).(Inst, SignExtend64cxx . . $ SignExtend64(2a41822c65b512db).(Imm, N));
252 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
253 }
254
255 static DecodeStatuscxx . . $ DecodeStatus# decodeSImmNonZeroOperandcxx . . $ decodeSImmNonZeroOperand(56c8623f6555d519).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# Imm,
256 int64_tcxx . . $ int64_t# Address,
257 const void *Decoder,
258 unsigned N)
259 {
260 if (Imm == 0)
261 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
262 return decodeSImmOperandcxx . . $ decodeSImmOperand(56c8623f6555d519).(Inst, Imm, Address, Decoder, N);
263 }
264
265 static DecodeStatuscxx . . $ DecodeStatus# decodeSImmOperandAndLsl1cxx . . $ decodeSImmOperandAndLsl1(56c8623f6555d519).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# Imm,
266 int64_tcxx . . $ int64_t# Address,
267 const void *Decoder,
268 unsigned N)
269 {
270 //CS_ASSERT(isUInt<N>(Imm) && "Invalid immediate");
271 // Sign-extend the number in the bottom N bits of Imm after accounting for
272 // the fact that the N bit immediate is stored in N-1 bits (the LSB is
273 // always zero)
274 //Inst.addOperand(MCOperand::createImm(SignExtend64<N>(Imm << 1)));
275 MCOperand_CreateImm0cxx . . $ MCOperand_CreateImm0(c25c894236a70359).(Inst, SignExtend64cxx . . $ SignExtend64(2a41822c65b512db).(Imm << 1, N));
276 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
277 }
278
279 static DecodeStatuscxx . . $ DecodeStatus# decodeCLUIImmOperandcxx . . $ decodeCLUIImmOperand(7052e3acb53cf835).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# Imm,
280 int64_tcxx . . $ int64_t# Address,
281 const void *Decoder)
282 {
283 //CS_ASSERT(isUInt<6>(Imm) && "Invalid immediate");
284 if (Imm > 31) {
285 Imm = (SignExtend64cxx . . $ SignExtend64(2a41822c65b512db).(Imm, 6) & 0xfffff);
286 }
287 //Inst.addOperand(MCOperand::createImm(Imm));
288 MCOperand_CreateImm0cxx . . $ MCOperand_CreateImm0(c25c894236a70359).(Inst, Imm);
289 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
290 }
291
292 static DecodeStatuscxx . . $ DecodeStatus# decodeFRMArgcxx . . $ decodeFRMArg(7052e3acb53cf835).(MCInstcxx . . $ MCInst# *Inst, uint64_tcxx . . $ uint64_t# Imm,
293 int64_tcxx . . $ int64_t# Address,
294 const void *Decoder)
295 {
296 //CS_ASSERT(isUInt<3>(Imm) && "Invalid immediate");
297 if (!RISCVFPRndMode_isValidRoundingModecxx . . $ RISCVFPRndMode_isValidRoundingMode(dfa6e707f7696010).(Imm))
298 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
299
300 //Inst.addOperand(MCOperand::createImm(Imm));
301 MCOperand_CreateImm0cxx . . $ MCOperand_CreateImm0(c25c894236a70359).(Inst, Imm);
302 return MCDisassembler_Successcxx . . $ MCDisassembler_Success.;
303 }
304
305
306 #include "RISCVGenDisassemblerTables.inc"cxx . . $ `<file>/arch/RISCV/RISCVGenDisassemblerTables.inc`/
307
308 static void init_MI_insn_detailcxx . . $ init_MI_insn_detail(94c8a3269074abe9).(MCInstcxx . . $ MCInst# *MI)
309 {
310 if (MI->flat_insncxx . . $ MCInst#flat_insn.->detailcxx . . $ cs_insn#detail.) {
311 memsetcxx . . $ memset(d1de1e4fb215f1c6).(MI->flat_insncxx . . $ MCInst#flat_insn.->detailcxx . . $ cs_insn#detail., 0, sizeof(cs_detailcxx . . $ cs_detail#));
312 }
313
314 return;
315 }
316
317 // mark the load/store instructions through the opcode.
318 static void markLSInsncxx . . $ markLSInsn(1d3fdd902ae43da2).(MCInstcxx . . $ MCInst# *MI, uint32_tcxx . . $ uint32_t# in)
319 {
320 /*
321 I ld 0000011 = 0x03
322 st 0100011 = 0x23
323 F/D ld 0000111 = 0x07
324 st 0100111 = 0x27
325 */
326 #define MASK_LS_INSNcxx . . $ `arch/RISCV/RISCVDisassembler.c:326:9`! 0x0000007f
327 uint32_tcxx . . $ uint32_t# opcode = in & MASK_LS_INSNcxx . . $ `arch/RISCV/RISCVDisassembler.c:326:9`!;
328 if (0 == (opcode ^ 0x03) || 0 == (opcode ^ 0x07) ||
329 0 == (opcode ^ 0x23) || 0 == (opcode ^ 0x27))
330 MI->flat_insncxx . . $ MCInst#flat_insn.->detailcxx . . $ cs_insn#detail.->riscvcxx . . $ cs_detail#$anonymous_type_0#riscv..need_effective_addrcxx . . $ cs_riscv#need_effective_addr. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!;
331 #undef MASK_LS_INSNcxx . . $ `arch/RISCV/RISCVDisassembler.c:326:9`!
332 return;
333 }
334
335 static DecodeStatuscxx . . $ DecodeStatus# RISCVDisassembler_getInstructioncxx . . $ RISCVDisassembler_getInstruction(12a97dec20a0076b).(int mode, MCInstcxx . . $ MCInst# *MI,
336 const uint8_tcxx . . $ uint8_t# *code, size_t code_len,
337 uint16_tcxx . . $ uint16_t# *Size, uint64_tcxx . . $ uint64_t# Address,
338 MCRegisterInfocxx . . $ MCRegisterInfo# *MRI)
339 {
340 // TODO: This will need modification when supporting instruction set
341 // extensions with instructions > 32-bits (up to 176 bits wide).
342 uint32_tcxx . . $ uint32_t# Inst = 0;
343 DecodeStatuscxx . . $ DecodeStatus# Result;
344
345 // It's a 32 bit instruction if bit 0 and 1 are 1.
346 if ((code[0] & 0x3) == 0x3) {
347 if (code_len < 4) {
348 *Size = 0;
349 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
350 }
351
352 *Size = 4;
353 // Get the four bytes of the instruction.
354 //Encoded as little endian 32 bits.
355 Inst = code[0] | (code[1] << 8) | (code[2] << 16) | ((uint32_tcxx . . $ uint32_t#)code[3] << 24);
356 init_MI_insn_detailcxx . . $ init_MI_insn_detail(94c8a3269074abe9).(MI);
357 // Now we need mark what instruction need fix effective address output.
358 if (MI->cshcxx . . $ MCInst#csh.->detailcxx . . $ cs_struct#detail.)
359 markLSInsncxx . . $ markLSInsn(1d3fdd902ae43da2).(MI, Inst);
360 Result = decodeInstructioncxx . . $ decodeInstruction(68ae61711395f7e7).(DecoderTable32cxx . . $ DecoderTable32., MI, Inst, Address, MRI, mode);
361 } else {
362 if (code_len < 2) {
363 *Size = 0;
364 return MCDisassembler_Failcxx . . $ MCDisassembler_Fail.;
365 }
366
367 // If not b4bit.
368 if (! (getFeatureBitscxx . . $ getFeatureBits(c104ebd7d68b2193).(mode) & ((uint64_tcxx . . $ uint64_t#)RISCV_Feature64Bitcxx . . $ RISCV_Feature64Bit.))) {
369 // Trying RISCV32Only_16 table (16-bit Instruction)
370 Inst = code[0] | (code[1] << 8);
371 init_MI_insn_detailcxx . . $ init_MI_insn_detail(94c8a3269074abe9).(MI);
372 Result = decodeInstructioncxx . . $ decodeInstruction(68ae61711395f7e7).(DecoderTableRISCV32Only_16cxx . . $ DecoderTableRISCV32Only_16., MI, Inst, Address,
373 MRI, mode);
374 if (Result != MCDisassembler_Failcxx . . $ MCDisassembler_Fail.) {
375 *Size = 2;
376 return Result;
377 }
378 }
379
380 // Trying RISCV_C table (16-bit Instruction)
381 Inst = code[0] | (code[1] << 8);
382 init_MI_insn_detailcxx . . $ init_MI_insn_detail(94c8a3269074abe9).(MI);
383 // Calling the auto-generated decoder function.
384 Result = decodeInstructioncxx . . $ decodeInstruction(68ae61711395f7e7).(DecoderTable16cxx . . $ DecoderTable16., MI, Inst, Address, MRI, mode);
385 *Size = 2;
386 }
387
388 return Result;
389 }
390
391 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! RISCV_getInstructioncxx . . $ RISCV_getInstruction(fe94ce91eeab61e9).(cshcxx . . $ csh# ud, const uint8_tcxx . . $ uint8_t# *code, size_t code_len,
392 MCInstcxx . . $ MCInst# *instr, uint16_tcxx . . $ uint16_t# *size, uint64_tcxx . . $ uint64_t# address,
393 void *info)
394 {
395 cs_structcxx . . $ cs_struct# *handle = (cs_structcxx . . $ cs_struct# *)(uintptr_tcxx . . $ uintptr_t#)ud;
396
397 return MCDisassembler_Successcxx . . $ MCDisassembler_Success. ==
398 RISCVDisassembler_getInstructioncxx . . $ RISCVDisassembler_getInstruction(12a97dec20a0076b).(handle->modecxx . . $ cs_struct#mode., instr,
399 code, code_len,
400 size, address,
401 (MCRegisterInfocxx . . $ MCRegisterInfo# *)info);
402
403 }
404
405 void RISCV_initcxx . . $ RISCV_init(c2e0c34190506c3d).(MCRegisterInfocxx . . $ MCRegisterInfo# * MRI)
406 {
407 /*
408 InitMCRegisterInfo(RISCVRegDesc, 97, RA, PC,
409 RISCVMCRegisterClasses, 11,
410 RISCVRegUnitRoots,
411 64,
412 RISCVRegDiffLists,
413 RISCVLaneMaskLists,
414 RISCVRegStrings,
415 RISCVRegClassStrings,
416 RISCVSubRegIdxLists,
417 2,
418 RISCVSubRegIdxRanges,
419 RISCVRegEncodingTable);
420 */
421
422 MCRegisterInfo_InitMCRegisterInfocxx . . $ MCRegisterInfo_InitMCRegisterInfo(5e86a0227010d6ff).(MRI, RISCVRegDesccxx . . $ RISCVRegDesc., 97, 0, 0,
423 RISCVMCRegisterClassescxx . . $ RISCVMCRegisterClasses., 11,
424 0,
425 0,
426 RISCVRegDiffListscxx . . $ RISCVRegDiffLists.,
427 0,
428 RISCVSubRegIdxListscxx . . $ RISCVSubRegIdxLists.,
429 2,
430 0);
431 }
432
433 #endif