sim_object.cc revision 9254:f1b35c618252
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 2001-2005 The Regents of The University of Michigan
36145Snate@binkert.org * Copyright (c) 2010 Advanced Micro Devices, Inc.
46145Snate@binkert.org * All rights reserved.
56145Snate@binkert.org *
66145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
76145Snate@binkert.org * modification, are permitted provided that the following conditions are
86145Snate@binkert.org * met: redistributions of source code must retain the above copyright
96145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
106145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
116145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
126145Snate@binkert.org * documentation and/or other materials provided with the distribution;
136145Snate@binkert.org * neither the name of the copyright holders nor the names of its
146145Snate@binkert.org * contributors may be used to endorse or promote products derived from
156145Snate@binkert.org * this software without specific prior written permission.
166145Snate@binkert.org *
176145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286145Snate@binkert.org *
297056Snate@binkert.org * Authors: Steve Reinhardt
307039Snate@binkert.org *          Nathan Binkert
317039Snate@binkert.org */
327039Snate@binkert.org
337039Snate@binkert.org#include <cassert>
347039Snate@binkert.org
357039Snate@binkert.org#include "base/callback.hh"
367039Snate@binkert.org#include "base/inifile.hh"
377039Snate@binkert.org#include "base/match.hh"
386845Sdrh5@cs.wisc.edu#include "base/misc.hh"
397039Snate@binkert.org#include "base/trace.hh"
407039Snate@binkert.org#include "base/types.hh"
417039Snate@binkert.org#include "debug/Checkpoint.hh"
427039Snate@binkert.org#include "sim/sim_object.hh"
436154Snate@binkert.org#include "sim/stats.hh"
446154Snate@binkert.org
456876Ssteve.reinhardt@amd.comusing namespace std;
466876Ssteve.reinhardt@amd.com
477055Snate@binkert.org
487055Snate@binkert.org////////////////////////////////////////////////////////////////////////
496876Ssteve.reinhardt@amd.com//
506876Ssteve.reinhardt@amd.com// SimObject member definitions
516285Snate@binkert.org//
526876Ssteve.reinhardt@amd.com////////////////////////////////////////////////////////////////////////
536285Snate@binkert.org
547039Snate@binkert.org//
556876Ssteve.reinhardt@amd.com// static list of all SimObjects, used for initialization etc.
566886SBrad.Beckmann@amd.com//
576876Ssteve.reinhardt@amd.comSimObject::SimObjectList SimObject::simObjectList;
586876Ssteve.reinhardt@amd.com
596876Ssteve.reinhardt@amd.com//
606876Ssteve.reinhardt@amd.com// SimObject constructor: used to maintain static simObjectList
616876Ssteve.reinhardt@amd.com//
627039Snate@binkert.orgSimObject::SimObject(const Params *p)
636876Ssteve.reinhardt@amd.com    : EventManager(p->eventq), _params(p)
646285Snate@binkert.org{
656876Ssteve.reinhardt@amd.com#ifdef DEBUG
666876Ssteve.reinhardt@amd.com    doDebugBreak = false;
676876Ssteve.reinhardt@amd.com#endif
686876Ssteve.reinhardt@amd.com
696145Snate@binkert.org    simObjectList.push_back(this);
706876Ssteve.reinhardt@amd.com    state = Running;
716876Ssteve.reinhardt@amd.com}
726876Ssteve.reinhardt@amd.com
736876Ssteve.reinhardt@amd.comvoid
746899SBrad.Beckmann@amd.comSimObject::init()
756899SBrad.Beckmann@amd.com{
766876Ssteve.reinhardt@amd.com}
776876Ssteve.reinhardt@amd.com
786876Ssteve.reinhardt@amd.comvoid
796876Ssteve.reinhardt@amd.comSimObject::loadState(Checkpoint *cp)
806145Snate@binkert.org{
816145Snate@binkert.org    if (cp->sectionExists(name())) {
827039Snate@binkert.org        DPRINTF(Checkpoint, "unserializing\n");
837039Snate@binkert.org        unserialize(cp, name());
846145Snate@binkert.org    } else {
856145Snate@binkert.org        DPRINTF(Checkpoint, "no checkpoint section found\n");
867039Snate@binkert.org    }
877039Snate@binkert.org}
887039Snate@binkert.org
897039Snate@binkert.orgvoid
907039Snate@binkert.orgSimObject::initState()
916145Snate@binkert.org{
927039Snate@binkert.org}
937039Snate@binkert.org
946285Snate@binkert.orgvoid
957039Snate@binkert.orgSimObject::startup()
967039Snate@binkert.org{
977039Snate@binkert.org}
987039Snate@binkert.org
997039Snate@binkert.org//
1007039Snate@binkert.org// no default statistics, so nothing to do in base implementation
1017039Snate@binkert.org//
1027039Snate@binkert.orgvoid
1037039Snate@binkert.orgSimObject::regStats()
1047039Snate@binkert.org{
1057039Snate@binkert.org}
1067039Snate@binkert.org
1077039Snate@binkert.orgvoid
1087039Snate@binkert.orgSimObject::resetStats()
1096145Snate@binkert.org{
1106145Snate@binkert.org}
1117039Snate@binkert.org
1127039Snate@binkert.org//
1137039Snate@binkert.org// static function: serialize all SimObjects.
1147039Snate@binkert.org//
1157039Snate@binkert.orgvoid
1167039Snate@binkert.orgSimObject::serializeAll(std::ostream &os)
1177039Snate@binkert.org{
1187039Snate@binkert.org    SimObjectList::reverse_iterator ri = simObjectList.rbegin();
1197039Snate@binkert.org    SimObjectList::reverse_iterator rend = simObjectList.rend();
1207039Snate@binkert.org
1217039Snate@binkert.org    for (; ri != rend; ++ri) {
1227039Snate@binkert.org        SimObject *obj = *ri;
1237039Snate@binkert.org        obj->nameOut(os);
1246145Snate@binkert.org        obj->serialize(os);
1256285Snate@binkert.org   }
1267039Snate@binkert.org}
1277039Snate@binkert.org
1286145Snate@binkert.org
1297039Snate@binkert.org#ifdef DEBUG
1307039Snate@binkert.org//
1317039Snate@binkert.org// static function: flag which objects should have the debugger break
1327039Snate@binkert.org//
1337039Snate@binkert.orgvoid
1347039Snate@binkert.orgSimObject::debugObjectBreak(const string &objs)
1357039Snate@binkert.org{
1367039Snate@binkert.org    SimObjectList::const_iterator i = simObjectList.begin();
1376145Snate@binkert.org    SimObjectList::const_iterator end = simObjectList.end();
1386145Snate@binkert.org
1397039Snate@binkert.org    ObjectMatch match(objs);
1407039Snate@binkert.org    for (; i != end; ++i) {
1417039Snate@binkert.org        SimObject *obj = *i;
1427039Snate@binkert.org        obj->doDebugBreak = match.match(obj->name());
1437039Snate@binkert.org   }
1447039Snate@binkert.org}
1457039Snate@binkert.org
1467039Snate@binkert.orgvoid
1477039Snate@binkert.orgdebugObjectBreak(const char *objs)
1487039Snate@binkert.org{
1497039Snate@binkert.org    SimObject::debugObjectBreak(string(objs));
1507039Snate@binkert.org}
1516859Sdrh5@cs.wisc.edu#endif
1526859Sdrh5@cs.wisc.edu
1537039Snate@binkert.orgunsigned int
1547039Snate@binkert.orgSimObject::drain(Event *drain_event)
1557039Snate@binkert.org{
1567039Snate@binkert.org    state = Drained;
1577039Snate@binkert.org    return 0;
1587039Snate@binkert.org}
1597039Snate@binkert.org
1607039Snate@binkert.orgvoid
1617039Snate@binkert.orgSimObject::resume()
1626145Snate@binkert.org{
1637039Snate@binkert.org    state = Running;
1647039Snate@binkert.org}
1657039Snate@binkert.org
1666145Snate@binkert.orgSimObject *
1677039Snate@binkert.orgSimObject::find(const char *name)
1687039Snate@binkert.org{
1697039Snate@binkert.org    SimObjectList::const_iterator i = simObjectList.begin();
1707039Snate@binkert.org    SimObjectList::const_iterator end = simObjectList.end();
1717039Snate@binkert.org
1727039Snate@binkert.org    for (; i != end; ++i) {
1737039Snate@binkert.org        SimObject *obj = *i;
1746145Snate@binkert.org        if (obj->name() == name)
1757039Snate@binkert.org            return obj;
1766145Snate@binkert.org    }
1777039Snate@binkert.org
1787039Snate@binkert.org    return NULL;
1797039Snate@binkert.org}
1806285Snate@binkert.org