sim_object.hh revision 7492
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
395491Sgblack@eecs.umich.edu#include <iostream>
405491Sgblack@eecs.umich.edu#include <list>
412SN/A#include <map>
425491Sgblack@eecs.umich.edu#include <string>
432SN/A#include <vector>
442SN/A
454762Snate@binkert.org#include "params/SimObject.hh"
465605Snate@binkert.org#include "sim/eventq.hh"
4756SN/A#include "sim/serialize.hh"
482SN/A
492797Sktlim@umich.educlass BaseCPU;
502797Sktlim@umich.educlass Event;
512609SN/A
522SN/A/*
532SN/A * Abstract superclass for simulation objects.  Represents things that
542SN/A * correspond to physical components and can be specified via the
552SN/A * config file (CPUs, caches, etc.).
562SN/A */
577492Ssteve.reinhardt@amd.comclass SimObject : public EventManager, public Serializable
582SN/A{
591553SN/A  public:
602797Sktlim@umich.edu    enum State {
612901Ssaidi@eecs.umich.edu        Running,
622839Sktlim@umich.edu        Draining,
632901Ssaidi@eecs.umich.edu        Drained
642797Sktlim@umich.edu    };
653202Shsul@eecs.umich.edu
662901Ssaidi@eecs.umich.edu  private:
672901Ssaidi@eecs.umich.edu    State state;
682797Sktlim@umich.edu
69265SN/A  protected:
702797Sktlim@umich.edu    void changeState(State new_state) { state = new_state; }
711553SN/A
721553SN/A  public:
732797Sktlim@umich.edu    State getState() { return state; }
742797Sktlim@umich.edu
752SN/A  private:
762SN/A    typedef std::vector<SimObject *> SimObjectList;
772SN/A
782SN/A    // list of all instantiated simulation objects
792SN/A    static SimObjectList simObjectList;
802SN/A
814762Snate@binkert.org  protected:
824762Snate@binkert.org    const SimObjectParams *_params;
834762Snate@binkert.org
842SN/A  public:
854762Snate@binkert.org    typedef SimObjectParams Params;
864762Snate@binkert.org    const Params *params() const { return _params; }
874762Snate@binkert.org    SimObject(const Params *_params);
882SN/A    virtual ~SimObject() {}
892SN/A
905034Smilesck@eecs.umich.edu  public:
915034Smilesck@eecs.umich.edu
921553SN/A    virtual const std::string name() const { return params()->name; }
93265SN/A
941127SN/A    // initialization pass of all objects.
951127SN/A    // Gets invoked after construction, before unserialize.
96465SN/A    virtual void init();
97465SN/A    static void initAll();
98465SN/A
992SN/A    // register statistics for this object
1002SN/A    virtual void regStats();
1012SN/A    virtual void regFormulas();
102330SN/A    virtual void resetStats();
1032SN/A
1047492Ssteve.reinhardt@amd.com    // final initialization before simulation
1057492Ssteve.reinhardt@amd.com    // all state is unserialized so
1067492Ssteve.reinhardt@amd.com    virtual void startup();
1077492Ssteve.reinhardt@amd.com    static void startupAll();
1087492Ssteve.reinhardt@amd.com
1092SN/A    // static: call reg_stats on all SimObjects
1102SN/A    static void regAllStats();
1112SN/A
112330SN/A    // static: call resetStats on all SimObjects
113330SN/A    static void resetAllStats();
114330SN/A
115395SN/A    // static: call nameOut() & serialize() on all SimObjects
116395SN/A    static void serializeAll(std::ostream &);
1172797Sktlim@umich.edu    static void unserializeAll(Checkpoint *cp);
118938SN/A
1192609SN/A    // Methods to drain objects in order to take checkpoints
1202609SN/A    // Or switch from timing -> atomic memory model
1212901Ssaidi@eecs.umich.edu    // Drain returns 0 if the simobject can drain immediately or
1222901Ssaidi@eecs.umich.edu    // the number of times the drain_event's process function will be called
1232901Ssaidi@eecs.umich.edu    // before the object will be done draining. Normally this should be 1
1242901Ssaidi@eecs.umich.edu    virtual unsigned int drain(Event *drain_event);
1252797Sktlim@umich.edu    virtual void resume();
1262797Sktlim@umich.edu    virtual void setMemoryMode(State new_mode);
1272797Sktlim@umich.edu    virtual void switchOut();
1282797Sktlim@umich.edu    virtual void takeOverFrom(BaseCPU *cpu);
1292609SN/A
1301031SN/A#ifdef DEBUG
1311031SN/A  public:
1321031SN/A    bool doDebugBreak;
1331031SN/A    static void debugObjectBreak(const std::string &objs);
1341031SN/A#endif
1351031SN/A
1365314Sstever@gmail.com    /**
1375314Sstever@gmail.com     * Find the SimObject with the given name and return a pointer to
1385315Sstever@gmail.com     * it.  Primarily used for interactive debugging.  Argument is
1395314Sstever@gmail.com     * char* rather than std::string to make it callable from gdb.
1405314Sstever@gmail.com     */
1415314Sstever@gmail.com    static SimObject *find(const char *name);
1422SN/A};
1432SN/A
1442SN/A#endif // __SIM_OBJECT_HH__
145