sim_object.hh revision 3202
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 472797Sktlim@umich.educlass BaseCPU; 482797Sktlim@umich.educlass Event; 492609SN/A 502SN/A/* 512SN/A * Abstract superclass for simulation objects. Represents things that 522SN/A * correspond to physical components and can be specified via the 532SN/A * config file (CPUs, caches, etc.). 542SN/A */ 551127SN/Aclass SimObject : public Serializable, protected StartupCallback 562SN/A{ 571553SN/A public: 581553SN/A struct Params { 591553SN/A std::string name; 601553SN/A }; 611553SN/A 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 683202Shsul@eecs.umich.edu enum MemoryMode { 693202Shsul@eecs.umich.edu Invalid=0, 703202Shsul@eecs.umich.edu Atomic, 713202Shsul@eecs.umich.edu Timing 723202Shsul@eecs.umich.edu }; 733202Shsul@eecs.umich.edu 742901Ssaidi@eecs.umich.edu private: 752901Ssaidi@eecs.umich.edu State state; 762797Sktlim@umich.edu 77265SN/A protected: 781553SN/A Params *_params; 792797Sktlim@umich.edu 802797Sktlim@umich.edu void changeState(State new_state) { state = new_state; } 811553SN/A 821553SN/A public: 831553SN/A const Params *params() const { return _params; } 84265SN/A 852797Sktlim@umich.edu State getState() { return state; } 862797Sktlim@umich.edu 872SN/A private: 882SN/A typedef std::vector<SimObject *> SimObjectList; 892SN/A 902SN/A // list of all instantiated simulation objects 912SN/A static SimObjectList simObjectList; 922SN/A 932SN/A public: 941553SN/A SimObject(Params *_params); 952SN/A SimObject(const std::string &_name); 962SN/A 972SN/A virtual ~SimObject() {} 982SN/A 991553SN/A virtual const std::string name() const { return params()->name; } 100265SN/A 1011127SN/A // initialization pass of all objects. 1021127SN/A // Gets invoked after construction, before unserialize. 103465SN/A virtual void init(); 1042499SN/A virtual void connect(); 105465SN/A static void initAll(); 1062499SN/A static void connectAll(); 107465SN/A 1082SN/A // register statistics for this object 1092SN/A virtual void regStats(); 1102SN/A virtual void regFormulas(); 111330SN/A virtual void resetStats(); 1122SN/A 1132SN/A // static: call reg_stats on all SimObjects 1142SN/A static void regAllStats(); 1152SN/A 116330SN/A // static: call resetStats on all SimObjects 117330SN/A static void resetAllStats(); 118330SN/A 119395SN/A // static: call nameOut() & serialize() on all SimObjects 120395SN/A static void serializeAll(std::ostream &); 1212797Sktlim@umich.edu static void unserializeAll(Checkpoint *cp); 122938SN/A 1232609SN/A // Methods to drain objects in order to take checkpoints 1242609SN/A // Or switch from timing -> atomic memory model 1252901Ssaidi@eecs.umich.edu // Drain returns 0 if the simobject can drain immediately or 1262901Ssaidi@eecs.umich.edu // the number of times the drain_event's process function will be called 1272901Ssaidi@eecs.umich.edu // before the object will be done draining. Normally this should be 1 1282901Ssaidi@eecs.umich.edu virtual unsigned int drain(Event *drain_event); 1292797Sktlim@umich.edu virtual void resume(); 1302797Sktlim@umich.edu virtual void setMemoryMode(State new_mode); 1312797Sktlim@umich.edu virtual void switchOut(); 1322797Sktlim@umich.edu virtual void takeOverFrom(BaseCPU *cpu); 1332609SN/A 1341031SN/A#ifdef DEBUG 1351031SN/A public: 1361031SN/A bool doDebugBreak; 1371031SN/A static void debugObjectBreak(const std::string &objs); 1381031SN/A#endif 1391031SN/A 140938SN/A public: 141938SN/A bool doRecordEvent; 142938SN/A void recordEvent(const std::string &stat); 1432SN/A}; 1442SN/A 1452SN/A#endif // __SIM_OBJECT_HH__ 146