simplescalar under Ubuntu/在Ubuntu10.04下安装simplescalar

来源:互联网 发布:nba2k16罗伊捏脸数据 编辑:程序博客网 时间:2024/05/16 12:32

声明,此日志是转载别人的:

中文版在后半部分.

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 VMware-workstation-full-v7.1.4.zip. 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 :

http://www.ubuntu.com/download/ubuntu/download


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. 

http://www.igoy.in/simplescalar-installation-video/


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 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

1uname -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

1export HOST=FROM_ABOVE_OPTION
2export IDIR=/home/YOUR_USER_NAME/simplescalar
3export 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.

1mkdir $IDIR
2cd $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:

1cd $IDIR
2tar xzvf simpletools-2v0.tgz
3rm -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:

1tar xzvf simpleutils-990811.tar.gz
2cd 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

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

Installing Simulator

Un-pack the simulator package.

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

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.

1cd $IDIR
2tar xzvf gcc-2.7.2.3.ss_.tar.gz
3cd gcc-2.7.2.3
4exportPATH=$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

makefile

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

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

To do so you can use command

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

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

1chmod +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.

1cp ./patched/sys/cdefs.h ../sslittle-na-sstrix/include/sys/cdefs.h
2cp ../sslittle-na-sstrix/lib/libc.a ../lib/
3cp ../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
2ls -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-2.7.2.3

 make

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

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

#define STRUCT_VALUE 0
1cd $IDIR/gcc-2.7.2.3/objc
2chmod +w sendmsg.c
3$ gedit sendmsg.c
4cd ..
5make 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.

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

Now cross your fingers, because we are about to execute the final error free make command.

1make LANGUAGES="c c++" CFLAGS="-O" CC="gcc"
2make install  LANGUAGES="c c++" CFLAGS="-O" CC="gcc"

Testing

To test the simulator use these commands

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

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

[c]
#include<stdio.h>
main (void)
{
printf("My name is brucebaozhiqiang. I'm a student in UFL. This is the first time sharing my knowledge. Hope this can be helpful!");
}
[/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

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

That's it! Congratulations! Hope my changes helpful

Thanks a lot to http://www.igoy.in . ^_^

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.



我的第一个任务是安装simplescalar。首先要装linux,在之前,要先装一个虚拟机。

虚拟机我装的是VMware-workstation-full-v7.1.4.大部分软件网站可以找得到。因为的我ip地址在国外,所以下载不了。。老爸帮忙下好,又用QQ传了一个晚上才搞定的。安装很顺畅。在装好虚拟机之后,安装Ubuntu10.04,这个是免费的,可以登录下面这个地址下载:

http://www.ubuntu.com/download/ubuntu/download

这个装起来也没什么问题。我有同学装好之后连不上网的,不过我没有遇到。

然后就要开始装simplescalar了。这个是个漫长的过程。。。。下面的链接是一个非常详细的安装过程,不过对于新手来说,还是有几个地方比较模糊,我装了3,4边才真正弄好。而且我不确定国内的ip是否能够看到这个视频。不过我会在下面重新写一遍,并且做一些修改跟解释。做出改动的地方我用不同的颜色标记,如果你看过原文,并且遇到一些问题,你可以直接看被标记的部分。

http://www.igoy.in/simplescalar-installation-video/


下载以下文件

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

设置环境

打开application,terminal,输入以下代码

1uname -a

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

根据上面得到的信息,决定下面HOST用哪一条
HOST=i686-pc-linux 或者 HOST=i386-pc-linux

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

在home里创建simplescalar文件夹,然后将下载到的四个文件放进去。然后进入simplescalar目录

1cd $IDIR

确定你安装了下面的几个包

  • flex
  • bison
  • build-essential

你可以用下面这条指令来安装这三个包。

1$ sudo apt-get install flex bison build-essential
有时候在这一步会遇到错误,我的解决办法就是将terminal关掉然后重新打开,再输入这条指令,就好了。
注意,当输入密码的时候,屏幕上没有显示,但实际已经输入进去了。

安装 Simple tools

解压文件,然后删掉gcc-2.6.3,你可以直接输入下面的代码或者手动解压删除

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

安装 SimpleUtils

解压文件

1tar xzvf simpleutils-990811.tar.gz
2cd simpleutils-990811

这里有一些源代码的错误需要修改。在ld中找到Idlex.l这个文件,然后将所有的yy_current_buffer 替换成 YY_CURRENT_BUFFER.

你可以打开文件进行改动,或者直接输入这些代码

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

安装 Simulator

解压文件

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

你可以测试simplesim的安装,输入以下代码

1$ ./sim-safe tests/bin.little/test-math
好像这里会出现my work is done here。说明你的安装没有问题。

安装 GCC Cross-Compiler

这步非常重要,大部分的新手都卡在这里,所以一定要仔细按照步骤做

1cd $IDIR
2tar xzvf gcc-2.7.2.3.ss_.tar.gz
3cd gcc-2.7.2.3
4exportPATH=$PATH:/home/YOUR_USER_NAME/simplescalar/sslittle-na-sstrix/bin
5$ ./configure –host=$HOST –target=$TARGET –with-gnu-as –with-gnu-ld –prefix=$IDIR

在往前运行之前,有一些文件需要改动

1.) Makefile 的130行, 将结尾改成  –I/usr/include 

