ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Plugin.h
Go to the documentation of this file.
1 
54 #ifndef ETISS_INCLUDE_PLUGIN_H_
55 #define ETISS_INCLUDE_PLUGIN_H_
56 
57 #include <sstream>
58 #include <string>
59 
60 #include "etiss/ClassDefs.h"
61 #include "etiss/jit/CPU.h"
62 #include "etiss/jit/System.h"
63 
64 #include "etiss/CodePart.h"
65 
66 namespace etiss
67 {
68 
76 class Plugin : public etiss::ToString
77 {
79  friend class TranslationPlugin;
80  friend class CoroutinePlugin;
81  friend class SystemWrapperPlugin;
82  friend class RegisterDevicePlugin;
83  friend class CPUCore;
84 
85  protected:
86  Plugin(unsigned type = 0);
87 
88  public:
89  virtual ~Plugin();
90 
91  public:
92  static const unsigned INTERRUPTLISTENER = 1 << 0;
93  static const unsigned COROUTINE = 1 << 1;
94  static const unsigned SYSTEMWRAPPER = 1 << 2;
95  static const unsigned REGISTERDEVICE =
96  1 << 3;
97  static const unsigned TRANSLATION =
98  1 << 4;
99  public:
104  inline unsigned getType() { return type_; }
121 
130  inline std::string getPluginName() const
131  {
132  if (name_.length() <= 0)
133  {
134  std::stringstream ss;
135  bool fe = true;
136  ss << _getPluginName();
137  ss << "{";
138  if (type_ & INTERRUPTLISTENER)
139  {
140  ss << (fe ? "" : ",") << "INTERRUPTLISTENER";
141  fe = false;
142  }
143  if (type_ & COROUTINE)
144  {
145  ss << (fe ? "" : ",") << "COROUTINE";
146  fe = false;
147  }
148  if (type_ & SYSTEMWRAPPER)
149  {
150  ss << (fe ? "" : ",") << "SYSTEMWRAPPER";
151  fe = false;
152  }
153  if (type_ & REGISTERDEVICE)
154  {
155  ss << (fe ? "" : ",") << "REGISTERDEVICE";
156  fe = false;
157  }
158  if (type_ & TRANSLATION)
159  {
160  ss << (fe ? "" : ",") << "TRANSLATION";
161  fe = false;
162  }
163  ss << "}";
164  name_ = ss.str();
165  }
166  return name_;
167  }
168 
175  const std::string &getLastAssignedCoreName() { return lastAssignedCoreName_; }
176 
177  inline std::string toString() const { return getPluginName(); }
178 
179  protected:
180  virtual std::string _getPluginName() const = 0;
181 
182  protected:
188  virtual void init(ETISS_CPU *cpu, ETISS_System *system, CPUArch *arch);
193  virtual void cleanup();
194  ETISS_CPU
198  CPUArch
203 
204  void setCorrespondingCPUCoreName(std::string name) { lastAssignedCoreName_ = name; }
210  virtual inline void addedToCPUCore(etiss::CPUCore *core) {}
215  virtual inline void removedFromCPUCore(etiss::CPUCore *core) {}
216 
217  private:
218  unsigned type_;
219  mutable std::string name_;
227 };
228 
233 class InterruptListenerPlugin : virtual public Plugin
234 {
235  public:
237  virtual ~InterruptListenerPlugin();
242  virtual bool interruptWrite(unsigned bit, bool value) = 0;
243 };
244 
261 class TranslationPlugin : virtual public Plugin
262 {
263  friend class etiss::Translation;
264 
265  public:
267  virtual ~TranslationPlugin();
269  virtual void initInstrSet(etiss::instr::ModedInstructionSet &) const;
273  virtual void initCodeBlock(etiss::CodeBlock &) const;
275  virtual void finalizeCodeBlock(etiss::CodeBlock &) const;
277  virtual void *getPluginHandle();
278 
279  protected:
285  std::string getPointerCode() const;
286 
287  private:
288  std::string pointerCode;
289 };
290 
298 class CoroutinePlugin : virtual public Plugin
299 {
300  public:
301  CoroutinePlugin();
302  virtual ~CoroutinePlugin();
306  virtual etiss::int32 execute() = 0;
311  virtual void executionEnd(int32_t code);
316  virtual bool isActive() { return true; }
317 };
318 
325 class SystemWrapperPlugin : virtual public Plugin
326 {
327  public:
329  virtual ~SystemWrapperPlugin();
334  virtual ETISS_System *wrap(ETISS_CPU *cpu, ETISS_System *system) = 0;
339  virtual ETISS_System *unwrap(ETISS_CPU *cpu, ETISS_System *system) = 0;
340 };
341 
347 class RegisterDevicePlugin : virtual public Plugin
348 {
349  public:
351  virtual ~RegisterDevicePlugin();
356  virtual void changedRegister(const char *name) = 0;
357 };
358 
359 } // namespace etiss
360 
361 #endif
etiss_int32 int32
Definition: 386-GCC.h:81
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:162
CPUCore is responsible for the simulation of a CPU core in ETISS.
Definition: CPUCore.h:113
A list of CodeSets.
Definition: CodePart.h:570
this plugin will be called before a block is executed.
Definition: Plugin.h:299
virtual ~CoroutinePlugin()
Definition: Plugin.cpp:111
virtual void executionEnd(int32_t code)
called when the simulation ends but before any deinitialization is done
Definition: Plugin.cpp:112
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:316
virtual bool interruptWrite(unsigned bit, bool value)=0
gets called whenever an external write to the interrrupt vector takes place
virtual ~InterruptListenerPlugin()
Definition: Plugin.cpp:83
base plugin class that provides access to different plugin functions if present
Definition: Plugin.h:77
CPUCore * plugin_core_
holds a pointer to the associated CPUCore instance.
Definition: Plugin.h:200
void setCorrespondingCPUCoreName(std::string name)
Definition: Plugin.h:204
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:95
InterruptListenerPlugin * tplugin_
Definition: Plugin.h:221
TranslationPlugin * getTranslationPlugin()
Definition: Plugin.h:125
std::string toString() const
Definition: Plugin.h:177
Plugin(unsigned type=0)
Definition: Plugin.cpp:57
static const unsigned COROUTINE
callback after execution of each translated block
Definition: Plugin.h:93
TranslationPlugin * trplugin_
Definition: Plugin.h:225
std::string name_
contains a name that is build from the return value of getPluginName_() + the implemented interfaces ...
Definition: Plugin.h:219
const std::string & getLastAssignedCoreName()
Definition: Plugin.h:175
static const unsigned TRANSLATION
access to translated code during translation phase or when instruction tree is built
Definition: Plugin.h:97
virtual void cleanup()
this function is called after cpu execution loop (etiss::CPUCore::execute) finished.
Definition: Plugin.cpp:75
SystemWrapperPlugin * getSystemWrapperPlugin()
Definition: Plugin.h:116
ETISS_CPU * plugin_cpu_
holds a pointer to the cpu structure. will be set before init call and after cleanup call
Definition: Plugin.h:195
std::string lastAssignedCoreName_
Definition: Plugin.h:226
InterruptListenerPlugin * getInterruptListenerPlugin()
Definition: Plugin.h:108
CoroutinePlugin * getCoroutinePlugin()
Definition: Plugin.h:112
CoroutinePlugin * cplugin_
Definition: Plugin.h:223
ETISS_System * plugin_system_
holds a pointer to the system structure.
Definition: Plugin.h:196
RegisterDevicePlugin * getRegisterDevicePlugin()
Definition: Plugin.h:120
SystemWrapperPlugin * splugin_
Definition: Plugin.h:222
static const unsigned INTERRUPTLISTENER
access to translated code
Definition: Plugin.h:92
virtual void removedFromCPUCore(etiss::CPUCore *core)
called as soon a plugin has been removed from its CPUCore.
Definition: Plugin.h:215
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:74
unsigned type_
Definition: Plugin.h:218
static const unsigned SYSTEMWRAPPER
can wrap/change ETISS_System structure at execution start
Definition: Plugin.h:94
CPUArch * plugin_arch_
holds a pointer to the CPUArch instance. will be set before init call and after cleanup call
Definition: Plugin.h:199
virtual void addedToCPUCore(etiss::CPUCore *core)
called as soon a plugin has been added to its CPUCore.
Definition: Plugin.h:210
std::string getPluginName() const
Definition: Plugin.h:130
unsigned getType()
Definition: Plugin.h:104
virtual ~Plugin()
Definition: Plugin.cpp:72
RegisterDevicePlugin * rplugin_
Definition: Plugin.h:224
RegisterDevicePlugin::changedRegister is called if a supported register has been changed.
Definition: Plugin.h:348
virtual ~RegisterDevicePlugin()
Definition: Plugin.cpp:126
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:326
virtual ~SystemWrapperPlugin()
Definition: Plugin.cpp:119
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.
Marker interface for toString() support.
Definition: Misc.h:137
allows to add code to the translation of instructions
Definition: Plugin.h:262
virtual void initCodeBlock(etiss::CodeBlock &) const
called before instructions are translated for the code block
Definition: Plugin.cpp:93
virtual void finalizeInstrSet(etiss::instr::ModedInstructionSet &) const
called after all instructions have been added to allow last changes
Definition: Plugin.cpp:92
virtual void finalizeCodeBlock(etiss::CodeBlock &) const
called after all instructions have been translated for the code block
Definition: Plugin.cpp:94
virtual void initInstrSet(etiss::instr::ModedInstructionSet &) const
called to add instructions to the instruction set
Definition: Plugin.cpp:91
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:101
std::string pointerCode
Definition: Plugin.h:288
virtual void * getPluginHandle()
called to get the handle that is available in translated code via getPoinerCode()....
Definition: Plugin.cpp:96
virtual ~TranslationPlugin()
Definition: Plugin.cpp:90
holds etiss::instr::VariableInstructionSet instances for different modes.
Definition: Instruction.h:562
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
basic cpu state structure needed for execution of any cpu architecture.
Definition: CPU.h:89
memory access and time synchronization functions.
Definition: System.h:78