ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
CPUCore.h
Go to the documentation of this file.
1 
51 #ifndef ETISS_INCLUDE_CPUCORE_H_
52 #define ETISS_INCLUDE_CPUCORE_H_
53 
54 #include "etiss/ClassDefs.h"
55 #include "etiss/Misc.h"
56 #include "etiss/LibraryInterface.h"
57 #include "etiss/JIT.h"
58 #include "etiss/CPUArch.h"
59 #include "etiss/Translation.h"
60 #include "etiss/System.h"
61 #include "etiss/InterruptHandler.h"
62 #include "etiss/InterruptEnable.h"
63 #include "etiss/Plugin.h"
64 #include "etiss/jit/ReturnCode.h"
65 #include "etiss/mm/MMU.h"
66 #include "etiss/mm/DMMUWrapper.h"
68 
69 #include <mutex>
70 #include <memory>
71 #include <list>
72 
73 namespace etiss
74 {
75 
76 // change this to enable an approximate instruction counter for processors. the instruction counter can be accessed via
77 // the VirtualStruct of the processor. the field is named "instructionCounter"
78 #define ETISS_CPUCORE_DBG_APPROXIMATE_INSTRUCTION_COUNTER 0
79 
113 {
116 
117  private:
127  CPUCore(std::shared_ptr<etiss::CPUArch> arch);
128 
130  {
131  private:
132  std::list<etiss::InterruptListenerPlugin *> plugins_;
133 
134  public:
137  virtual void setBit(unsigned bit, bool state);
138  virtual bool getBit(unsigned bit) const;
139  virtual unsigned width() const;
140  virtual bool isActive() const;
141  virtual void clear();
142  };
143 
144  public:
145  ~CPUCore();
153  inline void reset(etiss::uint64 *startindex) { arch_->resetCPU(cpu_, startindex); }
154 
160  inline ETISS_CPU *getState() { return cpu_; }
161 
170  virtual inline std::shared_ptr<VirtualStruct> getStruct() { return vcpu_; }
171 
181  virtual inline std::shared_ptr<etiss::mm::MMU> getMMU() { return mmu_; }
182 
189 
191 
197  inline std::shared_ptr<etiss::CPUArch> getArch() { return arch_; }
198 
211  inline void set(std::shared_ptr<etiss::JIT> jit) { jit_ = jit; }
212 
220  inline void setTimer(bool on)
221  {
222  std::lock_guard<std::mutex> lock(mu_);
223  timer_enabled_ = on;
224  }
225 
240  void addPlugin(std::shared_ptr<etiss::Plugin> plugin);
241 
247  void removePlugin(std::shared_ptr<etiss::Plugin> plugin);
248 
252  inline void removePlugins()
253  {
254  std::lock_guard<std::mutex> lock(mu_);
255  plugins.clear();
256  }
257 
262  inline void setBlockChainCount(unsigned bcc) { bcc_ = bcc; }
263 
276 
288  {
289  std::shared_ptr<ETISS_System> sys = etiss::wrap(&system);
290  if (sys.get() == 0)
291  return RETURNCODE::GENERALERROR;
292  etiss::uint32 ret = execute(*(sys.get()));
293  return ret;
294  }
295 
301  inline const std::string &getName() { return name_; }
302 
308  inline const int &getID() { return id_; }
309 
315  inline std::string getJITName()
316  {
317  std::shared_ptr<etiss::JIT> jit = jit_;
318  if (jit.get())
319  {
320  return jit->getName();
321  }
322  else
323  {
324  return "";
325  }
326  }
327 
331  inline std::shared_ptr<etiss::JIT> getJIT() { return jit_; }
332 
336  inline const std::string &toString() const { return name_; }
337 
341  inline std::shared_ptr<Plugin> getPlugin(std::string name)
342  {
343  for (auto iter : plugins)
344  {
345  // std::cout << "found plugin: " << iter->_getPluginName();
346  if (iter->_getPluginName() == name)
347  return iter;
348  }
349  return nullptr;
350  };
354  inline std::list<std::shared_ptr<Plugin>> const *getPlugins() { return &plugins; };
355  public:
372  static std::shared_ptr<CPUCore> create(
373  std::string archname,
374  std::string instancename = "",
375  std::map<std::string, std::string> archoptions = std::map<std::string, std::string>());
376 
377  static int getNextID();
378 
382  static std::list<std::string> list();
383 
384  private:
385  std::shared_ptr<etiss::CPUArch> arch_;
386  std::string name_;
387  const int id_;
389  std::shared_ptr<etiss::VirtualStruct> vcpu_;
394  std::shared_ptr<etiss::JIT>
396  std::mutex mu_;
398  std::list<std::shared_ptr<Plugin>> plugins;
399  unsigned bcc_;
400  unsigned blockCounter;
404  std::shared_ptr<etiss::mm::MMU> mmu_;
405 
406  public:
409 
410  private:
411  static std::mutex instances_mu_;
412  static std::list<std::weak_ptr<CPUCore>>
414 };
415 
416 } // namespace etiss
417 
418 #endif
etiss_int32 int32
Definition: 386-GCC.h:81
etiss_uint32 uint32
Definition: 386-GCC.h:80
etiss_uint64 uint64
Definition: 386-GCC.h:82
contains neccesary interfaces for instruction translation.
Wrapper class to wrap aroud data MMU.
interrupt checking and signaling
JIT compiler interface definition.
class for simple library access.
Modeling hardware memory management for virtual memory -> physical memory translation and protection.
general configuration and logging
Internal fault inside MMU and.
plugins for extensions to code translation and instruction execution
static __inline__ uint64_t
Definition: arm_cde.h:31
allows to inform plugins about changes to a register that is present in the cpu structure.
Definition: CPUArch.h:83
virtual void setBit(unsigned bit, bool state)
set the bit of an interrupt line to state (true = raised)
Definition: CPUCore.cpp:87
virtual unsigned width() const
number of interrupt bits
Definition: CPUCore.cpp:114
virtual bool getBit(unsigned bit) const
get the bit of an interrupt line
Definition: CPUCore.cpp:110
std::list< etiss::InterruptListenerPlugin * > plugins_
Definition: CPUCore.h:132
InterruptVectorWrapper(CPUCore &parent)
Definition: CPUCore.cpp:86
virtual void clear()
sets every bit to false
Definition: CPUCore.cpp:122
CPUCore is responsible for the simulation of a CPU core in ETISS.
Definition: CPUCore.h:113
const int & getID()
Get the ID of the CPUCore instance.
Definition: CPUCore.h:308
CPUCore(std::shared_ptr< etiss::CPUArch > arch)
Private constructor of CPUCore.
Definition: CPUCore.cpp:138
std::shared_ptr< etiss::mm::MMU > mmu_
Definition: CPUCore.h:404
void removePlugins()
Remove all plug-ins from the core simulator.
Definition: CPUCore.h:252
std::mutex mu_
JIT instance to use. may be 0 (etiss::getDefaultJIT() will be used in that case)
Definition: CPUCore.h:396
const int id_
name of the cpu core
Definition: CPUCore.h:387
std::list< std::shared_ptr< Plugin > > const * getPlugins()
returns the list of all plugins.
Definition: CPUCore.h:354
void setBlockChainCount(unsigned bcc)
Set the number of blocks jumps in between the coroutines are not executed.
Definition: CPUCore.h:262
etiss::InterruptVector * intvector_
Definition: CPUCore.h:390
etiss::int32 execute(etiss::System &system)
Start the simulation of the CPU core for the system model.
Definition: CPUCore.h:287
uint64_t instrcounter
Definition: CPUCore.h:407
std::list< std::shared_ptr< Plugin > > plugins
mutex to lock the configuration of this cpu core.
Definition: CPUCore.h:398
etiss::InterruptEnable * getInterruptEnable()
Definition: CPUCore.h:190
virtual std::shared_ptr< etiss::mm::MMU > getMMU()
Get the Memory Management Unit(MMU) of this CPUCore instance.
Definition: CPUCore.h:181
unsigned exception_skip_count_
Definition: CPUCore.h:401
etiss::int32 execute(ETISS_System &system)
Start the simulation of the CPU core for the system model.
Definition: CPUCore.cpp:503
static std::mutex instances_mu_
this field is always present to maintain API compatibility but it is only used if ETISS_CPUCORE_DBG_A...
Definition: CPUCore.h:411
bool mmu_enabled_
TODO: possibility to limit the cache size.
Definition: CPUCore.h:403
std::shared_ptr< etiss::JIT > jit_
if true the a timer plugin allocated by arch_ will be added in CPUCore::execute
Definition: CPUCore.h:395
static std::list< std::string > list()
returns a list of currently present CPU cores
Definition: CPUCore.cpp:275
std::shared_ptr< etiss::CPUArch > arch_
Definition: CPUCore.h:385
std::string getJITName()
Get the name of the JIT plug-in used by the CPUCore instance.
Definition: CPUCore.h:315
std::shared_ptr< etiss::CPUArch > getArch()
Get the CPU architecture.
Definition: CPUCore.h:197
InterruptVectorWrapper * intwrapper_
cpu interrupt vector derived from cpu_ and allocated by arch_
Definition: CPUCore.h:391
static std::shared_ptr< CPUCore > create(std::string archname, std::string instancename="", std::map< std::string, std::string > archoptions=std::map< std::string, std::string >())
Create a CPUCore instance.
Definition: CPUCore.cpp:249
std::shared_ptr< etiss::JIT > getJIT()
Get a reference to the JIT plugin.
Definition: CPUCore.h:331
unsigned bcc_
list of all plugins
Definition: CPUCore.h:399
static int getNextID()
Definition: CPUCore.cpp:134
const std::string & toString() const
Get a string representation of the object.
Definition: CPUCore.h:336
std::string name_
cpu architecture of this cpu core. may never be 0 or changed
Definition: CPUCore.h:386
ETISS_CPU * cpu_
ID of the cpu core.
Definition: CPUCore.h:388
void addPlugin(std::shared_ptr< etiss::Plugin > plugin)
Adds a plug-in to the core simulator.
Definition: CPUCore.cpp:190
void set(std::shared_ptr< etiss::JIT > jit)
Set the JIT plug-in used for execution.
Definition: CPUCore.h:211
ETISS_CPU * getState()
Get the CPU state structure containing instruction pointer, frequency, etc.
Definition: CPUCore.h:160
std::shared_ptr< etiss::VirtualStruct > vcpu_
cpu state structure allocated by arch_
Definition: CPUCore.h:389
static std::list< std::weak_ptr< CPUCore > > instances_
mutext for access to a list of cpu core instances
Definition: CPUCore.h:413
void removePlugin(std::shared_ptr< etiss::Plugin > plugin)
Remove a plug-in from the core simulator.
Definition: CPUCore.cpp:222
std::shared_ptr< Plugin > getPlugin(std::string name)
returns the plugin with the given name.
Definition: CPUCore.h:341
virtual std::shared_ptr< VirtualStruct > getStruct()
Get the virtual structure of this CPUCore instance.
Definition: CPUCore.h:170
unsigned blockCounter
Definition: CPUCore.h:400
int blockCacheLimit_
Definition: CPUCore.h:402
const std::string & getName()
Get the name of the CPUCore instance.
Definition: CPUCore.h:301
etiss::InterruptEnable * intenable_
wrapped interrupt vector to allow interrupt listening
Definition: CPUCore.h:392
bool timer_enabled_
Definition: CPUCore.h:393
void setTimer(bool on)
Enable or disable the timer of the CPU.
Definition: CPUCore.h:220
etiss::InterruptVector * getInterruptVector()
Get the interrupt vector of simulated CPU.
Definition: CPUCore.h:188
void reset(etiss::uint64 *startindex)
Reset the CPU state.
Definition: CPUCore.h:153
interface to set interrupt bits
System Interface for the basic system IO operations and time synchronization.
Definition: System.h:77
Marker interface for toString() support.
Definition: Misc.h:137
conatins a convinience class that can be wrapped as a ETISS_System structure
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
std::shared_ptr< ETISS_System > wrap(etiss::System *sys)
wraps a etiss::System in a ETISS_System structure.
Definition: System.cpp:94
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