sim_object.hh revision 1553
110259SAndrew.Bardsley@arm.com/*
210259SAndrew.Bardsley@arm.com * Copyright (c) 2001-2004 The Regents of The University of Michigan
310259SAndrew.Bardsley@arm.com * All rights reserved.
410259SAndrew.Bardsley@arm.com *
510259SAndrew.Bardsley@arm.com * Redistribution and use in source and binary forms, with or without
610259SAndrew.Bardsley@arm.com * modification, are permitted provided that the following conditions are
710259SAndrew.Bardsley@arm.com * met: redistributions of source code must retain the above copyright
810259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer;
910259SAndrew.Bardsley@arm.com * redistributions in binary form must reproduce the above copyright
1010259SAndrew.Bardsley@arm.com * notice, this list of conditions and the following disclaimer in the
1110259SAndrew.Bardsley@arm.com * documentation and/or other materials provided with the distribution;
1210259SAndrew.Bardsley@arm.com * neither the name of the copyright holders nor the names of its
1310259SAndrew.Bardsley@arm.com * contributors may be used to endorse or promote products derived from
1410259SAndrew.Bardsley@arm.com * this software without specific prior written permission.
1510259SAndrew.Bardsley@arm.com *
1610259SAndrew.Bardsley@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1710259SAndrew.Bardsley@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1810259SAndrew.Bardsley@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1910259SAndrew.Bardsley@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2010259SAndrew.Bardsley@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2110259SAndrew.Bardsley@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2210259SAndrew.Bardsley@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2310259SAndrew.Bardsley@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2410259SAndrew.Bardsley@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2510259SAndrew.Bardsley@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2610259SAndrew.Bardsley@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2710259SAndrew.Bardsley@arm.com */
2810259SAndrew.Bardsley@arm.com
2910259SAndrew.Bardsley@arm.com/* @file
3010259SAndrew.Bardsley@arm.com * User Console Definitions
3110259SAndrew.Bardsley@arm.com */
3210259SAndrew.Bardsley@arm.com
3310259SAndrew.Bardsley@arm.com#ifndef __SIM_OBJECT_HH__
3410259SAndrew.Bardsley@arm.com#define __SIM_OBJECT_HH__
3510259SAndrew.Bardsley@arm.com
3610259SAndrew.Bardsley@arm.com#include <map>
3710259SAndrew.Bardsley@arm.com#include <list>
3810259SAndrew.Bardsley@arm.com#include <vector>
3910259SAndrew.Bardsley@arm.com#include <iostream>
4010259SAndrew.Bardsley@arm.com
4110259SAndrew.Bardsley@arm.com#include "sim/serialize.hh"
4211800Sbrandon.potter@amd.com#include "sim/startup.hh"
4311800Sbrandon.potter@amd.com
4411800Sbrandon.potter@amd.com/*
4510259SAndrew.Bardsley@arm.com * Abstract superclass for simulation objects.  Represents things that
4610259SAndrew.Bardsley@arm.com * correspond to physical components and can be specified via the
4710259SAndrew.Bardsley@arm.com * config file (CPUs, caches, etc.).
4810259SAndrew.Bardsley@arm.com */
4910259SAndrew.Bardsley@arm.comclass SimObject : public Serializable, protected StartupCallback
5010259SAndrew.Bardsley@arm.com{
5110259SAndrew.Bardsley@arm.com  public:
5210259SAndrew.Bardsley@arm.com    struct Params {
5310259SAndrew.Bardsley@arm.com        std::string name;
5410259SAndrew.Bardsley@arm.com    };
5510259SAndrew.Bardsley@arm.com
5610259SAndrew.Bardsley@arm.com  protected:
5710259SAndrew.Bardsley@arm.com    Params *_params;
5810259SAndrew.Bardsley@arm.com
5910259SAndrew.Bardsley@arm.com  public:
6010259SAndrew.Bardsley@arm.com    const Params *params() const { return _params; }
6110259SAndrew.Bardsley@arm.com
6210259SAndrew.Bardsley@arm.com  private:
6310259SAndrew.Bardsley@arm.com    friend class Serializer;
6410259SAndrew.Bardsley@arm.com
6510259SAndrew.Bardsley@arm.com    typedef std::vector<SimObject *> SimObjectList;
6610259SAndrew.Bardsley@arm.com
6710259SAndrew.Bardsley@arm.com    // list of all instantiated simulation objects
6810259SAndrew.Bardsley@arm.com    static SimObjectList simObjectList;
6910259SAndrew.Bardsley@arm.com
7010259SAndrew.Bardsley@arm.com  public:
7110259SAndrew.Bardsley@arm.com    SimObject(Params *_params);
7210259SAndrew.Bardsley@arm.com    SimObject(const std::string &_name);
7310259SAndrew.Bardsley@arm.com
7410259SAndrew.Bardsley@arm.com    virtual ~SimObject() {}
7510259SAndrew.Bardsley@arm.com
7610259SAndrew.Bardsley@arm.com    virtual const std::string name() const { return params()->name; }
7710259SAndrew.Bardsley@arm.com
7810905Sandreas.sandberg@arm.com    // initialization pass of all objects.
7910259SAndrew.Bardsley@arm.com    // Gets invoked after construction, before unserialize.
8010259SAndrew.Bardsley@arm.com    virtual void init();
8110259SAndrew.Bardsley@arm.com    static void initAll();
8210905Sandreas.sandberg@arm.com
8310259SAndrew.Bardsley@arm.com    // register statistics for this object
8410259SAndrew.Bardsley@arm.com    virtual void regStats();
8510259SAndrew.Bardsley@arm.com    virtual void regFormulas();
8610905Sandreas.sandberg@arm.com    virtual void resetStats();
8710259SAndrew.Bardsley@arm.com
8810320SAndrew.Bardsley@arm.com    // static: call reg_stats on all SimObjects
8910259SAndrew.Bardsley@arm.com    static void regAllStats();
9010320SAndrew.Bardsley@arm.com
9110320SAndrew.Bardsley@arm.com    // static: call resetStats on all SimObjects
9210320SAndrew.Bardsley@arm.com    static void resetAllStats();
9310320SAndrew.Bardsley@arm.com
9410320SAndrew.Bardsley@arm.com    // static: call nameOut() & serialize() on all SimObjects
9510320SAndrew.Bardsley@arm.com    static void serializeAll(std::ostream &);
9610905Sandreas.sandberg@arm.com
9710259SAndrew.Bardsley@arm.com#ifdef DEBUG
9810259SAndrew.Bardsley@arm.com  public:
9910259SAndrew.Bardsley@arm.com    bool doDebugBreak;
10010259SAndrew.Bardsley@arm.com    static void debugObjectBreak(const std::string &objs);
10110259SAndrew.Bardsley@arm.com#endif
10210259SAndrew.Bardsley@arm.com
10310259SAndrew.Bardsley@arm.com  public:
10410259SAndrew.Bardsley@arm.com    bool doRecordEvent;
10510259SAndrew.Bardsley@arm.com    void recordEvent(const std::string &stat);
10610259SAndrew.Bardsley@arm.com};
10710259SAndrew.Bardsley@arm.com
10810259SAndrew.Bardsley@arm.com#endif // __SIM_OBJECT_HH__
10910259SAndrew.Bardsley@arm.com