sim_object.hh revision 10911
12623SN/A/*
22623SN/A * Copyright (c) 2015 ARM Limited
32623SN/A * All rights reserved
42623SN/A *
52623SN/A * The license below extends only to copyright in the software and shall
62623SN/A * not be construed as granting a license to any other intellectual
72623SN/A * property including but not limited to intellectual property relating
82623SN/A * to a hardware implementation of the functionality of the software
92623SN/A * licensed hereunder.  You may use the software subject to the license
102623SN/A * terms below provided that you ensure that this notice is replicated
112623SN/A * unmodified and in its entirety in all distributions of the software,
122623SN/A * modified or unmodified, in source code or in binary form.
132623SN/A *
142623SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
152623SN/A * Copyright (c) 2010 Advanced Micro Devices, Inc.
162623SN/A * All rights reserved.
172623SN/A *
182623SN/A * Redistribution and use in source and binary forms, with or without
192623SN/A * modification, are permitted provided that the following conditions are
202623SN/A * met: redistributions of source code must retain the above copyright
212623SN/A * notice, this list of conditions and the following disclaimer;
222623SN/A * redistributions in binary form must reproduce the above copyright
232623SN/A * notice, this list of conditions and the following disclaimer in the
242623SN/A * documentation and/or other materials provided with the distribution;
252623SN/A * neither the name of the copyright holders nor the names of its
262623SN/A * contributors may be used to endorse or promote products derived from
272665Ssaidi@eecs.umich.edu * this software without specific prior written permission.
282665Ssaidi@eecs.umich.edu *
292623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
356973Stjones1@inf.ed.ac.uk * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
365529Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
375529Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
392623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
402623SN/A *
412623SN/A * Authors: Steve Reinhardt
425529Snate@binkert.org *          Nathan Binkert
432623SN/A */
442623SN/A
452623SN/A/* @file
462623SN/A * User Console Definitions
472623SN/A */
482839Sktlim@umich.edu
492798Sktlim@umich.edu#ifndef __SIM_OBJECT_HH__
502623SN/A#define __SIM_OBJECT_HH__
512623SN/A
525728Sgblack@eecs.umich.edu#include <iostream>
535728Sgblack@eecs.umich.edu#include <list>
545728Sgblack@eecs.umich.edu#include <map>
555728Sgblack@eecs.umich.edu#include <string>
565728Sgblack@eecs.umich.edu#include <vector>
575728Sgblack@eecs.umich.edu
585728Sgblack@eecs.umich.edu#include "enums/MemoryMode.hh"
595728Sgblack@eecs.umich.edu#include "params/SimObject.hh"
605728Sgblack@eecs.umich.edu#include "sim/drain.hh"
615728Sgblack@eecs.umich.edu#include "sim/eventq_impl.hh"
625728Sgblack@eecs.umich.edu#include "sim/serialize.hh"
635728Sgblack@eecs.umich.edu
645728Sgblack@eecs.umich.educlass BaseCPU;
655728Sgblack@eecs.umich.educlass Event;
665728Sgblack@eecs.umich.educlass ProbeManager;
675728Sgblack@eecs.umich.edu/**
685728Sgblack@eecs.umich.edu * Abstract superclass for simulation objects.  Represents things that
695728Sgblack@eecs.umich.edu * correspond to physical components and can be specified via the
705728Sgblack@eecs.umich.edu * config file (CPUs, caches, etc.).
715728Sgblack@eecs.umich.edu *
725728Sgblack@eecs.umich.edu * SimObject initialization is controlled by the instantiate method in
735728Sgblack@eecs.umich.edu * src/python/m5/simulate.py. There are slightly different
745728Sgblack@eecs.umich.edu * initialization paths when starting the simulation afresh and when
755728Sgblack@eecs.umich.edu * loading from a checkpoint.  After instantiation and connecting
765728Sgblack@eecs.umich.edu * ports, simulate.py initializes the object using the following call
775728Sgblack@eecs.umich.edu * sequence:
785728Sgblack@eecs.umich.edu *
795728Sgblack@eecs.umich.edu * <ol>
805728Sgblack@eecs.umich.edu * <li>SimObject::init()
815728Sgblack@eecs.umich.edu * <li>SimObject::regStats()
825728Sgblack@eecs.umich.edu * <li><ul>
835728Sgblack@eecs.umich.edu *     <li>SimObject::initState() if starting afresh.
845728Sgblack@eecs.umich.edu *     <li>SimObject::loadState() if restoring from a checkpoint.
855728Sgblack@eecs.umich.edu *     </ul>
865728Sgblack@eecs.umich.edu * <li>SimObject::resetStats()
875728Sgblack@eecs.umich.edu * <li>SimObject::startup()
885728Sgblack@eecs.umich.edu * <li>Drainable::drainResume() if resuming from a checkpoint.
895728Sgblack@eecs.umich.edu * </ol>
905728Sgblack@eecs.umich.edu *
915728Sgblack@eecs.umich.edu * @note Whenever a method is called on all objects in the simulator's
925728Sgblack@eecs.umich.edu * object tree (e.g., init(), startup(), or loadState()), a pre-order
935728Sgblack@eecs.umich.edu * depth-first traversal is performed (see descendants() in
945728Sgblack@eecs.umich.edu * SimObject.py). This has the effect of calling the method on the
955728Sgblack@eecs.umich.edu * parent node <i>before</i> its children.
965728Sgblack@eecs.umich.edu */
975728Sgblack@eecs.umich.educlass SimObject : public EventManager, public Serializable, public Drainable
985728Sgblack@eecs.umich.edu{
995894Sgblack@eecs.umich.edu  private:
1005894Sgblack@eecs.umich.edu    typedef std::vector<SimObject *> SimObjectList;
1015894Sgblack@eecs.umich.edu
1025894Sgblack@eecs.umich.edu    /** List of all instantiated simulation objects. */
1035894Sgblack@eecs.umich.edu    static SimObjectList simObjectList;
1045894Sgblack@eecs.umich.edu
1056023Snate@binkert.org    /** Manager coordinates hooking up probe points with listeners. */
1066023Snate@binkert.org    ProbeManager *probeManager;
1075894Sgblack@eecs.umich.edu
1085894Sgblack@eecs.umich.edu  protected:
1096023Snate@binkert.org    /** Cached copy of the object parameters. */
1107944SGiacomo.Gabrielli@arm.com    const SimObjectParams *_params;
1117945SAli.Saidi@ARM.com
1127945SAli.Saidi@ARM.com  public:
1137945SAli.Saidi@ARM.com    typedef SimObjectParams Params;
1147945SAli.Saidi@ARM.com    const Params *params() const { return _params; }
1157944SGiacomo.Gabrielli@arm.com    SimObject(const Params *_params);
1167944SGiacomo.Gabrielli@arm.com    virtual ~SimObject();
1176023Snate@binkert.org
1186023Snate@binkert.org  public:
1195894Sgblack@eecs.umich.edu
1205894Sgblack@eecs.umich.edu    virtual const std::string name() const { return params()->name; }
1215894Sgblack@eecs.umich.edu
1225894Sgblack@eecs.umich.edu    /**
1235894Sgblack@eecs.umich.edu     * init() is called after all C++ SimObjects have been created and
1245894Sgblack@eecs.umich.edu     * all ports are connected.  Initializations that are independent
1256973Stjones1@inf.ed.ac.uk     * of unserialization but rely on a fully instantiated and
1266973Stjones1@inf.ed.ac.uk     * connected SimObject graph should be done here.
1276973Stjones1@inf.ed.ac.uk     */
1285894Sgblack@eecs.umich.edu    virtual void init();
1295894Sgblack@eecs.umich.edu
1305894Sgblack@eecs.umich.edu    /**
1315894Sgblack@eecs.umich.edu     * loadState() is called on each SimObject when restoring from a
1325894Sgblack@eecs.umich.edu     * checkpoint.  The default implementation simply calls
1335894Sgblack@eecs.umich.edu     * unserialize() if there is a corresponding section in the
1345894Sgblack@eecs.umich.edu     * checkpoint.  However, objects can override loadState() to get
1355744Sgblack@eecs.umich.edu     * other behaviors, e.g., doing other programmed initializations
1365728Sgblack@eecs.umich.edu     * after unserialize(), or complaining if no checkpoint section is
1375728Sgblack@eecs.umich.edu     * found.
1385728Sgblack@eecs.umich.edu     *
1395728Sgblack@eecs.umich.edu     * @param cp Checkpoint to restore the state from.
1408707Sandreas.hansson@arm.com     */
1418707Sandreas.hansson@arm.com    virtual void loadState(CheckpointIn &cp);
1428707Sandreas.hansson@arm.com
1438707Sandreas.hansson@arm.com    /**
1448707Sandreas.hansson@arm.com     * initState() is called on each SimObject when *not* restoring
1458707Sandreas.hansson@arm.com     * from a checkpoint.  This provides a hook for state
1468707Sandreas.hansson@arm.com     * initializations that are only required for a "cold start".
1472623SN/A     */
1482623SN/A    virtual void initState();
1492623SN/A
1508707Sandreas.hansson@arm.com    /**
1518707Sandreas.hansson@arm.com     * Register statistics for this object.
1522623SN/A     */
1532623SN/A    virtual void regStats();
1542623SN/A
1552623SN/A    /**
1568948Sandreas.hansson@arm.com     * Reset statistics associated with this object.
1578948Sandreas.hansson@arm.com     */
1588948Sandreas.hansson@arm.com    virtual void resetStats();
1598975Sandreas.hansson@arm.com
1608948Sandreas.hansson@arm.com    /**
1618707Sandreas.hansson@arm.com     * Register probe points for this object.
1622948Ssaidi@eecs.umich.edu     */
1632948Ssaidi@eecs.umich.edu    virtual void regProbePoints();
1642948Ssaidi@eecs.umich.edu
1653349Sbinkertn@umich.edu    /**
1662948Ssaidi@eecs.umich.edu     * Register probe listeners for this object.
1672948Ssaidi@eecs.umich.edu     */
1688707Sandreas.hansson@arm.com    virtual void regProbeListeners();
1695336Shines@cs.fsu.edu
1703349Sbinkertn@umich.edu    /**
1712948Ssaidi@eecs.umich.edu     * Get the probe manager for this object.
1722948Ssaidi@eecs.umich.edu     */
1739087Sandreas.hansson@arm.com    ProbeManager *getProbeManager();
1742623SN/A
1752623SN/A    /**
1768707Sandreas.hansson@arm.com     * startup() is the final initialization call before simulation.
1772623SN/A     * All state is initialized (including unserialized state, if any,
1782623SN/A     * such as the curTick() value), so this is the appropriate place to
1792623SN/A     * schedule initial event(s) for objects that need them.
1808707Sandreas.hansson@arm.com     */
1819095Sandreas.hansson@arm.com    virtual void startup();
1828707Sandreas.hansson@arm.com
1832623SN/A    /**
1842623SN/A     * Provide a default implementation of the drain interface that
1852623SN/A     * simply returns 0 (draining completed) and sets the drain state
1862623SN/A     * to Drained.
1878975Sandreas.hansson@arm.com     */
1882623SN/A    unsigned int drain(DrainManager *drainManger);
1892657Ssaidi@eecs.umich.edu
1902948Ssaidi@eecs.umich.edu    /**
1912948Ssaidi@eecs.umich.edu     * Write back dirty buffers to memory using functional writes.
1922948Ssaidi@eecs.umich.edu     *
1932948Ssaidi@eecs.umich.edu     * After returning, an object implementing this method should have
1942948Ssaidi@eecs.umich.edu     * written all its dirty data back to memory. This method is
1952948Ssaidi@eecs.umich.edu     * typically used to prepare a system with caches for
1962948Ssaidi@eecs.umich.edu     * checkpointing.
1975336Shines@cs.fsu.edu     */
1982948Ssaidi@eecs.umich.edu    virtual void memWriteback() {};
1992948Ssaidi@eecs.umich.edu
2002948Ssaidi@eecs.umich.edu    /**
2012948Ssaidi@eecs.umich.edu     * Invalidate the contents of memory buffers.
2022623SN/A     *
2032623SN/A     * When the switching to hardware virtualized CPU models, we need
2048707Sandreas.hansson@arm.com     * to make sure that we don't have any cached state in the system
2052623SN/A     * that might become stale when we return. This method is used to
2062623SN/A     * flush all such state back to main memory.
2072623SN/A     *
2088707Sandreas.hansson@arm.com     * @warn This does <i>not</i> cause any dirty state to be written
2099095Sandreas.hansson@arm.com     * back to memory.
2109095Sandreas.hansson@arm.com     */
2112623SN/A    virtual void memInvalidate() {};
2122623SN/A
2132623SN/A    void serialize(CheckpointOut &cp) const M5_ATTR_OVERRIDE {};
2142623SN/A    void unserialize(CheckpointIn &cp) M5_ATTR_OVERRIDE {};
2158975Sandreas.hansson@arm.com
2162623SN/A    /**
2172657Ssaidi@eecs.umich.edu     * Serialize all SimObjects in the system.
2182948Ssaidi@eecs.umich.edu     */
2192948Ssaidi@eecs.umich.edu    static void serializeAll(CheckpointOut &cp);
2202948Ssaidi@eecs.umich.edu
2212948Ssaidi@eecs.umich.edu#ifdef DEBUG
2222948Ssaidi@eecs.umich.edu  public:
2232948Ssaidi@eecs.umich.edu    bool doDebugBreak;
2245336Shines@cs.fsu.edu    static void debugObjectBreak(const std::string &objs);
2252948Ssaidi@eecs.umich.edu#endif
2262948Ssaidi@eecs.umich.edu
2272948Ssaidi@eecs.umich.edu    /**
2282948Ssaidi@eecs.umich.edu     * Find the SimObject with the given name and return a pointer to
2292623SN/A     * it.  Primarily used for interactive debugging.  Argument is
2302623SN/A     * char* rather than std::string to make it callable from gdb.
2312623SN/A     */
2322623SN/A    static SimObject *find(const char *name);
2332623SN/A};
2343349Sbinkertn@umich.edu
2353349Sbinkertn@umich.edu#ifdef DEBUG
2362623SN/Avoid debugObjectBreak(const char *objs);
2379179Sandreas.hansson@arm.com#endif
2383170Sstever@eecs.umich.edu
2398850Sandreas.hansson@arm.com#endif // __SIM_OBJECT_HH__
2408850Sandreas.hansson@arm.com