SIMPLESCALAR INSTALLATION MADE SIMPLE
Preface
The following text describes the procedure of installation of Simple Scalar on Linux distro – Ubuntu. It was tested on Ubuntu 9.04 by me, and 8.10. The sources used while writing the post have been listed at the bottom and they hold the highest credit.
Update:
[September 23rd 2009] – It has been tested on Redhat too with the exception of omitting/avoiding Error #1 of GCC Cross Compiler installation
[August 14th 2011] – Check the video tutorial for Installation of SimpleScalar.
[September 25th 2012] – Removed Error #1 of GCC (September 2009 update. No need to do that) Checked on Ubuntu 11.04 & 12.04. If you run into errors feel free to ping me via contact page. I WILL do my best to assist you via TeamViewer or Join.me
Necessary Files
Download the necessary Source code files.
(Just for precaution, I’ve uploaded to my web-host in case the actual source is not available. The link igoY.in directs to my host space)
Simpletools-2v0.tgz – igoY.in | Simplescalar.com
Simplesim-3v0d.tar.gz – igoY.in | Simplescalar.com
Simpleutils-990811.tar.gz – igoY.in | Simplescalar.com
Gcc-2.7.2.3.ss.tar.gz – igoY.in
Setting up environment
Open up the terminal and type
You will get to know your kernel version and the type of linux installed (i386/i686)
Depending on that change the Host id below as either
HOST=i686-pc-linux or HOST=i386-pc-linux
1 | $ export HOST=FROM_ABOVE_OPTION |
2 | $ export IDIR=/home/YOUR_USER_NAME/simplescalar |
3 | $ export TARGET=sslittle-na-sstrix |
(If you use tcsh or the like, the only difference should be in how environment variables are set.)
Create the directory “simplescalar” under your home directory and copy all the four tar files into it. To do so, use the following commands.
Make sure you have installed the following packages
- flex
- bison
- build-essential
You can use the command “sudo apt-get install <PACKAGE_NAME>” to retrieve and install these packages.
Installing Simple tools
Just un-pack the package file, and remove the old gcc folder. To do so, use:
2 | $ tar xzvf simpletools-2v0.tgz |
Installing SimpleUtils
First un-pack the package file. To do so, use:
1 | $ tar xzvf simpleutils-990811. tar .gz |
2 | $ cd simpleutils-990811 |
Before building the code, you need to fix some sources of errors. In directory ld find file ldlex.l and replace all instances of
yy_current_buffer with YY_CURRENT_BUFFER.
You may either do it manually by opening the respected file and renaming it or to make it simple just type this code
1 | $ find . - type f -print0 | xargs -0 sed -i -e 's,yy_current_buffer,YY_CURRENT_BUFFER,g' |
1 | $ ./configure –host=$HOST –target=$TARGET –with-gnu-as –with-gnu-ld –prefix=$IDIR |
Installing Simulator
Un-pack the simulator package.
2 | $ tar xzvf simplesim-3v0d.tgz |
You may test the installation of simplesim by
1 | $ ./sim-safe tests/bin.little/ test -math |
Installing GCC Cross-Compiler
This is the important step where most of the newbies (including me) are/were struggling. So please follow these steps carefully.
2 | $ tar xzvf gcc-2.7.2.3.ss. tar .gz |
4 | $ export PATH=$PATH:/home/YOUR_USER_NAME/simplescalar/sslittle-na-sstrix/bin |
5 | $ ./configure –host=$HOST –target=$TARGET –with-gnu-as –with-gnu-ld –prefix=$IDIR |
Now before you proceed ahead, there are quite a few corrections that have to be made in some files:
1.) Lets start encountering our errors. We begin by issueing make command
2.) Edit line 60 of protoize.c, and replace
#include <varargs.h> with #include <stdarg.h>
Todo so you can use command
—
3.) Edit obstack.h at line 341 and change
*((void **)__o->next_free)++=((void *)datum);
with
*((void **)__o->next_free++)=((void *)datum);
To do so you can use the following command
—
4.) Copy the patched files located in the patched directory to avoid some parse errors while compiling. To do so use the following command.
1 | $ cp ./patched/sys/cdefs.h ../sslittle-na-sstrix/include/sys/cdefs.h |
2 | $ cp ../sslittle-na-sstrix/lib/libc.a ../lib/ |
3 | $ cp ../sslittle-na-sstrix/lib/crt0.o ../lib/ |
*If you dont find the patched directory in your browser, you probably didnt unrar it properly. Again unrar the GCC tar file “at a different location” (say your Desktop) and copy from it.
—
5.) *** Crucial Step*** Download this file, un-tar it and place its contents .i.e ar & ranlib in $IDIR/sslittle-na-sstrix/bin – FILE
You would also want to confirm that these files have “execution & write permission” You can do so by
1 | $ cd $IDIR /sslittle-na-sstrix/bin |
If you see each file of this folder with write(w) & execution(x) permission then you are ready to go further. If not then you have to assign them the permission by using
chmod +w <filename>
chmod +x <filename>
—
Again you will face few errors
1.) Now you will get many insn-output.c errors. To solve this you need to add line breaks (‘’) after each of the three FIXME (line 675, 750 and 823) in the insn-output.c
To open this file, use
—
2.) In objc/sendmsg.c, add the following code at line 35
#define STRUCT_VALUE 0
1 | $ cd $IDIR/gcc-2.7.2.3/objc |
5 | $ make LANGUAGES= "c c++" CFLAGS= "-O" CC= "gcc" |
—
3.) The last make command will lead to an error message which requires you to edit cxxmain.c file
To solve this you need to remove lines 2978-2979 in file cxxmain.c .i.e Remove the following lines
char * malloc ();
char * realloc ();
To do so, use this command.
—
Now cross your fingers, because we are about to execute the final error free make command.
1 | $ make LANGUAGES= "c c++" CFLAGS= "-O" CC= "gcc" |
2 | $ make install LANGUAGES= "c c++" CFLAGS= "-O" CC= "gcc" |
Testing
To test the simulator use these commands
Now in Gedit you can write your program like this (You may modify it)
[c]
#include<stdio.h>
main (void)
{
printf(“My name is Yogesh Mhatre.”);
}
[/c]
Once you are done writing the code, use the following command to test it.
1 | $ $IDIR/bin/sslittle-na-sstrix-gcc -o hello hello.c |
2 | $ $IDIR/simplesim-3.0/sim-safe hello |
You would “hopefully” get an output similar to this
01 | sim: ** starting functional simulation ** |
02 | My name is Yogesh Mhatre. |
04 | sim: ** simulation statistics ** |
08 | sim_inst_rate 9242.0000 |
09 | ld_text_base 0×00400000 |
11 | ld_data_base 0×10000000 |
13 | ld_stack_base 0×7fffc000 |
15 | ld_prog_entry 0×00400140 |
16 | ld_environ_base 0×7fff8000 |
17 | ld_target_big_endian 0 |
21 | mem.ptab_accesses 495046 |
22 | mem.ptab_miss_rate 0.0001 |
Thats said. You may scream now. “Whoopiee”
Good Luck! (Now wake me up when september ends)