sim_object.hh revision 5315
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 444762Snate@binkert.org#include "params/SimObject.hh" 4556SN/A#include "sim/serialize.hh" 461127SN/A#include "sim/startup.hh" 472SN/A 482797Sktlim@umich.educlass BaseCPU; 492797Sktlim@umich.educlass Event; 502609SN/A 512SN/A/* 522SN/A * Abstract superclass for simulation objects. Represents things that 532SN/A * correspond to physical components and can be specified via the 542SN/A * config file (CPUs, caches, etc.). 552SN/A */ 561127SN/Aclass SimObject : public Serializable, protected StartupCallback 572SN/A{ 581553SN/A public: 592797Sktlim@umich.edu enum State { 602901Ssaidi@eecs.umich.edu Running, 612839Sktlim@umich.edu Draining, 622901Ssaidi@eecs.umich.edu Drained 632797Sktlim@umich.edu }; 643202Shsul@eecs.umich.edu 652901Ssaidi@eecs.umich.edu private: 662901Ssaidi@eecs.umich.edu State state; 672797Sktlim@umich.edu 68265SN/A protected: 692797Sktlim@umich.edu void changeState(State new_state) { state = new_state; } 701553SN/A 711553SN/A public: 722797Sktlim@umich.edu State getState() { return state; } 732797Sktlim@umich.edu 742SN/A private: 752SN/A typedef std::vector<SimObject *> SimObjectList; 762SN/A 772SN/A // list of all instantiated simulation objects 782SN/A static SimObjectList simObjectList; 792SN/A 804762Snate@binkert.org protected: 814762Snate@binkert.org const SimObjectParams *_params; 824762Snate@binkert.org 832SN/A public: 844762Snate@binkert.org typedef SimObjectParams Params; 854762Snate@binkert.org const Params *params() const { return _params; } 864762Snate@binkert.org SimObject(const Params *_params); 872SN/A virtual ~SimObject() {} 882SN/A 895034Smilesck@eecs.umich.edu protected: 905034Smilesck@eecs.umich.edu // static: support for old-style constructors (call manually) 915034Smilesck@eecs.umich.edu static Params *makeParams(const std::string &name); 925034Smilesck@eecs.umich.edu 935034Smilesck@eecs.umich.edu public: 945034Smilesck@eecs.umich.edu 951553SN/A virtual const std::string name() const { return params()->name; } 96265SN/A 971127SN/A // initialization pass of all objects. 981127SN/A // Gets invoked after construction, before unserialize. 99465SN/A virtual void init(); 100465SN/A static void initAll(); 101465SN/A 1022SN/A // register statistics for this object 1032SN/A virtual void regStats(); 1042SN/A virtual void regFormulas(); 105330SN/A virtual void resetStats(); 1062SN/A 1072SN/A // static: call reg_stats on all SimObjects 1082SN/A static void regAllStats(); 1092SN/A 110330SN/A // static: call resetStats on all SimObjects 111330SN/A static void resetAllStats(); 112330SN/A 113395SN/A // static: call nameOut() & serialize() on all SimObjects 114395SN/A static void serializeAll(std::ostream &); 1152797Sktlim@umich.edu static void unserializeAll(Checkpoint *cp); 116938SN/A 1172609SN/A // Methods to drain objects in order to take checkpoints 1182609SN/A // Or switch from timing -> atomic memory model 1192901Ssaidi@eecs.umich.edu // Drain returns 0 if the simobject can drain immediately or 1202901Ssaidi@eecs.umich.edu // the number of times the drain_event's process function will be called 1212901Ssaidi@eecs.umich.edu // before the object will be done draining. Normally this should be 1 1222901Ssaidi@eecs.umich.edu virtual unsigned int drain(Event *drain_event); 1232797Sktlim@umich.edu virtual void resume(); 1242797Sktlim@umich.edu virtual void setMemoryMode(State new_mode); 1252797Sktlim@umich.edu virtual void switchOut(); 1262797Sktlim@umich.edu virtual void takeOverFrom(BaseCPU *cpu); 1272609SN/A 1281031SN/A#ifdef DEBUG 1291031SN/A public: 1301031SN/A bool doDebugBreak; 1311031SN/A static void debugObjectBreak(const std::string &objs); 1321031SN/A#endif 1331031SN/A 1345314Sstever@gmail.com /** 1355314Sstever@gmail.com * Find the SimObject with the given name and return a pointer to 1365315Sstever@gmail.com * it. Primarily used for interactive debugging. Argument is 1375314Sstever@gmail.com * char* rather than std::string to make it callable from gdb. 1385314Sstever@gmail.com */ 1395314Sstever@gmail.com static SimObject *find(const char *name); 1405314Sstever@gmail.com 141938SN/A public: 142938SN/A void recordEvent(const std::string &stat); 1432SN/A}; 1442SN/A 1452SN/A#endif // __SIM_OBJECT_HH__ 146