sim_object.cc revision 10422
12SN/A/*
21762SN/A * Copyright (c) 2001-2005 The Regents of The University of Michigan
37534Ssteve.reinhardt@amd.com * Copyright (c) 2010 Advanced Micro Devices, Inc.
42SN/A * All rights reserved.
52SN/A *
62SN/A * Redistribution and use in source and binary forms, with or without
72SN/A * modification, are permitted provided that the following conditions are
82SN/A * met: redistributions of source code must retain the above copyright
92SN/A * notice, this list of conditions and the following disclaimer;
102SN/A * redistributions in binary form must reproduce the above copyright
112SN/A * notice, this list of conditions and the following disclaimer in the
122SN/A * documentation and/or other materials provided with the distribution;
132SN/A * neither the name of the copyright holders nor the names of its
142SN/A * contributors may be used to endorse or promote products derived from
152SN/A * this software without specific prior written permission.
162SN/A *
172SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
182SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
192SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
202SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
212SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
222SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
232SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
242SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
252SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
262SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
272SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu *
292665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt
302665Ssaidi@eecs.umich.edu *          Nathan Binkert
312SN/A */
322SN/A
336216Snate@binkert.org#include <cassert>
342SN/A
35330SN/A#include "base/callback.hh"
3656SN/A#include "base/inifile.hh"
371031SN/A#include "base/match.hh"
38330SN/A#include "base/misc.hh"
39330SN/A#include "base/trace.hh"
406214Snate@binkert.org#include "base/types.hh"
418320Ssteve.reinhardt@amd.com#include "debug/Checkpoint.hh"
4210023Smatt.horsnell@ARM.com#include "sim/probe/probe.hh"
43330SN/A#include "sim/sim_object.hh"
44695SN/A#include "sim/stats.hh"
452SN/A
462SN/Ausing namespace std;
472SN/A
482SN/A
492SN/A////////////////////////////////////////////////////////////////////////
502SN/A//
512SN/A// SimObject member definitions
522SN/A//
532SN/A////////////////////////////////////////////////////////////////////////
542SN/A
552SN/A//
562SN/A// static list of all SimObjects, used for initialization etc.
572SN/A//
582SN/ASimObject::SimObjectList SimObject::simObjectList;
592SN/A
602SN/A//
612SN/A// SimObject constructor: used to maintain static simObjectList
622SN/A//
634762Snate@binkert.orgSimObject::SimObject(const Params *p)
649983Sstever@gmail.com    : EventManager(getEventQueue(p->eventq_index)), _params(p)
652SN/A{
661031SN/A#ifdef DEBUG
671031SN/A    doDebugBreak = false;
681031SN/A#endif
691553SN/A    simObjectList.push_back(this);
7010023Smatt.horsnell@ARM.com    probeManager = new ProbeManager(this);
711553SN/A}
721553SN/A
7310422Sandreas.hansson@arm.comSimObject::~SimObject()
7410422Sandreas.hansson@arm.com{
7510422Sandreas.hansson@arm.com    delete probeManager;
7610422Sandreas.hansson@arm.com}
7710422Sandreas.hansson@arm.com
78465SN/Avoid
79465SN/ASimObject::init()
80465SN/A{
81465SN/A}
82465SN/A
837492Ssteve.reinhardt@amd.comvoid
847532Ssteve.reinhardt@amd.comSimObject::loadState(Checkpoint *cp)
857532Ssteve.reinhardt@amd.com{
868320Ssteve.reinhardt@amd.com    if (cp->sectionExists(name())) {
878320Ssteve.reinhardt@amd.com        DPRINTF(Checkpoint, "unserializing\n");
887532Ssteve.reinhardt@amd.com        unserialize(cp, name());
898320Ssteve.reinhardt@amd.com    } else {
908320Ssteve.reinhardt@amd.com        DPRINTF(Checkpoint, "no checkpoint section found\n");
918320Ssteve.reinhardt@amd.com    }
927532Ssteve.reinhardt@amd.com}
937532Ssteve.reinhardt@amd.com
947532Ssteve.reinhardt@amd.comvoid
957532Ssteve.reinhardt@amd.comSimObject::initState()
967532Ssteve.reinhardt@amd.com{
977532Ssteve.reinhardt@amd.com}
987532Ssteve.reinhardt@amd.com
997532Ssteve.reinhardt@amd.comvoid
1007492Ssteve.reinhardt@amd.comSimObject::startup()
1017492Ssteve.reinhardt@amd.com{
1027492Ssteve.reinhardt@amd.com}
1037492Ssteve.reinhardt@amd.com
1042SN/A//
1052SN/A// no default statistics, so nothing to do in base implementation
1062SN/A//
1072SN/Avoid
1082SN/ASimObject::regStats()
1092SN/A{
1102SN/A}
1112SN/A
1122SN/Avoid
113330SN/ASimObject::resetStats()
114330SN/A{
115330SN/A}
116330SN/A
11710023Smatt.horsnell@ARM.com/**
11810023Smatt.horsnell@ARM.com * No probe points by default, so do nothing in base.
11910023Smatt.horsnell@ARM.com */
12010023Smatt.horsnell@ARM.comvoid
12110023Smatt.horsnell@ARM.comSimObject::regProbePoints()
12210023Smatt.horsnell@ARM.com{
12310023Smatt.horsnell@ARM.com}
12410023Smatt.horsnell@ARM.com
12510023Smatt.horsnell@ARM.com/**
12610023Smatt.horsnell@ARM.com * No probe listeners by default, so do nothing in base.
12710023Smatt.horsnell@ARM.com */
12810023Smatt.horsnell@ARM.comvoid
12910023Smatt.horsnell@ARM.comSimObject::regProbeListeners()
13010023Smatt.horsnell@ARM.com{
13110023Smatt.horsnell@ARM.com}
13210023Smatt.horsnell@ARM.com
13310023Smatt.horsnell@ARM.comProbeManager *
13410023Smatt.horsnell@ARM.comSimObject::getProbeManager()
13510023Smatt.horsnell@ARM.com{
13610023Smatt.horsnell@ARM.com    return probeManager;
13710023Smatt.horsnell@ARM.com}
13810023Smatt.horsnell@ARM.com
1392SN/A//
140395SN/A// static function: serialize all SimObjects.
141395SN/A//
142395SN/Avoid
1439196SAndreas.Sandberg@arm.comSimObject::serializeAll(std::ostream &os)
144395SN/A{
145573SN/A    SimObjectList::reverse_iterator ri = simObjectList.rbegin();
146573SN/A    SimObjectList::reverse_iterator rend = simObjectList.rend();
147395SN/A
148573SN/A    for (; ri != rend; ++ri) {
149573SN/A        SimObject *obj = *ri;
150395SN/A        obj->nameOut(os);
151395SN/A        obj->serialize(os);
152395SN/A   }
153395SN/A}
154843SN/A
1557492Ssteve.reinhardt@amd.com
1561031SN/A#ifdef DEBUG
1571031SN/A//
1581031SN/A// static function: flag which objects should have the debugger break
1591031SN/A//
1601031SN/Avoid
1611031SN/ASimObject::debugObjectBreak(const string &objs)
1621031SN/A{
1631031SN/A    SimObjectList::const_iterator i = simObjectList.begin();
1641031SN/A    SimObjectList::const_iterator end = simObjectList.end();
1651031SN/A
1661031SN/A    ObjectMatch match(objs);
1671031SN/A    for (; i != end; ++i) {
1681031SN/A        SimObject *obj = *i;
1691031SN/A        obj->doDebugBreak = match.match(obj->name());
1701031SN/A   }
1711031SN/A}
1721031SN/A
1731031SN/Avoid
1741031SN/AdebugObjectBreak(const char *objs)
1751031SN/A{
1761031SN/A    SimObject::debugObjectBreak(string(objs));
1771031SN/A}
1781031SN/A#endif
1791031SN/A
1802901Ssaidi@eecs.umich.eduunsigned int
1819342SAndreas.Sandberg@arm.comSimObject::drain(DrainManager *drain_manager)
1822797Sktlim@umich.edu{
1839342SAndreas.Sandberg@arm.com    setDrainState(Drained);
1842901Ssaidi@eecs.umich.edu    return 0;
1852797Sktlim@umich.edu}
1862797Sktlim@umich.edu
1872797Sktlim@umich.edu
1885314Sstever@gmail.comSimObject *
1895314Sstever@gmail.comSimObject::find(const char *name)
1905314Sstever@gmail.com{
1915314Sstever@gmail.com    SimObjectList::const_iterator i = simObjectList.begin();
1925314Sstever@gmail.com    SimObjectList::const_iterator end = simObjectList.end();
1935314Sstever@gmail.com
1945314Sstever@gmail.com    for (; i != end; ++i) {
1955314Sstever@gmail.com        SimObject *obj = *i;
1965314Sstever@gmail.com        if (obj->name() == name)
1975314Sstever@gmail.com            return obj;
1985314Sstever@gmail.com    }
1995314Sstever@gmail.com
2005314Sstever@gmail.com    return NULL;
2015314Sstever@gmail.com}
202