16#ifndef SIMICS_SYSTEMC_IFACE_SIMICS_ADAPTER_H
17#define SIMICS_SYSTEMC_IFACE_SIMICS_ADAPTER_H
19#include <simics/iface/interface-info.h>
20#include <simics/devs/io-memory.h>
45template<
typename TSimicsInterface>
57 std::string
name()
const override {
60 const interface_t *
cstruct()
const override {
66 conf_class_ = conf_class;
79 template<
typename TBase,
typename TInterface>
81 FATAL_ERROR_IF(!obj,
"NULL object passed to Simics interface");
82 TBase *so =
static_cast<TBase*
>(SIM_object_data(obj));
83 TInterface *
adapter =
dynamic_cast<TInterface*
>(so);
84 FATAL_ERROR_IF(
adapter == NULL,
"Unable to locate GasketAdapter");
89 template<
typename TBase,
typename TInterface>
91 conf_object_t *obj_lock) {
93 if (obj_lock != cached_obj_lock_
94 || cached_obj_id_ != SIM_object_id(obj_lock)) {
95 ConfObject *lock_base =
96 static_cast<ConfObject*
>(SIM_object_data(obj_lock));
98 if (simulation ==
nullptr) {
99 conf_object_t *parent = SIM_port_object_parent(obj_lock);
102 lock_base =
static_cast<ConfObject*
>(
103 SIM_object_data(parent));
107 FATAL_ERROR_IF(simulation == NULL,
"Unable to locate Simulation");
108 cached_obj_lock_ = obj_lock;
109 cached_obj_id_ = SIM_object_id(obj_lock);
110 cached_simulation_ = simulation;
112 return {simulation, adapterWithoutLocking<TBase, TInterface>(obj)};
114 template<
typename TBase,
typename TInterface>
116 return adapter<TBase, TInterface>(obj, obj);
118 template<
typename TBase,
typename TInterface>
121 if (SIM_object_class(obj) != conf_class_ )
124 TInterface *iface = adapterWithoutLocking<TBase, TInterface>(obj);
129 std::vector<std::string> description =
adapter->description(type);
130 if (description.empty())
133 description.insert(description.begin(), name_);
134 description.insert(description.begin(), SIM_object_name(obj));
140 TSimicsInterface iface_;
141 conf_class_t *conf_class_;
146 static conf_object_t *cached_obj_lock_;
147 static std::string cached_obj_id_;
151template<
typename TSimicsInterface> conf_object_t*
152SimicsAdapter<TSimicsInterface>::cached_obj_lock_ =
nullptr;
153template<
typename TSimicsInterface> std::string
154SimicsAdapter<TSimicsInterface>::cached_obj_id_ =
"";
155template<
typename TSimicsInterface> SimulationInterface*
156SimicsAdapter<TSimicsInterface>::cached_simulation_ =
nullptr;
171template <
typename InterfaceSimicsAdapter>
173 static InterfaceSimicsAdapter adapter;
Definition: description_interface.h:34
Definition: registry.h:88
Definition: simics_lock.h:27
Base class for mapping Simics interface to a C++ interface.
Definition: simics_adapter.h:47
static TInterface * adapterWithoutLocking(conf_object_t *obj)
Definition: simics_adapter.h:80
const interface_t * cstruct() const override
Definition: simics_adapter.h:60
void set_map_adapter(bool map) override
Definition: simics_adapter.h:71
conf_class_t * simics_class() const override
Definition: simics_adapter.h:68
static SimicsLock< TInterface > adapter(conf_object_t *obj)
Definition: simics_adapter.h:115
SimicsAdapter(const char *name, TSimicsInterface iface)
Definition: simics_adapter.h:49
std::vector< std::string > descriptionBase(conf_object_t *obj, DescriptionType type)
Definition: simics_adapter.h:119
static SimicsLock< TInterface > adapter(conf_object_t *obj, conf_object_t *obj_lock)
Definition: simics_adapter.h:90
void set_simics_class(conf_class_t *conf_class) override
Definition: simics_adapter.h:64
std::string name() const override
Definition: simics_adapter.h:57
bool map_adapter() const override
Definition: simics_adapter.h:74
Interface to the SystemC simulation.
Definition: simulation_interface.h:27
InterfaceSimicsAdapter & createAdapter()
Create a SimicsAdapter that can be registered with a ConfClass.
Definition: simics_adapter.h:172
DescriptionType
Definition: description_interface.h:25
Definition: pci_bus_interface.h:24