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

abstract representation of an module of a simulation which could be a embedded device of the cpu of an embedded device. More...

#include <VirtualStruct.h>

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

Classes

class  Field
 a Field instance represents e.g. More...
 
class  FieldT
 

Public Member Functions

virtual ~VirtualStruct ()
 
bool addField (Field *f, bool noerrorprint=false)
 
template<typename structT , typename retT , retT structT::* field>
bool addField (const std::string &name, const std::string &prettyname="", bool noerrorprint=false)
 add a structure field to this VirtualStructure More...
 
template<typename T >
bool addField (const std::string &name, const std::string &prettyname, std::function< T()> read, std::function< void(T)> write, bool supportsListener=false, bool noerrorprint=false)
 
std::shared_ptr< FieldfindName (const std::string &name) const
 
std::shared_ptr< FieldfindPrettyName (const std::string &name) const
 
void foreachField (const std::function< void(std::shared_ptr< Field >)> &func)
 
bool mountStruct (const std::string &name, const std::shared_ptr< VirtualStruct > vs)
 
std::shared_ptr< VirtualStructfindStruct (const std::string &name)
 
void foreachStruct (const std::function< void(const std::string &name, VirtualStruct &vs)> &func)
 
void close ()
 
bool isClosed ()
 
virtual std::list< std::string > listFields ()
 list all fields directly reachable by this injector More...
 
virtual std::list< std::string > listSubInjectors ()
 list all sub injectors. More...
 
virtual std::shared_ptr< etiss::fault::InjectorgetSubInjector (const std::string &name)
 get a sub injector. More...
 
virtual std::shared_ptr< etiss::fault::InjectorgetParentInjector ()
 get a the parent injector (root returns 0). More...
 
virtual bool acceleratedTrigger (const etiss::fault::Trigger &, int32_t fault_id)
 
std::shared_ptr< VirtualStructgetVirtualStruct (const std::string &path)
 
std::shared_ptr< VirtualStruct::FieldgetResolvedField (const std::string &path)
 
- Public Member Functions inherited from etiss::fault::Injector
 Injector ()
 
virtual ~Injector ()
 
virtual bool needsCallbacks ()
 
virtual bool cycleAccurateCallback (uint64_t time_ps)
 
virtual bool instructionAccurateCallback (uint64_t time_ps)
 
virtual void freeFastFieldAccessPtr (void *)
 MUST be called to cleanup a pointer acquired with fastFieldAccessPtr() default implementation is nop. More...
 
virtual std::string getInjectorPath ()
 returns the path of the current object. More...
 
void addTrigger (const Trigger &t, int32_t fault_id)
 > Triggers to look at in callbacks More...
 

Static Public Member Functions

static std::shared_ptr< VirtualStructallocate (void *structure, std::function< void(Field *)> delete_)
 
static std::shared_ptr< VirtualStructroot ()
 
static std::shared_ptr< VirtualStructallocateFromC (void *handle, VirtualStruct_names names, VirtualStruct_prettyNames prettyNames_optional, VirtualStruct_read read_recommended, VirtualStruct_write write_optional, VirtualStruct_setListenerCallback setListenerCallback_optional, std::function< void(void *handle)> cleanup)
 implemented in CVirtualStruct.cpp More...
 
- Static Public Member Functions inherited from etiss::fault::Injector
static ptr get (const std::string &injectorPath)
 

Public Attributes

std::function< bool(const etiss::fault::Fault &, const etiss::fault::Action &, std::string &)> applyCustomAction
 set this function to handle custom commands passed by etiss::fault::Action of the type etiss::fault::Action::COMMAND More...
 
void *const structure_
 
std::function< bool(const etiss::fault::Trigger &, int32_t)> acceleratedTrigger_
 

Protected Member Functions

virtual void * fastFieldAccessPtr (const std::string &name, std::string &errormsg)
 
virtual bool readField (void *fastfieldaccessptr, uint64_t &val, std::string &errormsg)
 read the value of a field More...
 
virtual bool applyAction (const etiss::fault::Fault &fault, const etiss::fault::Action &action, std::string &errormsg)
 

Private Member Functions

 VirtualStruct (void *structure, std::function< void(Field *)> dtor=[](Field *f) { delete f;})
 

Private Attributes

std::list< Field * > fields_
 
std::map< std::string, Field * > fieldNames_
 
std::map< std::string, Field * > fieldPrettyNames_
 
std::map< std::string, std::weak_ptr< VirtualStruct > > subStructs_
 
std::function< void(Field *)> dtor_
 
bool closed
 
std::shared_ptr< VirtualStructparent_
 

Friends

class VSSync
 

Additional Inherited Members

