ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
RV64IMACFDArchSpecificImp.cpp
Go to the documentation of this file.
1
11#include <vector>
12
13#include "RV64IMACFDArch.h"
15#include "RV64IMACFDFuncs.h"
16
36etiss::int32 RV64IMACFDArch::handleException(etiss::int32 cause, ETISS_CPU *cpu)
37{
38 RV64IMACFD_translate_exc_code(cpu, nullptr, nullptr, cause);
39 cpu->instructionPointer = cpu->nextPc;
40 return 0;
41}
42
69{
70
71 {
72 /* Set default JIT Extensions. Read Parameters set from ETISS configuration and append with architecturally
73 * needed */
74 std::string cfgPar = "";
75 cfgPar = etiss::cfg().get<std::string>("jit.external_headers", ";");
76 etiss::cfg().set<std::string>("jit.external_headers", cfgPar + "etiss/jit/libsoftfloat.h");
77
78 cfgPar = etiss::cfg().get<std::string>("jit.external_libs", ";");
79 etiss::cfg().set<std::string>("jit.external_libs", cfgPar + "softfloat");
80
81 cfgPar = etiss::cfg().get<std::string>("jit.external_header_paths", ";");
82 etiss::cfg().set<std::string>("jit.external_header_paths", cfgPar + "/etiss/jit");
83
84 cfgPar = etiss::cfg().get<std::string>("jit.external_lib_paths", ";");
85 etiss::cfg().set<std::string>("jit.external_lib_paths", cfgPar + "/etiss/jit");
86 }
87
88 if (false)
89 {
90 // Pre-compilation of instruction set to view instruction tree. Could be disabled.
91 etiss::instr::ModedInstructionSet iset("RV64IMACFDISA");
92 bool ok = true;
93 RV64IMACFDISA.addTo(iset, ok);
94
95 iset.compile();
96
97 std::cout << iset.print() << std::endl;
98 }
99
100 bool ok = true;
101 RV64IMACFDISA.addTo(mis, ok);
102 if (!ok)
103 etiss::log(etiss::FATALERROR, "Failed to add instructions for RV64IMACFDISA");
104
106
107 using namespace etiss;
108 using namespace etiss::instr;
109
110 vis->get(32)->getInvalid().addCallback(
112 {
113 // -----------------------------------------------------------------------------
114
115 // -----------------------------------------------------------------------------
116
117 // -----------------------------------------------------------------------------
118 etiss_uint32 error_code = 0;
119 static BitArrayRange R_error_code_0(31, 0);
120 error_code += R_error_code_0.read(ba) << 0;
121
122 // -----------------------------------------------------------------------------
123
124 {
125 CodePart &cp = cs.append(CodePart::INITIALREQUIRED);
126
127 cp.code() = std::string("//trap_entry 32\n");
128
129 // -----------------------------------------------------------------------------
130 { // procedure
131 cp.code() += "{ // procedure\n";
132 cp.code() += "RV64IMACFD_translate_exc_code(cpu, system, plugin_pointers, " +
133 std::to_string(error_code) + "ULL);\n";
134 cp.code() += "goto instr_exit_" + std::to_string(ic.current_address_) + ";\n";
135 cp.code() += "} // procedure\n";
136 } // procedure
137 cp.code() += "instr_exit_" + std::to_string(ic.current_address_) + ":\n";
138 cp.code() += "cpu->instructionPointer = cpu->nextPc;\n";
139 // -----------------------------------------------------------------------------
140 cp.getAffectedRegisters().add("instructionPointer", 32);
141 }
142 {
143 CodePart &cp = cs.append(CodePart::APPENDEDRETURNINGREQUIRED);
144
145 cp.code() = std::string("//trap_entry 32\n");
146
147 // -----------------------------------------------------------------------------
148 cp.code() += "return cpu->exception;\n";
149 // -----------------------------------------------------------------------------
150 }
151
152 return true;
153 },
154 0);
155
156 vis->get(16)->getInvalid().addCallback(
158 {
159 // -----------------------------------------------------------------------------
160
161 // -----------------------------------------------------------------------------
162
163 // -----------------------------------------------------------------------------
164 etiss_uint32 error_code = 0;
165 static BitArrayRange R_error_code_0(31, 0);
166 error_code += R_error_code_0.read(ba) << 0;
167
168 // -----------------------------------------------------------------------------
169
170 {
171 CodePart &cp = cs.append(CodePart::INITIALREQUIRED);
172
173 cp.code() = std::string("//trap_entry 16\n");
174
175 // -----------------------------------------------------------------------------
176 { // procedure
177 cp.code() += "{ // procedure\n";
178 cp.code() += "RV64IMACFD_translate_exc_code(cpu, system, plugin_pointers, " +
179 std::to_string(error_code) + "ULL);\n";
180 cp.code() += "goto instr_exit_" + std::to_string(ic.current_address_) + ";\n";
181 cp.code() += "} // procedure\n";
182 } // procedure
183 cp.code() += "instr_exit_" + std::to_string(ic.current_address_) + ":\n";
184 cp.code() += "cpu->instructionPointer = cpu->nextPc;\n";
185 // -----------------------------------------------------------------------------
186 cp.getAffectedRegisters().add("instructionPointer", 32);
187 }
188 {
189 CodePart &cp = cs.append(CodePart::APPENDEDRETURNINGREQUIRED);
190
191 cp.code() = std::string("//trap_entry 16\n");
192
193 // -----------------------------------------------------------------------------
194 cp.code() += "return cpu->exception;\n";
195 // -----------------------------------------------------------------------------
196 }
197
198 return true;
199 },
200 0);
201
203 {
204 std::function<void(InstructionContext & ic, etiss_uint32 opRd)> updateRV64IMACFDInstrLength =
205 [](InstructionContext &ic, etiss_uint32 opRd)
206 {
208 ic.is_not_default_width_ = true;
209 if (opRd == 0x3f)
210 ic.instr_width_ = 64;
211 else if ((opRd & 0x3f) == 0x1f)
212 ic.instr_width_ = 48;
213 else if (((opRd & 0x1f) >= 0x3) && ((opRd & 0x1f) < 0x1f))
214 ic.instr_width_ = 32;
215 else if (opRd == 0x7f) /* P-Extension instructions */
216 ic.instr_width_ = 32;
217 else if ((opRd & 0x3) != 0x3)
218 ic.instr_width_ = 16;
219 else
220 // This might happen when code is followed by data.
221 ic.is_not_default_width_ = false;
222 };
223
224 BitArrayRange op(6, 0);
225 etiss_uint32 opRd = op.read(ba);
226
227 /*BitArrayRange fullOp(ba.byteCount()*8-1,0);
228 etiss_uint32 fullOpRd = fullOp.read(ba);
229
230 std::stringstream ss;
231 ss << "Byte count: " << ba.byteCount()<< std::endl;
232 ss << "opcode: 0x" <<std::hex<< fullOpRd << std::endl;
233 ss << "Current PC: 0x" <<std::hex<< ic.current_address_ << std::endl;
234 std::cout << ss.str() << std::endl;*/
235
236 switch (ba.byteCount())
237 {
238 case 2:
239 if (((opRd & 0x3) != 0x3) || (opRd == 0))
240 {
241 ic.is_not_default_width_ = false;
242 break;
243 }
244 else
245 {
246 updateRV64IMACFDInstrLength(ic, opRd);
247 break;
248 }
249 case 4:
250 if ((((opRd & 0x1f) >= 0x3) || ((opRd & 0x1f) < 0x1f)) || (opRd == 0))
251 {
252 ic.is_not_default_width_ = false;
253 break;
254 }
255 else if (opRd == 0x7f) /* P-Extension instructions */
256 {
257 updateRV64IMACFDInstrLength(ic, opRd);
258 break;
259 }
260 else
261 {
262 updateRV64IMACFDInstrLength(ic, opRd);
263 break;
264 }
265 case 6:
266 if (((opRd & 0x3f) == 0x1f) || (opRd == 0))
267 {
268 ic.is_not_default_width_ = false;
269 break;
270 }
271 else
272 {
273 updateRV64IMACFDInstrLength(ic, opRd);
274 break;
275 }
276 case 8:
277 if ((opRd == 0x3f) || (opRd == 0))
278 {
279 ic.is_not_default_width_ = false;
280 break;
281 }
282 else
283 {
284 updateRV64IMACFDInstrLength(ic, opRd);
285 break;
286 }
287 default:
288 // This might happen when code is followed by data.
289 ic.is_not_default_width_ = false;
290 }
291 };
292}
293
323{
324 /**************************************************************************
325 * Endianess compensation *
326 ***************************************************************************/
327}
328
329std::shared_ptr<etiss::VirtualStruct> RV64IMACFDArch::getVirtualStruct(ETISS_CPU *cpu)
330{
331 auto ret = etiss::VirtualStruct::allocate(cpu, [](etiss::VirtualStruct::Field *f) { delete f; });
332
333 for (uint32_t i = 0; i < 32; ++i)
334 {
335 ret->addField(new RegField_RV64IMACFD(*ret, i));
336 }
337
338 ret->addField(new pcField_RV64IMACFD(*ret));
339 return ret;
340}
341
349{
350 if (cpu == 0)
351 return 0;
352
353 std::vector<etiss::uint64 *> vec;
354 std::vector<etiss::uint64 *> mask;
355
356 vec.push_back(&((RV64IMACFD *)cpu)->MIP);
357 mask.push_back(&((RV64IMACFD *)cpu)->MIE);
358
360}
361
366
371
etiss::instr::InstructionCollection RV64IMACFDISA
void RV64IMACFD_translate_exc_code(ETISS_CPU *const cpu, ETISS_System *const system, void *const *const plugin_pointers, etiss_int32 cause)
static __inline__ uint32_t
Definition arm_cde.h:25
uint32_t etiss_uint32
Definition types.h:55
virtual void compensateEndianess(ETISS_CPU *cpu, etiss::instr::BitArray &ba) const
Target architecture may have inconsistent endianess.
virtual etiss::int32 handleException(etiss::int32 code, ETISS_CPU *cpu)
This function will be called automatically in order to handling architecure dependent exceptions such...
virtual void initInstrSet(etiss::instr::ModedInstructionSet &) const
This function is called during CPUArch initialization.
virtual etiss::InterruptVector * createInterruptVector(ETISS_CPU *cpu)
If interrupt handling is expected, vector table could be provided to support interrupt triggering.
virtual void deleteInterruptEnable(etiss::InterruptEnable *en, ETISS_CPU *cpu)
virtual void deleteInterruptVector(etiss::InterruptVector *vec, ETISS_CPU *cpu)
delete an allocated interrupt vector object
virtual std::shared_ptr< etiss::VirtualStruct > getVirtualStruct(ETISS_CPU *cpu)
get the VirtualStruct of the core to mitigate register access
virtual etiss::InterruptEnable * createInterruptEnable(ETISS_CPU *cpu)
Generated on Mon, 10 Nov 2025 11:27:24 +0000.
Contains a small code snipped.
Definition CodePart.h:348
std::string & code()
Definition CodePart.h:378
RegisterSet & getAffectedRegisters()
Definition CodePart.h:376
A set of CodeParts.
Definition CodePart.h:399
void append(const CodePart &part, CodePart::TYPE type)
Definition CodePart.h:412
bool set(const std::string &key, T value)
template function to set the value of a configuration key.
Definition Misc.h:335
T get(const std::string &key, T default_, bool *default_used=0)
template function to read the value of a configuration key.
Definition Misc.h:312
interface to set interrupt bits
template implementation of an InterruptVector that uses integer variables to store interrupt bit valu...
void add(const RegisterPart &rp)
add a registerPart to the set or just its relevant bits if a register with the same name is already p...
Definition CodePart.h:184
a Field instance represents e.g.
static std::shared_ptr< VirtualStruct > allocate(void *structure, std::function< void(Field *)> delete_)
Reading through it will only return bits within the range.
I read(const BitArray &ba)
reads bits from the range to the return value starting at the lsb.
stores a bit vector
unsigned byteCount() const
void addTo(ModedInstructionSet &set, bool &ok)
this class contains parameters that persist in between instruction lookpus/translation within a trans...
bool is_not_default_width_
if true the this instruction is not as long as the width of the variable instruction set
bool instr_width_fully_evaluated_
if true the length_updater_ function will be called again after instr_width_ bits are available
uint64_t current_address_
start address of current instruction
bool addCallback(std::function< bool(BitArray &, etiss::CodeSet &, InstructionContext &)> callback, uint32_t builtinGroups, const std::set< uint32_t > &groups=std::set< uint32_t >())
holds etiss::instr::VariableInstructionSet instances for different modes.
std::string print(std::string prefix=std::string())
VariableInstructionSet * get(uint32_t mode)
holds etiss::instr::InstructionSet instances with different bit widths.
InstructionSet * get(unsigned width)
std::function< void(VariableInstructionSet &, InstructionContext &, BitArray &)> length_updater_
forwards: include/jit/*
Definition Benchmark.h:17
@ FATALERROR
Definition Misc.h:84
Configuration & cfg()
Definition Misc.cpp:548
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94
basic cpu state structure needed for execution of any cpu architecture.
Definition CPU.h:51
etiss_uint64 instructionPointer
pointer to next instruction.
Definition CPU.h:54
etiss_uint64 nextPc
Definition CPU.h:57
Generated on Mon, 10 Nov 2025 11:27:24 +0000.
Definition RV64IMACFD.h:18