params: Get rid of the remnants of the old style parameter configuration stuff.
[gem5.git] / src / sim / sim_object.cc
1 /*
2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Steve Reinhardt
29 * Nathan Binkert
30 */
31
32 #include <assert.h>
33
34 #include "base/callback.hh"
35 #include "base/inifile.hh"
36 #include "base/match.hh"
37 #include "base/misc.hh"
38 #include "base/trace.hh"
39 #include "base/stats/events.hh"
40 #include "sim/host.hh"
41 #include "sim/sim_object.hh"
42 #include "sim/stats.hh"
43
44 using namespace std;
45
46
47 ////////////////////////////////////////////////////////////////////////
48 //
49 // SimObject member definitions
50 //
51 ////////////////////////////////////////////////////////////////////////
52
53 //
54 // static list of all SimObjects, used for initialization etc.
55 //
56 SimObject::SimObjectList SimObject::simObjectList;
57
58 //
59 // SimObject constructor: used to maintain static simObjectList
60 //
61 SimObject::SimObject(const Params *p)
62 : _params(p)
63 {
64 #ifdef DEBUG
65 doDebugBreak = false;
66 #endif
67
68 simObjectList.push_back(this);
69 state = Running;
70 }
71
72 void
73 SimObject::init()
74 {
75 }
76
77 //
78 // no default statistics, so nothing to do in base implementation
79 //
80 void
81 SimObject::regStats()
82 {
83 }
84
85 void
86 SimObject::regFormulas()
87 {
88 }
89
90 void
91 SimObject::resetStats()
92 {
93 }
94
95 //
96 // static function:
97 // call regStats() on all SimObjects and then regFormulas() on all
98 // SimObjects.
99 //
100 struct SimObjectResetCB : public Callback
101 {
102 virtual void process() { SimObject::resetAllStats(); }
103 };
104
105 namespace {
106 static SimObjectResetCB StatResetCB;
107 }
108
109 void
110 SimObject::regAllStats()
111 {
112 SimObjectList::iterator i;
113 SimObjectList::iterator end = simObjectList.end();
114
115 /**
116 * @todo change cprintfs to DPRINTFs
117 */
118 for (i = simObjectList.begin(); i != end; ++i) {
119 #ifdef STAT_DEBUG
120 cprintf("registering stats for %s\n", (*i)->name());
121 #endif
122 (*i)->regStats();
123 }
124
125 for (i = simObjectList.begin(); i != end; ++i) {
126 #ifdef STAT_DEBUG
127 cprintf("registering formulas for %s\n", (*i)->name());
128 #endif
129 (*i)->regFormulas();
130 }
131
132 Stats::registerResetCallback(&StatResetCB);
133 }
134
135 //
136 // static function: call init() on all SimObjects.
137 //
138 void
139 SimObject::initAll()
140 {
141 SimObjectList::iterator i = simObjectList.begin();
142 SimObjectList::iterator end = simObjectList.end();
143
144 for (; i != end; ++i) {
145 SimObject *obj = *i;
146 obj->init();
147 }
148 }
149
150 //
151 // static function: call resetStats() on all SimObjects.
152 //
153 void
154 SimObject::resetAllStats()
155 {
156 SimObjectList::iterator i = simObjectList.begin();
157 SimObjectList::iterator end = simObjectList.end();
158
159 for (; i != end; ++i) {
160 SimObject *obj = *i;
161 obj->resetStats();
162 }
163 }
164
165 //
166 // static function: serialize all SimObjects.
167 //
168 void
169 SimObject::serializeAll(ostream &os)
170 {
171 SimObjectList::reverse_iterator ri = simObjectList.rbegin();
172 SimObjectList::reverse_iterator rend = simObjectList.rend();
173
174 for (; ri != rend; ++ri) {
175 SimObject *obj = *ri;
176 obj->nameOut(os);
177 obj->serialize(os);
178 }
179 }
180
181 void
182 SimObject::unserializeAll(Checkpoint *cp)
183 {
184 SimObjectList::reverse_iterator ri = simObjectList.rbegin();
185 SimObjectList::reverse_iterator rend = simObjectList.rend();
186
187 for (; ri != rend; ++ri) {
188 SimObject *obj = *ri;
189 DPRINTFR(Config, "Unserializing '%s'\n",
190 obj->name());
191 if(cp->sectionExists(obj->name()))
192 obj->unserialize(cp, obj->name());
193 else
194 warn("Not unserializing '%s': no section found in checkpoint.\n",
195 obj->name());
196 }
197 }
198
199 #ifdef DEBUG
200 //
201 // static function: flag which objects should have the debugger break
202 //
203 void
204 SimObject::debugObjectBreak(const string &objs)
205 {
206 SimObjectList::const_iterator i = simObjectList.begin();
207 SimObjectList::const_iterator end = simObjectList.end();
208
209 ObjectMatch match(objs);
210 for (; i != end; ++i) {
211 SimObject *obj = *i;
212 obj->doDebugBreak = match.match(obj->name());
213 }
214 }
215
216 void
217 debugObjectBreak(const char *objs)
218 {
219 SimObject::debugObjectBreak(string(objs));
220 }
221 #endif
222
223 void
224 SimObject::recordEvent(const std::string &stat)
225 {
226 Stats::recordEvent(stat);
227 }
228
229 unsigned int
230 SimObject::drain(Event *drain_event)
231 {
232 state = Drained;
233 return 0;
234 }
235
236 void
237 SimObject::resume()
238 {
239 state = Running;
240 }
241
242 void
243 SimObject::setMemoryMode(State new_mode)
244 {
245 panic("setMemoryMode() should only be called on systems");
246 }
247
248 void
249 SimObject::switchOut()
250 {
251 panic("Unimplemented!");
252 }
253
254 void
255 SimObject::takeOverFrom(BaseCPU *cpu)
256 {
257 panic("Unimplemented!");
258 }
259
260
261 SimObject *
262 SimObject::find(const char *name)
263 {
264 SimObjectList::const_iterator i = simObjectList.begin();
265 SimObjectList::const_iterator end = simObjectList.end();
266
267 for (; i != end; ++i) {
268 SimObject *obj = *i;
269 if (obj->name() == name)
270 return obj;
271 }
272
273 return NULL;
274 }