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 "base/serializer.hh"
41 #include "sim/host.hh"
42 #include "sim/sim_object.hh"
43 #include "sim/stats.hh"
44 #include "sim/param.hh"
49 ////////////////////////////////////////////////////////////////////////
51 // SimObject member definitions
53 ////////////////////////////////////////////////////////////////////////
56 // static list of all SimObjects, used for initialization etc.
58 SimObject::SimObjectList
SimObject::simObjectList
;
61 extern ObjectMatch event_ignore
;
65 // SimObject constructor: used to maintain static simObjectList
67 SimObject::SimObject(Params
*p
)
74 doRecordEvent
= !Stats::event_ignore
.match(name());
75 simObjectList
.push_back(this);
80 // SimObject constructor: used to maintain static simObjectList
82 SimObject::SimObject(const string
&_name
)
85 _params
->name
= _name
;
90 doRecordEvent
= !Stats::event_ignore
.match(name());
91 simObjectList
.push_back(this);
106 // no default statistics, so nothing to do in base implementation
109 SimObject::regStats()
114 SimObject::regFormulas()
119 SimObject::resetStats()
125 // call regStats() on all SimObjects and then regFormulas() on all
128 struct SimObjectResetCB
: public Callback
130 virtual void process() { SimObject::resetAllStats(); }
134 static SimObjectResetCB StatResetCB
;
138 SimObject::regAllStats()
140 SimObjectList::iterator i
;
141 SimObjectList::iterator end
= simObjectList
.end();
144 * @todo change cprintfs to DPRINTFs
146 for (i
= simObjectList
.begin(); i
!= end
; ++i
) {
148 cprintf("registering stats for %s\n", (*i
)->name());
153 for (i
= simObjectList
.begin(); i
!= end
; ++i
) {
155 cprintf("registering formulas for %s\n", (*i
)->name());
160 Stats::registerResetCallback(&StatResetCB
);
164 // static function: call connect() on all SimObjects.
167 SimObject::connectAll()
169 SimObjectList::iterator i
= simObjectList
.begin();
170 SimObjectList::iterator end
= simObjectList
.end();
172 for (; i
!= end
; ++i
) {
179 // static function: call init() on all SimObjects.
184 SimObjectList::iterator i
= simObjectList
.begin();
185 SimObjectList::iterator end
= simObjectList
.end();
187 for (; i
!= end
; ++i
) {
194 // static function: call resetStats() on all SimObjects.
197 SimObject::resetAllStats()
199 SimObjectList::iterator i
= simObjectList
.begin();
200 SimObjectList::iterator end
= simObjectList
.end();
202 for (; i
!= end
; ++i
) {
209 // static function: serialize all SimObjects.
212 SimObject::serializeAll(ostream
&os
)
214 SimObjectList::reverse_iterator ri
= simObjectList
.rbegin();
215 SimObjectList::reverse_iterator rend
= simObjectList
.rend();
217 for (; ri
!= rend
; ++ri
) {
218 SimObject
*obj
= *ri
;
225 SimObject::unserializeAll(Checkpoint
*cp
)
227 SimObjectList::reverse_iterator ri
= simObjectList
.rbegin();
228 SimObjectList::reverse_iterator rend
= simObjectList
.rend();
230 for (; ri
!= rend
; ++ri
) {
231 SimObject
*obj
= *ri
;
232 DPRINTFR(Config
, "Unserializing '%s'\n",
234 if(cp
->sectionExists(obj
->name()))
235 obj
->unserialize(cp
, obj
->name());
237 warn("Not unserializing '%s': no section found in checkpoint.\n",
244 // static function: flag which objects should have the debugger break
247 SimObject::debugObjectBreak(const string
&objs
)
249 SimObjectList::const_iterator i
= simObjectList
.begin();
250 SimObjectList::const_iterator end
= simObjectList
.end();
252 ObjectMatch
match(objs
);
253 for (; i
!= end
; ++i
) {
255 obj
->doDebugBreak
= match
.match(obj
->name());
260 debugObjectBreak(const char *objs
)
262 SimObject::debugObjectBreak(string(objs
));
267 SimObject::recordEvent(const std::string
&stat
)
270 Stats::recordEvent(stat
);
274 SimObject::drain(Event
*drain_event
)
276 if (state
!= DrainedAtomic
&& state
!= Atomic
) {
277 panic("Must implement your own drain function if it is to be used "
280 state
= DrainedAtomic
;
287 if (state
== DrainedAtomic
) {
289 } else if (state
== DrainedTiming
) {
295 SimObject::setMemoryMode(State new_mode
)
297 assert(new_mode
== Timing
|| new_mode
== Atomic
);
298 if (state
== DrainedAtomic
&& new_mode
== Timing
) {
299 state
= DrainedTiming
;
300 } else if (state
== DrainedTiming
&& new_mode
== Atomic
) {
301 state
= DrainedAtomic
;
308 SimObject::switchOut()
310 panic("Unimplemented!");
314 SimObject::takeOverFrom(BaseCPU
*cpu
)
316 panic("Unimplemented!");
319 DEFINE_SIM_OBJECT_CLASS_NAME("SimObject", SimObject
)