summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/python/m5/SimObject.py2
-rw-r--r--src/python/m5/simulate.py14
-rw-r--r--src/sim/Root.py25
3 files changed, 37 insertions, 4 deletions
diff --git a/src/python/m5/SimObject.py b/src/python/m5/SimObject.py
index 3b84d6000..8e14b63d2 100644
--- a/src/python/m5/SimObject.py
+++ b/src/python/m5/SimObject.py
@@ -623,7 +623,7 @@ class SimObject(object):
def path(self):
if not self._parent:
- return 'root'
+ return '(orphan)'
ppath = self._parent.path()
if ppath == 'root':
return self._name
diff --git a/src/python/m5/simulate.py b/src/python/m5/simulate.py
index e43f90173..2db5c6952 100644
--- a/src/python/m5/simulate.py
+++ b/src/python/m5/simulate.py
@@ -39,13 +39,19 @@ from main import options
import SimObject
import ticks
import objects
+from util import fatal
# define a MaxTick parameter
MaxTick = 2**63 - 1
# The final hook to generate .ini files. Called from the user script
# once the config is built.
-def instantiate(root):
+def instantiate():
+ root = objects.Root.getInstance()
+
+ if not root:
+ fatal("Need to instantiate Root() before calling instantiate()")
+
# we need to fix the global frequency
ticks.fixGlobalFrequency()
@@ -136,7 +142,8 @@ def drain(root):
def resume(root):
root.resume()
-def checkpoint(root, dir):
+def checkpoint(dir):
+ root = objects.Root.getInstance()
if not isinstance(root, objects.Root):
raise TypeError, "Checkpoint must be called on a root object."
doDrain(root)
@@ -144,7 +151,8 @@ def checkpoint(root, dir):
internal.core.serializeAll(dir)
resume(root)
-def restoreCheckpoint(root, dir):
+def restoreCheckpoint(dir):
+ root = objects.Root.getInstance()
print "Restoring from checkpoint"
internal.core.unserializeAll(dir)
need_resume.append(root)
diff --git a/src/sim/Root.py b/src/sim/Root.py
index fff998e0d..c7404a11f 100644
--- a/src/sim/Root.py
+++ b/src/sim/Root.py
@@ -28,7 +28,32 @@
from m5.SimObject import SimObject
from m5.params import *
+from m5.util import fatal
class Root(SimObject):
+
+ _the_instance = None
+
+ def __new__(cls, **kwargs):
+ if Root._the_instance:
+ fatal("Attempt to allocate multiple instances of Root.")
+ return None
+
+ # first call: allocate the unique instance
+ #
+ # If SimObject ever implements __new__, we may want to pass
+ # kwargs here, but for now this goes straight to
+ # object.__new__ which prints an ugly warning if you pass it
+ # args. Seems like a bad design but that's the way it is.
+ Root._the_instance = SimObject.__new__(cls)
+ return Root._the_instance
+
+ @classmethod
+ def getInstance(cls):
+ return Root._the_instance
+
+ def path(self):
+ return 'root'
+
type = 'Root'
dummy = Param.Int(0, "We don't support objects without params")