sim_object.hh revision 3202
12623SN/A/*
22623SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
32623SN/A * All rights reserved.
42623SN/A *
52623SN/A * Redistribution and use in source and binary forms, with or without
62623SN/A * modification, are permitted provided that the following conditions are
72623SN/A * met: redistributions of source code must retain the above copyright
82623SN/A * notice, this list of conditions and the following disclaimer;
92623SN/A * redistributions in binary form must reproduce the above copyright
102623SN/A * notice, this list of conditions and the following disclaimer in the
112623SN/A * documentation and/or other materials provided with the distribution;
122623SN/A * neither the name of the copyright holders nor the names of its
132623SN/A * contributors may be used to endorse or promote products derived from
142623SN/A * this software without specific prior written permission.
152623SN/A *
162623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
292623SN/A *          Nathan Binkert
302623SN/A */
312623SN/A
322623SN/A/* @file
332623SN/A * User Console Definitions
342623SN/A */
352623SN/A
362623SN/A#ifndef __SIM_OBJECT_HH__
372623SN/A#define __SIM_OBJECT_HH__
382623SN/A
392623SN/A#include <map>
402623SN/A#include <list>
412623SN/A#include <vector>
422623SN/A#include <iostream>
432623SN/A
442623SN/A#include "sim/serialize.hh"
452623SN/A#include "sim/startup.hh"
462623SN/A
472623SN/Aclass BaseCPU;
482623SN/Aclass Event;
492623SN/A
502623SN/A/*
512623SN/A * Abstract superclass for simulation objects.  Represents things that
522623SN/A * correspond to physical components and can be specified via the
532623SN/A * config file (CPUs, caches, etc.).
542623SN/A */
552680Sktlim@umich.educlass SimObject : public Serializable, protected StartupCallback
562680Sktlim@umich.edu{
572623SN/A  public:
582623SN/A    struct Params {
592680Sktlim@umich.edu        std::string name;
602623SN/A    };
612623SN/A
622623SN/A    enum State {
632623SN/A        Running,
642623SN/A        Draining,
652630SN/A        Drained
662623SN/A    };
672623SN/A
682623SN/A    enum MemoryMode {
692623SN/A        Invalid=0,
702623SN/A        Atomic,
712623SN/A        Timing
722630SN/A    };
732623SN/A
742623SN/A  private:
752623SN/A    State state;
762623SN/A
772623SN/A  protected:
782623SN/A    Params *_params;
792623SN/A
802631SN/A    void changeState(State new_state) { state = new_state; }
812631SN/A
822631SN/A  public:
832623SN/A    const Params *params() const { return _params; }
842623SN/A
852623SN/A    State getState() { return state; }
862623SN/A
872623SN/A  private:
882623SN/A    typedef std::vector<SimObject *> SimObjectList;
892623SN/A
902623SN/A    // list of all instantiated simulation objects
912839Sktlim@umich.edu    static SimObjectList simObjectList;
922798Sktlim@umich.edu
932623SN/A  public:
942623SN/A    SimObject(Params *_params);
952623SN/A    SimObject(const std::string &_name);
962623SN/A
972623SN/A    virtual ~SimObject() {}
982623SN/A
992623SN/A    virtual const std::string name() const { return params()->name; }
1002623SN/A
1012623SN/A    // initialization pass of all objects.
1022623SN/A    // Gets invoked after construction, before unserialize.
1032798Sktlim@umich.edu    virtual void init();
1042623SN/A    virtual void connect();
1052623SN/A    static void initAll();
1062623SN/A    static void connectAll();
1072623SN/A
1082623SN/A    // register statistics for this object
1092623SN/A    virtual void regStats();
1102798Sktlim@umich.edu    virtual void regFormulas();
1112623SN/A    virtual void resetStats();
1122798Sktlim@umich.edu
1132798Sktlim@umich.edu    // static: call reg_stats on all SimObjects
1142798Sktlim@umich.edu    static void regAllStats();
1152839Sktlim@umich.edu
1162798Sktlim@umich.edu    // static: call resetStats on all SimObjects
1172839Sktlim@umich.edu    static void resetAllStats();
1182798Sktlim@umich.edu
1192798Sktlim@umich.edu    // static: call nameOut() & serialize() on all SimObjects
1202839Sktlim@umich.edu    static void serializeAll(std::ostream &);
1212798Sktlim@umich.edu    static void unserializeAll(Checkpoint *cp);
1222798Sktlim@umich.edu
1232839Sktlim@umich.edu    // Methods to drain objects in order to take checkpoints
1242839Sktlim@umich.edu    // Or switch from timing -> atomic memory model
1252798Sktlim@umich.edu    // Drain returns 0 if the simobject can drain immediately or
1262798Sktlim@umich.edu    // the number of times the drain_event's process function will be called
1272623SN/A    // before the object will be done draining. Normally this should be 1
1282623SN/A    virtual unsigned int drain(Event *drain_event);
1292623SN/A    virtual void resume();
1302798Sktlim@umich.edu    virtual void setMemoryMode(State new_mode);
1312623SN/A    virtual void switchOut();
1322798Sktlim@umich.edu    virtual void takeOverFrom(BaseCPU *cpu);
1332798Sktlim@umich.edu
1342798Sktlim@umich.edu#ifdef DEBUG
1352798Sktlim@umich.edu  public:
1362623SN/A    bool doDebugBreak;
1372798Sktlim@umich.edu    static void debugObjectBreak(const std::string &objs);
1382798Sktlim@umich.edu#endif
1392798Sktlim@umich.edu
1402798Sktlim@umich.edu  public:
1412798Sktlim@umich.edu    bool doRecordEvent;
1422798Sktlim@umich.edu    void recordEvent(const std::string &stat);
1432798Sktlim@umich.edu};
1442798Sktlim@umich.edu
1452798Sktlim@umich.edu#endif // __SIM_OBJECT_HH__
1462798Sktlim@umich.edu