sim: move iterating over SimObjects into Python.
[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 <cassert>
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/types.hh"
40 #include "sim/sim_object.hh"
41 #include "sim/stats.hh"
42
43 using namespace std;
44
45
46 ////////////////////////////////////////////////////////////////////////
47 //
48 // SimObject member definitions
49 //
50 ////////////////////////////////////////////////////////////////////////
51
52 //
53 // static list of all SimObjects, used for initialization etc.
54 //
55 SimObject::SimObjectList SimObject::simObjectList;
56
57 //
58 // SimObject constructor: used to maintain static simObjectList
59 //
60 SimObject::SimObject(const Params *p)
61 : EventManager(p->eventq), _params(p)
62 {
63 #ifdef DEBUG
64 doDebugBreak = false;
65 #endif
66
67 simObjectList.push_back(this);
68 state = Running;
69 }
70
71 void
72 SimObject::init()
73 {
74 }
75
76 void
77 SimObject::startup()
78 {
79 }
80
81 //
82 // no default statistics, so nothing to do in base implementation
83 //
84 void
85 SimObject::regStats()
86 {
87 }
88
89 void
90 SimObject::regFormulas()
91 {
92 }
93
94 void
95 SimObject::resetStats()
96 {
97 }
98
99 //
100 // static function: serialize all SimObjects.
101 //
102 void
103 SimObject::serializeAll(ostream &os)
104 {
105 SimObjectList::reverse_iterator ri = simObjectList.rbegin();
106 SimObjectList::reverse_iterator rend = simObjectList.rend();
107
108 for (; ri != rend; ++ri) {
109 SimObject *obj = *ri;
110 obj->nameOut(os);
111 obj->serialize(os);
112 }
113 }
114
115 void
116 SimObject::unserializeAll(Checkpoint *cp)
117 {
118 SimObjectList::reverse_iterator ri = simObjectList.rbegin();
119 SimObjectList::reverse_iterator rend = simObjectList.rend();
120
121 for (; ri != rend; ++ri) {
122 SimObject *obj = *ri;
123 DPRINTFR(Config, "Unserializing '%s'\n",
124 obj->name());
125 if(cp->sectionExists(obj->name()))
126 obj->unserialize(cp, obj->name());
127 else
128 warn("Not unserializing '%s': no section found in checkpoint.\n",
129 obj->name());
130 }
131 }
132
133
134
135 #ifdef DEBUG
136 //
137 // static function: flag which objects should have the debugger break
138 //
139 void
140 SimObject::debugObjectBreak(const string &objs)
141 {
142 SimObjectList::const_iterator i = simObjectList.begin();
143 SimObjectList::const_iterator end = simObjectList.end();
144
145 ObjectMatch match(objs);
146 for (; i != end; ++i) {
147 SimObject *obj = *i;
148 obj->doDebugBreak = match.match(obj->name());
149 }
150 }
151
152 void
153 debugObjectBreak(const char *objs)
154 {
155 SimObject::debugObjectBreak(string(objs));
156 }
157 #endif
158
159 unsigned int
160 SimObject::drain(Event *drain_event)
161 {
162 state = Drained;
163 return 0;
164 }
165
166 void
167 SimObject::resume()
168 {
169 state = Running;
170 }
171
172 void
173 SimObject::setMemoryMode(State new_mode)
174 {
175 panic("setMemoryMode() should only be called on systems");
176 }
177
178 void
179 SimObject::switchOut()
180 {
181 panic("Unimplemented!");
182 }
183
184 void
185 SimObject::takeOverFrom(BaseCPU *cpu)
186 {
187 panic("Unimplemented!");
188 }
189
190
191 SimObject *
192 SimObject::find(const char *name)
193 {
194 SimObjectList::const_iterator i = simObjectList.begin();
195 SimObjectList::const_iterator end = simObjectList.end();
196
197 for (; i != end; ++i) {
198 SimObject *obj = *i;
199 if (obj->name() == name)
200 return obj;
201 }
202
203 return NULL;
204 }