Download PTLsim User's Guide and Reference - Facom-UFMS
Transcript
Chapter 11 PTLsim Classic Internals 11.1 Low Level Startup and Injection Note: This section deals with the internal operation of the PTLsim low level code, independent of the out of order simulation engine. If you are only interested in modifying the simulator itself, you can skip this section. Note: This section does not apply to the full system PTLsim/X; please see the corresponding sections in Part III instead. 11.1.1 Startup on x86-64 PTLsim is a very unusual Linux program. It does its own internal memory management and threading without help from the standard libraries, injects itself into other processes to take control of them, and switches between 32-bit and 64-bit mode within a single process image. For these reasons, it is very closely tied to the Linux kernel and uses a number of undocumented system calls and features only available in late 2.6 series kernels. PTLsim always starts and runs as a 64-bit process even when running 32-bit threads; it context switches between modes as needed. The statically linked ptlsim executable begins executing at ptlsim_preinit_entry in lowlevel-64bit.S. This code calls ptlsim_preinit() in kernel.cpp to set up our custom memory manager and threading environment before any standard C/C++ functions are used. After doing so, the normal main() function is invoked. The ptlsim binary can run in two modes. If executed from the command line as a normal program, it starts up in inject mode. Specifically, main() in ptlsim.cpp checks if the inside_ptlsim variable has been set by ptlsim_preinit_entry, and if not, PTLsim enters inject mode. In this mode, ptlsim_inject() in kernel.cpp is called to effectively inject the ptlsim binary into another process and pass control to it before even the dynamic linker gets to load the program. In ptlsim_inject(), the PTLsim process is forked and the child is placed under the parent’s control using ptrace(). The child process then uses exec() to start the user program to simulate (this can be either a 32-bit or 64-bit program). 52