#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"
CxxConfigManager *root_manager;
Gem5SystemC::Logger logger;
+ /** Things to do at end_of_elaborate */
+ std::list<void (*)()> endOfElaborationFuncs;
+
public:
SC_HAS_PROCESS(Gem5TopLevelModule);
/** 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_,
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<std::string> ¶m_values)
{
(object != "" ? "." + object : ""), param_name, param_values);
}
-void Gem5System::instantiate()
+void
+Gem5System::instantiate()
{
try {
/* Make a new System */
Gem5Control::~Gem5Control()
{ }
+void
+Gem5Control::registerEndOfElaboration(void (*func)())
+{
+ module->registerEndOfElaboration(func);
+}
+
void
Gem5Control::setDebugFlag(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)
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),
/* @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();
delete root_manager;
}
-void Gem5TopLevelModule::run()
+void
+Gem5TopLevelModule::run()
{
GlobalSimLoopExitEvent *exit_event = NULL;
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);
}
/** 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);
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);
};
}