sim_object.hh revision 8737
12SN/A/* 21762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan 37534Ssteve.reinhardt@amd.com * Copyright (c) 2010 Advanced Micro Devices, Inc. 42SN/A * All rights reserved. 52SN/A * 62SN/A * Redistribution and use in source and binary forms, with or without 72SN/A * modification, are permitted provided that the following conditions are 82SN/A * met: redistributions of source code must retain the above copyright 92SN/A * notice, this list of conditions and the following disclaimer; 102SN/A * redistributions in binary form must reproduce the above copyright 112SN/A * notice, this list of conditions and the following disclaimer in the 122SN/A * documentation and/or other materials provided with the distribution; 132SN/A * neither the name of the copyright holders nor the names of its 142SN/A * contributors may be used to endorse or promote products derived from 152SN/A * this software without specific prior written permission. 162SN/A * 172SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 182SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 192SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 202SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 212SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 222SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 232SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 242SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 252SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 262SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 272SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu * 292665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 302665Ssaidi@eecs.umich.edu * Nathan Binkert 312SN/A */ 322SN/A 332SN/A/* @file 342SN/A * User Console Definitions 352SN/A */ 362SN/A 372SN/A#ifndef __SIM_OBJECT_HH__ 382SN/A#define __SIM_OBJECT_HH__ 392SN/A 405491Sgblack@eecs.umich.edu#include <iostream> 415491Sgblack@eecs.umich.edu#include <list> 422SN/A#include <map> 435491Sgblack@eecs.umich.edu#include <string> 442SN/A#include <vector> 452SN/A 468737Skoansin.tan@gmail.com#include "enums/MemoryMode.hh" 474762Snate@binkert.org#include "params/SimObject.hh" 485605Snate@binkert.org#include "sim/eventq.hh" 4956SN/A#include "sim/serialize.hh" 502SN/A 512797Sktlim@umich.educlass BaseCPU; 522797Sktlim@umich.educlass Event; 532609SN/A 542SN/A/* 552SN/A * Abstract superclass for simulation objects. Represents things that 562SN/A * correspond to physical components and can be specified via the 572SN/A * config file (CPUs, caches, etc.). 582SN/A */ 597492Ssteve.reinhardt@amd.comclass SimObject : public EventManager, public Serializable 602SN/A{ 611553SN/A public: 622797Sktlim@umich.edu enum State { 632901Ssaidi@eecs.umich.edu Running, 642839Sktlim@umich.edu Draining, 652901Ssaidi@eecs.umich.edu Drained 662797Sktlim@umich.edu }; 673202Shsul@eecs.umich.edu 682901Ssaidi@eecs.umich.edu private: 692901Ssaidi@eecs.umich.edu State state; 702797Sktlim@umich.edu 71265SN/A protected: 722797Sktlim@umich.edu void changeState(State new_state) { state = new_state; } 731553SN/A 741553SN/A public: 752797Sktlim@umich.edu State getState() { return state; } 762797Sktlim@umich.edu 772SN/A private: 782SN/A typedef std::vector<SimObject *> SimObjectList; 792SN/A 802SN/A // list of all instantiated simulation objects 812SN/A static SimObjectList simObjectList; 822SN/A 834762Snate@binkert.org protected: 844762Snate@binkert.org const SimObjectParams *_params; 854762Snate@binkert.org 862SN/A public: 874762Snate@binkert.org typedef SimObjectParams Params; 884762Snate@binkert.org const Params *params() const { return _params; } 894762Snate@binkert.org SimObject(const Params *_params); 902SN/A virtual ~SimObject() {} 912SN/A 925034Smilesck@eecs.umich.edu public: 935034Smilesck@eecs.umich.edu 941553SN/A virtual const std::string name() const { return params()->name; } 95265SN/A 967532Ssteve.reinhardt@amd.com // The following SimObject initialization methods are called from 977532Ssteve.reinhardt@amd.com // the instantiate() method in src/python/m5/simulate.py. See 987532Ssteve.reinhardt@amd.com // that function for details on how/when these methods are 997532Ssteve.reinhardt@amd.com // invoked. 1007532Ssteve.reinhardt@amd.com 1017532Ssteve.reinhardt@amd.com /** 1027532Ssteve.reinhardt@amd.com * init() is called after all C++ SimObjects have been created and 1037532Ssteve.reinhardt@amd.com * all ports are connected. Initializations that are independent 1047532Ssteve.reinhardt@amd.com * of unserialization but rely on a fully instantiated and 1057532Ssteve.reinhardt@amd.com * connected SimObject graph should be done here. 1067532Ssteve.reinhardt@amd.com */ 107465SN/A virtual void init(); 108465SN/A 1097532Ssteve.reinhardt@amd.com /** 1107532Ssteve.reinhardt@amd.com * loadState() is called on each SimObject when restoring from a 1117532Ssteve.reinhardt@amd.com * checkpoint. The default implementation simply calls 1127532Ssteve.reinhardt@amd.com * unserialize() if there is a corresponding section in the 1137532Ssteve.reinhardt@amd.com * checkpoint. However, objects can override loadState() to get 1147532Ssteve.reinhardt@amd.com * other behaviors, e.g., doing other programmed initializations 1157532Ssteve.reinhardt@amd.com * after unserialize(), or complaining if no checkpoint section is 1167532Ssteve.reinhardt@amd.com * found. 1177532Ssteve.reinhardt@amd.com */ 1187532Ssteve.reinhardt@amd.com virtual void loadState(Checkpoint *cp); 1197532Ssteve.reinhardt@amd.com 1207532Ssteve.reinhardt@amd.com /** 1217532Ssteve.reinhardt@amd.com * initState() is called on each SimObject when *not* restoring 1227532Ssteve.reinhardt@amd.com * from a checkpoint. This provides a hook for state 1237532Ssteve.reinhardt@amd.com * initializations that are only required for a "cold start". 1247532Ssteve.reinhardt@amd.com */ 1257532Ssteve.reinhardt@amd.com virtual void initState(); 1267532Ssteve.reinhardt@amd.com 1272SN/A // register statistics for this object 1282SN/A virtual void regStats(); 1292SN/A virtual void regFormulas(); 130330SN/A virtual void resetStats(); 1312SN/A 1327532Ssteve.reinhardt@amd.com /** 1337532Ssteve.reinhardt@amd.com * startup() is the final initialization call before simulation. 1347532Ssteve.reinhardt@amd.com * All state is initialized (including unserialized state, if any, 1357823Ssteve.reinhardt@amd.com * such as the curTick() value), so this is the appropriate place to 1367532Ssteve.reinhardt@amd.com * schedule initial event(s) for objects that need them. 1377532Ssteve.reinhardt@amd.com */ 1387492Ssteve.reinhardt@amd.com virtual void startup(); 139330SN/A 140395SN/A // static: call nameOut() & serialize() on all SimObjects 141395SN/A static void serializeAll(std::ostream &); 142938SN/A 1432609SN/A // Methods to drain objects in order to take checkpoints 1442609SN/A // Or switch from timing -> atomic memory model 1452901Ssaidi@eecs.umich.edu // Drain returns 0 if the simobject can drain immediately or 1462901Ssaidi@eecs.umich.edu // the number of times the drain_event's process function will be called 1472901Ssaidi@eecs.umich.edu // before the object will be done draining. Normally this should be 1 1482901Ssaidi@eecs.umich.edu virtual unsigned int drain(Event *drain_event); 1492797Sktlim@umich.edu virtual void resume(); 1508737Skoansin.tan@gmail.com virtual void setMemoryMode(Enums::MemoryMode new_mode); 1512797Sktlim@umich.edu virtual void switchOut(); 1522797Sktlim@umich.edu virtual void takeOverFrom(BaseCPU *cpu); 1532609SN/A 1541031SN/A#ifdef DEBUG 1551031SN/A public: 1561031SN/A bool doDebugBreak; 1571031SN/A static void debugObjectBreak(const std::string &objs); 1581031SN/A#endif 1591031SN/A 1605314Sstever@gmail.com /** 1615314Sstever@gmail.com * Find the SimObject with the given name and return a pointer to 1625315Sstever@gmail.com * it. Primarily used for interactive debugging. Argument is 1635314Sstever@gmail.com * char* rather than std::string to make it callable from gdb. 1645314Sstever@gmail.com */ 1655314Sstever@gmail.com static SimObject *find(const char *name); 1662SN/A}; 1672SN/A 1682SN/A#endif // __SIM_OBJECT_HH__ 169