sim_object.cc revision 13781:280e5206fd97
112853Sgabeblack@google.com/* 212853Sgabeblack@google.com * Copyright (c) 2001-2005 The Regents of The University of Michigan 312853Sgabeblack@google.com * Copyright (c) 2010 Advanced Micro Devices, Inc. 412853Sgabeblack@google.com * All rights reserved. 512853Sgabeblack@google.com * 612853Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 712853Sgabeblack@google.com * modification, are permitted provided that the following conditions are 812853Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 912853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 1012853Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 1112853Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1212853Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1312853Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1412853Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1512853Sgabeblack@google.com * this software without specific prior written permission. 1612853Sgabeblack@google.com * 1712853Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1812853Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1912853Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2012853Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2112853Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2212853Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2312853Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2412853Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2512853Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2612853Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2712853Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2812853Sgabeblack@google.com * 2912853Sgabeblack@google.com * Authors: Steve Reinhardt 3012853Sgabeblack@google.com * Nathan Binkert 3112853Sgabeblack@google.com */ 3212853Sgabeblack@google.com 3312853Sgabeblack@google.com#include "sim/sim_object.hh" 3412853Sgabeblack@google.com 3512853Sgabeblack@google.com#include "base/logging.hh" 3612853Sgabeblack@google.com#include "base/match.hh" 3712853Sgabeblack@google.com#include "base/trace.hh" 3812853Sgabeblack@google.com#include "debug/Checkpoint.hh" 3912853Sgabeblack@google.com#include "sim/probe/probe.hh" 4012853Sgabeblack@google.com 4112853Sgabeblack@google.comusing namespace std; 4212853Sgabeblack@google.com 4312853Sgabeblack@google.com 4412853Sgabeblack@google.com//////////////////////////////////////////////////////////////////////// 4512853Sgabeblack@google.com// 4612853Sgabeblack@google.com// SimObject member definitions 4712853Sgabeblack@google.com// 4812853Sgabeblack@google.com//////////////////////////////////////////////////////////////////////// 4912853Sgabeblack@google.com 5012853Sgabeblack@google.com// 5112853Sgabeblack@google.com// static list of all SimObjects, used for initialization etc. 5212853Sgabeblack@google.com// 5312853Sgabeblack@google.comSimObject::SimObjectList SimObject::simObjectList; 5412853Sgabeblack@google.com 5512853Sgabeblack@google.com// 5612853Sgabeblack@google.com// SimObject constructor: used to maintain static simObjectList 5712853Sgabeblack@google.com// 5812853Sgabeblack@google.comSimObject::SimObject(const Params *p) 5912853Sgabeblack@google.com : EventManager(getEventQueue(p->eventq_index)), _params(p) 6012853Sgabeblack@google.com{ 6112853Sgabeblack@google.com#ifdef DEBUG 6212853Sgabeblack@google.com doDebugBreak = false; 6312853Sgabeblack@google.com#endif 6412853Sgabeblack@google.com simObjectList.push_back(this); 6513325Sgabeblack@google.com probeManager = new ProbeManager(this); 6612853Sgabeblack@google.com} 6712853Sgabeblack@google.com 6812853Sgabeblack@google.comSimObject::~SimObject() 6912853Sgabeblack@google.com{ 7013245Sgabeblack@google.com delete probeManager; 7112853Sgabeblack@google.com} 7212853Sgabeblack@google.com 7313245Sgabeblack@google.comvoid 7413245Sgabeblack@google.comSimObject::init() 7512853Sgabeblack@google.com{ 7612853Sgabeblack@google.com} 7712853Sgabeblack@google.com 7812853Sgabeblack@google.comvoid 7912853Sgabeblack@google.comSimObject::loadState(CheckpointIn &cp) 8012853Sgabeblack@google.com{ 8112853Sgabeblack@google.com if (cp.sectionExists(name())) { 8212853Sgabeblack@google.com DPRINTF(Checkpoint, "unserializing\n"); 8312853Sgabeblack@google.com // This works despite name() returning a fully qualified name 8412853Sgabeblack@google.com // since we are at the top level. 8512853Sgabeblack@google.com unserializeSection(cp, name()); 8612853Sgabeblack@google.com } else { 8712853Sgabeblack@google.com DPRINTF(Checkpoint, "no checkpoint section found\n"); 8812853Sgabeblack@google.com } 8912853Sgabeblack@google.com} 9012853Sgabeblack@google.com 9112853Sgabeblack@google.comvoid 9212853Sgabeblack@google.comSimObject::initState() 9312853Sgabeblack@google.com{ 9412853Sgabeblack@google.com} 9512853Sgabeblack@google.com 9612853Sgabeblack@google.comvoid 9712853Sgabeblack@google.comSimObject::startup() 9812853Sgabeblack@google.com{ 9912853Sgabeblack@google.com} 10012853Sgabeblack@google.com 10112853Sgabeblack@google.com// 10212853Sgabeblack@google.com// no default statistics, so nothing to do in base implementation 10312853Sgabeblack@google.com// 10412853Sgabeblack@google.comvoid 10512853Sgabeblack@google.comSimObject::regStats() 10612853Sgabeblack@google.com{ 10712853Sgabeblack@google.com} 10812853Sgabeblack@google.com 10912853Sgabeblack@google.comvoid 11012853Sgabeblack@google.comSimObject::resetStats() 11112853Sgabeblack@google.com{ 11212853Sgabeblack@google.com} 11312853Sgabeblack@google.com 11412853Sgabeblack@google.com/** 11512853Sgabeblack@google.com * No probe points by default, so do nothing in base. 11612853Sgabeblack@google.com */ 11712853Sgabeblack@google.comvoid 11812853Sgabeblack@google.comSimObject::regProbePoints() 11912853Sgabeblack@google.com{ 12012853Sgabeblack@google.com} 12112853Sgabeblack@google.com 12212853Sgabeblack@google.com/** 12312853Sgabeblack@google.com * No probe listeners by default, so do nothing in base. 12412853Sgabeblack@google.com */ 12512853Sgabeblack@google.comvoid 12612853Sgabeblack@google.comSimObject::regProbeListeners() 12712853Sgabeblack@google.com{ 12812853Sgabeblack@google.com} 12912853Sgabeblack@google.com 13012853Sgabeblack@google.comProbeManager * 13112853Sgabeblack@google.comSimObject::getProbeManager() 13212853Sgabeblack@google.com{ 13312853Sgabeblack@google.com return probeManager; 13412853Sgabeblack@google.com} 13512853Sgabeblack@google.com 13612853Sgabeblack@google.comPort & 13712853Sgabeblack@google.comSimObject::getPort(const std::string &if_name, PortID idx) 13812853Sgabeblack@google.com{ 13912853Sgabeblack@google.com fatal("%s does not have any port named %s\n", name(), if_name); 14012853Sgabeblack@google.com} 14112853Sgabeblack@google.com 14212853Sgabeblack@google.com// 14312853Sgabeblack@google.com// static function: serialize all SimObjects. 14412853Sgabeblack@google.com// 14512853Sgabeblack@google.comvoid 14612853Sgabeblack@google.comSimObject::serializeAll(CheckpointOut &cp) 14712853Sgabeblack@google.com{ 14812853Sgabeblack@google.com SimObjectList::reverse_iterator ri = simObjectList.rbegin(); 14912853Sgabeblack@google.com SimObjectList::reverse_iterator rend = simObjectList.rend(); 15012853Sgabeblack@google.com 15112853Sgabeblack@google.com for (; ri != rend; ++ri) { 15212853Sgabeblack@google.com SimObject *obj = *ri; 15312853Sgabeblack@google.com // This works despite name() returning a fully qualified name 15412853Sgabeblack@google.com // since we are at the top level. 15512853Sgabeblack@google.com obj->serializeSection(cp, obj->name()); 15612853Sgabeblack@google.com } 15712853Sgabeblack@google.com} 15812853Sgabeblack@google.com 15912853Sgabeblack@google.com 16012853Sgabeblack@google.com#ifdef DEBUG 16112853Sgabeblack@google.com// 16212853Sgabeblack@google.com// static function: flag which objects should have the debugger break 16312853Sgabeblack@google.com// 16412853Sgabeblack@google.comvoid 16512853Sgabeblack@google.comSimObject::debugObjectBreak(const string &objs) 16612853Sgabeblack@google.com{ 16712853Sgabeblack@google.com SimObjectList::const_iterator i = simObjectList.begin(); 16812853Sgabeblack@google.com SimObjectList::const_iterator end = simObjectList.end(); 16912853Sgabeblack@google.com 17012853Sgabeblack@google.com ObjectMatch match(objs); 17112853Sgabeblack@google.com for (; i != end; ++i) { 17212853Sgabeblack@google.com SimObject *obj = *i; 17312853Sgabeblack@google.com obj->doDebugBreak = match.match(obj->name()); 17412853Sgabeblack@google.com } 17512853Sgabeblack@google.com} 17612853Sgabeblack@google.com 17712853Sgabeblack@google.comvoid 17812853Sgabeblack@google.comdebugObjectBreak(const char *objs) 17912853Sgabeblack@google.com{ 18012853Sgabeblack@google.com SimObject::debugObjectBreak(string(objs)); 18112853Sgabeblack@google.com} 18212853Sgabeblack@google.com#endif 18312853Sgabeblack@google.com 18412853Sgabeblack@google.comSimObject * 18512853Sgabeblack@google.comSimObject::find(const char *name) 18612853Sgabeblack@google.com{ 18712853Sgabeblack@google.com SimObjectList::const_iterator i = simObjectList.begin(); 18812853Sgabeblack@google.com SimObjectList::const_iterator end = simObjectList.end(); 18912853Sgabeblack@google.com 19012853Sgabeblack@google.com for (; i != end; ++i) { 19112853Sgabeblack@google.com SimObject *obj = *i; 19212853Sgabeblack@google.com if (obj->name() == name) 19312853Sgabeblack@google.com return obj; 19412853Sgabeblack@google.com } 19512853Sgabeblack@google.com 19612853Sgabeblack@google.com return NULL; 19712853Sgabeblack@google.com} 19812853Sgabeblack@google.com