sim_object.cc revision 7460:41550bb10e08
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 43using 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// 55SimObject::SimObjectList SimObject::simObjectList; 56 57// 58// SimObject constructor: used to maintain static simObjectList 59// 60SimObject::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 71void 72SimObject::init() 73{ 74} 75 76// 77// no default statistics, so nothing to do in base implementation 78// 79void 80SimObject::regStats() 81{ 82} 83 84void 85SimObject::regFormulas() 86{ 87} 88 89void 90SimObject::resetStats() 91{ 92} 93 94// 95// static function: 96// call regStats() on all SimObjects and then regFormulas() on all 97// SimObjects. 98// 99struct SimObjectResetCB : public Callback 100{ 101 virtual void process() { SimObject::resetAllStats(); } 102}; 103 104namespace { 105 static SimObjectResetCB StatResetCB; 106} 107 108void 109SimObject::regAllStats() 110{ 111 SimObjectList::iterator i; 112 SimObjectList::iterator end = simObjectList.end(); 113 114 /** 115 * @todo change cprintfs to DPRINTFs 116 */ 117 for (i = simObjectList.begin(); i != end; ++i) { 118#ifdef STAT_DEBUG 119 cprintf("registering stats for %s\n", (*i)->name()); 120#endif 121 (*i)->regStats(); 122 } 123 124 for (i = simObjectList.begin(); i != end; ++i) { 125#ifdef STAT_DEBUG 126 cprintf("registering formulas for %s\n", (*i)->name()); 127#endif 128 (*i)->regFormulas(); 129 } 130 131 Stats::registerResetCallback(&StatResetCB); 132} 133 134// 135// static function: call init() on all SimObjects. 136// 137void 138SimObject::initAll() 139{ 140 SimObjectList::iterator i = simObjectList.begin(); 141 SimObjectList::iterator end = simObjectList.end(); 142 143 for (; i != end; ++i) { 144 SimObject *obj = *i; 145 obj->init(); 146 } 147} 148 149// 150// static function: call resetStats() on all SimObjects. 151// 152void 153SimObject::resetAllStats() 154{ 155 SimObjectList::iterator i = simObjectList.begin(); 156 SimObjectList::iterator end = simObjectList.end(); 157 158 for (; i != end; ++i) { 159 SimObject *obj = *i; 160 obj->resetStats(); 161 } 162} 163 164// 165// static function: serialize all SimObjects. 166// 167void 168SimObject::serializeAll(ostream &os) 169{ 170 SimObjectList::reverse_iterator ri = simObjectList.rbegin(); 171 SimObjectList::reverse_iterator rend = simObjectList.rend(); 172 173 for (; ri != rend; ++ri) { 174 SimObject *obj = *ri; 175 obj->nameOut(os); 176 obj->serialize(os); 177 } 178} 179 180void 181SimObject::unserializeAll(Checkpoint *cp) 182{ 183 SimObjectList::reverse_iterator ri = simObjectList.rbegin(); 184 SimObjectList::reverse_iterator rend = simObjectList.rend(); 185 186 for (; ri != rend; ++ri) { 187 SimObject *obj = *ri; 188 DPRINTFR(Config, "Unserializing '%s'\n", 189 obj->name()); 190 if(cp->sectionExists(obj->name())) 191 obj->unserialize(cp, obj->name()); 192 else 193 warn("Not unserializing '%s': no section found in checkpoint.\n", 194 obj->name()); 195 } 196} 197 198#ifdef DEBUG 199// 200// static function: flag which objects should have the debugger break 201// 202void 203SimObject::debugObjectBreak(const string &objs) 204{ 205 SimObjectList::const_iterator i = simObjectList.begin(); 206 SimObjectList::const_iterator end = simObjectList.end(); 207 208 ObjectMatch match(objs); 209 for (; i != end; ++i) { 210 SimObject *obj = *i; 211 obj->doDebugBreak = match.match(obj->name()); 212 } 213} 214 215void 216debugObjectBreak(const char *objs) 217{ 218 SimObject::debugObjectBreak(string(objs)); 219} 220#endif 221 222unsigned int 223SimObject::drain(Event *drain_event) 224{ 225 state = Drained; 226 return 0; 227} 228 229void 230SimObject::resume() 231{ 232 state = Running; 233} 234 235void 236SimObject::setMemoryMode(State new_mode) 237{ 238 panic("setMemoryMode() should only be called on systems"); 239} 240 241void 242SimObject::switchOut() 243{ 244 panic("Unimplemented!"); 245} 246 247void 248SimObject::takeOverFrom(BaseCPU *cpu) 249{ 250 panic("Unimplemented!"); 251} 252 253 254SimObject * 255SimObject::find(const char *name) 256{ 257 SimObjectList::const_iterator i = simObjectList.begin(); 258 SimObjectList::const_iterator end = simObjectList.end(); 259 260 for (; i != end; ++i) { 261 SimObject *obj = *i; 262 if (obj->name() == name) 263 return obj; 264 } 265 266 return NULL; 267} 268