summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConscript2
-rw-r--r--sim/main.cc7
-rw-r--r--sim/param.hh3
-rw-r--r--sim/sim_events.cc26
-rw-r--r--sim/sim_object.hh6
-rw-r--r--sim/startup.cc51
-rw-r--r--sim/startup.hh41
7 files changed, 108 insertions, 28 deletions
diff --git a/SConscript b/SConscript
index c8a97810d..a41680ed4 100644
--- a/SConscript
+++ b/SConscript
@@ -187,8 +187,8 @@ base_sources = Split('''
sim/serialize.cc
sim/sim_events.cc
sim/sim_exit.cc
- sim/sim_init.cc
sim/sim_object.cc
+ sim/startup.cc
sim/stat_context.cc
sim/stat_control.cc
sim/trace_context.cc
diff --git a/sim/main.cc b/sim/main.cc
index 46738a4c7..e8ac58786 100644
--- a/sim/main.cc
+++ b/sim/main.cc
@@ -51,7 +51,6 @@
#include "sim/host.hh"
#include "sim/sim_events.hh"
#include "sim/sim_exit.hh"
-#include "sim/sim_init.hh"
#include "sim/sim_object.hh"
#include "sim/stat_control.hh"
#include "sim/stats.hh"
@@ -350,6 +349,9 @@ main(int argc, char **argv)
configHierarchy.build();
configHierarchy.createSimObjects();
+ // Do a second pass to finish initializing the sim objects
+ SimObject::initAll();
+
// Restore checkpointed state, if any.
configHierarchy.unserializeSimObjects();
@@ -382,9 +384,8 @@ main(int argc, char **argv)
exit(1);
}
- SimInit();
warn("Entering event queue. Starting simulation...\n");
-
+ SimStartup();
while (!mainEventQueue.empty()) {
assert(curTick <= mainEventQueue.nextTick() &&
"event scheduled in the past");
diff --git a/sim/param.hh b/sim/param.hh
index 6706820c2..ac57afa31 100644
--- a/sim/param.hh
+++ b/sim/param.hh
@@ -34,6 +34,7 @@
#include <vector>
#include "sim/configfile.hh"
+#include "sim/startup.hh"
// forward decls
class BaseParam;
@@ -44,7 +45,7 @@ class SimObject;
// SimObjectBuilder (which derives from ParamContext), but abstracted
// here to support more global simulator control parameters as well.
//
-class ParamContext
+class ParamContext : protected StartupCallback
{
private:
diff --git a/sim/sim_events.cc b/sim/sim_events.cc
index c454fdcf9..99c09f259 100644
--- a/sim/sim_events.cc
+++ b/sim/sim_events.cc
@@ -34,7 +34,7 @@
#include "sim/param.hh"
#include "sim/sim_events.hh"
#include "sim/sim_exit.hh"
-#include "sim/sim_init.hh"
+#include "sim/startup.hh"
#include "sim/stats.hh"
using namespace std;
@@ -210,12 +210,11 @@ ProgressEvent::description()
// Parameter space for execution address tracing options. Derive
// from ParamContext so we can override checkParams() function.
-class ProgressParamContext : public ParamContext
+struct ProgressParamContext : public ParamContext
{
- public:
ProgressParamContext(const string &_iniSection)
: ParamContext(_iniSection) {}
- void checkParams();
+ void startup();
};
ProgressParamContext progessMessageParams("progress");
@@ -223,24 +222,9 @@ ProgressParamContext progessMessageParams("progress");
Param<Tick> progress_interval(&progessMessageParams, "cycle",
"cycle interval for progress messages");
-namespace {
- struct SetupProgress : public Callback
- {
- Tick interval;
- SetupProgress(Tick tick) : interval(tick) {}
-
- virtual void process()
- {
- new ProgressEvent(&mainEventQueue, interval);
- delete this;
- }
- };
-}
-
-/* check execute options */
void
-ProgressParamContext::checkParams()
+ProgressParamContext::startup()
{
if (progress_interval.isValid())
- registerInitCallback(new SetupProgress(progress_interval));
+ new ProgressEvent(&mainEventQueue, progress_interval);
}
diff --git a/sim/sim_object.hh b/sim/sim_object.hh
index dfd70f8ec..f4b316ebb 100644
--- a/sim/sim_object.hh
+++ b/sim/sim_object.hh
@@ -39,13 +39,14 @@
#include <iostream>
#include "sim/serialize.hh"
+#include "sim/startup.hh"
/*
* Abstract superclass for simulation objects. Represents things that
* correspond to physical components and can be specified via the
* config file (CPUs, caches, etc.).
*/
-class SimObject : public Serializable
+class SimObject : public Serializable, protected StartupCallback
{
protected:
std::string objName;
@@ -65,7 +66,8 @@ class SimObject : public Serializable
virtual const std::string name() const { return objName; }
- // initialization pass of all objects. Gets invoked by SimInit()
+ // initialization pass of all objects.
+ // Gets invoked after construction, before unserialize.
virtual void init();
static void initAll();
diff --git a/sim/startup.cc b/sim/startup.cc
new file mode 100644
index 000000000..ebb4c0bc0
--- /dev/null
+++ b/sim/startup.cc
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2004 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <list>
+
+#include "base/misc.hh"
+#include "sim/startup.hh"
+#include "sim/debug.hh"
+
+typedef std::list<StartupCallback *> startupq_t;
+startupq_t &startupq() { static startupq_t queue; return queue; }
+StartupCallback::StartupCallback() { startupq().push_back(this); }
+StartupCallback::~StartupCallback() { startupq().remove(this); }
+void StartupCallback::startup() { }
+
+void
+SimStartup()
+{
+ startupq_t::iterator i = startupq().begin();
+ startupq_t::iterator end = startupq().end();
+
+ while (i != end) {
+ (*i)->startup();
+ ++i;
+ }
+}
diff --git a/sim/startup.hh b/sim/startup.hh
new file mode 100644
index 000000000..e6c03a500
--- /dev/null
+++ b/sim/startup.hh
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2004 The Regents of The University of Michigan
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef __SIM_STARTUP_HH__
+#define __SIM_STARTUP_HH__
+
+struct StartupCallback
+{
+ StartupCallback();
+ virtual ~StartupCallback();
+ virtual void startup();
+};
+
+void SimStartup();
+
+#endif // __SIM_STARTUP_HH__