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/stats/events.hh"
40 #include "sim/host.hh"
41 #include "sim/sim_object.hh"
42 #include "sim/stats.hh"
43 #include "sim/param.hh"
48 ////////////////////////////////////////////////////////////////////////
50 // SimObject member definitions
52 ////////////////////////////////////////////////////////////////////////
55 // static list of all SimObjects, used for initialization etc.
57 SimObject::SimObjectList
SimObject::simObjectList
;
60 extern ObjectMatch event_ignore
;
64 // SimObject constructor: used to maintain static simObjectList
66 SimObject::SimObject(Params
*p
)
73 doRecordEvent
= !Stats::event_ignore
.match(name());
74 simObjectList
.push_back(this);
79 // SimObject constructor: used to maintain static simObjectList
81 SimObject::SimObject(const string
&_name
)
84 _params
->name
= _name
;
89 doRecordEvent
= !Stats::event_ignore
.match(name());
90 simObjectList
.push_back(this);
105 // no default statistics, so nothing to do in base implementation
108 SimObject::regStats()
113 SimObject::regFormulas()
118 SimObject::resetStats()
124 // call regStats() on all SimObjects and then regFormulas() on all
127 struct SimObjectResetCB
: public Callback
129 virtual void process() { SimObject::resetAllStats(); }
133 static SimObjectResetCB StatResetCB
;
137 SimObject::regAllStats()
139 SimObjectList::iterator i
;
140 SimObjectList::iterator end
= simObjectList
.end();
143 * @todo change cprintfs to DPRINTFs
145 for (i
= simObjectList
.begin(); i
!= end
; ++i
) {
147 cprintf("registering stats for %s\n", (*i
)->name());
152 for (i
= simObjectList
.begin(); i
!= end
; ++i
) {
154 cprintf("registering formulas for %s\n", (*i
)->name());
159 Stats::registerResetCallback(&StatResetCB
);
163 // static function: call connect() on all SimObjects.
166 SimObject::connectAll()
168 SimObjectList::iterator i
= simObjectList
.begin();
169 SimObjectList::iterator end
= simObjectList
.end();
171 for (; i
!= end
; ++i
) {
178 // static function: call init() on all SimObjects.
183 SimObjectList::iterator i
= simObjectList
.begin();
184 SimObjectList::iterator end
= simObjectList
.end();
186 for (; i
!= end
; ++i
) {
193 // static function: call resetStats() on all SimObjects.
196 SimObject::resetAllStats()
198 SimObjectList::iterator i
= simObjectList
.begin();
199 SimObjectList::iterator end
= simObjectList
.end();
201 for (; i
!= end
; ++i
) {
208 // static function: serialize all SimObjects.
211 SimObject::serializeAll(ostream
&os
)
213 SimObjectList::reverse_iterator ri
= simObjectList
.rbegin();
214 SimObjectList::reverse_iterator rend
= simObjectList
.rend();
216 for (; ri
!= rend
; ++ri
) {
217 SimObject
*obj
= *ri
;
224 SimObject::unserializeAll(Checkpoint
*cp
)
226 SimObjectList::reverse_iterator ri
= simObjectList
.rbegin();
227 SimObjectList::reverse_iterator rend
= simObjectList
.rend();
229 for (; ri
!= rend
; ++ri
) {
230 SimObject
*obj
= *ri
;
231 DPRINTFR(Config
, "Unserializing '%s'\n",
233 if(cp
->sectionExists(obj
->name()))
234 obj
->unserialize(cp
, obj
->name());
236 warn("Not unserializing '%s': no section found in checkpoint.\n",
243 // static function: flag which objects should have the debugger break
246 SimObject::debugObjectBreak(const string
&objs
)
248 SimObjectList::const_iterator i
= simObjectList
.begin();
249 SimObjectList::const_iterator end
= simObjectList
.end();
251 ObjectMatch
match(objs
);
252 for (; i
!= end
; ++i
) {
254 obj
->doDebugBreak
= match
.match(obj
->name());
259 debugObjectBreak(const char *objs
)
261 SimObject::debugObjectBreak(string(objs
));
266 SimObject::recordEvent(const std::string
&stat
)
269 Stats::recordEvent(stat
);
273 SimObject::drain(Event
*drain_event
)
286 SimObject::setMemoryMode(State new_mode
)
288 panic("setMemoryMode() should only be called on systems");
292 SimObject::switchOut()
294 panic("Unimplemented!");
298 SimObject::takeOverFrom(BaseCPU
*cpu
)
300 panic("Unimplemented!");
303 DEFINE_SIM_OBJECT_CLASS_NAME("SimObject", SimObject
)