sim_object.hh revision 2665
12SN/A/* 21762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292665Ssaidi@eecs.umich.edu * Nathan Binkert 302SN/A */ 312SN/A 322SN/A/* @file 332SN/A * User Console Definitions 342SN/A */ 352SN/A 362SN/A#ifndef __SIM_OBJECT_HH__ 372SN/A#define __SIM_OBJECT_HH__ 382SN/A 392SN/A#include <map> 402SN/A#include <list> 412SN/A#include <vector> 422SN/A#include <iostream> 432SN/A 4456SN/A#include "sim/serialize.hh" 451127SN/A#include "sim/startup.hh" 462SN/A 472609SN/Aclass Serializer; 482609SN/A 492SN/A/* 502SN/A * Abstract superclass for simulation objects. Represents things that 512SN/A * correspond to physical components and can be specified via the 522SN/A * config file (CPUs, caches, etc.). 532SN/A */ 541127SN/Aclass SimObject : public Serializable, protected StartupCallback 552SN/A{ 561553SN/A public: 571553SN/A struct Params { 581553SN/A std::string name; 591553SN/A }; 601553SN/A 61265SN/A protected: 621553SN/A Params *_params; 631553SN/A 641553SN/A public: 651553SN/A const Params *params() const { return _params; } 66265SN/A 672SN/A private: 682SN/A friend class Serializer; 692SN/A 702SN/A typedef std::vector<SimObject *> SimObjectList; 712SN/A 722SN/A // list of all instantiated simulation objects 732SN/A static SimObjectList simObjectList; 742SN/A 752SN/A public: 761553SN/A SimObject(Params *_params); 772SN/A SimObject(const std::string &_name); 782SN/A 792SN/A virtual ~SimObject() {} 802SN/A 811553SN/A virtual const std::string name() const { return params()->name; } 82265SN/A 831127SN/A // initialization pass of all objects. 841127SN/A // Gets invoked after construction, before unserialize. 85465SN/A virtual void init(); 862499SN/A virtual void connect(); 87465SN/A static void initAll(); 882499SN/A static void connectAll(); 89465SN/A 902SN/A // register statistics for this object 912SN/A virtual void regStats(); 922SN/A virtual void regFormulas(); 93330SN/A virtual void resetStats(); 942SN/A 952SN/A // static: call reg_stats on all SimObjects 962SN/A static void regAllStats(); 972SN/A 98330SN/A // static: call resetStats on all SimObjects 99330SN/A static void resetAllStats(); 100330SN/A 101395SN/A // static: call nameOut() & serialize() on all SimObjects 102395SN/A static void serializeAll(std::ostream &); 103938SN/A 1042609SN/A // Methods to drain objects in order to take checkpoints 1052609SN/A // Or switch from timing -> atomic memory model 1062609SN/A virtual void drain(Serializer *serializer); 1072609SN/A virtual void resume() { return;} ; 1082609SN/A virtual void serializationComplete() 1092609SN/A { assert(0 && "Unimplemented"); }; 1102609SN/A 1111031SN/A#ifdef DEBUG 1121031SN/A public: 1131031SN/A bool doDebugBreak; 1141031SN/A static void debugObjectBreak(const std::string &objs); 1151031SN/A#endif 1161031SN/A 117938SN/A public: 118938SN/A bool doRecordEvent; 119938SN/A void recordEvent(const std::string &stat); 1202SN/A}; 1212SN/A 1222SN/A#endif // __SIM_OBJECT_HH__ 123