changeset 5d7af9fa9809 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=5d7af9fa9809
description:
        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:

 util/systemc/sc_gem5_control.cc |  70 +++++++++++++++++++++++++++++++++++++---
 util/systemc/sc_gem5_control.hh |  14 ++++++++
 2 files changed, 78 insertions(+), 6 deletions(-)

diffs (202 lines):

diff -r de2979ff873a -r 5d7af9fa9809 util/systemc/sc_gem5_control.cc
--- a/util/systemc/sc_gem5_control.cc   Tue Dec 02 06:08:05 2014 -0500
+++ b/util/systemc/sc_gem5_control.cc   Tue Dec 02 06:08:06 2014 -0500
@@ -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 @@
     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 @@
     /** 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 @@
     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 @@
         (object != "" ? "." + object : ""), param_name, param_values);
 }
 
-void Gem5System::instantiate()
+void
+Gem5System::instantiate()
 {
     try {
         /* Make a new System */
@@ -142,6 +159,12 @@
 { }
 
 void
+Gem5Control::registerEndOfElaboration(void (*func)())
+{
+    module->registerEndOfElaboration(func);
+}
+
+void
 Gem5Control::setDebugFlag(const char *flag)
 {
     ::setDebugFlag(flag);
@@ -153,6 +176,12 @@
     ::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 @@
     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 @@
 
     /* @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 @@
     delete root_manager;
 }
 
-void Gem5TopLevelModule::run()
+void
+Gem5TopLevelModule::run()
 {
     GlobalSimLoopExitEvent *exit_event = NULL;
 
@@ -239,9 +286,20 @@
     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 -r de2979ff873a -r 5d7af9fa9809 util/systemc/sc_gem5_control.hh
--- a/util/systemc/sc_gem5_control.hh   Tue Dec 02 06:08:05 2014 -0500
+++ b/util/systemc/sc_gem5_control.hh   Tue Dec 02 06:08:06 2014 -0500
@@ -129,6 +129,9 @@
     /** 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 @@
     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);
 };
 
 }
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to