main.cc revision 2737
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"
581717SN/A#include "cpu/base.hh"
591717SN/A#include "cpu/smt.hh"
60146SN/A#include "sim/async.hh"
61146SN/A#include "sim/builder.hh"
62146SN/A#include "sim/configfile.hh"
63146SN/A#include "sim/host.hh"
6456SN/A#include "sim/sim_events.hh"
6556SN/A#include "sim/sim_exit.hh"
6656SN/A#include "sim/sim_object.hh"
67695SN/A#include "sim/stat_control.hh"
68695SN/A#include "sim/stats.hh"
691696SN/A#include "sim/root.hh"
702SN/A
712SN/Ausing namespace std;
722SN/A
732SN/A// See async.h.
742SN/Avolatile bool async_event = false;
752SN/Avolatile bool async_dump = false;
76329SN/Avolatile bool async_dumpreset = false;
772SN/Avolatile bool async_exit = false;
782SN/Avolatile bool async_io = false;
792SN/Avolatile bool async_alarm = false;
802SN/A
812SN/A/// Stats signal handler.
822SN/Avoid
832SN/AdumpStatsHandler(int sigtype)
842SN/A{
852SN/A    async_event = true;
862SN/A    async_dump = true;
872SN/A}
882SN/A
89329SN/Avoid
90329SN/AdumprstStatsHandler(int sigtype)
91329SN/A{
92329SN/A    async_event = true;
93329SN/A    async_dumpreset = true;
94329SN/A}
95329SN/A
962SN/A/// Exit signal handler.
972SN/Avoid
982SN/AexitNowHandler(int sigtype)
992SN/A{
1002SN/A    async_event = true;
1012SN/A    async_exit = true;
1022SN/A}
1032SN/A
104764SN/A/// Abort signal handler.
105764SN/Avoid
106764SN/AabortHandler(int sigtype)
107764SN/A{
108764SN/A    cerr << "Program aborted at cycle " << curTick << endl;
109764SN/A
110764SN/A#if TRACING_ON
111764SN/A    // dump trace buffer, if there is one
112764SN/A    Trace::theLog.dump(cerr);
113764SN/A#endif
114764SN/A}
115764SN/A
1162729Ssaidi@eecs.umich.edu/// Simulator executable name
1172729Ssaidi@eecs.umich.educhar *myProgName = "";
1182729Ssaidi@eecs.umich.edu
1192729Ssaidi@eecs.umich.edu/// Show brief help message.
1202729Ssaidi@eecs.umich.eduvoid
1212729Ssaidi@eecs.umich.edushowBriefHelp(ostream &out)
1222729Ssaidi@eecs.umich.edu{
1232729Ssaidi@eecs.umich.edu    char *prog = basename(myProgName);
1242729Ssaidi@eecs.umich.edu
1252729Ssaidi@eecs.umich.edu    ccprintf(out, "Usage:\n");
1262729Ssaidi@eecs.umich.edu    ccprintf(out,
1272729Ssaidi@eecs.umich.edu"%s [-p <path>] [-i ] [-h] <config file>\n"
1282729Ssaidi@eecs.umich.edu"\n"
1292729Ssaidi@eecs.umich.edu" -p, --path <path>  prepends <path> to PYTHONPATH instead of using\n"
1302729Ssaidi@eecs.umich.edu"                    built-in zip archive.  Useful when developing/debugging\n"
1312729Ssaidi@eecs.umich.edu"                    changes to built-in Python libraries, as the new Python\n"
1322729Ssaidi@eecs.umich.edu"                    can be tested without building a new m5 binary.\n\n"
1332729Ssaidi@eecs.umich.edu" -i, --interactive  forces entry into interactive mode after the supplied\n"
1342729Ssaidi@eecs.umich.edu"                    script is executed (just like the -i option to  the\n"
1352729Ssaidi@eecs.umich.edu"                    Python interpreter).\n\n"
1362729Ssaidi@eecs.umich.edu" -h                 Prints this help\n\n"
1372737Ssaidi@eecs.umich.edu" <configfile>       config file name which ends in .py. (Normally you can\n"
1382737Ssaidi@eecs.umich.edu"                    run <configfile> --help to get help on that config files\n"
1392737Ssaidi@eecs.umich.edu"                    parameters.\n\n",
1402729Ssaidi@eecs.umich.edu             prog);
1412729Ssaidi@eecs.umich.edu
1422729Ssaidi@eecs.umich.edu}
1432SN/A
1442667Sstever@eecs.umich.educonst char *briefCopyright =
1452667Sstever@eecs.umich.edu"Copyright (c) 2001-2006\n"
1462667Sstever@eecs.umich.edu"The Regents of The University of Michigan\n"
1472667Sstever@eecs.umich.edu"All Rights Reserved\n";
1482667Sstever@eecs.umich.edu
1492667Sstever@eecs.umich.edu/// Print welcome message.
1501388SN/Avoid
1512667Sstever@eecs.umich.edusayHello(ostream &out)
1522SN/A{
1532667Sstever@eecs.umich.edu    extern const char *compileDate;     // from date.cc
1542SN/A
1552667Sstever@eecs.umich.edu    ccprintf(out, "M5 Simulator System\n");
1562667Sstever@eecs.umich.edu    // display copyright
1572667Sstever@eecs.umich.edu    ccprintf(out, "%s\n", briefCopyright);
1582667Sstever@eecs.umich.edu    ccprintf(out, "M5 compiled %d\n", compileDate);
1592667Sstever@eecs.umich.edu    ccprintf(out, "M5 started %s\n", Time::start);
1602SN/A
1612667Sstever@eecs.umich.edu    char *host = getenv("HOSTNAME");
1622667Sstever@eecs.umich.edu    if (!host)
1632667Sstever@eecs.umich.edu        host = getenv("HOST");
1642SN/A
1652667Sstever@eecs.umich.edu    if (host)
1662667Sstever@eecs.umich.edu        ccprintf(out, "M5 executing on %s\n", host);
1672667Sstever@eecs.umich.edu}
1682SN/A
1692SN/A
1702667Sstever@eecs.umich.eduextern "C" { void init_main(); }
1712SN/A
1722SN/Aint
1732SN/Amain(int argc, char **argv)
1742SN/A{
1752729Ssaidi@eecs.umich.edu    // Saze off program name
1762729Ssaidi@eecs.umich.edu    myProgName = argv[0];
1772729Ssaidi@eecs.umich.edu
1782667Sstever@eecs.umich.edu    sayHello(cerr);
1792SN/A
1802SN/A    signal(SIGFPE, SIG_IGN);		// may occur on misspeculated paths
1812SN/A    signal(SIGTRAP, SIG_IGN);
182329SN/A    signal(SIGUSR1, dumpStatsHandler);		// dump intermediate stats
183329SN/A    signal(SIGUSR2, dumprstStatsHandler);	// dump and reset stats
184329SN/A    signal(SIGINT, exitNowHandler);		// dump final stats and exit
185764SN/A    signal(SIGABRT, abortHandler);
1862SN/A
1872655Sstever@eecs.umich.edu    Py_SetProgramName(argv[0]);
1882667Sstever@eecs.umich.edu
1892667Sstever@eecs.umich.edu    // default path to m5 python code is the currently executing
1902667Sstever@eecs.umich.edu    // file... Python ZipImporter will find embedded zip archive
1912667Sstever@eecs.umich.edu    char *pythonpath = argv[0];
1922667Sstever@eecs.umich.edu
1932667Sstever@eecs.umich.edu    bool interactive = false;
1942729Ssaidi@eecs.umich.edu    bool show_help = false;
1952667Sstever@eecs.umich.edu    bool getopt_done = false;
1962729Ssaidi@eecs.umich.edu    int opt_index = 0;
1972729Ssaidi@eecs.umich.edu
1982729Ssaidi@eecs.umich.edu    static struct option long_options[] = {
1992729Ssaidi@eecs.umich.edu        {"python", 1, 0, 'p'},
2002729Ssaidi@eecs.umich.edu        {"interactive", 0, 0, 'i'},
2012729Ssaidi@eecs.umich.edu        {"help", 0, 0, 'h'},
2022729Ssaidi@eecs.umich.edu        {0,0,0,0}
2032729Ssaidi@eecs.umich.edu    };
2042729Ssaidi@eecs.umich.edu
2052667Sstever@eecs.umich.edu    do {
2062729Ssaidi@eecs.umich.edu        switch (getopt_long(argc, argv, "+p:ih", long_options, &opt_index)) {
2072667Sstever@eecs.umich.edu            // -p <path> prepends <path> to PYTHONPATH instead of
2082667Sstever@eecs.umich.edu            // using built-in zip archive.  Useful when
2092667Sstever@eecs.umich.edu            // developing/debugging changes to built-in Python
2102667Sstever@eecs.umich.edu            // libraries, as the new Python can be tested without
2112667Sstever@eecs.umich.edu            // building a new m5 binary.
2122667Sstever@eecs.umich.edu          case 'p':
2132667Sstever@eecs.umich.edu            pythonpath = optarg;
2142667Sstever@eecs.umich.edu            break;
2152667Sstever@eecs.umich.edu
2162667Sstever@eecs.umich.edu            // -i forces entry into interactive mode after the
2172667Sstever@eecs.umich.edu            // supplied script is executed (just like the -i option to
2182667Sstever@eecs.umich.edu            // the Python interpreter).
2192667Sstever@eecs.umich.edu          case 'i':
2202667Sstever@eecs.umich.edu            interactive = true;
2212667Sstever@eecs.umich.edu            break;
2222667Sstever@eecs.umich.edu
2232729Ssaidi@eecs.umich.edu          case 'h':
2242729Ssaidi@eecs.umich.edu            show_help = true;
2252729Ssaidi@eecs.umich.edu            break;
2262667Sstever@eecs.umich.edu          case -1:
2272667Sstever@eecs.umich.edu            getopt_done = true;
2282667Sstever@eecs.umich.edu            break;
2292667Sstever@eecs.umich.edu
2302667Sstever@eecs.umich.edu          default:
2312667Sstever@eecs.umich.edu            fatal("Unrecognized option %c\n", optopt);
2322667Sstever@eecs.umich.edu        }
2332667Sstever@eecs.umich.edu    } while (!getopt_done);
2342667Sstever@eecs.umich.edu
2352729Ssaidi@eecs.umich.edu    if (show_help) {
2362729Ssaidi@eecs.umich.edu        showBriefHelp(cerr);
2372729Ssaidi@eecs.umich.edu        exit(1);
2382729Ssaidi@eecs.umich.edu    }
2392729Ssaidi@eecs.umich.edu
2402667Sstever@eecs.umich.edu    // Fix up argc & argv to hide arguments we just processed.
2412667Sstever@eecs.umich.edu    // getopt() sets optind to the index of the first non-processed
2422667Sstever@eecs.umich.edu    // argv element.
2432667Sstever@eecs.umich.edu    argc -= optind;
2442667Sstever@eecs.umich.edu    argv += optind;
2452667Sstever@eecs.umich.edu
2462667Sstever@eecs.umich.edu    // Set up PYTHONPATH to make sure the m5 module is found
2472667Sstever@eecs.umich.edu    string newpath(pythonpath);
2482667Sstever@eecs.umich.edu
2492667Sstever@eecs.umich.edu    char *oldpath = getenv("PYTHONPATH");
2502667Sstever@eecs.umich.edu    if (oldpath != NULL) {
2512667Sstever@eecs.umich.edu        newpath += ":";
2522667Sstever@eecs.umich.edu        newpath += oldpath;
2532667Sstever@eecs.umich.edu    }
2542667Sstever@eecs.umich.edu
2552667Sstever@eecs.umich.edu    if (setenv("PYTHONPATH", newpath.c_str(), true) == -1)
2562667Sstever@eecs.umich.edu        fatal("setenv: %s\n", strerror(errno));
2572667Sstever@eecs.umich.edu
2582667Sstever@eecs.umich.edu    // initialize embedded Python interpreter
2592655Sstever@eecs.umich.edu    Py_Initialize();
2602655Sstever@eecs.umich.edu    PySys_SetArgv(argc, argv);
2611311SN/A
2622667Sstever@eecs.umich.edu    // initialize SWIG 'main' module
2632667Sstever@eecs.umich.edu    init_main();
2641703SN/A
2652667Sstever@eecs.umich.edu    if (argc > 0) {
2662667Sstever@eecs.umich.edu        // extra arg(s): first is script file, remaining ones are args
2672667Sstever@eecs.umich.edu        // to script file
2682667Sstever@eecs.umich.edu        char *filename = argv[0];
2692667Sstever@eecs.umich.edu        FILE *fp = fopen(filename, "r");
2702667Sstever@eecs.umich.edu        if (!fp) {
2712667Sstever@eecs.umich.edu            fatal("cannot open file '%s'\n", filename);
2722667Sstever@eecs.umich.edu        }
2731703SN/A
2742667Sstever@eecs.umich.edu        PyRun_AnyFile(fp, filename);
2752667Sstever@eecs.umich.edu    } else {
2762667Sstever@eecs.umich.edu        // no script file argument... force interactive prompt
2772667Sstever@eecs.umich.edu        interactive = true;
2782667Sstever@eecs.umich.edu    }
2792SN/A
2802667Sstever@eecs.umich.edu    if (interactive) {
2812667Sstever@eecs.umich.edu        // The following code to import readline was copied from Python
2822667Sstever@eecs.umich.edu        // 2.4.3's Modules/main.c.
2832667Sstever@eecs.umich.edu        // Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006
2842667Sstever@eecs.umich.edu        // Python Software Foundation; All Rights Reserved
2852667Sstever@eecs.umich.edu        // We should only enable this if we're actually using an
2862667Sstever@eecs.umich.edu        // interactive prompt.
2872667Sstever@eecs.umich.edu        PyObject *v;
2882667Sstever@eecs.umich.edu        v = PyImport_ImportModule("readline");
2892667Sstever@eecs.umich.edu        if (v == NULL)
2902667Sstever@eecs.umich.edu            PyErr_Clear();
2912667Sstever@eecs.umich.edu        else
2922667Sstever@eecs.umich.edu            Py_DECREF(v);
2932667Sstever@eecs.umich.edu
2942667Sstever@eecs.umich.edu        PyRun_InteractiveLoop(stdin, "stdin");
2952667Sstever@eecs.umich.edu    }
2962667Sstever@eecs.umich.edu
2972667Sstever@eecs.umich.edu    // clean up Python intepreter.
2982655Sstever@eecs.umich.edu    Py_Finalize();
2992667Sstever@eecs.umich.edu}
3001388SN/A
3012667Sstever@eecs.umich.edu
3022667Sstever@eecs.umich.edu/// Initialize C++ configuration.  Exported to Python via SWIG; invoked
3032667Sstever@eecs.umich.edu/// from m5.instantiate().
3042667Sstever@eecs.umich.eduvoid
3052667Sstever@eecs.umich.eduinitialize()
3062667Sstever@eecs.umich.edu{
3072655Sstever@eecs.umich.edu    configStream = simout.find("config.out");
3081388SN/A
3092SN/A    // The configuration database is now complete; start processing it.
3101388SN/A    IniFile inifile;
3112655Sstever@eecs.umich.edu    inifile.load("config.ini");
3122SN/A
3131388SN/A    // Initialize statistics database
3141388SN/A    Stats::InitSimStats();
3152SN/A
3161310SN/A    // Now process the configuration hierarchy and create the SimObjects.
3171388SN/A    ConfigHierarchy configHierarchy(inifile);
3181310SN/A    configHierarchy.build();
3191310SN/A    configHierarchy.createSimObjects();
3201310SN/A
3211388SN/A    // Parse and check all non-config-hierarchy parameters.
3221388SN/A    ParamContext::parseAllContexts(inifile);
3231388SN/A    ParamContext::checkAllContexts();
3241388SN/A
3252667Sstever@eecs.umich.edu    // Echo all parameter settings to stats file as well.
3261104SN/A    ParamContext::showAllContexts(*configStream);
3272SN/A
3282499SN/A    // Any objects that can't connect themselves until after construction should
3292499SN/A    // do so now
3302499SN/A    SimObject::connectAll();
3312499SN/A
3321127SN/A    // Do a second pass to finish initializing the sim objects
3331127SN/A    SimObject::initAll();
3341127SN/A
3352SN/A    // Restore checkpointed state, if any.
3362SN/A    configHierarchy.unserializeSimObjects();
3372SN/A
3382SN/A    // Done processing the configuration database.
3392SN/A    // Check for unreferenced entries.
3401388SN/A    if (inifile.printUnreferenced())
3411388SN/A        panic("unreferenced sections/entries in the intermediate ini file");
3422SN/A
3432SN/A    SimObject::regAllStats();
3442SN/A
3452SN/A    // uncomment the following to get PC-based execution-time profile
3462SN/A#ifdef DO_PROFILE
3472SN/A    init_profile((char *)&_init, (char *)&_fini);
3482SN/A#endif
3492SN/A
3502SN/A    // Check to make sure that the stats package is properly initialized
351729SN/A    Stats::check();
3522SN/A
353395SN/A    // Reset to put the stats in a consistent state.
354729SN/A    Stats::reset();
355395SN/A
3561127SN/A    SimStartup();
3572667Sstever@eecs.umich.edu}
3582667Sstever@eecs.umich.edu
3592667Sstever@eecs.umich.edu
3602667Sstever@eecs.umich.edu/** Simulate for num_cycles additional cycles.  If num_cycles is -1
3612667Sstever@eecs.umich.edu * (the default), do not limit simulation; some other event must
3622667Sstever@eecs.umich.edu * terminate the loop.  Exported to Python via SWIG.
3632667Sstever@eecs.umich.edu * @return The SimLoopExitEvent that caused the loop to exit.
3642667Sstever@eecs.umich.edu */
3652667Sstever@eecs.umich.eduSimLoopExitEvent *
3662667Sstever@eecs.umich.edusimulate(Tick num_cycles = -1)
3672667Sstever@eecs.umich.edu{
3682667Sstever@eecs.umich.edu    warn("Entering event queue @ %d.  Starting simulation...\n", curTick);
3692667Sstever@eecs.umich.edu
3702667Sstever@eecs.umich.edu    // Fix up num_cycles.  Special default value -1 means simulate
3712667Sstever@eecs.umich.edu    // "forever"... schedule event at MaxTick just to be safe.
3722667Sstever@eecs.umich.edu    // Otherwise it's a delta for additional cycles to simulate past
3732667Sstever@eecs.umich.edu    // curTick, and thus must be non-negative.
3742667Sstever@eecs.umich.edu    if (num_cycles == -1)
3752667Sstever@eecs.umich.edu        num_cycles = MaxTick;
3762667Sstever@eecs.umich.edu    else if (num_cycles < 0)
3772667Sstever@eecs.umich.edu        fatal("simulate: num_cycles must be >= 0 (was %d)\n", num_cycles);
3782667Sstever@eecs.umich.edu    else
3792667Sstever@eecs.umich.edu        num_cycles = curTick + num_cycles;
3802667Sstever@eecs.umich.edu
3812667Sstever@eecs.umich.edu    Event *limit_event = new SimLoopExitEvent(num_cycles,
3822667Sstever@eecs.umich.edu                                              "simulate() limit reached");
3832667Sstever@eecs.umich.edu
3842667Sstever@eecs.umich.edu    while (1) {
3852667Sstever@eecs.umich.edu        // there should always be at least one event (the SimLoopExitEvent
3862667Sstever@eecs.umich.edu        // we just scheduled) in the queue
3872667Sstever@eecs.umich.edu        assert(!mainEventQueue.empty());
3882SN/A        assert(curTick <= mainEventQueue.nextTick() &&
3892SN/A               "event scheduled in the past");
3902SN/A
3912SN/A        // forward current cycle to the time of the first event on the
3922SN/A        // queue
3932SN/A        curTick = mainEventQueue.nextTick();
3942667Sstever@eecs.umich.edu        Event *exit_event = mainEventQueue.serviceOne();
3952667Sstever@eecs.umich.edu        if (exit_event != NULL) {
3962667Sstever@eecs.umich.edu            // hit some kind of exit event; return to Python
3972667Sstever@eecs.umich.edu            // event must be subclass of SimLoopExitEvent...
3982667Sstever@eecs.umich.edu            SimLoopExitEvent *se_event = dynamic_cast<SimLoopExitEvent *>(exit_event);
3992667Sstever@eecs.umich.edu            if (se_event == NULL)
4002667Sstever@eecs.umich.edu                panic("Bogus exit event class!");
4012667Sstever@eecs.umich.edu
4022667Sstever@eecs.umich.edu            // if we didn't hit limit_event, delete it
4032667Sstever@eecs.umich.edu            if (se_event != limit_event) {
4042667Sstever@eecs.umich.edu                assert(limit_event->scheduled());
4052667Sstever@eecs.umich.edu                limit_event->deschedule();
4062667Sstever@eecs.umich.edu                delete limit_event;
4072667Sstever@eecs.umich.edu            }
4082667Sstever@eecs.umich.edu
4092667Sstever@eecs.umich.edu            return se_event;
4102667Sstever@eecs.umich.edu        }
4112SN/A
4122SN/A        if (async_event) {
4132SN/A            async_event = false;
4142SN/A            if (async_dump) {
4152SN/A                async_dump = false;
416294SN/A
417729SN/A                using namespace Stats;
418294SN/A                SetupEvent(Dump, curTick);
4192SN/A            }
4202SN/A
421329SN/A            if (async_dumpreset) {
422329SN/A                async_dumpreset = false;
423329SN/A
424729SN/A                using namespace Stats;
425329SN/A                SetupEvent(Dump | Reset, curTick);
426329SN/A            }
427329SN/A
4282SN/A            if (async_exit) {
4292SN/A                async_exit = false;
4302667Sstever@eecs.umich.edu                exitSimLoop("user interrupt received");
4312SN/A            }
4322SN/A
4332SN/A            if (async_io || async_alarm) {
4342SN/A                async_io = false;
4352SN/A                async_alarm = false;
4362SN/A                pollQueue.service();
4372SN/A            }
4382SN/A        }
4392SN/A    }
4402SN/A
4412667Sstever@eecs.umich.edu    // not reached... only exit is return on SimLoopExitEvent
4422667Sstever@eecs.umich.edu}
4432SN/A
4442667Sstever@eecs.umich.edu/**
4452667Sstever@eecs.umich.edu * Queue of C++ callbacks to invoke on simulator exit.
4462667Sstever@eecs.umich.edu */
4472667Sstever@eecs.umich.eduCallbackQueue exitCallbacks;
4482667Sstever@eecs.umich.edu
4492667Sstever@eecs.umich.edu/**
4502667Sstever@eecs.umich.edu * Register an exit callback.
4512667Sstever@eecs.umich.edu */
4522667Sstever@eecs.umich.eduvoid
4532667Sstever@eecs.umich.eduregisterExitCallback(Callback *callback)
4542667Sstever@eecs.umich.edu{
4552667Sstever@eecs.umich.edu    exitCallbacks.add(callback);
4562SN/A}
4572667Sstever@eecs.umich.edu
4582667Sstever@eecs.umich.edu/**
4592667Sstever@eecs.umich.edu * Do C++ simulator exit processing.  Exported to SWIG to be invoked
4602667Sstever@eecs.umich.edu * when simulator terminates via Python's atexit mechanism.
4612667Sstever@eecs.umich.edu */
4622667Sstever@eecs.umich.eduvoid
4632667Sstever@eecs.umich.edudoExitCleanup()
4642667Sstever@eecs.umich.edu{
4652667Sstever@eecs.umich.edu    exitCallbacks.process();
4662667Sstever@eecs.umich.edu    exitCallbacks.clear();
4672667Sstever@eecs.umich.edu
4682667Sstever@eecs.umich.edu    cout.flush();
4692667Sstever@eecs.umich.edu
4702667Sstever@eecs.umich.edu    ParamContext::cleanupAllContexts();
4712667Sstever@eecs.umich.edu
4722667Sstever@eecs.umich.edu    // print simulation stats
4732667Sstever@eecs.umich.edu    Stats::DumpNow();
4742667Sstever@eecs.umich.edu}
475