2 * Copyright (c) 2001-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Steve Reinhardt
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/types.hh"
40 #include "sim/sim_object.hh"
41 #include "sim/stats.hh"
46 ////////////////////////////////////////////////////////////////////////
48 // SimObject member definitions
50 ////////////////////////////////////////////////////////////////////////
53 // static list of all SimObjects, used for initialization etc.
55 SimObject::SimObjectList
SimObject::simObjectList
;
58 // SimObject constructor: used to maintain static simObjectList
60 SimObject::SimObject(const Params
*p
)
61 : EventManager(p
->eventq
), _params(p
)
67 simObjectList
.push_back(this);
82 // no default statistics, so nothing to do in base implementation
90 SimObject::regFormulas()
95 SimObject::resetStats()
101 // call regStats() on all SimObjects and then regFormulas() on all
104 struct SimObjectResetCB
: public Callback
106 virtual void process() { SimObject::resetAllStats(); }
110 static SimObjectResetCB StatResetCB
;
114 SimObject::regAllStats()
116 SimObjectList::iterator i
;
117 SimObjectList::iterator end
= simObjectList
.end();
120 * @todo change cprintfs to DPRINTFs
122 for (i
= simObjectList
.begin(); i
!= end
; ++i
) {
124 cprintf("registering stats for %s\n", (*i
)->name());
129 for (i
= simObjectList
.begin(); i
!= end
; ++i
) {
131 cprintf("registering formulas for %s\n", (*i
)->name());
136 Stats::registerResetCallback(&StatResetCB
);
140 // static function: call init() on all SimObjects.
145 SimObjectList::iterator i
= simObjectList
.begin();
146 SimObjectList::iterator end
= simObjectList
.end();
148 for (; i
!= end
; ++i
) {
155 // static function: call resetStats() on all SimObjects.
158 SimObject::resetAllStats()
160 SimObjectList::iterator i
= simObjectList
.begin();
161 SimObjectList::iterator end
= simObjectList
.end();
163 for (; i
!= end
; ++i
) {
170 // static function: serialize all SimObjects.
173 SimObject::serializeAll(ostream
&os
)
175 SimObjectList::reverse_iterator ri
= simObjectList
.rbegin();
176 SimObjectList::reverse_iterator rend
= simObjectList
.rend();
178 for (; ri
!= rend
; ++ri
) {
179 SimObject
*obj
= *ri
;
186 SimObject::unserializeAll(Checkpoint
*cp
)
188 SimObjectList::reverse_iterator ri
= simObjectList
.rbegin();
189 SimObjectList::reverse_iterator rend
= simObjectList
.rend();
191 for (; ri
!= rend
; ++ri
) {
192 SimObject
*obj
= *ri
;
193 DPRINTFR(Config
, "Unserializing '%s'\n",
195 if(cp
->sectionExists(obj
->name()))
196 obj
->unserialize(cp
, obj
->name());
198 warn("Not unserializing '%s': no section found in checkpoint.\n",
205 SimObject::startupAll()
207 SimObjectList::iterator i
= simObjectList
.begin();
208 SimObjectList::iterator end
= simObjectList
.end();
219 // static function: flag which objects should have the debugger break
222 SimObject::debugObjectBreak(const string
&objs
)
224 SimObjectList::const_iterator i
= simObjectList
.begin();
225 SimObjectList::const_iterator end
= simObjectList
.end();
227 ObjectMatch
match(objs
);
228 for (; i
!= end
; ++i
) {
230 obj
->doDebugBreak
= match
.match(obj
->name());
235 debugObjectBreak(const char *objs
)
237 SimObject::debugObjectBreak(string(objs
));
242 SimObject::drain(Event
*drain_event
)
255 SimObject::setMemoryMode(State new_mode
)
257 panic("setMemoryMode() should only be called on systems");
261 SimObject::switchOut()
263 panic("Unimplemented!");
267 SimObject::takeOverFrom(BaseCPU
*cpu
)
269 panic("Unimplemented!");
274 SimObject::find(const char *name
)
276 SimObjectList::const_iterator i
= simObjectList
.begin();
277 SimObjectList::const_iterator end
= simObjectList
.end();
279 for (; i
!= end
; ++i
) {
281 if (obj
->name() == name
)