SimpleScalar Notes
[ Path: > Evan Jones' Scratch Pad > Patches | Written by Evan Jones ]
[ 2006-April-08 10:29 ]
SimpleScalar is a CPU simulator that is very useful for computer architecture research. However, it has not been updated for a long time, and I've found a couple of small bugs. Additionally, it took me a bit of work to be able to figure out how to compile a binary without linking against the C library.
Minimal SimpleScalar Binary
Typically SimpleScalar binaries link against the C library. This is fine unless you are mucking around with the CPU internals and have broken backwards compatibility. I've created a minimal "library" that you can use to link C programs: libinit.s. Basically, the steps are:
- Assemble this library (
as -o libinit.o libinit.s) - Compile your C program (
gcc -c program.c). You may wish to use the-ffast-mathswitch to get GCC to convert some math function calls into instructions. For example, it will convert calls to the C library'ssqrtfunction into calls to thesqrtinstruction. - Link the two together (
ld -o program program.o libinit.o)
The result is a C program that does not use the C library. Of course, this also means you can't use any of the C library functions, such as printf or malloc. You may also need my loader patch to get SimpleScalar to execute your binary.
Loader Patch
The SimpleScalar loader has a bug: it will fail to run binaries if they are missing some sections. Here is a tiny patch to the loader to fix this problem. Without this patch, it will print: fatal: could not read text section from executable." Interestingly enough, the Alpha code already had part of this fix.
Mac OS X patch
SimpleScalar runs just fine under Mac OS X. However, to get it to build you will need to apply my quick and dirty patch This patch applies cleanly against simplesim-3v0d-1.tgz. It passes all the tests, and I've used it for a course project so I'm reasonably confident that it is correct. Note: To apply the patch use patch -p0 < simplesim-3-macosx.patch. If you need more help using GNU patch, check out the manual.