ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
RV32IMACFDArchSpecificImp.cpp
Go to the documentation of this file.
1
11#include <vector>
12
13#include "RV32IMACFDArch.h"
15#include "RV32IMACFDFuncs.h"
16
35etiss::int32 RV32IMACFDArch::handleException(etiss::int32 cause, ETISS_CPU *cpu)
36{
37 RV32IMACFD_translate_exc_code(cpu, nullptr, nullptr, cause);
38 cpu->instructionPointer = cpu->nextPc;
39 return 0;
40}
41
67{
68
69 {
70 /* Set default JIT Extensions. Read Parameters set from ETISS configuration and append with architecturally
71 * needed */
72 std::string cfgPar = "";
73 cfgPar = etiss::cfg().get<std::string>("jit.external_headers", ";");
74 etiss::cfg().set<std::string>("jit.external_headers", cfgPar + "etiss/jit/libsoftfloat.h");
75
76 cfgPar = etiss::cfg().get<std::string>("jit.external_libs", ";");
77 etiss::cfg().set<std::string>("jit.external_libs", cfgPar + "softfloat");
78
79 cfgPar = etiss::cfg().get<std::string>("jit.external_header_paths", ";");
80 etiss::cfg().set<std::string>("jit.external_header_paths", cfgPar + "/etiss/jit");
81
82 cfgPar = etiss::cfg().get<std::string>("jit.external_lib_paths", ";");
83 etiss::cfg().set<std::string>("jit.external_lib_paths", cfgPar + "/etiss/jit");
84 }
85
86 if (false)
87 {
88 // Pre-compilation of instruction set to view instruction tree. Could be disabled.
89 etiss::instr::ModedInstructionSet iset("RV32IMACFDISA");
90 bool ok = true;
91 RV32IMACFDISA.addTo(iset, ok);
92
93 iset.compile();
94
95 std::cout << iset.print() << std::endl;
96 }
97
98 bool ok = true;
99 RV32IMACFDISA.addTo(mis, ok);
100 if (!ok)
101 etiss::log(etiss::FATALERROR, "Failed to add instructions for RV32IMACFDISA");
102
104
105 using namespace etiss;
106 using namespace etiss::instr;
107
108 vis->get(32)->getInvalid().addCallback(
110 {
111 // -----------------------------------------------------------------------------
112
113 // -----------------------------------------------------------------------------
114
115 // -----------------------------------------------------------------------------
116 etiss_uint32 error_code = 0;
117 static BitArrayRange R_error_code_0(31, 0);
118 error_code += R_error_code_0.read(ba) << 0;
119
120 // -----------------------------------------------------------------------------
121
122 {
123 CodePart &cp = cs.append(CodePart::INITIALREQUIRED);
124
125 cp.code() = std::string("//trap_entry 32\n");
126
127 // -----------------------------------------------------------------------------
128 { // procedure
129 cp.code() += "{ // procedure\n";
130 cp.code() += "RV32IMACFD_translate_exc_code(cpu, system, plugin_pointers, " +
131 std::to_string(error_code) + "ULL);\n";
132 cp.code() += "goto instr_exit_" + std::to_string(ic.current_address_) + ";\n";
133 cp.code() += "} // procedure\n";
134 } // procedure
135 cp.code() += "instr_exit_" + std::to_string(ic.current_address_) + ":\n";
136 cp.code() += "cpu->instructionPointer = cpu->nextPc;\n";
137 // -----------------------------------------------------------------------------
138 cp.getAffectedRegisters().add("instructionPointer", 32);
139 }
140 {
141 CodePart &cp = cs.append(CodePart::APPENDEDRETURNINGREQUIRED);
142
143 cp.code() = std::string("//trap_entry 32\n");
144
145 // -----------------------------------------------------------------------------
146 cp.code() += "return cpu->exception;\n";
147 // -----------------------------------------------------------------------------
148 }
149
150 return true;
151 },
152 0);
153
154 vis->get(16)->getInvalid().addCallback(
156 {
157 // -----------------------------------------------------------------------------
158
159 // -----------------------------------------------------------------------------
160
161 // -----------------------------------------------------------------------------
162 etiss_uint32 error_code = 0;
163 static BitArrayRange R_error_code_0(31, 0);
164 error_code += R_error_code_0.read(ba) << 0;
165
166 // -----------------------------------------------------------------------------
167
168 {
169 CodePart &cp = cs.append(CodePart::INITIALREQUIRED);
170
171 cp.code() = std::string("//trap_entry 16\n");
172
173 // -----------------------------------------------------------------------------
174 { // procedure
175 cp.code() += "{ // procedure\n";
176 cp.code() += "RV32IMACFD_translate_exc_code(cpu, system, plugin_pointers, " +
177 std::to_string(error_code) + "ULL);\n";
178 cp.code() += "goto instr_exit_" + std::to_string(ic.current_address_) + ";\n";
179 cp.code() += "} // procedure\n";
180 } // procedure
181 cp.code() += "instr_exit_" + std::to_string(ic.current_address_) + ":\n";
182 cp.code() += "cpu->instructionPointer = cpu->nextPc;\n";
183 // -----------------------------------------------------------------------------
184 cp.getAffectedRegisters().add("instructionPointer", 32);
185 }
186 {
187 CodePart &cp = cs.append(CodePart::APPENDEDRETURNINGREQUIRED);
188
189 cp.code() = std::string("//trap_entry 16\n");
190
191 // -----------------------------------------------------------------------------
192 cp.code() += "return cpu->exception;\n";
193 // -----------------------------------------------------------------------------
194 }
195
196 return true;
197 },
198 0);
199
201 {
202 std::function<void(InstructionContext & ic, etiss_uint32 opRd)> updateRV32IMACFDInstrLength =
203 [](InstructionContext &ic, etiss_uint32 opRd)
204 {
206 ic.is_not_default_width_ = true;
207 if (opRd == 0x3f)
208 ic.instr_width_ = 64;
209 else if ((opRd & 0x3f) == 0x1f)
210 ic.instr_width_ = 48;
211 else if (((opRd & 0x1f) >= 0x3) && ((opRd & 0x1f) < 0x1f))
212 ic.instr_width_ = 32;
213 else if (opRd == 0x7f) /* P-Extension instructions */
214 ic.instr_width_ = 32;
215 else if ((opRd & 0x3) != 0x3)
216 ic.instr_width_ = 16;
217 else
218 // This might happen when code is followed by data.
219 ic.is_not_default_width_ = false;
220 };
221
222 BitArrayRange op(6, 0);
223 etiss_uint32 opRd = op.read(ba);
224
225 /*BitArrayRange fullOp(ba.byteCount()*8-1,0);
226 etiss_uint32 fullOpRd = fullOp.read(ba);
227
228 std::stringstream ss;
229 ss << "Byte count: " << ba.byteCount()<< std::endl;
230 ss << "opcode: 0x" <<std::hex<< fullOpRd << std::endl;
231 ss << "Current PC: 0x" <<std::hex<< ic.current_address_ << std::endl;
232 std::cout << ss.str() << std::endl;*/
233
234 switch (ba.byteCount())
235 {
236 case 2:
237 if (((opRd & 0x3) != 0x3) || (opRd == 0))
238 {
239 ic.is_not_default_width_ = false;
240 break;
241 }
242 else
243 {
244 updateRV32IMACFDInstrLength(ic, opRd);
245 break;
246 }
247 case 4:
248 if ((((opRd & 0x1f) >= 0x3) || ((opRd & 0x1f) < 0x1f)) || (opRd == 0))
249 {
250 ic.is_not_default_width_ = false;
251 break;
252 }
253 else if (opRd == 0x7f) /* P-Extension instructions */
254 {
255 updateRV32IMACFDInstrLength(ic, opRd);
256 break;
257 }
258 else
259 {
260 updateRV32IMACFDInstrLength(ic, opRd);
261 break;
262 }
263 case 6:
264 if (((opRd & 0x3f) == 0x1f) || (opRd == 0))
265 {
266 ic.is_not_default_width_ = false;
267 break;
268 }
269 else
270 {
271 updateRV32IMACFDInstrLength(ic, opRd);
272 break;
273 }
274 case 8:
275 if ((opRd == 0x3f) || (opRd == 0))
276 {
277 ic.is_not_default_width_ = false;
278 break;
279 }
280 else
281 {
282 updateRV32IMACFDInstrLength(ic, opRd);
283 break;
284 }
285 default:
286 // This might happen when code is followed by data.
287 ic.is_not_default_width_ = false;
288 }
289 };
290}
291
321{
322 /**************************************************************************
323 * Endianess compensation *
324 **************************************************************************/
325}
326
327std::shared_ptr<etiss::VirtualStruct> RV32IMACFDArch::getVirtualStruct(ETISS_CPU *cpu)
328{
329 auto ret = etiss::VirtualStruct::allocate(cpu, [](etiss::VirtualStruct::Field *f) { delete f; });
330
331 for (uint32_t i = 0; i < 32; ++i)
332 {
333 ret->addField(new RegField_RV32IMACFD(*ret, i));
334 }
335
336 ret->addField(new pcField_RV32IMACFD(*ret));
337 return ret;
338}
339
347{
348 if (cpu == 0)
349 return 0;
350
351 std::vector<etiss::uint32 *> vec;
352 std::vector<etiss::uint32 *> mask;
353
354 vec.push_back(&((RV32IMACFD *)cpu)->MIP);
355 mask.push_back(&((RV32IMACFD *)cpu)->MIE);
356
358}
359
364
369
etiss::instr::InstructionCollection RV32IMACFDISA
void RV32IMACFD_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 deleteInterruptVector(etiss::InterruptVector *vec, ETISS_CPU *cpu)
delete an allocated interrupt vector object
virtual void deleteInterruptEnable(etiss::InterruptEnable *en, ETISS_CPU *cpu)
virtual void initInstrSet(etiss::instr::ModedInstructionSet &) const
This function is called during CPUArch initialization.
virtual etiss::InterruptEnable * createInterruptEnable(ETISS_CPU *cpu)
virtual etiss::InterruptVector * createInterruptVector(ETISS_CPU *cpu)
If interrupt handling is expected, vector table could be provided to support interrupt triggering.
virtual std::shared_ptr< etiss::VirtualStruct > getVirtualStruct(ETISS_CPU *cpu)
get the VirtualStruct of the core to mitigate register access
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...
Generated on Mon, 10 Nov 2025 11:27:12 +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:12 +0000.
Definition RV32IMACFD.h:18