1/* 2 * Copyright (c) 2001-2005 The Regents of The University of Michigan 3 * Copyright (c) 2010 Advanced Micro Devices, Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * Authors: Steve Reinhardt 30 * Nathan Binkert 31 */ 32 33/* @file 34 * User Console Definitions 35 */ 36 37#ifndef __SIM_OBJECT_HH__ 38#define __SIM_OBJECT_HH__ 39 40#include <iostream> 41#include <list> 42#include <map> 43#include <string> 44#include <vector> 45 46#include "params/SimObject.hh" 47#include "sim/eventq.hh" 48#include "sim/serialize.hh" 49 50class BaseCPU; 51class Event; 52 53/* 54 * Abstract superclass for simulation objects. Represents things that 55 * correspond to physical components and can be specified via the 56 * config file (CPUs, caches, etc.). 57 */ 58class SimObject : public EventManager, public Serializable 59{ 60 public: 61 enum State { 62 Running, 63 Draining, 64 Drained 65 }; 66 67 private: 68 State state; 69 70 protected: 71 void changeState(State new_state) { state = new_state; } 72 73 public: 74 State getState() { return state; } 75 76 private: 77 typedef std::vector<SimObject *> SimObjectList; 78 79 // list of all instantiated simulation objects 80 static SimObjectList simObjectList; 81 82 protected: 83 const SimObjectParams *_params; 84 85 public: 86 typedef SimObjectParams Params; 87 const Params *params() const { return _params; } 88 SimObject(const Params *_params); 89 virtual ~SimObject() {} 90 91 public: 92 93 virtual const std::string name() const { return params()->name; } 94 95 // The following SimObject initialization methods are called from 96 // the instantiate() method in src/python/m5/simulate.py. See 97 // that function for details on how/when these methods are 98 // invoked. 99 100 /** 101 * init() is called after all C++ SimObjects have been created and 102 * all ports are connected. Initializations that are independent 103 * of unserialization but rely on a fully instantiated and 104 * connected SimObject graph should be done here. 105 */ 106 virtual void init(); 107 108 /** 109 * loadState() is called on each SimObject when restoring from a 110 * checkpoint. The default implementation simply calls 111 * unserialize() if there is a corresponding section in the 112 * checkpoint. However, objects can override loadState() to get 113 * other behaviors, e.g., doing other programmed initializations 114 * after unserialize(), or complaining if no checkpoint section is 115 * found. 116 */ 117 virtual void loadState(Checkpoint *cp); 118 119 /** 120 * initState() is called on each SimObject when *not* restoring 121 * from a checkpoint. This provides a hook for state 122 * initializations that are only required for a "cold start". 123 */ 124 virtual void initState(); 125 126 // register statistics for this object 127 virtual void regStats(); 128 virtual void regFormulas(); 129 virtual void resetStats(); 130 131 /** 132 * startup() is the final initialization call before simulation. 133 * All state is initialized (including unserialized state, if any,
|