sim_object.hh revision 4762
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    SimObject(const std::string &_name);
882SN/A    virtual ~SimObject() {}
892SN/A
901553SN/A    virtual const std::string name() const { return params()->name; }
91265SN/A
921127SN/A    // initialization pass of all objects.
931127SN/A    // Gets invoked after construction, before unserialize.
94465SN/A    virtual void init();
95465SN/A    static void initAll();
96465SN/A
972SN/A    // register statistics for this object
982SN/A    virtual void regStats();
992SN/A    virtual void regFormulas();
100330SN/A    virtual void resetStats();
1012SN/A
1022SN/A    // static: call reg_stats on all SimObjects
1032SN/A    static void regAllStats();
1042SN/A
105330SN/A    // static: call resetStats on all SimObjects
106330SN/A    static void resetAllStats();
107330SN/A
108395SN/A    // static: call nameOut() & serialize() on all SimObjects
109395SN/A    static void serializeAll(std::ostream &);
1102797Sktlim@umich.edu    static void unserializeAll(Checkpoint *cp);
111938SN/A
1122609SN/A    // Methods to drain objects in order to take checkpoints
1132609SN/A    // Or switch from timing -> atomic memory model
1142901Ssaidi@eecs.umich.edu    // Drain returns 0 if the simobject can drain immediately or
1152901Ssaidi@eecs.umich.edu    // the number of times the drain_event's process function will be called
1162901Ssaidi@eecs.umich.edu    // before the object will be done draining. Normally this should be 1
1172901Ssaidi@eecs.umich.edu    virtual unsigned int drain(Event *drain_event);
1182797Sktlim@umich.edu    virtual void resume();
1192797Sktlim@umich.edu    virtual void setMemoryMode(State new_mode);
1202797Sktlim@umich.edu    virtual void switchOut();
1212797Sktlim@umich.edu    virtual void takeOverFrom(BaseCPU *cpu);
1222609SN/A
1231031SN/A#ifdef DEBUG
1241031SN/A  public:
1251031SN/A    bool doDebugBreak;
1261031SN/A    static void debugObjectBreak(const std::string &objs);
1271031SN/A#endif
1281031SN/A
129938SN/A  public:
130938SN/A    void recordEvent(const std::string &stat);
1312SN/A};
1322SN/A
1332SN/A#endif // __SIM_OBJECT_HH__
134