sim_object.hh revision 2499
12914Ssaidi@eecs.umich.edu/*
28856Sandreas.hansson@arm.com * Copyright (c) 2001-2005 The Regents of The University of Michigan
38856Sandreas.hansson@arm.com * All rights reserved.
48856Sandreas.hansson@arm.com *
58856Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
68856Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
78856Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
88856Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
98856Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
108856Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
118856Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
128856Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
138856Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from
142914Ssaidi@eecs.umich.edu * this software without specific prior written permission.
152914Ssaidi@eecs.umich.edu *
162914Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172914Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182914Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192914Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202914Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212914Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222914Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232914Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242914Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252914Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262914Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272914Ssaidi@eecs.umich.edu */
282914Ssaidi@eecs.umich.edu
292914Ssaidi@eecs.umich.edu/* @file
302914Ssaidi@eecs.umich.edu * User Console Definitions
312914Ssaidi@eecs.umich.edu */
322914Ssaidi@eecs.umich.edu
332914Ssaidi@eecs.umich.edu#ifndef __SIM_OBJECT_HH__
342914Ssaidi@eecs.umich.edu#define __SIM_OBJECT_HH__
352914Ssaidi@eecs.umich.edu
362914Ssaidi@eecs.umich.edu#include <map>
372914Ssaidi@eecs.umich.edu#include <list>
382914Ssaidi@eecs.umich.edu#include <vector>
392914Ssaidi@eecs.umich.edu#include <iostream>
402914Ssaidi@eecs.umich.edu
418856Sandreas.hansson@arm.com#include "sim/serialize.hh"
422914Ssaidi@eecs.umich.edu#include "sim/startup.hh"
432914Ssaidi@eecs.umich.edu
448708Sandreas.hansson@arm.com/*
452914Ssaidi@eecs.umich.edu * Abstract superclass for simulation objects.  Represents things that
462914Ssaidi@eecs.umich.edu * correspond to physical components and can be specified via the
478914Sandreas.hansson@arm.com * config file (CPUs, caches, etc.).
488914Sandreas.hansson@arm.com */
498922Swilliam.wang@arm.comclass SimObject : public Serializable, protected StartupCallback
505740Snate@binkert.org{
515740Snate@binkert.org  public:
525740Snate@binkert.org    struct Params {
534490Sstever@eecs.umich.edu        std::string name;
544490Sstever@eecs.umich.edu    };
554490Sstever@eecs.umich.edu
568914Sandreas.hansson@arm.com  protected:
578914Sandreas.hansson@arm.com    Params *_params;
583296Ssaidi@eecs.umich.edu
594929Sstever@gmail.com  public:
603091Sstever@eecs.umich.edu    const Params *params() const { return _params; }
613091Sstever@eecs.umich.edu
623091Sstever@eecs.umich.edu  private:
638975Sandreas.hansson@arm.com    friend class Serializer;
643091Sstever@eecs.umich.edu
659063SAli.Saidi@ARM.com    typedef std::vector<SimObject *> SimObjectList;
669063SAli.Saidi@ARM.com
679063SAli.Saidi@ARM.com    // list of all instantiated simulation objects
689063SAli.Saidi@ARM.com    static SimObjectList simObjectList;
699063SAli.Saidi@ARM.com
709063SAli.Saidi@ARM.com  public:
714670Sstever@eecs.umich.edu    SimObject(Params *_params);
724670Sstever@eecs.umich.edu    SimObject(const std::string &_name);
734670Sstever@eecs.umich.edu
744670Sstever@eecs.umich.edu    virtual ~SimObject() {}
754670Sstever@eecs.umich.edu
764670Sstever@eecs.umich.edu    virtual const std::string name() const { return params()->name; }
774670Sstever@eecs.umich.edu
784626Sstever@eecs.umich.edu    // initialization pass of all objects.
793091Sstever@eecs.umich.edu    // Gets invoked after construction, before unserialize.
803175Srdreslin@umich.edu    virtual void init();
814626Sstever@eecs.umich.edu    virtual void connect();
824670Sstever@eecs.umich.edu    static void initAll();
834670Sstever@eecs.umich.edu    static void connectAll();
844626Sstever@eecs.umich.edu
858914Sandreas.hansson@arm.com    // register statistics for this object
864626Sstever@eecs.umich.edu    virtual void regStats();
879063SAli.Saidi@ARM.com    virtual void regFormulas();
889063SAli.Saidi@ARM.com    virtual void resetStats();
899063SAli.Saidi@ARM.com
909063SAli.Saidi@ARM.com    // static: call reg_stats on all SimObjects
913309Srdreslin@umich.edu    static void regAllStats();
924670Sstever@eecs.umich.edu
933091Sstever@eecs.umich.edu    // static: call resetStats on all SimObjects
943091Sstever@eecs.umich.edu    static void resetAllStats();
95
96    // static: call nameOut() & serialize() on all SimObjects
97    static void serializeAll(std::ostream &);
98
99#ifdef DEBUG
100  public:
101    bool doDebugBreak;
102    static void debugObjectBreak(const std::string &objs);
103#endif
104
105  public:
106    bool doRecordEvent;
107    void recordEvent(const std::string &stat);
108};
109
110#endif // __SIM_OBJECT_HH__
111