Computer Architecture project——simplescalar under Ubuntu/在Ubuntu10.04下安装simplescalar

原创 2011年10月13日 13:32:45


My first mission is installing simplescalar. And before that I need a linux. And before that, I need a visual machine :(  

So I just use the I believe this software can be easily found everywhere. But because of the ip problem,I cannot download this software free, my father helped me to do this and sent it to me via QQ.... The good thing is that everything about VM goes smoothly. And then ,I installed Ubuntu10.04, which you can find here :

Also, it only takes no more than one hour for me, although some of my classmates faced the problem that the Ubuntu cannot connected to the Internet.

Now comes Simplescalar. Here is a great video teaching how to install simplescalar under Ubuntu.

If you follow the video step by step and make every stage right, then congratulation! However, there are still some parts unclear in the video, especially to the beginner of Linux,like me. I tried four times and finally made it. So I made some changes, add some code and explanation to make it easier to understand. The changes and explanation made by me are in a different color.  If you have read the original blog and faced some problems, you can just look for these color. 

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 directs to my host space)

Simpletools-2v0.tgz – |

Simplesim-3v0d.tar.gz – |

Simpleutils-990811.tar.gz – | –

Setting up environment

Open up the terminal and type

1 uname -a

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

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.

1 mkdir $IDIR
2 cd $IDIR

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.

1 $ sudo apt-get install flex bison build-essential

Sometimes errors occur, what I did is just restarting the terminal and trying this command again. You can use this command as the first step.
Please note, when you enter the passwords,they will not show up in the screen, but actually, they are there.

Installing Simple tools

Just un-pack the package file, and remove the old gcc folder. To do so, use:

1 cd $IDIR
2 tar xzvf simpletools-2v0.tgz
3 rm -rf gcc-2.6.3

These can be done in the folder by yourself. Extract the file and delete gcc-2.6.3

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
2 make
3 make install

Installing Simulator

Un-pack the simulator package.

1 cd $IDIR
2 tar xzvf simplesim-3v0d.tgz
3 cd simplesim-3.0
4 make config-pisa
5 make

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.

1 cd $IDIR
2 tar xzvf gcc-
3 cd gcc-
4 exportPATH=$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.) Change the Makefile at line 130, by appending –I/usr/include to the end of the line

To do so you can use command

1 $ gedit Makefile


2.) Edit line 60 of protoize.c, and replace

#include <varargs.h> with #include <stdarg.h>

To do so you can use command

1 chmod +w protoize.c
2 $ gedit protoize.c

3.) Edit obstack.h at line 341 and change

*((void **)__o->next_free)++=((void *)datum); 


*((void **)__o->next_free++)=((void *)datum);

To do so you can use the following command

1 chmod +w obstack.h
2 $ gedit obstack.h

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

This is really the most important step. If you did wrong in this step, there is no way to install it successfully. Also, if you follow the video,you will find some instructions he/she uses do not work on your ubuntu. So, what I did is to do it manually. Extract this file and you will get a folder,named ar&ranlib. Two files,ar and ranlib, are in this folder. And in the destination folder, also exist two files with the same name, ar and ranlib.REPLACE the old ones with the new ones.

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
2 ls -al

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>

$ cd $IDIR/gcc-


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

1 $ gedit insn-output.c
2 make

2.) In objc/sendmsg.c, add the following code at line 35

#define STRUCT_VALUE 0
1 cd $IDIR/gcc-
2 chmod +w sendmsg.c
3 $ gedit sendmsg.c
4 cd ..
5 make LANGUAGES="c c++" CFLAGS="-O" CC="gcc"

Here it is an "O",not zero.

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.

1 chmod +w cxxmain.c
2 $ gedit cxxmain.c

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"


To test the simulator use these commands

1 clear
2 cd $IDIR
3 $ gedit hello.c

Now in Gedit you can write your program like this (You may modify it)

main (void)
printf("My name is T.J. I'm a student in UFL. This is the first time sharing my knowledge. Hope this can be helpful!");

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 **
My name is T.J. I'm a student in UFL. This is the first time sharing my knowledge. Hope this can be helpful!
05 sim: ** simulation statistics **
06 sim_num_insn                   9242 # total number of instructions executed
07 sim_num_refs                   4328 # total number of loads and stores executed
08 sim_elapsed_time                  1 # total simulation time in seconds
09 sim_inst_rate             9242.0000 # simulation speed (in insts/sec)
10 ld_text_base             0×00400000 # program text (code) segment base
11 ld_text_size                  71968 # program text (code) size in bytes
12 ld_data_base             0×10000000 # program initialized data segment base
13 ld_data_size                   8528 # program init’ed `.data’ and uninit’ed `.bss’ size in bytes
14 ld_stack_base            0×7fffc000 # program stack segment base (highest address in stack)
15 ld_stack_size                 16384 # program initial stack size
16 ld_prog_entry            0×00400140 # program entry point (initial PC)
17 ld_environ_base          0×7fff8000 # program environment base address address
18 ld_target_big_endian              0 # target executable endian-ness, non-zero if big endian
19 mem.page_count                   26 # total number of pages allocated
20 mem.page_mem                   104k # total size of memory pages allocated
21 mem.ptab_misses                  26 # total first level page table misses
22 mem.ptab_accesses            495046 # total page table accesses
23 mem.ptab_miss_rate           0.0001 # first level page table miss rate

That's it! Congratulations! Hope my changes helpful

Thanks a lot to . ^_^

Simplescalar is installed successfully. However, I still do not know how to use is.And I am facing the task of the next week, implementing PAs branch predictor.......Seems really hard to me. Anyway, I will work on it.






Simpletools-2v0.tgz – |

Simplesim-3v0d.tar.gz – |

Simpleutils-990811.tar.gz – | –



1 uname -a

然后可以知道你的版本还有linux的类型 (i386/i686)

HOST=i686-pc-linux 或者 HOST=i386-pc-linux

2 export IDIR=/home/YOUR_USER_NAME/simplescalar
3 export TARGET=sslittle-na-sstrix


1 cd $IDIR


  • flex
  • bison
  • build-essential


1 $ sudo apt-get install flex bison build-essential


安装 Simple tools


1 cd $IDIR
2 tar xzvf simpletools-2v0.tgz