你可以输入这条指令打开文件

1$ gedit Makefile

makefile

2.) protoize.c的第60行,将#include <varargs.h> 改成 #include <stdarg.h>

你可以输入这条指令打开文件

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

3.) obstack.h第341行 将*((void **)__o->next_free)++=((void *)datum); 改成*((void **)__o->next_free++)=((void *)datum);

你可以输入这条指令打开文件

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

4.) 将目录patched中的文件拷贝到其他文件夹中,你可以输入以下指令

1cp ./patched/sys/cdefs.h ../sslittle-na-sstrix/include/sys/cdefs.h
2cp ../sslittle-na-sstrix/lib/libc.a ../lib/
3cp ../sslittle-na-sstrix/lib/crt0.o ../lib/

*如果你没有找到patched这个目录,有可能是解压的时候出现了问题,可以在别的位置解压一下gcc,然后将patched文件夹拷贝过来

5.) *** 至关重要的一步*** 下载这个文件,解压,并且将里面的内容放到$IDIR/sslittle-na-sstrix/bin 里– FILE

这一步的确非常重要。如果这步错了,安装肯定会出问题。而且如果你看视频的话,那你会发现他用的有些指令在你的电脑上不好用。所以我没有用代码来实现这部分,而且是手动解压。文件解压后会得到一个新文件夹ar&ranlib,里面有两个文件ar and ranlib在目的文件夹中,也有名字一样的两个文件。用下载下来的两个文件将原来的替换掉。

要保证对这些文件有执行/写权限,可以利用以下代码查询

1$ cd $IDIR/sslittle-na-sstrix/bin
2ls -al

如果这个文件夹中哪个文件没有写(w) & 执行(x) 权限,你可以用下面的代码来提升权限

chmod +w <filename> chmod +x <filename>


$ cd $IDIR/gcc-2.7.2.3

 make

然后会遇到一些错误

1.) 现在会遇到insn-output.c的错误。要解决这个问题,要在insn-output.c的第675, 750, 823行尾加‘\’.

你可以输入这条指令打开文件

1$ gedit insn-output.c
2make

2.)在objc中的sendmsg.c 第35行,加入下面这句代码

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

Here it is an "O",not zero.

3.) 最后出现的错误是关于cxxmain.c的。打开这个文件,将第 2978-2979行的两句代码char * malloc ();char * realloc ();删掉

用以下代码打开文件

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

现在再执行下面的代码,如果你按照上面的过程来,应该就没有错误了。

1make LANGUAGES="c c++" CFLAGS="-O" CC="gcc"
2make install  LANGUAGES="c c++" CFLAGS="-O" CC="gcc"

测试

测试模拟器,用下面的指令

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

在打开的文件中,你可以输入以下代码(你可以进行改动)

#include<stdio.h>
main (void)
{
printf("My name is baozhiqiang. I'm a student in UFL. This is the first time sharing my knowledge. Hope this can be helpful!");
}

写完保存,然后用下面的语句运行测试

1$ $IDIR/bin/sslittle-na-sstrix-gcc -o hello hello.c
2$ $IDIR/simplesim-3.0/sim-safe hello

你应该会得到下面的结果:

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

恭喜啦,你已经成功了^_^

非常感谢http://www.igoy.in . ^_^

好了,现在已经装好软件了,不过我还不会用。。。而且面临着下周的任务,用这个软件模拟PAs分支预测器。。。加油咯~