ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
etiss::CPUCore Class Reference

CPUCore is responsible for the simulation of a CPU core in ETISS. More...

#include <CPUCore.h>

Inheritance diagram for etiss::CPUCore:
Inheritance graph
[legend]
Collaboration diagram for etiss::CPUCore:
Collaboration graph
[legend]

Classes

class  InterruptVectorWrapper
 

Public Member Functions

 ~CPUCore ()
 
void reset (etiss::uint64 *startindex)
 Reset the CPU state. More...
 
ETISS_CPUgetState ()
 Get the CPU state structure containing instruction pointer, frequency, etc. More...
 
virtual std::shared_ptr< VirtualStructgetStruct ()
 Get the virtual structure of this CPUCore instance. More...
 
virtual std::shared_ptr< etiss::mm::MMUgetMMU ()
 Get the Memory Management Unit(MMU) of this CPUCore instance. More...
 
etiss::InterruptVectorgetInterruptVector ()
 Get the interrupt vector of simulated CPU. More...
 
etiss::InterruptEnablegetInterruptEnable ()
 
std::shared_ptr< etiss::CPUArchgetArch ()
 Get the CPU architecture. More...
 
void set (std::shared_ptr< etiss::JIT > jit)
 Set the JIT plug-in used for execution. More...
 
void setTimer (bool on)
 Enable or disable the timer of the CPU. More...
 
void addPlugin (std::shared_ptr< etiss::Plugin > plugin)
 Adds a plug-in to the core simulator. More...
 
void removePlugin (std::shared_ptr< etiss::Plugin > plugin)
 Remove a plug-in from the core simulator. More...
 
void removePlugins ()
 Remove all plug-ins from the core simulator. More...
 
void setBlockChainCount (unsigned bcc)
 Set the number of blocks jumps in between the coroutines are not executed. More...
 
etiss::int32 execute (ETISS_System &system)
 Start the simulation of the CPU core for the system model. More...
 
etiss::int32 execute (etiss::System &system)
 Start the simulation of the CPU core for the system model. More...
 
const std::string & getName ()
 Get the name of the CPUCore instance. More...
 
const intgetID ()
 Get the ID of the CPUCore instance. More...
 
std::string getJITName ()
 Get the name of the JIT plug-in used by the CPUCore instance. More...
 
std::shared_ptr< etiss::JITgetJIT ()
 Get a reference to the JIT plugin. More...
 
const std::string & toString () const
 Get a string representation of the object. More...
 
std::shared_ptr< PlugingetPlugin (std::string name)
 returns the plugin with the given name. More...
 
std::list< std::shared_ptr< Plugin > > const * getPlugins ()
 returns the list of all plugins. More...
 
- Public Member Functions inherited from etiss::VirtualStructSupport
virtual ~VirtualStructSupport ()
 
- Public Member Functions inherited from etiss::ToString
 ToString ()
 
virtual ~ToString ()
 

Static Public Member Functions

static std::shared_ptr< CPUCorecreate (std::string archname, std::string instancename="", std::map< std::string, std::string > archoptions=std::map< std::string, std::string >())
 Create a CPUCore instance. More...
 
static int getNextID ()
 
static std::list< std::string > list ()
 returns a list of currently present CPU cores More...
 

Public Attributes

uint64_t instrcounter
 

Private Member Functions

 CPUCore (std::shared_ptr< etiss::CPUArch > arch)
 Private constructor of CPUCore. More...
 

Private Attributes

std::shared_ptr< etiss::CPUArcharch_
 
std::string name_
 cpu architecture of this cpu core. may never be 0 or changed More...
 
const int id_
 name of the cpu core More...
 
ETISS_CPUcpu_
 ID of the cpu core. More...
 
std::shared_ptr< etiss::VirtualStructvcpu_
 cpu state structure allocated by arch_ More...
 
etiss::InterruptVectorintvector_
 
