2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * Copyright (c) 2010 Advanced Micro Devices, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * Authors: Steve Reinhardt
34 * User Console Definitions
37 #ifndef __SIM_OBJECT_HH__
38 #define __SIM_OBJECT_HH__
46 #include "params/SimObject.hh"
47 #include "sim/eventq.hh"
48 #include "sim/serialize.hh"
54 * Abstract superclass for simulation objects. Represents things that
55 * correspond to physical components and can be specified via the
56 * config file (CPUs, caches, etc.).
58 class SimObject : public EventManager, public Serializable
71 void changeState(State new_state) { state = new_state; }
74 State getState() { return state; }
77 typedef std::vector<SimObject *> SimObjectList;
79 // list of all instantiated simulation objects
80 static SimObjectList simObjectList;
83 const SimObjectParams *_params;
86 typedef SimObjectParams Params;
87 const Params *params() const { return _params; }
88 SimObject(const Params *_params);
89 virtual ~SimObject() {}
93 virtual const std::string name() const { return params()->name; }
95 // The following SimObject initialization methods are called from
96 // the instantiate() method in src/python/m5/simulate.py. See
97 // that function for details on how/when these methods are
101 * init() is called after all C++ SimObjects have been created and
102 * all ports are connected. Initializations that are independent
103 * of unserialization but rely on a fully instantiated and
104 * connected SimObject graph should be done here.
109 * loadState() is called on each SimObject when restoring from a
110 * checkpoint. The default implementation simply calls
111 * unserialize() if there is a corresponding section in the
112 * checkpoint. However, objects can override loadState() to get
113 * other behaviors, e.g., doing other programmed initializations
114 * after unserialize(), or complaining if no checkpoint section is
117 virtual void loadState(Checkpoint *cp);
120 * initState() is called on each SimObject when *not* restoring
121 * from a checkpoint. This provides a hook for state
122 * initializations that are only required for a "cold start".
124 virtual void initState();
126 // register statistics for this object
127 virtual void regStats();
128 virtual void regFormulas();
129 virtual void resetStats();
132 * startup() is the final initialization call before simulation.
133 * All state is initialized (including unserialized state, if any,
134 * such as the curTick() value), so this is the appropriate place to
135 * schedule initial event(s) for objects that need them.
137 virtual void startup();
139 // static: call nameOut() & serialize() on all SimObjects
140 static void serializeAll(std::ostream &);
142 // Methods to drain objects in order to take checkpoints
143 // Or switch from timing -> atomic memory model
144 // Drain returns 0 if the simobject can drain immediately or
145 // the number of times the drain_event's process function will be called
146 // before the object will be done draining. Normally this should be 1
147 virtual unsigned int drain(Event *drain_event);
148 virtual void resume();
149 virtual void setMemoryMode(State new_mode);
150 virtual void switchOut();
151 virtual void takeOverFrom(BaseCPU *cpu);
156 static void debugObjectBreak(const std::string &objs);
160 * Find the SimObject with the given name and return a pointer to
161 * it. Primarily used for interactive debugging. Argument is
162 * char* rather than std::string to make it callable from gdb.
164 static SimObject *find(const char *name);
167 #endif // __SIM_OBJECT_HH__