sim_object.hh revision 7532:3f6413fc37a2
12810SN/A/* 212724Snikos.nikoleris@arm.com * Copyright (c) 2001-2005 The Regents of The University of Michigan 38856Sandreas.hansson@arm.com * All rights reserved. 48856Sandreas.hansson@arm.com * 58856Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68856Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78856Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88856Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98856Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108856Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118856Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128856Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 138856Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 142810SN/A * this software without specific prior written permission. 152810SN/A * 162810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272810SN/A * 282810SN/A * Authors: Steve Reinhardt 292810SN/A * Nathan Binkert 302810SN/A */ 312810SN/A 322810SN/A/* @file 332810SN/A * User Console Definitions 342810SN/A */ 352810SN/A 362810SN/A#ifndef __SIM_OBJECT_HH__ 372810SN/A#define __SIM_OBJECT_HH__ 382810SN/A 392810SN/A#include <iostream> 402810SN/A#include <list> 414458SN/A#include <map> 424458SN/A#include <string> 4312724Snikos.nikoleris@arm.com#include <vector> 4412724Snikos.nikoleris@arm.com 452810SN/A#include "params/SimObject.hh" 462810SN/A#include "sim/eventq.hh" 472810SN/A#include "sim/serialize.hh" 482810SN/A 492810SN/Aclass BaseCPU; 502810SN/Aclass Event; 512810SN/A 5211051Sandreas.hansson@arm.com/* 5311051Sandreas.hansson@arm.com * Abstract superclass for simulation objects. Represents things that 542810SN/A * correspond to physical components and can be specified via the 5512724Snikos.nikoleris@arm.com * config file (CPUs, caches, etc.). 5612724Snikos.nikoleris@arm.com */ 577676Snate@binkert.orgclass SimObject : public EventManager, public Serializable 582810SN/A{ 5912724Snikos.nikoleris@arm.com public: 602810SN/A enum State { 612810SN/A Running, 626215Snate@binkert.org Draining, 638232Snate@binkert.org Drained 648232Snate@binkert.org }; 6512724Snikos.nikoleris@arm.com 6613223Sodanrc@yahoo.com.br private: 6713945Sodanrc@yahoo.com.br State state; 685338Sstever@gmail.com 6912724Snikos.nikoleris@arm.com protected: 7011375Sandreas.hansson@arm.com void changeState(State new_state) { state = new_state; } 7112724Snikos.nikoleris@arm.com 722810SN/A public: 7312724Snikos.nikoleris@arm.com State getState() { return state; } 748914Sandreas.hansson@arm.com 758229Snate@binkert.org private: 7613352Snikos.nikoleris@arm.com typedef std::vector<SimObject *> SimObjectList; 7713892Sgabeblack@google.com 782811SN/A // list of all instantiated simulation objects 7913416Sjavier.bueno@metempsy.com static SimObjectList simObjectList; 8012724Snikos.nikoleris@arm.com 814626SN/A protected: 828833Sdam.sunwoo@arm.com const SimObjectParams *_params; 832810SN/A 8412724Snikos.nikoleris@arm.com public: 8512724Snikos.nikoleris@arm.com typedef SimObjectParams Params; 8612724Snikos.nikoleris@arm.com const Params *params() const { return _params; } 8712724Snikos.nikoleris@arm.com SimObject(const Params *_params); 8812724Snikos.nikoleris@arm.com virtual ~SimObject() {} 8912724Snikos.nikoleris@arm.com 9012724Snikos.nikoleris@arm.com public: 9112724Snikos.nikoleris@arm.com 922810SN/A virtual const std::string name() const { return params()->name; } 932810SN/A 942810SN/A // The following SimObject initialization methods are called from 9513892Sgabeblack@google.com // the instantiate() method in src/python/m5/simulate.py. See 962810SN/A // that function for details on how/when these methods are 9711375Sandreas.hansson@arm.com // invoked. 984628SN/A 994628SN/A /** 1004628SN/A * init() is called after all C++ SimObjects have been created and 1014628SN/A * all ports are connected. Initializations that are independent 1024628SN/A * of unserialization but rely on a fully instantiated and 1034628SN/A * connected SimObject graph should be done here. 1044628SN/A */ 1054628SN/A virtual void init(); 1068737Skoansin.tan@gmail.com 1074628SN/A /** 1084628SN/A * loadState() is called on each SimObject when restoring from a 1094628SN/A * checkpoint. The default implementation simply calls 1104628SN/A * unserialize() if there is a corresponding section in the 1114628SN/A * checkpoint. However, objects can override loadState() to get 1124628SN/A * other behaviors, e.g., doing other programmed initializations 1134628SN/A * after unserialize(), or complaining if no checkpoint section is 1144628SN/A * found. 1154628SN/A */ 1164628SN/A virtual void loadState(Checkpoint *cp); 1178737Skoansin.tan@gmail.com 1184628SN/A /** 1198856Sandreas.hansson@arm.com * initState() is called on each SimObject when *not* restoring 1208856Sandreas.hansson@arm.com * from a checkpoint. This provides a hook for state 1218856Sandreas.hansson@arm.com * initializations that are only required for a "cold start". 1228856Sandreas.hansson@arm.com */ 1238856Sandreas.hansson@arm.com virtual void initState(); 12410942Sandreas.hansson@arm.com 1258856Sandreas.hansson@arm.com // register statistics for this object 1268856Sandreas.hansson@arm.com virtual void regStats(); 1278856Sandreas.hansson@arm.com virtual void regFormulas(); 1288922Swilliam.wang@arm.com virtual void resetStats(); 1292810SN/A 1308856Sandreas.hansson@arm.com /** 1312844SN/A * startup() is the final initialization call before simulation. 1328856Sandreas.hansson@arm.com * All state is initialized (including unserialized state, if any, 1338856Sandreas.hansson@arm.com * such as the curTick value), so this is the appropriate place to 1348856Sandreas.hansson@arm.com * schedule initial event(s) for objects that need them. 13510713Sandreas.hansson@arm.com */ 1368856Sandreas.hansson@arm.com virtual void startup(); 13710942Sandreas.hansson@arm.com 1388856Sandreas.hansson@arm.com // static: call nameOut() & serialize() on all SimObjects 13910942Sandreas.hansson@arm.com static void serializeAll(std::ostream &); 14010713Sandreas.hansson@arm.com static void unserializeAll(Checkpoint *cp); 1418856Sandreas.hansson@arm.com 1428856Sandreas.hansson@arm.com // Methods to drain objects in order to take checkpoints 1433738SN/A // Or switch from timing -> atomic memory model 1444458SN/A // Drain returns 0 if the simobject can drain immediately or 1458856Sandreas.hansson@arm.com // the number of times the drain_event's process function will be called 14610713Sandreas.hansson@arm.com // before the object will be done draining. Normally this should be 1 14710713Sandreas.hansson@arm.com virtual unsigned int drain(Event *drain_event); 14810713Sandreas.hansson@arm.com virtual void resume(); 1498914Sandreas.hansson@arm.com virtual void setMemoryMode(State new_mode); 1502810SN/A virtual void switchOut(); 1518856Sandreas.hansson@arm.com virtual void takeOverFrom(BaseCPU *cpu); 1528856Sandreas.hansson@arm.com 1538856Sandreas.hansson@arm.com#ifdef DEBUG 1548914Sandreas.hansson@arm.com public: 1558856Sandreas.hansson@arm.com bool doDebugBreak; 1568922Swilliam.wang@arm.com static void debugObjectBreak(const std::string &objs); 1578856Sandreas.hansson@arm.com#endif 1583013SN/A 1598856Sandreas.hansson@arm.com /** 16012724Snikos.nikoleris@arm.com * Find the SimObject with the given name and return a pointer to 16112724Snikos.nikoleris@arm.com * it. Primarily used for interactive debugging. Argument is 16212724Snikos.nikoleris@arm.com * char* rather than std::string to make it callable from gdb. 16312724Snikos.nikoleris@arm.com */ 16412724Snikos.nikoleris@arm.com static SimObject *find(const char *name); 16512724Snikos.nikoleris@arm.com}; 16612724Snikos.nikoleris@arm.com 16712724Snikos.nikoleris@arm.com#endif // __SIM_OBJECT_HH__ 16812724Snikos.nikoleris@arm.com