main.cc revision 4123
111666Stushar@ece.gatech.edu/* 211666Stushar@ece.gatech.edu * Copyright (c) 2000-2005 The Regents of The University of Michigan 311666Stushar@ece.gatech.edu * All rights reserved. 411666Stushar@ece.gatech.edu * 511666Stushar@ece.gatech.edu * Redistribution and use in source and binary forms, with or without 611666Stushar@ece.gatech.edu * modification, are permitted provided that the following conditions are 711666Stushar@ece.gatech.edu * met: redistributions of source code must retain the above copyright 811666Stushar@ece.gatech.edu * notice, this list of conditions and the following disclaimer; 911666Stushar@ece.gatech.edu * redistributions in binary form must reproduce the above copyright 1011666Stushar@ece.gatech.edu * notice, this list of conditions and the following disclaimer in the 1111666Stushar@ece.gatech.edu * documentation and/or other materials provided with the distribution; 1211666Stushar@ece.gatech.edu * neither the name of the copyright holders nor the names of its 1311666Stushar@ece.gatech.edu * contributors may be used to endorse or promote products derived from 1411666Stushar@ece.gatech.edu * this software without specific prior written permission. 1511666Stushar@ece.gatech.edu * 1611666Stushar@ece.gatech.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1711666Stushar@ece.gatech.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1811666Stushar@ece.gatech.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1911666Stushar@ece.gatech.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2011666Stushar@ece.gatech.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2111666Stushar@ece.gatech.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2211666Stushar@ece.gatech.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2311666Stushar@ece.gatech.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2411666Stushar@ece.gatech.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2511666Stushar@ece.gatech.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2611666Stushar@ece.gatech.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2711666Stushar@ece.gatech.edu * 2811666Stushar@ece.gatech.edu * Authors: Nathan Binkert 2911666Stushar@ece.gatech.edu */ 3011666Stushar@ece.gatech.edu 3111666Stushar@ece.gatech.edu#include <Python.h> 3211666Stushar@ece.gatech.edu 3313665Sandreas.sandberg@arm.com#include <iostream> 3413665Sandreas.sandberg@arm.com#include <string> 3513665Sandreas.sandberg@arm.com 3611666Stushar@ece.gatech.edu#include "base/cprintf.hh" 3711666Stushar@ece.gatech.edu#include "base/misc.hh" 3811666Stushar@ece.gatech.edu#include "config/pythonhome.hh" 3911666Stushar@ece.gatech.edu#include "python/swig/init.hh" 4011666Stushar@ece.gatech.edu#include "sim/async.hh" 4111666Stushar@ece.gatech.edu#include "sim/host.hh" 4211666Stushar@ece.gatech.edu#include "sim/root.hh" 4311666Stushar@ece.gatech.edu 4411666Stushar@ece.gatech.eduusing namespace std; 4511666Stushar@ece.gatech.edu 4611666Stushar@ece.gatech.edu/// Stats signal handler. 4711666Stushar@ece.gatech.eduvoid 4811666Stushar@ece.gatech.edudumpStatsHandler(int sigtype) 4911762Sjieming.yin@amd.com{ 5011762Sjieming.yin@amd.com async_event = true; 5111666Stushar@ece.gatech.edu async_statdump = true; 5211666Stushar@ece.gatech.edu} 5311666Stushar@ece.gatech.edu 5411666Stushar@ece.gatech.eduvoid 5511666Stushar@ece.gatech.edudumprstStatsHandler(int sigtype) 5611666Stushar@ece.gatech.edu{ 5711666Stushar@ece.gatech.edu async_event = true; 5811666Stushar@ece.gatech.edu async_statdump = true; 5911666Stushar@ece.gatech.edu async_statreset = true; 6011666Stushar@ece.gatech.edu} 6111666Stushar@ece.gatech.edu 6211762Sjieming.yin@amd.com/// Exit signal handler. 6311762Sjieming.yin@amd.comvoid 6411666Stushar@ece.gatech.eduexitNowHandler(int sigtype) 6511666Stushar@ece.gatech.edu{ 6611666Stushar@ece.gatech.edu async_event = true; 6711666Stushar@ece.gatech.edu async_exit = true; 6811666Stushar@ece.gatech.edu} 6911666Stushar@ece.gatech.edu 7011666Stushar@ece.gatech.edu/// Abort signal handler. 7111666Stushar@ece.gatech.eduvoid 7211666Stushar@ece.gatech.eduabortHandler(int sigtype) 73{ 74 ccprintf(cerr, "Program aborted at cycle %d\n", curTick); 75} 76 77int 78main(int argc, char **argv) 79{ 80 signal(SIGFPE, SIG_IGN); // may occur on misspeculated paths 81 signal(SIGTRAP, SIG_IGN); 82 signal(SIGUSR1, dumpStatsHandler); // dump intermediate stats 83 signal(SIGUSR2, dumprstStatsHandler); // dump and reset stats 84 signal(SIGINT, exitNowHandler); // dump final stats and exit 85 signal(SIGABRT, abortHandler); 86 87 Py_SetProgramName(argv[0]); 88 89 // default path to m5 python code is the currently executing 90 // file... Python ZipImporter will find embedded zip archive. 91 // The M5_ARCHIVE environment variable can be used to override this. 92 char *m5_archive = getenv("M5_ARCHIVE"); 93 string pythonpath = m5_archive ? m5_archive : argv[0]; 94 95 char *oldpath = getenv("PYTHONPATH"); 96 if (oldpath != NULL) { 97 pythonpath += ":"; 98 pythonpath += oldpath; 99 } 100 101 if (setenv("PYTHONPATH", pythonpath.c_str(), true) == -1) 102 fatal("setenv: %s\n", strerror(errno)); 103 104 char *python_home = getenv("PYTHONHOME"); 105 if (!python_home) 106 python_home = PYTHONHOME; 107 Py_SetPythonHome(python_home); 108 109 // initialize embedded Python interpreter 110 Py_Initialize(); 111 PySys_SetArgv(argc, argv); 112 113 // initialize SWIG modules 114 init_swig(); 115 116 PyRun_SimpleString("import m5.main"); 117 PyRun_SimpleString("m5.main.main()"); 118 119 // clean up Python intepreter. 120 Py_Finalize(); 121} 122