InterruptVectorWrapperintwrapper_
 cpu interrupt vector derived from cpu_ and allocated by arch_ More...
 
etiss::InterruptEnableintenable_
 wrapped interrupt vector to allow interrupt listening More...
 
bool timer_enabled_
 
std::shared_ptr< etiss::JITjit_
 if true the a timer plugin allocated by arch_ will be added in CPUCore::execute More...
 
std::mutex mu_
 JIT instance to use. may be 0 (etiss::getDefaultJIT() will be used in that case) More...
 
std::list< std::shared_ptr< Plugin > > plugins
 mutex to lock the configuration of this cpu core. More...
 
unsigned bcc_
 list of all plugins More...
 
unsigned blockCounter
 
unsigned exception_skip_count_
 
int blockCacheLimit_
 
bool mmu_enabled_
 TODO: possibility to limit the cache size. More...
 
std::shared_ptr< etiss::mm::MMUmmu_
 

Static Private Attributes

static std::mutex instances_mu_
 this field is always present to maintain API compatibility but it is only used if ETISS_CPUCORE_DBG_APPROXIMATE_INSTRUCTION_COUNTER is set to 1 More...
 
static std::list< std::weak_ptr< CPUCore > > instances_
 mutext for access to a list of cpu core instances More...
 

Friends

class CPUArchRegListenerInterface
 
class InterruptVectorWrapper
 

Detailed Description

CPUCore is responsible for the simulation of a CPU core in ETISS.

CPUCore is responsible for the simulation of a CPU core in ETISS. An instance of CPUCore is always tied to a single CPU architecture. If plug-ins should be active during the simulation they need to be added to the CPUCore instance. Before the simulation can be start a JIT compilier must be present if the default JIT plug-in should not be used (etiss::getDefaultJIT()). A JIT plug-in must be specified with CPUCore::set(). To start the simulation of a system model with a CPUCore instance call CPUCore::execute().

