summaryrefslogtreecommitdiff
path: root/util/systemc/sc_gem5_control.cc
diff options
context:
space:
mode:
authorAndrew Bardsley <Andrew.Bardsley@arm.com>2014-12-02 06:08:06 -0500
committerAndrew Bardsley <Andrew.Bardsley@arm.com>2014-12-02 06:08:06 -0500
commit05bba75cdc346184da7ff40958673da980a06df2 (patch)
tree817b43e5bb0479a968ac10dc6f584c6825133563 /util/systemc/sc_gem5_control.cc
parent726f626e87dbe601b4c608d78d53907b15986681 (diff)
downloadgem5-05bba75cdc346184da7ff40958673da980a06df2.tar.xz
config: SystemC Gem5Control top level additions
This patch cleans up a few style issues and adds a few capabilities to the SystemC top level 'Gem5Control/Gem5System' mechanism. These include: 1) A space to store/retrieve a version string for a model 2) A mechanism for registering functions to be called at the end of elaboration to perform simulation setup tasks in SystemC 3) Adding setGDBRemotePort to the Gem5Control 4) Changing the sc_set_time_resolution behaviour to instead check that the SystemC time resolution is already acceptable
Diffstat (limited to 'util/systemc/sc_gem5_control.cc')
-rw-r--r--util/systemc/sc_gem5_control.cc70
1 files changed, 64 insertions, 6 deletions
diff --git a/util/systemc/sc_gem5_control.cc b/util/systemc/sc_gem5_control.cc
index 09a1be995..ec46a7dc9 100644
--- a/util/systemc/sc_gem5_control.cc
+++ b/util/systemc/sc_gem5_control.cc
@@ -39,10 +39,12 @@
#include <cstdlib>
#include <iostream>
+#include <list>
#include "base/statistics.hh"
#include "sim/cxx_config_ini.hh"
#include "sim/cxx_manager.hh"
+#include "sim/debug.hh"
#include "sim/init_signals.hh"
#include "sim/stat_control.hh"
#include "sc_gem5_control.hh"
@@ -63,6 +65,9 @@ class Gem5TopLevelModule : public Gem5SystemC::Module
CxxConfigManager *root_manager;
Gem5SystemC::Logger logger;
+ /** Things to do at end_of_elaborate */
+ std::list<void (*)()> endOfElaborationFuncs;
+
public:
SC_HAS_PROCESS(Gem5TopLevelModule);
@@ -73,6 +78,15 @@ class Gem5TopLevelModule : public Gem5SystemC::Module
/** gem5 simulate. @todo for more interesting simulation control,
* this needs to be more complicated */
void run();
+
+ /* Register an action to happen at the end of elaboration */
+ void registerEndOfElaboration(void (*func)())
+ {
+ endOfElaborationFuncs.push_back(func);
+ }
+
+ /** SystemC startup */
+ void end_of_elaboration();
};
Gem5System::Gem5System(CxxConfigManager *manager_,
@@ -90,14 +104,16 @@ Gem5System::~Gem5System()
delete manager;
}
-void Gem5System::setParam(const std::string &object,
+void
+Gem5System::setParam(const std::string &object,
const std::string &param_name, const std::string &param_value)
{
manager->setParam(systemName + (object != "" ? "." + object : ""),
param_name, param_value);
}
-void Gem5System::setParamVector(const std::string &object,
+void
+Gem5System::setParamVector(const std::string &object,
const std::string &param_name,
const std::vector<std::string> &param_values)
{
@@ -105,7 +121,8 @@ void Gem5System::setParamVector(const std::string &object,
(object != "" ? "." + object : ""), param_name, param_values);
}
-void Gem5System::instantiate()
+void
+Gem5System::instantiate()
{
try {
/* Make a new System */
@@ -142,6 +159,12 @@ Gem5Control::~Gem5Control()
{ }
void
+Gem5Control::registerEndOfElaboration(void (*func)())
+{
+ module->registerEndOfElaboration(func);
+}
+
+void
Gem5Control::setDebugFlag(const char *flag)
{
::setDebugFlag(flag);
@@ -153,6 +176,12 @@ Gem5Control::clearDebugFlag(const char *flag)
::clearDebugFlag(flag);
}
+void
+Gem5Control::setRemoteGDBPort(unsigned int port)
+{
+ ::setRemoteGDBPort(port);
+}
+
Gem5System *
Gem5Control::makeSystem(const std::string &system_name,
const std::string &instance_name)
@@ -164,6 +193,21 @@ Gem5Control::makeSystem(const std::string &system_name,
return ret;
}
+const std::string &
+Gem5Control::getVersion() const
+{
+ return version;
+}
+
+void
+Gem5Control::setVersion(const std::string &new_version)
+{
+ if (version != "")
+ fatal("Gem5Control::setVersion called for a second time");
+
+ version = new_version;
+}
+
Gem5TopLevelModule::Gem5TopLevelModule(sc_core::sc_module_name name,
const std::string &config_filename) :
Gem5SystemC::Module(name),
@@ -179,12 +223,14 @@ Gem5TopLevelModule::Gem5TopLevelModule(sc_core::sc_module_name name,
/* @todo need this as an option */
Gem5SystemC::setTickFrequency();
- sc_core::sc_set_time_resolution(1, sc_core::SC_PS);
/* Make a SystemC-synchronising event queue and install it as the
* sole top level gem5 EventQueue */
Gem5SystemC::Module::setupEventQueues(*this);
+ if (sc_core::sc_get_time_resolution() != sc_core::sc_time(1, sc_core::SC_PS))
+ fatal("Time resolution must be set to 1 ps for gem5 to work");
+
/* Enable keyboard interrupt, async I/O etc. */
initSignals();
@@ -227,7 +273,8 @@ Gem5TopLevelModule::~Gem5TopLevelModule()
delete root_manager;
}
-void Gem5TopLevelModule::run()
+void
+Gem5TopLevelModule::run()
{
GlobalSimLoopExitEvent *exit_event = NULL;
@@ -239,9 +286,20 @@ void Gem5TopLevelModule::run()
getEventQueue(0)->dump();
}
+void
+Gem5TopLevelModule::end_of_elaboration()
+{
+ for (auto i = endOfElaborationFuncs.begin();
+ i != endOfElaborationFuncs.end(); ++i)
+ {
+ (*i)();
+ }
+}
+
}
-Gem5SystemC::Gem5Control *makeGem5Control(const std::string &config_filename)
+Gem5SystemC::Gem5Control *
+makeGem5Control(const std::string &config_filename)
{
return new Gem5SystemC::Gem5Control(config_filename);
}