- Public Types inherited from etiss::fault::Injector
typedef Injectorptr
 

Detailed Description

abstract representation of an module of a simulation which could be a embedded device of the cpu of an embedded device.

it is recommended to model and address the full hardware hirachy. e.g.

 device1
            -> cpu
                -> cache
            -> bus
            -> memory
                -> bank1
                -> bank2

        example address: "device1::cpu::cache"
    

To resolve a path to a VirtualStruct use VirtualStruct::root()->getVirtualStruct("device1::cpu::cache");

Fields of a VirtualStruct can be addressed by appending ".FIELDNAME" to the pass and pass it to getResolvedField(). e.g. VirtualStruct::root()->getResolvedField("device1::cpu::cache.tag1");

Syntax (Wirth syntax notation):

    module_path_to_field:   module_path "." { ASCII-character }
    module_path:            module_name { "::" module_name } .
    module_name:            letter { digit | letter } .
    letter:                 "a" | "A" | "b" | "B" | ... | "z" | "Z" .
    digit:                  "0" | "1" | "2" | "3" | "4" | "5" | "6" | 7" | "8" |
"9" .

    module_path_to_field is the full path to a field.
    module_path is always relative to the current module

EXTENSION for absolute paths:

    absolute_module_path_to_field:  "::" module_path_to_field
    absolute_module_path:           "::" module_path .

    absolute module path will NOT use root()!
        it will traverse from the current module upward until no parent exists
and then the path will be resolved


the tree of modules uses weak/shared pointers to create a tree that will clean itself up as soon as possible depending on the lifetime of the virtual structs that were associated with said module.

weak reference: –> ( x holds a weak reference to y [x.weak_ptr = y]) strong reference: x -> y ( x holds a strong reference to y [x.shared_ptr = y])

Relations:

    VirtualStruct
        --> <- VirtualStruct
            --> <- VirtualStruct

    VirtualStruct holds a weak reference to child VirtualStructs and a child VirtualStruct holds a strong reference to
VirtualStruct. Module holds a weak reference to a child Module and a child Module holds a strong reference to parent
Module VirtualStructs are deleted if the original shared_ptr is deleted, there is no child and there is no shared_ptr to
a field




Attention
: while VirtualStruct won't throw exceptions by itself, VirtualStruct::Field will throw exception upon invalid access or if the associated VirtualStruct has been closed

Definition at line 139 of file VirtualStruct.h.

Constructor & Destructor Documentation

◆ VirtualStruct()

etiss::VirtualStruct::VirtualStruct ( void *  structure,
std::function< void(Field *)>  dtor = [](Field *f) { delete f; } 
)
private

Definition at line 232 of file VirtualStruct.cpp.

Referenced by allocate().

Here is the caller graph for this function:

◆ ~VirtualStruct()

etiss::VirtualStruct::~VirtualStruct ( )
virtual

Definition at line 236 of file VirtualStruct.cpp.

References close(), dtor_, etiss::ERROR, fields_, and etiss::log().

Here is the call graph for this function:

Member Function Documentation

◆ acceleratedTrigger()

bool etiss::VirtualStruct::acceleratedTrigger ( const etiss::fault::Trigger t,
int32_t  fault_id 
)
virtual

Reimplemented from etiss::fault::Injector.

Definition at line 341 of file VirtualStruct.cpp.

References acceleratedTrigger_.

◆ addField() [1/3]

template<typename T >
bool etiss::VirtualStruct::addField ( const std::string &  name,
const std::string &  prettyname,
std::function< T()>  read,
std::function< void(T)>  write,
bool  supportsListener = false,
bool  noerrorprint = false 
)
inline

Definition at line 328 of file VirtualStruct.h.

References addField(), etiss::VirtualStruct::Field::L, etiss::VirtualStruct::Field::R, uint64_t, v, and etiss::VirtualStruct::Field::W.

Here is the call graph for this function:

◆ addField() [2/3]

template<typename structT , typename retT , retT structT::* field>
bool etiss::VirtualStruct::addField ( const std::string &  name,
const std::string &  prettyname = "",
bool  noerrorprint = false 
)
inline

add a structure field to this VirtualStructure

Definition at line 313 of file VirtualStruct.h.

References addField().

Here is the call graph for this function:

◆ addField() [3/3]

bool etiss::VirtualStruct::addField ( VirtualStruct::Field f,
bool  noerrorprint = false 
)

Definition at line 264 of file VirtualStruct.cpp.

References etiss::ERROR, ETISS_SRCLOC, fieldNames_, fieldPrettyNames_, fields_, etiss::log(), etiss::VirtualStruct::Field::name_, etiss::VirtualStruct::Field::prettyname_, and etiss::VERBOSE.