etiss::Initializer initialzer(); // initialize ETISS
{ // ensure that the object using ETISS are deleted before the shutdown of ETISS
// create CPU simulator instance for the or1k architecture
std::shared_ptr<etiss:CPUCore> cpu = etiss::CPUCore::create("or1k", "core0");
cpu.set(etiss::getJIT("GCCJIT"); // set JIT plug-in to be used for the simulation
cpu.addPlugin(etiss::getPlugin("PrintInstruction")); // add a plug-in to the simulation
MySystemModel system(); // instance of the system model to be simulated
cpu.execute(system); // run the simulation
}
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
Wrapper for the initialize and shutdown of the ETISS environment.
Definition: ETISS.h:253
std::shared_ptr< Plugin > getPlugin(std::string name, std::map< std::string, std::string > options=std::map< std::string, std::string >())
Get a present Plugin plug-in by name.
Definition: ETISS.cpp:241
std::shared_ptr< JIT > getJIT(std::string name, std::map< std::string, std::string > options=std::map< std::string, std::string >())
Get a present JIT plug-in by name.
Definition: ETISS.cpp:153
See also
ETISS_System
etiss::System

Definition at line 112 of file CPUCore.h.

Constructor & Destructor Documentation

◆ CPUCore()

CPUCore::CPUCore ( std::shared_ptr< etiss::CPUArch arch)
private

Private constructor of CPUCore.

To create a new instance of CPUCore use the CPUCore::create().

Parameters
nameThe name of the CPUCore instance.
archPointer to the CPU architecture used by the CPU core simulator.

Definition at line 138 of file CPUCore.cpp.

References arch_, bcc_, blockCacheLimit_, blockCounter, cpu_, exception_skip_count_, instrcounter, ETISS_CPU::instructionPointer, InterruptVectorWrapper, intvector_, intwrapper_, etiss::VirtualStruct::Field::P, etiss::VirtualStruct::Field::R, timer_enabled_, uint64_t, v, vcpu_, and etiss::VirtualStruct::Field::W.

Referenced by create().

Here is the caller graph for this function:

◆ ~CPUCore()

CPUCore::~CPUCore ( )

Definition at line 293 of file CPUCore.cpp.

References arch_, cpu_, intvector_, intwrapper_, and vcpu_.

Member Function Documentation

◆ addPlugin()

void CPUCore::addPlugin ( std::shared_ptr< etiss::Plugin plugin)

Adds a plug-in to the core simulator.

See the different plug-in classes, for information on how the plug-in influences the simulation.

Attention
The same plug-in may not be added multiple times.
See also
etiss::TransTranslatorPlugin
etiss::CoroutinePlugin
etiss::SystemWrapperPlugin
Parameters
pluginPointer to the plug-in that shall be added.

Definition at line 190 of file CPUCore.cpp.

References getName(), etiss::log(), mu_, plugins, and etiss::WARNING.

Here is the call graph for this function:

◆ create()

std::shared_ptr< CPUCore > CPUCore::create ( std::string  archname,
std::string  instancename = "",
std::map< std::string, std::string >  archoptions = std::map<std::string, std::string>() 
)
static

Create a CPUCore instance.

This is the factory method to create a new CPUCore instance for a specific CPU architecture.

Parameters
archnameThe name of a CPUArch plug-in. This plug-in must be present in ETISS in order to create the CPUCore instance.
instancenameA descriptive name for the new instance.
archoptionsA key value map with options for the CPUArch plug-in.
Returns
A pointer to the new instance or 0, if the given architecture is not present
Parameters
archoptionsobsolet: now defined by ID - "core[ID]"

Definition at line 249 of file CPUCore.cpp.

References CPUCore(), etiss::FATALERROR, etiss::forceInitialization(), etiss::getCPUArch(), instances_, instances_mu_, and etiss::log().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute() [1/2]

etiss::int32 etiss::CPUCore::execute ( etiss::System system)
inline

Start the simulation of the CPU core for the system model.

This method works the same as execute(ETISS_System & system), but uses the etiss::System interface to access the model.

See also
execute(ETISS_System & system)
Returns
A return code as result of the simulation (ReturnCode.h)

Definition at line 287 of file CPUCore.h.

References execute(), and etiss::wrap().

Here is the call graph for this function:

◆ execute() [2/2]

etiss::int32 CPUCore::execute ( ETISS_System system)

Start the simulation of the CPU core for the system model.

This method starts the simulation of the CPU core for the provided system model. It uses the C-structure interface to access the system model. This method is (like any other methods of this class) thread-safe. However if any method of this class including this one is called while this method is running, it will block until this method is finished returns.

Returns
A return code as result of the simulation (ReturnCode.h)

Definition at line 503 of file CPUCore.cpp.

References ETISS_CPU::_etiss_private_handle_, arch_, bcc_, c, etiss::cfg(), clock(), cpu_, ETISS_CPU::cpuCycleTime_ps, ETISS_CPU::cpuTime_ps, ETISS_CPU::cycles, double, etiss::BlockLink::end, etiss::ERROR, etiss_CPUCore_handleException(), ETISS_MAX_RESOURCES, ETISS_System_isvalid(), etiss::BlockLink::execBlock, etiss::FATALERROR, float, etiss::Configuration::get(), etiss::Translation::getBlockFast(), etiss::Plugin::getPluginName(), ETISS_System::handle, etiss::INFO, etiss::Translation::init(), instrcounter, ETISS_CPU::instructionPointer, etiss::Configuration::isSet(), jit_, likely, etiss::log(), max(), mmu_, mmu_enabled_, mu_, name_, etiss::mm::NOERROR, plugins, ETISS_CPU::resources, ETISS_CPU::resourceUsages, ETISS_System::syncTime, timer_enabled_, etiss::toString(), uint64_t, unlikely, vcpu_, verifyJITPragmaPack(), verifyJITSizeOf(), etiss::WARNING, and etiss::mm::X_ACCESS.

Referenced by execute().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getArch()

std::shared_ptr<etiss::CPUArch> etiss::CPUCore::getArch ( )
inline

Get the CPU architecture.

Returns
A pointer to the CPU architecture.

Definition at line 197 of file CPUCore.h.

References arch_.

◆ getID()

const int& etiss::CPUCore::getID ( )
inline

Get the ID of the CPUCore instance.

Returns
The ID string of the instance.

Definition at line 308 of file CPUCore.h.

References id_.

◆ getInterruptEnable()

etiss::InterruptEnable* etiss::CPUCore::getInterruptEnable ( )
inline

Definition at line 190 of file CPUCore.h.

References intenable_.

◆ getInterruptVector()

etiss::InterruptVector* etiss::CPUCore::getInterruptVector ( )
inline

Get the interrupt vector of simulated CPU.

Returns
A pointer to the interrupt vector of the simulated CPU.

Definition at line 188 of file CPUCore.h.

References intwrapper_.

◆ getJIT()

std::shared_ptr<etiss::JIT> etiss::CPUCore::getJIT ( )
inline

Get a reference to the JIT plugin.

Definition at line 331 of file CPUCore.h.

References jit_.

◆ getJITName()

std::string etiss::CPUCore::getJITName ( )
inline

Get the name of the JIT plug-in used by the CPUCore instance.

Returns
Name string of the JIT plug-in;

Definition at line 315 of file CPUCore.h.

References jit_.

◆ getMMU()

virtual std::shared_ptr<etiss::mm::MMU> etiss::CPUCore::getMMU ( )
inlinevirtual

Get the Memory Management Unit(MMU) of this CPUCore instance.

MMU is responsible to translate virtual address to physical address, which is essential to support multi-taking operationg systems, such as Linux

Returns
A shared pointer to the MMU

Definition at line 181 of file CPUCore.h.

References mmu_.

Referenced by ETISS_SIGNAL_MMU().

Here is the caller graph for this function:

◆ getName()

const std::string& etiss::CPUCore::getName ( )
inline

Get the name of the CPUCore instance.

Returns
The name string of the instance.

Definition at line 301 of file CPUCore.h.

References name_.

Referenced by addPlugin().

Here is the caller graph for this function:

◆ getNextID()

int CPUCore::getNextID ( )
static

Definition at line 134 of file CPUCore.cpp.

References currID.

Referenced by etiss::CPUArch::CPUArch().

Here is the caller graph for this function:

◆ getPlugin()

std::shared_ptr<Plugin> etiss::CPUCore::getPlugin ( std::string  name)
inline

returns the plugin with the given name.

Definition at line 341 of file CPUCore.h.

References plugins.

◆ getPlugins()

std::list<std::shared_ptr<Plugin> > const* etiss::CPUCore::getPlugins ( )
inline

returns the list of all plugins.

Definition at line 354 of file CPUCore.h.

References plugins.

◆ getState()

ETISS_CPU* etiss::CPUCore::getState ( )
inline

Get the CPU state structure containing instruction pointer, frequency, etc.

Returns
A pointer to the architecture specific cpu state structure

Definition at line 160 of file CPUCore.h.

References cpu_.

◆ getStruct()

virtual std::shared_ptr<VirtualStruct> etiss::CPUCore::getStruct ( )
inlinevirtual

Get the virtual structure of this CPUCore instance.

The virtual structure allows the to access the fields of the CPU structure and sub structures (e.g. plug-ins) used by CPUCore.

Returns
A pointer to the virtual structure.

Implements etiss::VirtualStructSupport.

Definition at line 170 of file CPUCore.h.

References vcpu_.

Referenced by etiss::plugin::InstructionAccurateCallback::call(), etiss::plugin::errorInjection::BlockAccurateHandler::execute(), etiss::plugin::VariableValueLogger::finalizeInstrSet(), etiss::plugin::gdb::Server::handlePacket(), etiss::CPUArchRegListenerInterface::signalChangedRegisterValue(), and etiss::plugin::VariableValueLogger::writeValue().

Here is the caller graph for this function:

◆ list()

std::list< std::string > CPUCore::list ( )
static

returns a list of currently present CPU cores

Definition at line 275 of file CPUCore.cpp.

References instances_, and instances_mu_.

Referenced by etiss::shutdown().

Here is the caller graph for this function:

◆ removePlugin()

void CPUCore::removePlugin ( std::shared_ptr< etiss::Plugin plugin)

Remove a plug-in from the core simulator.

Parameters
pluginPointer to the plug-in that shall be removed.

Definition at line 222 of file CPUCore.cpp.

References mu_, etiss::Plugin::plugin_core_, plugins, and etiss::Plugin::removedFromCPUCore().

Here is the call graph for this function:

◆ removePlugins()

void etiss::CPUCore::removePlugins ( )
inline

Remove all plug-ins from the core simulator.

Definition at line 252 of file CPUCore.h.

References mu_, and plugins.

◆ reset()

void etiss::CPUCore::reset ( etiss::uint64 startindex)
inline

Reset the CPU state.

Note
startindex != start address
Todo:
Add explanation of start index.

Definition at line 153 of file CPUCore.h.

References arch_, and cpu_.

◆ set()

void etiss::CPUCore::set ( std::shared_ptr< etiss::JIT jit)
inline

Set the JIT plug-in used for execution.

If no JIT plug-in is specified then the first loaded JIT plug-in is used.

See also
etiss::loadJIT
etiss::getJIT
etiss::listJIT
Parameters
jitA pointer to the JIT plug-in, that should be used.

Definition at line 211 of file CPUCore.h.

References jit_.

◆ setBlockChainCount()

void etiss::CPUCore::setBlockChainCount ( unsigned  bcc)
inline

Set the number of blocks jumps in between the coroutines are not executed.

Definition at line 262 of file CPUCore.h.

References bcc_.

◆ setTimer()

void etiss::CPUCore::setTimer ( bool  on)
inline

Enable or disable the timer of the CPU.

Note
Has no effect if the architecture does not support a timer.
Parameters
ontrue to enable the timer / false to disable the timer

Definition at line 220 of file CPUCore.h.

References mu_, and timer_enabled_.

◆ toString()

const std::string& etiss::CPUCore::toString ( ) const
inline

Get a string representation of the object.

Definition at line 336 of file CPUCore.h.

References name_.

Friends And Related Function Documentation

◆ CPUArchRegListenerInterface

friend class CPUArchRegListenerInterface
friend

Definition at line 114 of file CPUCore.h.

◆ InterruptVectorWrapper

friend class InterruptVectorWrapper
friend

Definition at line 115 of file CPUCore.h.

Referenced by CPUCore().

Member Data Documentation

◆ arch_

std::shared_ptr<etiss::CPUArch> etiss::CPUCore::arch_
private

Definition at line 385 of file CPUCore.h.

Referenced by CPUCore(), execute(), getArch(), reset(), and ~CPUCore().

◆ bcc_

unsigned etiss::CPUCore::bcc_
private

list of all plugins

Definition at line 399 of file CPUCore.h.

Referenced by CPUCore(), execute(), and setBlockChainCount().

◆ blockCacheLimit_

int etiss::CPUCore::blockCacheLimit_
private

Definition at line 402 of file CPUCore.h.

Referenced by CPUCore().

◆ blockCounter

unsigned etiss::CPUCore::blockCounter
private

Definition at line 400 of file CPUCore.h.

Referenced by CPUCore().

◆ cpu_

ETISS_CPU* etiss::CPUCore::cpu_
private

ID of the cpu core.

Definition at line 388 of file CPUCore.h.

Referenced by CPUCore(), execute(), getState(), reset(), and ~CPUCore().

◆ exception_skip_count_

unsigned etiss::CPUCore::exception_skip_count_
private

Definition at line 401 of file CPUCore.h.

Referenced by CPUCore().

◆ id_

const int etiss::CPUCore::id_
private

name of the cpu core

Definition at line 387 of file CPUCore.h.

Referenced by getID().

◆ instances_

std::list< std::weak_ptr< CPUCore > > CPUCore::instances_
staticprivate

mutext for access to a list of cpu core instances

Definition at line 413 of file CPUCore.h.

Referenced by create(), and list().

◆ instances_mu_

std::mutex CPUCore::instances_mu_
staticprivate

this field is always present to maintain API compatibility but it is only used if ETISS_CPUCORE_DBG_APPROXIMATE_INSTRUCTION_COUNTER is set to 1

Definition at line 411 of file CPUCore.h.

Referenced by create(), and list().

◆ instrcounter

uint64_t etiss::CPUCore::instrcounter

Definition at line 407 of file CPUCore.h.

Referenced by CPUCore(), and execute().

◆ intenable_

etiss::InterruptEnable* etiss::CPUCore::intenable_
private

wrapped interrupt vector to allow interrupt listening

Definition at line 392 of file CPUCore.h.

Referenced by getInterruptEnable().

◆ intvector_

etiss::InterruptVector* etiss::CPUCore::intvector_
private

Definition at line 390 of file CPUCore.h.

Referenced by CPUCore(), and ~CPUCore().

◆ intwrapper_

InterruptVectorWrapper* etiss::CPUCore::intwrapper_
private

cpu interrupt vector derived from cpu_ and allocated by arch_

Definition at line 391 of file CPUCore.h.

Referenced by CPUCore(), getInterruptVector(), and ~CPUCore().

◆ jit_

std::shared_ptr<etiss::JIT> etiss::CPUCore::jit_
private

if true the a timer plugin allocated by arch_ will be added in CPUCore::execute

Definition at line 395 of file CPUCore.h.

Referenced by execute(), getJIT(), getJITName(), and set().

◆ mmu_

std::shared_ptr<etiss::mm::MMU> etiss::CPUCore::mmu_
private

Definition at line 404 of file CPUCore.h.

Referenced by execute(), and getMMU().

◆ mmu_enabled_

bool etiss::CPUCore::mmu_enabled_
private

TODO: possibility to limit the cache size.

Definition at line 403 of file CPUCore.h.

Referenced by execute().

◆ mu_

std::mutex etiss::CPUCore::mu_
private

JIT instance to use. may be 0 (etiss::getDefaultJIT() will be used in that case)

Definition at line 396 of file CPUCore.h.

Referenced by addPlugin(), execute(), removePlugin(), removePlugins(), and setTimer().

◆ name_

std::string etiss::CPUCore::name_
private

cpu architecture of this cpu core. may never be 0 or changed

Definition at line 386 of file CPUCore.h.

Referenced by execute(), getName(), and toString().

◆ plugins

std::list<std::shared_ptr<Plugin> > etiss::CPUCore::plugins
private

mutex to lock the configuration of this cpu core.

etiss::CPUCore::execution holds this lock during execution

Definition at line 398 of file CPUCore.h.

Referenced by addPlugin(), execute(), getPlugin(), getPlugins(), removePlugin(), and removePlugins().

◆ timer_enabled_

bool etiss::CPUCore::timer_enabled_
private

Definition at line 393 of file CPUCore.h.

Referenced by CPUCore(), execute(), and setTimer().

◆ vcpu_

std::shared_ptr<etiss::VirtualStruct> etiss::CPUCore::vcpu_
private

cpu state structure allocated by arch_

Definition at line 389 of file CPUCore.h.

Referenced by CPUCore(), execute(), getStruct(), and ~CPUCore().


The documentation for this class was generated from the following files: