GEM5源码阅读笔记 - embedclub/Lavender GitHub Wiki

阅读代码也是一种……^~^

src/sim/main.cc

// main() is now pretty stripped down and just sets up python and then
// calls initM5Python which loads the various embedded python modules
// into the python environment and then starts things running by
// calling m5Main.
int
main(int argc, char **argv)
{
   int ret;
   //该函数存在于同目录下init_signals.cc文件中
   // Initialize m5 special signal handling.
   initSignals();
   //未索引到该函数
   Py_SetProgramName(argv[0]);

   // initialize embedded Python interpreter
   Py_Initialize();

   // Initialize the embedded m5 python library
   ret = initM5Python();

   if (ret == 0) {
       // start m5
       //存在于文件init.cc中
       ret = m5Main(argc, argv);
   }

   // clean up Python intepreter.
   Py_Finalize();

   return ret;
}

gem5/src/sim/init_signals.cc

void
initSignals()
{
// Floating point exceptions may happen on misspeculated paths, so
// ignore them
signal(SIGFPE, SIG_IGN);

// Dump intermediate stats
installSignalHandler(SIGUSR1, dumpStatsHandler);

// Dump intermediate stats and reset them
installSignalHandler(SIGUSR2, dumprstStatsHandler);

// Exit cleanly on Interrupt (Ctrl-C)
installSignalHandler(SIGINT, exitNowHandler);

// Print the current cycle number and a backtrace on abort. Make
// sure the signal is unmasked and the handler reset when a signal
// is delivered to be able to invoke the default handler.
installSignalHandler(SIGABRT, abortHandler, SA_RESETHAND | SA_NODEFER);

// Setup a SIGSEGV handler with a private stack
if (setupAltStack()) {
    installSignalHandler(SIGSEGV, segvHandler,
                         SA_RESETHAND | SA_NODEFER | SA_ONSTACK);
} else {
    warn("Failed to setup stack for SIGSEGV handler, "
         "using default signal handler.\n");
}
            
// Install a SIGIO handler to handle asynchronous file IO. See the
// PollQueue class.
installSignalHandler(SIGIO, ioHandler);
}

src/sim/init.cc

/*

  • Start up the M5 simulator. This mostly vectors into the python

  • main function. */ int m5Main(int argc, char **argv) { #if HAVE_PROTOBUF // Verify that the version of the protobuf library that we linked // against is compatible with the version of the headers we // compiled against. GOOGLE_PROTOBUF_VERIFY_VERSION; #endif

    PySys_SetArgv(argc, argv);

    // We have to set things up in the special main module PyObject *module = PyImport_AddModule(PyCC("main")); if (module == NULL) panic("Could not import main"); PyObject *dict = PyModule_GetDict(module);

    // import the main m5 module PyObject *result; const char **command = m5MainCommands;

    // evaluate each command in the m5MainCommands array (basically a // bunch of python statements. while (*command) { result = PyRun_String(*command, Py_file_input, dict, dict); if (!result) { PyErr_Print(); return 1; } Py_DECREF(result);

     command++;
    

    }

#if HAVE_PROTOBUF google::protobuf::ShutdownProtobufLibrary(); #endif

return 0;

}