ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
Plugin.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
15#ifndef ETISS_INCLUDE_PLUGIN_H_
16#define ETISS_INCLUDE_PLUGIN_H_
17
18#include <sstream>
19#include <string>
20
21#include "etiss/ClassDefs.h"
22#include "etiss/jit/CPU.h"
23#include "etiss/jit/System.h"
24
25#include "etiss/CodePart.h"
26
27namespace etiss
28{
29
37class Plugin : public etiss::ToString
38{
40 friend class TranslationPlugin;
41 friend class CoroutinePlugin;
42 friend class SystemWrapperPlugin;
44 friend class CPUCore;
45
46 protected:
47 Plugin(unsigned type = 0);
48
49 public:
50 virtual ~Plugin();
51
52 public:
53 static const unsigned INTERRUPTLISTENER = 1 << 0;
54 static const unsigned COROUTINE = 1 << 1;
55 static const unsigned SYSTEMWRAPPER = 1 << 2;
56 static const unsigned REGISTERDEVICE =
57 1 << 3;
58 static const unsigned TRANSLATION =
59 1 << 4;
60 public:
65 inline unsigned getType() { return type_; }
82
91 inline std::string getPluginName() const
92 {
93 if (name_.length() <= 0)
94 {
95 std::stringstream ss;
96 bool fe = true;
97 ss << _getPluginName();
98 ss << "{";
100 {
101 ss << (fe ? "" : ",") << "INTERRUPTLISTENER";
102 fe = false;
103 }
104 if (type_ & COROUTINE)
105 {
106 ss << (fe ? "" : ",") << "COROUTINE";
107 fe = false;
108 }
109 if (type_ & SYSTEMWRAPPER)
110 {
111 ss << (fe ? "" : ",") << "SYSTEMWRAPPER";
112 fe = false;
113 }
114 if (type_ & REGISTERDEVICE)
115 {
116 ss << (fe ? "" : ",") << "REGISTERDEVICE";
117 fe = false;
118 }
119 if (type_ & TRANSLATION)
120 {
121 ss << (fe ? "" : ",") << "TRANSLATION";
122 }
123 ss << "}";
124 name_ = ss.str();
125 }
126 return name_;
127 }
128
135 const std::string &getLastAssignedCoreName() { return lastAssignedCoreName_; }
136
137 inline std::string toString() const { return getPluginName(); }
138
139 protected:
140 virtual std::string _getPluginName() const = 0;
141
142 protected:
148 virtual void init(ETISS_CPU *cpu, ETISS_System *system, CPUArch *arch);
153 virtual void cleanup();
158 CPUArch
163
164 void setCorrespondingCPUCoreName(std::string name) { lastAssignedCoreName_ = name; }
170 virtual inline void addedToCPUCore(etiss::CPUCore *core) {}
175 virtual inline void removedFromCPUCore(etiss::CPUCore *core) {}
176
177 private:
178 unsigned type_;
179 mutable std::string name_;
187};
188
193class InterruptListenerPlugin : virtual public Plugin
194{
195 public:
197 virtual ~InterruptListenerPlugin();
202 virtual bool interruptWrite(unsigned bit, bool value) = 0;
203};
204
221class TranslationPlugin : virtual public Plugin
222{
223 friend class etiss::Translation;
224
225 public:
227 virtual ~TranslationPlugin();
233 virtual void initCodeBlock(etiss::CodeBlock &) const;
235 virtual void finalizeCodeBlock(etiss::CodeBlock &) const;
237 virtual void *getPluginHandle();
238
239 protected:
245 std::string getPointerCode() const;
246
247 private:
248 std::string pointerCode;
249};
250
258class CoroutinePlugin : virtual public Plugin
259{
260 public:
262 virtual ~CoroutinePlugin();
266 virtual etiss::int32 execute() = 0;
271 virtual void executionEnd(int32_t code);
276 virtual bool isActive() { return true; }
277};
278
285class SystemWrapperPlugin : virtual public Plugin
286{
287 public:
289 virtual ~SystemWrapperPlugin();
294 virtual ETISS_System *wrap(ETISS_CPU *cpu, ETISS_System *system) = 0;
299 virtual ETISS_System *unwrap(ETISS_CPU *cpu, ETISS_System *system) = 0;
300};
301
307class RegisterDevicePlugin : virtual public Plugin
308{
309 public:
311 virtual ~RegisterDevicePlugin();
316 virtual void changedRegister(const char *name) = 0;
317};
318
319} // namespace etiss
320
321#endif
classes to hold code and additional information used for optimization of instruction translations
static __inline__ int32_t
Definition arm_mve.h:51
the interface to translate instructions of and processor architecture
Definition CPUArch.h:116
CPUCore is responsible for the simulation of a CPU core in ETISS.
Definition CPUCore.h:64
A list of CodeSets.
Definition CodePart.h:532
this plugin will be called before a block is executed.
Definition Plugin.h:259
virtual ~CoroutinePlugin()
Definition Plugin.cpp:73
virtual void executionEnd(int32_t code)
called when the simulation ends but before any deinitialization is done
Definition Plugin.cpp:74
virtual etiss::int32 execute()=0
called before a block and may act in the same way as a block
virtual bool isActive()
indicates if the plugin will do something in execution loop.
Definition Plugin.h:276
virtual bool interruptWrite(unsigned bit, bool value)=0
gets called whenever an external write to the interrrupt vector takes place
base plugin class that provides access to different plugin functions if present
Definition Plugin.h:38
CPUCore * plugin_core_
holds a pointer to the associated CPUCore instance.
Definition Plugin.h:160
void setCorrespondingCPUCoreName(std::string name)
Definition Plugin.h:164
virtual std::string _getPluginName() const =0
static const unsigned REGISTERDEVICE
gets noticed of changes to special registers (e.g. mmu register etc. [depends on architecture])
Definition Plugin.h:56
InterruptListenerPlugin * tplugin_
Definition Plugin.h:181
std::string toString() const
Definition Plugin.h:137
SystemWrapperPlugin * getSystemWrapperPlugin()
Definition Plugin.h:77
CoroutinePlugin * getCoroutinePlugin()
Definition Plugin.h:73
static const unsigned COROUTINE
callback after execution of each translated block
Definition Plugin.h:54
TranslationPlugin * trplugin_
Definition Plugin.h:185
std::string name_
contains a name that is build from the return value of getPluginName_() + the implemented interfaces ...
Definition Plugin.h:179
static const unsigned TRANSLATION
access to translated code during translation phase or when instruction tree is built
Definition Plugin.h:58
virtual void cleanup()
this function is called after cpu execution loop (etiss::CPUCore::execute) finished.
Definition Plugin.cpp:37
ETISS_CPU * plugin_cpu_
holds a pointer to the cpu structure. will be set before init call and after cleanup call
Definition Plugin.h:155
const std::string & getLastAssignedCoreName()
Definition Plugin.h:135
std::string lastAssignedCoreName_
Definition Plugin.h:186
CoroutinePlugin * cplugin_
Definition Plugin.h:183
ETISS_System * plugin_system_
holds a pointer to the system structure.
Definition Plugin.h:156
SystemWrapperPlugin * splugin_
Definition Plugin.h:182
static const unsigned INTERRUPTLISTENER
access to translated code
Definition Plugin.h:53
virtual void removedFromCPUCore(etiss::CPUCore *core)
called as soon a plugin has been removed from its CPUCore.
Definition Plugin.h:175
virtual void init(ETISS_CPU *cpu, ETISS_System *system, CPUArch *arch)
this function is called before the plugin is used in the cpu execution loop (etiss::CPUCore::execute)...
Definition Plugin.cpp:36
unsigned type_
Definition Plugin.h:178
static const unsigned SYSTEMWRAPPER
can wrap/change ETISS_System structure at execution start
Definition Plugin.h:55
CPUArch * plugin_arch_
holds a pointer to the CPUArch instance. will be set before init call and after cleanup call
Definition Plugin.h:159
InterruptListenerPlugin * getInterruptListenerPlugin()
Definition Plugin.h:69
TranslationPlugin * getTranslationPlugin()
Definition Plugin.h:86
virtual void addedToCPUCore(etiss::CPUCore *core)
called as soon a plugin has been added to its CPUCore.
Definition Plugin.h:170
std::string getPluginName() const
Definition Plugin.h:91
unsigned getType()
Definition Plugin.h:65
virtual ~Plugin()
Definition Plugin.cpp:34
RegisterDevicePlugin * getRegisterDevicePlugin()
Definition Plugin.h:81
RegisterDevicePlugin * rplugin_
Definition Plugin.h:184
RegisterDevicePlugin::changedRegister is called if a supported register has been changed.
Definition Plugin.h:308
virtual ~RegisterDevicePlugin()
Definition Plugin.cpp:88
virtual void changedRegister(const char *name)=0
called when an observable register has been changed
this plugin allows to wrap the ETISS_System interface
Definition Plugin.h:286
virtual ETISS_System * unwrap(ETISS_CPU *cpu, ETISS_System *system)=0
undo wrap function call this function will be called AFTER etiss::Plugin::cleanup
virtual ETISS_System * wrap(ETISS_CPU *cpu, ETISS_System *system)=0
change/wrap the passed system structure.
virtual ~SystemWrapperPlugin()
Definition Plugin.cpp:81
Marker interface for toString() support.
Definition Misc.h:95
allows to add code to the translation of instructions
Definition Plugin.h:222
virtual void initCodeBlock(etiss::CodeBlock &) const
called before instructions are translated for the code block
Definition Plugin.cpp:55
virtual void finalizeInstrSet(etiss::instr::ModedInstructionSet &) const
called after all instructions have been added to allow last changes
Definition Plugin.cpp:54
virtual void finalizeCodeBlock(etiss::CodeBlock &) const
called after all instructions have been translated for the code block
Definition Plugin.cpp:56
virtual void initInstrSet(etiss::instr::ModedInstructionSet &) const
called to add instructions to the instruction set
Definition Plugin.cpp:53
std::string getPointerCode() const
returns a C code expression that allows to get or assign a pointer to the variable assigned to this t...
Definition Plugin.cpp:63
std::string pointerCode
Definition Plugin.h:248
virtual void * getPluginHandle()
called to get the handle that is available in translated code via getPoinerCode()....
Definition Plugin.cpp:58
virtual ~TranslationPlugin()
Definition Plugin.cpp:52
holds etiss::instr::VariableInstructionSet instances for different modes.
forwards: include/jit/*
Definition Benchmark.h:17
basic cpu state structure needed for execution of any cpu architecture.
Definition CPU.h:51
memory access and time synchronization functions.
Definition System.h:40