main.cc revision 3868
12SN/A/* 21762SN/A * Copyright (c) 2000-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Raasch 292665Ssaidi@eecs.umich.edu * Nathan Binkert 302665Ssaidi@eecs.umich.edu * Steve Reinhardt 312SN/A */ 322SN/A 332SN/A/// 342SN/A/// @file sim/main.cc 352SN/A/// 362655Sstever@eecs.umich.edu#include <Python.h> // must be before system headers... see Python docs 372655Sstever@eecs.umich.edu 382SN/A#include <sys/types.h> 392SN/A#include <sys/stat.h> 401399SN/A#include <errno.h> 411396SN/A#include <libgen.h> 422SN/A#include <stdlib.h> 432SN/A#include <signal.h> 442729Ssaidi@eecs.umich.edu#include <getopt.h> 452SN/A 461310SN/A#include <list> 472SN/A#include <string> 482SN/A#include <vector> 492SN/A 502667Sstever@eecs.umich.edu#include "base/callback.hh" 5156SN/A#include "base/inifile.hh" 52146SN/A#include "base/misc.hh" 531388SN/A#include "base/output.hh" 5456SN/A#include "base/pollevent.hh" 5556SN/A#include "base/statistics.hh" 561311SN/A#include "base/str.hh" 57400SN/A#include "base/time.hh" 583356Sbinkertn@umich.edu#include "config/pythonhome.hh" 591717SN/A#include "cpu/base.hh" 601717SN/A#include "cpu/smt.hh" 612738Sstever@eecs.umich.edu#include "mem/mem_object.hh" 622738Sstever@eecs.umich.edu#include "mem/port.hh" 633868Sbinkertn@umich.edu#include "python/swig/init.hh" 64146SN/A#include "sim/async.hh" 65146SN/A#include "sim/builder.hh" 66146SN/A#include "sim/host.hh" 672797Sktlim@umich.edu#include "sim/serialize.hh" 6856SN/A#include "sim/sim_events.hh" 6956SN/A#include "sim/sim_exit.hh" 7056SN/A#include "sim/sim_object.hh" 713202Shsul@eecs.umich.edu#include "sim/system.hh" 72695SN/A#include "sim/stat_control.hh" 73695SN/A#include "sim/stats.hh" 741696SN/A#include "sim/root.hh" 752SN/A 762SN/Ausing namespace std; 772SN/A 782SN/A// See async.h. 792SN/Avolatile bool async_event = false; 802SN/Avolatile bool async_dump = false; 81329SN/Avolatile bool async_dumpreset = false; 822SN/Avolatile bool async_exit = false; 832SN/Avolatile bool async_io = false; 842SN/Avolatile bool async_alarm = false; 852SN/A 862SN/A/// Stats signal handler. 872SN/Avoid 882SN/AdumpStatsHandler(int sigtype) 892SN/A{ 902SN/A async_event = true; 912SN/A async_dump = true; 922SN/A} 932SN/A 94329SN/Avoid 95329SN/AdumprstStatsHandler(int sigtype) 96329SN/A{ 97329SN/A async_event = true; 98329SN/A async_dumpreset = true; 99329SN/A} 100329SN/A 1012SN/A/// Exit signal handler. 1022SN/Avoid 1032SN/AexitNowHandler(int sigtype) 1042SN/A{ 1052SN/A async_event = true; 1062SN/A async_exit = true; 1072SN/A} 1082SN/A 109764SN/A/// Abort signal handler. 110764SN/Avoid 111764SN/AabortHandler(int sigtype) 112764SN/A{ 113764SN/A cerr << "Program aborted at cycle " << curTick << endl; 114764SN/A 115764SN/A#if TRACING_ON 116764SN/A // dump trace buffer, if there is one 117764SN/A Trace::theLog.dump(cerr); 118764SN/A#endif 119764SN/A} 120764SN/A 1212SN/Aint 1222SN/Amain(int argc, char **argv) 1232SN/A{ 1242SN/A signal(SIGFPE, SIG_IGN); // may occur on misspeculated paths 1252SN/A signal(SIGTRAP, SIG_IGN); 126329SN/A signal(SIGUSR1, dumpStatsHandler); // dump intermediate stats 127329SN/A signal(SIGUSR2, dumprstStatsHandler); // dump and reset stats 128329SN/A signal(SIGINT, exitNowHandler); // dump final stats and exit 129764SN/A signal(SIGABRT, abortHandler); 1302SN/A 1312655Sstever@eecs.umich.edu Py_SetProgramName(argv[0]); 1322667Sstever@eecs.umich.edu 1332667Sstever@eecs.umich.edu // default path to m5 python code is the currently executing 1342889Sbinkertn@umich.edu // file... Python ZipImporter will find embedded zip archive. 1352889Sbinkertn@umich.edu // The M5_ARCHIVE environment variable can be used to override this. 1362889Sbinkertn@umich.edu char *m5_archive = getenv("M5_ARCHIVE"); 1372889Sbinkertn@umich.edu string pythonpath = m5_archive ? m5_archive : argv[0]; 1382667Sstever@eecs.umich.edu 1392667Sstever@eecs.umich.edu char *oldpath = getenv("PYTHONPATH"); 1402667Sstever@eecs.umich.edu if (oldpath != NULL) { 1412889Sbinkertn@umich.edu pythonpath += ":"; 1422889Sbinkertn@umich.edu pythonpath += oldpath; 1432667Sstever@eecs.umich.edu } 1442667Sstever@eecs.umich.edu 1452889Sbinkertn@umich.edu if (setenv("PYTHONPATH", pythonpath.c_str(), true) == -1) 1462667Sstever@eecs.umich.edu fatal("setenv: %s\n", strerror(errno)); 1472667Sstever@eecs.umich.edu 1483356Sbinkertn@umich.edu char *python_home = getenv("PYTHONHOME"); 1493356Sbinkertn@umich.edu if (!python_home) 1503356Sbinkertn@umich.edu python_home = PYTHONHOME; 1513356Sbinkertn@umich.edu Py_SetPythonHome(python_home); 1523356Sbinkertn@umich.edu 1532667Sstever@eecs.umich.edu // initialize embedded Python interpreter 1542655Sstever@eecs.umich.edu Py_Initialize(); 1552655Sstever@eecs.umich.edu PySys_SetArgv(argc, argv); 1561311SN/A 1573645Sbinkertn@umich.edu // initialize SWIG modules 1583868Sbinkertn@umich.edu init_swig(); 1591703SN/A 1603102Sstever@eecs.umich.edu PyRun_SimpleString("import m5.main"); 1613102Sstever@eecs.umich.edu PyRun_SimpleString("m5.main.main()"); 1622667Sstever@eecs.umich.edu 1632667Sstever@eecs.umich.edu // clean up Python intepreter. 1642655Sstever@eecs.umich.edu Py_Finalize(); 1652667Sstever@eecs.umich.edu} 1661388SN/A 1672762Sstever@eecs.umich.edu 1682762Sstever@eecs.umich.eduvoid 1692762Sstever@eecs.umich.edusetOutputDir(const string &dir) 1702762Sstever@eecs.umich.edu{ 1712762Sstever@eecs.umich.edu simout.setDirectory(dir); 1722762Sstever@eecs.umich.edu} 1732762Sstever@eecs.umich.edu 1742762Sstever@eecs.umich.edu 1752738Sstever@eecs.umich.eduIniFile inifile; 1762667Sstever@eecs.umich.edu 1772738Sstever@eecs.umich.eduSimObject * 1782738Sstever@eecs.umich.educreateSimObject(const string &name) 1792738Sstever@eecs.umich.edu{ 1802738Sstever@eecs.umich.edu return SimObjectClass::createObject(inifile, name); 1812738Sstever@eecs.umich.edu} 1822738Sstever@eecs.umich.edu 1832738Sstever@eecs.umich.edu 1842738Sstever@eecs.umich.edu/** 1852738Sstever@eecs.umich.edu * Pointer to the Python function that maps names to SimObjects. 1862738Sstever@eecs.umich.edu */ 1872738Sstever@eecs.umich.eduPyObject *resolveFunc = NULL; 1882738Sstever@eecs.umich.edu 1892738Sstever@eecs.umich.edu/** 1902738Sstever@eecs.umich.edu * Convert a pointer to the Python object that SWIG wraps around a C++ 1912738Sstever@eecs.umich.edu * SimObject pointer back to the actual C++ pointer. See main.i. 1922738Sstever@eecs.umich.edu */ 1932738Sstever@eecs.umich.eduextern "C" SimObject *convertSwigSimObjectPtr(PyObject *); 1942738Sstever@eecs.umich.edu 1952738Sstever@eecs.umich.edu 1962738Sstever@eecs.umich.eduSimObject * 1972738Sstever@eecs.umich.eduresolveSimObject(const string &name) 1982738Sstever@eecs.umich.edu{ 1992738Sstever@eecs.umich.edu PyObject *pyPtr = PyEval_CallFunction(resolveFunc, "(s)", name.c_str()); 2002738Sstever@eecs.umich.edu if (pyPtr == NULL) { 2012738Sstever@eecs.umich.edu PyErr_Print(); 2022738Sstever@eecs.umich.edu panic("resolveSimObject: failure on call to Python for %s", name); 2032738Sstever@eecs.umich.edu } 2042738Sstever@eecs.umich.edu 2052738Sstever@eecs.umich.edu SimObject *simObj = convertSwigSimObjectPtr(pyPtr); 2062738Sstever@eecs.umich.edu if (simObj == NULL) 2072738Sstever@eecs.umich.edu panic("resolveSimObject: failure on pointer conversion for %s", name); 2082738Sstever@eecs.umich.edu 2092738Sstever@eecs.umich.edu return simObj; 2102738Sstever@eecs.umich.edu} 2112738Sstever@eecs.umich.edu 2122738Sstever@eecs.umich.edu 2132738Sstever@eecs.umich.edu/** 2142738Sstever@eecs.umich.edu * Load config.ini into C++ database. Exported to Python via SWIG; 2152738Sstever@eecs.umich.edu * invoked from m5.instantiate(). 2162738Sstever@eecs.umich.edu */ 2172667Sstever@eecs.umich.eduvoid 2182738Sstever@eecs.umich.eduloadIniFile(PyObject *_resolveFunc) 2192667Sstever@eecs.umich.edu{ 2202738Sstever@eecs.umich.edu resolveFunc = _resolveFunc; 2212655Sstever@eecs.umich.edu configStream = simout.find("config.out"); 2221388SN/A 2232SN/A // The configuration database is now complete; start processing it. 2242928Sktlim@umich.edu inifile.load(simout.resolve("config.ini")); 2252SN/A 2261388SN/A // Initialize statistics database 2271388SN/A Stats::InitSimStats(); 2282738Sstever@eecs.umich.edu} 2292SN/A 2301310SN/A 2312738Sstever@eecs.umich.edu/** 2322738Sstever@eecs.umich.edu * Look up a MemObject port. Helper function for connectPorts(). 2332738Sstever@eecs.umich.edu */ 2342738Sstever@eecs.umich.eduPort * 2352738Sstever@eecs.umich.edulookupPort(SimObject *so, const std::string &name, int i) 2362738Sstever@eecs.umich.edu{ 2372738Sstever@eecs.umich.edu MemObject *mo = dynamic_cast<MemObject *>(so); 2382738Sstever@eecs.umich.edu if (mo == NULL) { 2392738Sstever@eecs.umich.edu warn("error casting SimObject %s to MemObject", so->name()); 2402738Sstever@eecs.umich.edu return NULL; 2412738Sstever@eecs.umich.edu } 2422738Sstever@eecs.umich.edu 2432738Sstever@eecs.umich.edu Port *p = mo->getPort(name, i); 2442738Sstever@eecs.umich.edu if (p == NULL) 2452738Sstever@eecs.umich.edu warn("error looking up port %s on object %s", name, so->name()); 2462738Sstever@eecs.umich.edu return p; 2472738Sstever@eecs.umich.edu} 2482738Sstever@eecs.umich.edu 2492738Sstever@eecs.umich.edu 2502738Sstever@eecs.umich.edu/** 2512738Sstever@eecs.umich.edu * Connect the described MemObject ports. Called from Python via SWIG. 2522738Sstever@eecs.umich.edu */ 2532738Sstever@eecs.umich.eduint 2542738Sstever@eecs.umich.educonnectPorts(SimObject *o1, const std::string &name1, int i1, 2552738Sstever@eecs.umich.edu SimObject *o2, const std::string &name2, int i2) 2562738Sstever@eecs.umich.edu{ 2572738Sstever@eecs.umich.edu Port *p1 = lookupPort(o1, name1, i1); 2582738Sstever@eecs.umich.edu Port *p2 = lookupPort(o2, name2, i2); 2592738Sstever@eecs.umich.edu 2602738Sstever@eecs.umich.edu if (p1 == NULL || p2 == NULL) { 2612738Sstever@eecs.umich.edu warn("connectPorts: port lookup error"); 2622738Sstever@eecs.umich.edu return 0; 2632738Sstever@eecs.umich.edu } 2642738Sstever@eecs.umich.edu 2652738Sstever@eecs.umich.edu p1->setPeer(p2); 2662738Sstever@eecs.umich.edu p2->setPeer(p1); 2672738Sstever@eecs.umich.edu 2682738Sstever@eecs.umich.edu return 1; 2692738Sstever@eecs.umich.edu} 2702738Sstever@eecs.umich.edu 2712738Sstever@eecs.umich.edu/** 2722738Sstever@eecs.umich.edu * Do final initialization steps after object construction but before 2732738Sstever@eecs.umich.edu * start of simulation. 2742738Sstever@eecs.umich.edu */ 2752738Sstever@eecs.umich.eduvoid 2762738Sstever@eecs.umich.edufinalInit() 2772738Sstever@eecs.umich.edu{ 2781388SN/A // Parse and check all non-config-hierarchy parameters. 2791388SN/A ParamContext::parseAllContexts(inifile); 2801388SN/A ParamContext::checkAllContexts(); 2811388SN/A 2822667Sstever@eecs.umich.edu // Echo all parameter settings to stats file as well. 2831104SN/A ParamContext::showAllContexts(*configStream); 2842SN/A 2851127SN/A // Do a second pass to finish initializing the sim objects 2861127SN/A SimObject::initAll(); 2871127SN/A 2882SN/A // Restore checkpointed state, if any. 2892738Sstever@eecs.umich.edu#if 0 2902SN/A configHierarchy.unserializeSimObjects(); 2912738Sstever@eecs.umich.edu#endif 2922SN/A 2932SN/A SimObject::regAllStats(); 2942SN/A 2952SN/A // Check to make sure that the stats package is properly initialized 296729SN/A Stats::check(); 2972SN/A 298395SN/A // Reset to put the stats in a consistent state. 299729SN/A Stats::reset(); 300395SN/A 3011127SN/A SimStartup(); 3022667Sstever@eecs.umich.edu} 3032667Sstever@eecs.umich.edu 3042667Sstever@eecs.umich.edu 3052667Sstever@eecs.umich.edu/** Simulate for num_cycles additional cycles. If num_cycles is -1 3062667Sstever@eecs.umich.edu * (the default), do not limit simulation; some other event must 3072667Sstever@eecs.umich.edu * terminate the loop. Exported to Python via SWIG. 3082667Sstever@eecs.umich.edu * @return The SimLoopExitEvent that caused the loop to exit. 3092667Sstever@eecs.umich.edu */ 3102667Sstever@eecs.umich.eduSimLoopExitEvent * 3113511Shsul@eecs.umich.edusimulate(Tick num_cycles = MaxTick) 3122667Sstever@eecs.umich.edu{ 3132667Sstever@eecs.umich.edu warn("Entering event queue @ %d. Starting simulation...\n", curTick); 3142667Sstever@eecs.umich.edu 3153511Shsul@eecs.umich.edu if (num_cycles < 0) 3163511Shsul@eecs.umich.edu fatal("simulate: num_cycles must be >= 0 (was %d)\n", num_cycles); 3173511Shsul@eecs.umich.edu else if (curTick + num_cycles < 0) //Overflow 3182667Sstever@eecs.umich.edu num_cycles = MaxTick; 3192667Sstever@eecs.umich.edu else 3202667Sstever@eecs.umich.edu num_cycles = curTick + num_cycles; 3212667Sstever@eecs.umich.edu 3223144Shsul@eecs.umich.edu Event *limit_event = schedExitSimLoop("simulate() limit reached", 3233144Shsul@eecs.umich.edu num_cycles); 3242667Sstever@eecs.umich.edu 3252667Sstever@eecs.umich.edu while (1) { 3262667Sstever@eecs.umich.edu // there should always be at least one event (the SimLoopExitEvent 3272667Sstever@eecs.umich.edu // we just scheduled) in the queue 3282667Sstever@eecs.umich.edu assert(!mainEventQueue.empty()); 3292SN/A assert(curTick <= mainEventQueue.nextTick() && 3302SN/A "event scheduled in the past"); 3312SN/A 3322SN/A // forward current cycle to the time of the first event on the 3332SN/A // queue 3342SN/A curTick = mainEventQueue.nextTick(); 3352667Sstever@eecs.umich.edu Event *exit_event = mainEventQueue.serviceOne(); 3362667Sstever@eecs.umich.edu if (exit_event != NULL) { 3372667Sstever@eecs.umich.edu // hit some kind of exit event; return to Python 3382667Sstever@eecs.umich.edu // event must be subclass of SimLoopExitEvent... 3392667Sstever@eecs.umich.edu SimLoopExitEvent *se_event = dynamic_cast<SimLoopExitEvent *>(exit_event); 3402667Sstever@eecs.umich.edu if (se_event == NULL) 3412667Sstever@eecs.umich.edu panic("Bogus exit event class!"); 3422667Sstever@eecs.umich.edu 3432667Sstever@eecs.umich.edu // if we didn't hit limit_event, delete it 3442667Sstever@eecs.umich.edu if (se_event != limit_event) { 3452667Sstever@eecs.umich.edu assert(limit_event->scheduled()); 3462667Sstever@eecs.umich.edu limit_event->deschedule(); 3472667Sstever@eecs.umich.edu delete limit_event; 3482667Sstever@eecs.umich.edu } 3492667Sstever@eecs.umich.edu 3502667Sstever@eecs.umich.edu return se_event; 3512667Sstever@eecs.umich.edu } 3522SN/A 3532SN/A if (async_event) { 3542SN/A async_event = false; 3552SN/A if (async_dump) { 3562SN/A async_dump = false; 357294SN/A 358729SN/A using namespace Stats; 359294SN/A SetupEvent(Dump, curTick); 3602SN/A } 3612SN/A 362329SN/A if (async_dumpreset) { 363329SN/A async_dumpreset = false; 364329SN/A 365729SN/A using namespace Stats; 366329SN/A SetupEvent(Dump | Reset, curTick); 367329SN/A } 368329SN/A 3692SN/A if (async_exit) { 3702SN/A async_exit = false; 3712667Sstever@eecs.umich.edu exitSimLoop("user interrupt received"); 3722SN/A } 3732SN/A 3742SN/A if (async_io || async_alarm) { 3752SN/A async_io = false; 3762SN/A async_alarm = false; 3772SN/A pollQueue.service(); 3782SN/A } 3792SN/A } 3802SN/A } 3812SN/A 3822667Sstever@eecs.umich.edu // not reached... only exit is return on SimLoopExitEvent 3832667Sstever@eecs.umich.edu} 3842SN/A 3852797Sktlim@umich.eduEvent * 3862839Sktlim@umich.educreateCountedDrain() 3872797Sktlim@umich.edu{ 3882839Sktlim@umich.edu return new CountedDrainEvent(); 3892797Sktlim@umich.edu} 3902797Sktlim@umich.edu 3912797Sktlim@umich.eduvoid 3922839Sktlim@umich.educleanupCountedDrain(Event *counted_drain) 3932797Sktlim@umich.edu{ 3942839Sktlim@umich.edu CountedDrainEvent *event = 3952839Sktlim@umich.edu dynamic_cast<CountedDrainEvent *>(counted_drain); 3962797Sktlim@umich.edu if (event == NULL) { 3972839Sktlim@umich.edu fatal("Called cleanupCountedDrain() on an event that was not " 3982839Sktlim@umich.edu "a CountedDrainEvent."); 3992797Sktlim@umich.edu } 4002797Sktlim@umich.edu assert(event->getCount() == 0); 4012797Sktlim@umich.edu delete event; 4022797Sktlim@umich.edu} 4032797Sktlim@umich.edu 4042797Sktlim@umich.eduvoid 4052868Sktlim@umich.eduserializeAll(const std::string &cpt_dir) 4062797Sktlim@umich.edu{ 4072868Sktlim@umich.edu Serializable::serializeAll(cpt_dir); 4082797Sktlim@umich.edu} 4092797Sktlim@umich.edu 4102797Sktlim@umich.eduvoid 4112868Sktlim@umich.eduunserializeAll(const std::string &cpt_dir) 4122797Sktlim@umich.edu{ 4132868Sktlim@umich.edu Serializable::unserializeAll(cpt_dir); 4142797Sktlim@umich.edu} 4152797Sktlim@umich.edu 4162667Sstever@eecs.umich.edu/** 4172667Sstever@eecs.umich.edu * Queue of C++ callbacks to invoke on simulator exit. 4182667Sstever@eecs.umich.edu */ 4193132Sbinkertn@umich.eduCallbackQueue& 4203132Sbinkertn@umich.eduexitCallbacks() 4213132Sbinkertn@umich.edu{ 4223132Sbinkertn@umich.edu static CallbackQueue theQueue; 4233132Sbinkertn@umich.edu return theQueue; 4243132Sbinkertn@umich.edu} 4252667Sstever@eecs.umich.edu 4262667Sstever@eecs.umich.edu/** 4272667Sstever@eecs.umich.edu * Register an exit callback. 4282667Sstever@eecs.umich.edu */ 4292667Sstever@eecs.umich.eduvoid 4302667Sstever@eecs.umich.eduregisterExitCallback(Callback *callback) 4312667Sstever@eecs.umich.edu{ 4323132Sbinkertn@umich.edu exitCallbacks().add(callback); 4332SN/A} 4342667Sstever@eecs.umich.edu 4352797Sktlim@umich.eduBaseCPU * 4362797Sktlim@umich.educonvertToBaseCPUPtr(SimObject *obj) 4372797Sktlim@umich.edu{ 4382797Sktlim@umich.edu BaseCPU *ptr = dynamic_cast<BaseCPU *>(obj); 4392797Sktlim@umich.edu 4402797Sktlim@umich.edu if (ptr == NULL) 4412797Sktlim@umich.edu warn("Casting to BaseCPU pointer failed"); 4422797Sktlim@umich.edu return ptr; 4432797Sktlim@umich.edu} 4442797Sktlim@umich.edu 4453202Shsul@eecs.umich.eduSystem * 4463202Shsul@eecs.umich.educonvertToSystemPtr(SimObject *obj) 4473202Shsul@eecs.umich.edu{ 4483202Shsul@eecs.umich.edu System *ptr = dynamic_cast<System *>(obj); 4493202Shsul@eecs.umich.edu 4503202Shsul@eecs.umich.edu if (ptr == NULL) 4513202Shsul@eecs.umich.edu warn("Casting to System pointer failed"); 4523202Shsul@eecs.umich.edu return ptr; 4533202Shsul@eecs.umich.edu} 4543202Shsul@eecs.umich.edu 4553202Shsul@eecs.umich.edu 4562667Sstever@eecs.umich.edu/** 4572667Sstever@eecs.umich.edu * Do C++ simulator exit processing. Exported to SWIG to be invoked 4582667Sstever@eecs.umich.edu * when simulator terminates via Python's atexit mechanism. 4592667Sstever@eecs.umich.edu */ 4602667Sstever@eecs.umich.eduvoid 4612667Sstever@eecs.umich.edudoExitCleanup() 4622667Sstever@eecs.umich.edu{ 4633132Sbinkertn@umich.edu exitCallbacks().process(); 4643132Sbinkertn@umich.edu exitCallbacks().clear(); 4652667Sstever@eecs.umich.edu 4662667Sstever@eecs.umich.edu cout.flush(); 4672667Sstever@eecs.umich.edu 4682667Sstever@eecs.umich.edu ParamContext::cleanupAllContexts(); 4692667Sstever@eecs.umich.edu 4702667Sstever@eecs.umich.edu // print simulation stats 4712667Sstever@eecs.umich.edu Stats::DumpNow(); 4722667Sstever@eecs.umich.edu} 473