From 05bba75cdc346184da7ff40958673da980a06df2 Mon Sep 17 00:00:00 2001 From: Andrew Bardsley Date: Tue, 2 Dec 2014 06:08:06 -0500 Subject: 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 --- util/systemc/sc_gem5_control.cc | 70 +++++++++++++++++++++++++++++++++++++---- util/systemc/sc_gem5_control.hh | 14 +++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) (limited to 'util/systemc') 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 #include +#include #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 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 ¶m_name, const std::string ¶m_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 ¶m_name, const std::vector ¶m_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 */ @@ -141,6 +158,12 @@ Gem5Control::Gem5Control(const std::string &config_filename) Gem5Control::~Gem5Control() { } +void +Gem5Control::registerEndOfElaboration(void (*func)()) +{ + module->registerEndOfElaboration(func); +} + void Gem5Control::setDebugFlag(const char *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); } diff --git a/util/systemc/sc_gem5_control.hh b/util/systemc/sc_gem5_control.hh index e08ec3cc8..a5a372344 100644 --- a/util/systemc/sc_gem5_control.hh +++ b/util/systemc/sc_gem5_control.hh @@ -129,6 +129,9 @@ class Gem5Control /** Private SystemC module containing top level simulation control */ Gem5TopLevelModule *module; + /** One-time-settable version string */ + std::string version; + public: Gem5Control(const std::string &config_filename); @@ -138,10 +141,21 @@ class Gem5Control virtual void setDebugFlag(const char *flag); virtual void clearDebugFlag(const char *flag); + /** Choose a base port number for GDB to connect to the model + * (0 disables connections) */ + virtual void setRemoteGDBPort(unsigned int port); + + /* Register an action to happen at the end of elaboration */ + virtual void registerEndOfElaboration(void (*func)()); + /** Make a System from the config file description for system * system_name and call it instance_name in gem5 */ virtual Gem5System *makeSystem(const std::string &system_name, const std::string &top_instance); + + /** set/get version string */ + virtual const std::string &getVersion() const; + virtual void setVersion(const std::string &new_version); }; } -- cgit v1.2.3