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/stats/events.hh"
39 #include "base/trace.hh"
40 #include "base/types.hh"
41 #include "sim/sim_object.hh"
42 #include "sim/stats.hh"
47 ////////////////////////////////////////////////////////////////////////
49 // SimObject member definitions
51 ////////////////////////////////////////////////////////////////////////
54 // static list of all SimObjects, used for initialization etc.
56 SimObject::SimObjectList
SimObject::simObjectList
;
59 // SimObject constructor: used to maintain static simObjectList
61 SimObject::SimObject(const Params
*p
)
62 : EventManager(p
->eventq
), _params(p
)
68 simObjectList
.push_back(this);
78 // no default statistics, so nothing to do in base implementation
86 SimObject::regFormulas()
91 SimObject::resetStats()
97 // call regStats() on all SimObjects and then regFormulas() on all
100 struct SimObjectResetCB
: public Callback
102 virtual void process() { SimObject::resetAllStats(); }
106 static SimObjectResetCB StatResetCB
;
110 SimObject::regAllStats()
112 SimObjectList::iterator i
;
113 SimObjectList::iterator end
= simObjectList
.end();
116 * @todo change cprintfs to DPRINTFs
118 for (i
= simObjectList
.begin(); i
!= end
; ++i
) {
120 cprintf("registering stats for %s\n", (*i
)->name());
125 for (i
= simObjectList
.begin(); i
!= end
; ++i
) {
127 cprintf("registering formulas for %s\n", (*i
)->name());
132 Stats::registerResetCallback(&StatResetCB
);
136 // static function: call init() on all SimObjects.
141 SimObjectList::iterator i
= simObjectList
.begin();
142 SimObjectList::iterator end
= simObjectList
.end();
144 for (; i
!= end
; ++i
) {
151 // static function: call resetStats() on all SimObjects.
154 SimObject::resetAllStats()
156 SimObjectList::iterator i
= simObjectList
.begin();
157 SimObjectList::iterator end
= simObjectList
.end();
159 for (; i
!= end
; ++i
) {
166 // static function: serialize all SimObjects.
169 SimObject::serializeAll(ostream
&os
)
171 SimObjectList::reverse_iterator ri
= simObjectList
.rbegin();
172 SimObjectList::reverse_iterator rend
= simObjectList
.rend();
174 for (; ri
!= rend
; ++ri
) {
175 SimObject
*obj
= *ri
;
182 SimObject::unserializeAll(Checkpoint
*cp
)
184 SimObjectList::reverse_iterator ri
= simObjectList
.rbegin();
185 SimObjectList::reverse_iterator rend
= simObjectList
.rend();
187 for (; ri
!= rend
; ++ri
) {
188 SimObject
*obj
= *ri
;
189 DPRINTFR(Config
, "Unserializing '%s'\n",
191 if(cp
->sectionExists(obj
->name()))
192 obj
->unserialize(cp
, obj
->name());
194 warn("Not unserializing '%s': no section found in checkpoint.\n",
201 // static function: flag which objects should have the debugger break
204 SimObject::debugObjectBreak(const string
&objs
)
206 SimObjectList::const_iterator i
= simObjectList
.begin();
207 SimObjectList::const_iterator end
= simObjectList
.end();
209 ObjectMatch
match(objs
);
210 for (; i
!= end
; ++i
) {
212 obj
->doDebugBreak
= match
.match(obj
->name());
217 debugObjectBreak(const char *objs
)
219 SimObject::debugObjectBreak(string(objs
));
224 SimObject::recordEvent(const std::string
&stat
)
226 Stats::recordEvent(stat
);
230 SimObject::drain(Event
*drain_event
)
243 SimObject::setMemoryMode(State new_mode
)
245 panic("setMemoryMode() should only be called on systems");
249 SimObject::switchOut()
251 panic("Unimplemented!");
255 SimObject::takeOverFrom(BaseCPU
*cpu
)
257 panic("Unimplemented!");
262 SimObject::find(const char *name
)
264 SimObjectList::const_iterator i
= simObjectList
.begin();
265 SimObjectList::const_iterator end
= simObjectList
.end();
267 for (; i
!= end
; ++i
) {
269 if (obj
->name() == name
)