Referenced by addField().

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

◆ allocate()

std::shared_ptr< VirtualStruct > etiss::VirtualStruct::allocate ( void *  structure,
std::function< void(Field *)>  delete_ 
)
static

Definition at line 596 of file VirtualStruct.cpp.

References VirtualStruct().

Referenced by allocateFromC(), RV32IMACFDArch::getVirtualStruct(), RV64IMACFDArch::getVirtualStruct(), and root().

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

◆ allocateFromC()

std::shared_ptr< VirtualStruct > etiss::VirtualStruct::allocateFromC ( void *  handle,
VirtualStruct_names  names,
VirtualStruct_prettyNames  prettyNames_optional,
VirtualStruct_read  read_recommended,
VirtualStruct_write  write_optional,
VirtualStruct_setListenerCallback  setListenerCallback_optional,
std::function< void(void *handle)>  cleanup 
)
static

◆ applyAction()

bool etiss::VirtualStruct::applyAction ( const etiss::fault::Fault fault,
const etiss::fault::Action action,
std::string &  errormsg 
)
protectedvirtual

◆ close()

void etiss::VirtualStruct::close ( )

Definition at line 396 of file VirtualStruct.cpp.

References closed.

Referenced by ~VirtualStruct().

Here is the caller graph for this function:

◆ fastFieldAccessPtr()

void * etiss::VirtualStruct::fastFieldAccessPtr ( const std::string &  name,
std::string &  errormsg 
)
protectedvirtual
Attention
MUST NOT be called from without the callback functions cycleAccurateCallback() and instructionAccurateCallback(). The assumption of a singlethreaded access/use of these functions MUST hold.
Returns
0 in case of failure. otherwise an internal pointer shall be retuned that allows to access a field in a quick manner. freefastFieldAccessPtr MUST be called after use.

Implements etiss::fault::Injector.

Definition at line 433 of file VirtualStruct.cpp.

References fieldNames_, and fieldPrettyNames_.

◆ findName()

std::shared_ptr< VirtualStruct::Field > etiss::VirtualStruct::findName ( const std::string &  name) const

Definition at line 303 of file VirtualStruct.cpp.

References closed, and fieldNames_.

Referenced by etiss::copy().

Here is the caller graph for this function:

◆ findPrettyName()

std::shared_ptr< VirtualStruct::Field > etiss::VirtualStruct::findPrettyName ( const std::string &  name) const

Definition at line 317 of file VirtualStruct.cpp.

References closed, and fieldPrettyNames_.

◆ findStruct()

std::shared_ptr< VirtualStruct > etiss::VirtualStruct::findStruct ( const std::string &  name)

Definition at line 374 of file VirtualStruct.cpp.

References subStructs_.

Referenced by getSubInjector().

Here is the caller graph for this function:

◆ foreachField()

void etiss::VirtualStruct::foreachField ( const std::function< void(std::shared_ptr< Field >)> &  func)

Definition at line 330 of file VirtualStruct.cpp.

References closed, and fields_.

Referenced by etiss::copy(), and listFields().

Here is the caller graph for this function:

◆ foreachStruct()

void etiss::VirtualStruct::foreachStruct ( const std::function< void(const std::string &name, VirtualStruct &vs)> &  func)

Definition at line 382 of file VirtualStruct.cpp.

References subStructs_.

Referenced by listSubInjectors().

Here is the caller graph for this function:

◆ getParentInjector()

std::shared_ptr< etiss::fault::Injector > etiss::VirtualStruct::getParentInjector ( )
virtual

get a the parent injector (root returns 0).

in case of c++11 this function returns a smart pointer (std::shared_ptr<Injector>)

See also
etiss::VirtualStruct for example implemention

Implements etiss::fault::Injector.

Definition at line 428 of file VirtualStruct.cpp.

References parent_.

◆ getResolvedField()

std::shared_ptr< VirtualStruct::Field > etiss::VirtualStruct::getResolvedField ( const std::string &  path)

Definition at line 660 of file VirtualStruct.cpp.

References getVirtualStruct().

Here is the call graph for this function:

◆ getSubInjector()

std::shared_ptr< etiss::fault::Injector > etiss::VirtualStruct::getSubInjector ( const std::string &  name)
virtual

get a sub injector.

in case of c++11 this function returns a smart pointer (std::shared_ptr<Injector>)

See also
etiss::VirtualStruct for example implemention

Implements etiss::fault::Injector.

Definition at line 424 of file VirtualStruct.cpp.

References findStruct().

Here is the call graph for this function:

◆ getVirtualStruct()

