24.22.3. gem5 entry point

The main is at: src/sim/main.cc. It calls:

ret = initM5Python();

src/sim/init.cc:

230 int
231 initM5Python()
232 {
233     EmbeddedPyBind::initAll();
234     return EmbeddedPython::initAll();
235 }

initAll basically just initializes the _m5 Python object, which is used across multiple .py.

Back on main:

ret = m5Main(argc, argv);

which goes to:

result = PyRun_String(*command, Py_file_input, dict, dict);

with commands looping over:

import m5
m5.main()

which leads into:

src/python/m5/main.py#main

which finally calls your config file like fs.py with:

filename = sys.argv[0]
filedata = file(filename, 'r').read()
filecode = compile(filedata, filename, 'exec')
[...]
exec filecode in scope

TODO: the file path name appears to be passed as a command line argument to the Python script, but I didn’t have the patience to fully understand the details.

The Python config files then set the entire system up in Python, and finally call m5.simulate() to run the actual simulation. This function has a C++ native implementation at:

src/sim/simulate.cc

and that is where the main event loop, doSimLoop, gets called and starts kicking off the gem5 event queue.

Tested at gem5 b4879ae5b0b6644e6836b0881e4da05c64a6550d.