ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
CPUCore.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.
13#ifndef ETISS_INCLUDE_CPUCORE_H_
14#define ETISS_INCLUDE_CPUCORE_H_
15
16#include "etiss/Misc.h"
18#include "etiss/VirtualStruct.h"
19
20#include <mutex>
21#include <memory>
22#include <list>
23
24namespace etiss
25{
26
27// change this to enable an approximate instruction counter for processors. the instruction counter can be accessed via
28// the VirtualStruct of the processor. the field is named "instructionCounter"
29#define ETISS_CPUCORE_DBG_APPROXIMATE_INSTRUCTION_COUNTER 0
30
64{
67
68 protected:
78 CPUCore(std::shared_ptr<etiss::CPUArch> arch, std::string const &name);
79 CPUCore(std::shared_ptr<etiss::CPUArch> arch);
80
82 {
83 private:
84 std::list<etiss::InterruptListenerPlugin *> plugins_;
85
86 public:
89 virtual void setBit(unsigned bit, bool state);
90 virtual bool getBit(unsigned bit) const;
91 virtual unsigned width() const;
92 virtual bool isActive() const;
93 virtual void clear();
94 };
95
96 public:
97 ~CPUCore();
105 void reset(etiss::uint64 *startindex);
106
112 inline ETISS_CPU *getState() { return cpu_; }
113
122 virtual inline std::shared_ptr<VirtualStruct> getStruct() { return vcpu_; }
123
133 virtual inline std::shared_ptr<etiss::mm::MMU> getMMU() { return mmu_; }
134
141
143
149 inline std::shared_ptr<etiss::CPUArch> getArch() { return arch_; }
150
163 inline void set(std::shared_ptr<etiss::JIT> jit) { jit_ = jit; }
164
172 inline void setTimer(bool on)
173 {
174 std::lock_guard<std::mutex> lock(mu_);
175 timer_enabled_ = on;
176 }
177
192 void addPlugin(std::shared_ptr<etiss::Plugin> plugin);
193
199 void removePlugin(std::shared_ptr<etiss::Plugin> plugin);
200
204 inline void removePlugins()
205 {
206 std::lock_guard<std::mutex> lock(mu_);
207 plugins.clear();
208 }
209
214 inline void setBlockChainCount(unsigned bcc) { bcc_ = bcc; }
215
227 etiss::int32 execute(ETISS_System &system);
228
239 etiss::int32 execute(etiss::System &system);
240
246 inline const std::string &getName() { return name_; }
247
253 inline const int &getID() { return id_; }
254
260 std::string getJITName();
261
265 inline std::shared_ptr<etiss::JIT> getJIT() { return jit_; }
266
270 inline const std::string &toString() const { return name_; }
271
275 std::shared_ptr<Plugin> getPlugin(std::string name);
279 inline std::list<std::shared_ptr<Plugin>> const *getPlugins() { return &plugins; };
280
281 public:
298 static std::shared_ptr<CPUCore> create(
299 std::string archname,
300 std::string instancename = "",
301 std::map<std::string, std::string> archoptions = std::map<std::string, std::string>());
302
303 static int getNextID();
304
308 static std::list<std::string> list();
309
310 private:
311 std::shared_ptr<etiss::CPUArch> arch_;
312 std::string name_;
313 const int id_;
315 std::shared_ptr<etiss::VirtualStruct> vcpu_;
320 std::shared_ptr<etiss::JIT>
322 std::mutex mu_;
324 std::list<std::shared_ptr<Plugin>> plugins;
325 unsigned bcc_;
326 unsigned blockCounter;
330 std::shared_ptr<etiss::mm::MMU> mmu_;
331
332 public:
335
336 private:
337 static std::mutex instances_mu_;
338 static std::list<std::weak_ptr<CPUCore>>
340};
341
342} // namespace etiss
343
344#endif
defines a general interface to set interrupt bits
general configuration and logging
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:37
virtual void setBit(unsigned bit, bool state)
set the bit of an interrupt line to state (true = raised)
Definition CPUCore.cpp:71
virtual unsigned width() const
number of interrupt bits
Definition CPUCore.cpp:98
virtual bool getBit(unsigned bit) const
get the bit of an interrupt line
Definition CPUCore.cpp:94
std::list< etiss::InterruptListenerPlugin * > plugins_
Definition CPUCore.h:84
virtual void clear()
sets every bit to false
Definition CPUCore.cpp:106
CPUCore is responsible for the simulation of a CPU core in ETISS.
Definition CPUCore.h:64
std::shared_ptr< etiss::mm::MMU > mmu_
Definition CPUCore.h:330
void removePlugins()
Remove all plug-ins from the core simulator.
Definition CPUCore.h:204
ETISS_CPU * getState()
Get the CPU state structure containing instruction pointer, frequency, etc.
Definition CPUCore.h:112
std::mutex mu_
JIT instance to use. may be 0 (etiss::getDefaultJIT() will be used in that case)
Definition CPUCore.h:322
const int & getID()
Get the ID of the CPUCore instance.
Definition CPUCore.h:253
const int id_
name of the cpu core
Definition CPUCore.h:313
const std::string & toString() const
Get a string representation of the object.
Definition CPUCore.h:270
std::string getJITName()
Get the name of the JIT plug-in used by the CPUCore instance.
Definition CPUCore.cpp:954
void setBlockChainCount(unsigned bcc)
Set the number of blocks jumps in between the coroutines are not executed.
Definition CPUCore.h:214
etiss::InterruptVector * intvector_
Definition CPUCore.h:316
uint64_t instrcounter
Definition CPUCore.h:333
std::list< std::shared_ptr< Plugin > > plugins
mutex to lock the configuration of this cpu core.
Definition CPUCore.h:324
unsigned exception_skip_count_
Definition CPUCore.h:327
etiss::int32 execute(ETISS_System &system)
Start the simulation of the CPU core for the system model.
Definition CPUCore.cpp:495
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:337
std::list< std::shared_ptr< Plugin > > const * getPlugins()
returns the list of all plugins.
Definition CPUCore.h:279
bool mmu_enabled_
TODO: possibility to limit the cache size.
Definition CPUCore.h:329
std::shared_ptr< etiss::JIT > jit_
if true the a timer plugin allocated by arch_ will be added in CPUCore::execute
Definition CPUCore.h:321
static std::list< std::string > list()
returns a list of currently present CPU cores
Definition CPUCore.cpp:264
virtual std::shared_ptr< etiss::mm::MMU > getMMU()
Get the Memory Management Unit(MMU) of this CPUCore instance.
Definition CPUCore.h:133
std::shared_ptr< etiss::CPUArch > arch_
Definition CPUCore.h:311
InterruptVectorWrapper * intwrapper_
cpu interrupt vector derived from cpu_ and allocated by arch_
Definition CPUCore.h:317
void reset(etiss::uint64 *startindex)
Reset the CPU state.
Definition CPUCore.cpp:967
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:234
unsigned bcc_
list of all plugins
Definition CPUCore.h:325
static int getNextID()
Definition CPUCore.cpp:118
std::shared_ptr< etiss::JIT > getJIT()
Get a reference to the JIT plugin.
Definition CPUCore.h:265
std::string name_
cpu architecture of this cpu core. may never be 0 or changed
Definition CPUCore.h:312
ETISS_CPU * cpu_
ID of the cpu core.
Definition CPUCore.h:314
void addPlugin(std::shared_ptr< etiss::Plugin > plugin)
Adds a plug-in to the core simulator.
Definition CPUCore.cpp:175
void set(std::shared_ptr< etiss::JIT > jit)
Set the JIT plug-in used for execution.
Definition CPUCore.h:163
std::shared_ptr< Plugin > getPlugin(std::string name)
returns the plugin with the given name.
Definition CPUCore.cpp:972
std::shared_ptr< etiss::CPUArch > getArch()
Get the CPU architecture.
Definition CPUCore.h:149
std::shared_ptr< etiss::VirtualStruct > vcpu_
cpu state structure allocated by arch_
Definition CPUCore.h:315
static std::list< std::weak_ptr< CPUCore > > instances_
mutext for access to a list of cpu core instances
Definition CPUCore.h:339
void removePlugin(std::shared_ptr< etiss::Plugin > plugin)
Remove a plug-in from the core simulator.
Definition CPUCore.cpp:207
virtual std::shared_ptr< VirtualStruct > getStruct()
Get the virtual structure of this CPUCore instance.
Definition CPUCore.h:122
etiss::InterruptEnable * getInterruptEnable()
Definition CPUCore.h:142
const std::string & getName()
Get the name of the CPUCore instance.
Definition CPUCore.h:246
etiss::InterruptVector * getInterruptVector()
Get the interrupt vector of simulated CPU.
Definition CPUCore.h:140
unsigned blockCounter
Definition CPUCore.h:326
int blockCacheLimit_
Definition CPUCore.h:328
etiss::InterruptEnable * intenable_
wrapped interrupt vector to allow interrupt listening
Definition CPUCore.h:318
bool timer_enabled_
Definition CPUCore.h:319
void setTimer(bool on)
Enable or disable the timer of the CPU.
Definition CPUCore.h:172
interface to set interrupt bits
System Interface for the basic system IO operations and time synchronization.
Definition System.h:38
Marker interface for toString() support.
Definition Misc.h:95
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