std::shared_ptr< VirtualStruct > etiss::VirtualStruct::getVirtualStruct ( const std::string &  path)

Definition at line 609 of file VirtualStruct.cpp.

References parent_, and subStructs_.

Referenced by getResolvedField().

Here is the caller graph for this function:

◆ isClosed()

bool etiss::VirtualStruct::isClosed ( )

Definition at line 402 of file VirtualStruct.cpp.

References closed.

◆ listFields()

std::list< std::string > etiss::VirtualStruct::listFields ( )
virtual

list all fields directly reachable by this injector

See also
etiss::VirtualStruct for example implemention

Implements etiss::fault::Injector.

Definition at line 408 of file VirtualStruct.cpp.

References foreachField().

Here is the call graph for this function:

◆ listSubInjectors()

std::list< std::string > etiss::VirtualStruct::listSubInjectors ( )
virtual

list all sub injectors.

See also
etiss::VirtualStruct for example implemention

Implements etiss::fault::Injector.

Definition at line 417 of file VirtualStruct.cpp.

References foreachStruct().

Here is the call graph for this function:

◆ mountStruct()

bool etiss::VirtualStruct::mountStruct ( const std::string &  name,
const std::shared_ptr< VirtualStruct vs 
)

Definition at line 352 of file VirtualStruct.cpp.

References subStructs_.

◆ readField()

bool etiss::VirtualStruct::readField ( void *  fastfieldaccessptr,
uint64_t val,
std::string &  errormsg 
)
protectedvirtual

read the value of a field

Returns
true if read succeded
Attention
MUST NOT be called from outside the callback functions cycleAccurateCallback() and instructionAccurateCallback(). The assumption of a singlethreaded access/use of these functions MUST hold.

Implements etiss::fault::Injector.

Definition at line 448 of file VirtualStruct.cpp.

References etiss::VirtualStruct::Field::flags_, etiss::VirtualStruct::Field::R, and etiss::VirtualStruct::Field::read().

Here is the call graph for this function:

◆ root()

std::shared_ptr< VirtualStruct > etiss::VirtualStruct::root ( )
static

Definition at line 603 of file VirtualStruct.cpp.

References allocate().

Referenced by etiss::fault::Injector::get(), and main().

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

Friends And Related Function Documentation

◆ VSSync

friend class VSSync
friend

Definition at line 141 of file VirtualStruct.h.

Member Data Documentation

◆ acceleratedTrigger_

std::function<bool(const etiss::fault::Trigger &, int32_t)> etiss::VirtualStruct::acceleratedTrigger_

Definition at line 380 of file VirtualStruct.h.

Referenced by acceleratedTrigger().

◆ applyCustomAction

std::function<bool(const etiss::fault::Fault &, const etiss::fault::Action &, std::string & )> etiss::VirtualStruct::applyCustomAction

set this function to handle custom commands passed by etiss::fault::Action of the type etiss::fault::Action::COMMAND

Definition at line 376 of file VirtualStruct.h.

Referenced by applyAction().

◆ closed

bool etiss::VirtualStruct::closed
private

Definition at line 388 of file VirtualStruct.h.

Referenced by close(), findName(), findPrettyName(), foreachField(), and isClosed().

◆ dtor_

std::function<void(Field *)> etiss::VirtualStruct::dtor_
private

Definition at line 387 of file VirtualStruct.h.

Referenced by ~VirtualStruct().

◆ fieldNames_

std::map<std::string, Field *> etiss::VirtualStruct::fieldNames_
private

Definition at line 384 of file VirtualStruct.h.

Referenced by addField(), applyAction(), fastFieldAccessPtr(), and findName().

◆ fieldPrettyNames_

std::map<std::string, Field *> etiss::VirtualStruct::fieldPrettyNames_
private

Definition at line 385 of file VirtualStruct.h.

Referenced by addField(), applyAction(), fastFieldAccessPtr(), and findPrettyName().

◆ fields_

std::list<Field *> etiss::VirtualStruct::fields_
private

Definition at line 383 of file VirtualStruct.h.

Referenced by addField(), foreachField(), and ~VirtualStruct().

◆ parent_

std::shared_ptr<VirtualStruct> etiss::VirtualStruct::parent_
private

Definition at line 391 of file VirtualStruct.h.

Referenced by getParentInjector(), and getVirtualStruct().

◆ structure_

void* const etiss::VirtualStruct::structure_

◆ subStructs_

std::map<std::string, std::weak_ptr<VirtualStruct> > etiss::VirtualStruct::subStructs_
private

Definition at line 386 of file VirtualStruct.h.

Referenced by findStruct(), foreachStruct(), getVirtualStruct(), and mountStruct().


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