学习《深入理解计算机系统》安装YAS模拟器

我是在CentOS7的虚拟机上安装的,系统版本为:Linux version 3.10.0-957.21.3.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) )。

一、准备工作

1、换yum源

这一步换不换完全看个人系统的yum源包不包含安装YAS过程中的依赖库,由于只是学习使用,我的虚拟机之前未更换yum源,所以在安装YAS过程中出现找不到依赖库的问题,更换yum源后,即可正常进行安装。我使用的是阿里的源。

更换方法:

(1)下载repo文件 http://mirrors.aliyun.com/repo/Centos-7.repo

(2)删除/etc/yum.repos.d/CentOS-Base.repo文件里面内容

(3)将下载文件的内容拷贝到CentOS-Base.repo文件里面,保存退出

(4)执行yum源更新命令 :

#yum clean all 

#yum makecache 

#yum update 

2、下载YAS安装源

直接到http://csapp.cs.cmu.edu/3e/students.html,第四章直接下载源代码,和帮助文档。

 

二、进行安装

根据帮助文档进行安装:

在make阶段,出现下面错误:

[root@localhost sim]# make
(cd misc; make all)
make[1]: 进入目录“/home/test/sim/misc”
gcc -Wall -O1 -g -c yis.c
gcc -Wall -O1 -g -c isa.c
gcc -Wall -O1 -g yis.o isa.o -o yis
gcc -Wall -O1 -g -c yas.c
flex yas-grammar.lex
mv lex.yy.c yas-grammar.c
gcc -O1 -c yas-grammar.c
gcc -Wall -O1 -g yas-grammar.o yas.o isa.o -lfl -o yas
bison -d hcl.y
flex hcl.lex
gcc -O1 node.c lex.yy.c hcl.tab.c outgen.c -o hcl2c
make[1]: 离开目录“/home/test/sim/misc”
(cd pipe; make all GUIMODE= TKLIBS="-L/usr/lib -ltk -ltcl" TKINC="-isystem /usr/include/tcl8.5")
make[1]: 进入目录“/home/test/sim/pipe”
# Building the pipe-std.hcl version of PIPE
../misc/hcl2c -n pipe-std.hcl < pipe-std.hcl > pipe-std.c
gcc -Wall -O2 -isystem /usr/include/tcl8.5 -I../misc  -o psim psim.c pipe-std.c \
	../misc/isa.c -L/usr/lib -ltk -ltcl -lm
/usr/bin/ld: 找不到 -ltk
/usr/bin/ld: 找不到 -ltcl
collect2: 错误:ld 返回 1
make[1]: *** [psim] 错误 1
make[1]: 离开目录“/home/test/sim/pipe”
make: *** [all] 错误 2

解决:使用yum对tk和tcl单独进行安装,实际上,下面一条指令即可解决(它会安装依赖,其中包括tcl)。

[root@localhost ~]# yum install tk-devel-8.5.13

安装完后对Makefile文件进行修改,我是对sim根目录和子目录下的所有Makefile文件均做了以下相同的修改:

# Comment this out if you don't have Tcl/Tk on your system

#GUIMODE=-DHAS_GUI

# Modify the following line so that gcc can find the libtcl.so and
# libtk.so libraries on your system. You may need to use the -L option
# to tell gcc which directory to look in. Comment this out if you
# don't have Tcl/Tk.

TKLIBS=-L/usr/lib -ltk8.5 -ltcl8.5

# Modify the following line so that gcc can find the tcl.h and tk.h
# header files on your system. Comment this out if you don't have
# Tcl/Tk.

TKINC=-isystem /usr/include/tcl8.5

未修改之前TKLIBS中没有8.5,由于我安装的是8.5版本的tk和tcl,所以在修改为如上状态。TKINC没改动,应该是安装tk后自动修改的(个人理解)。

修改后再次进行make操作:

[root@localhost sim]# make clean
[root@localhost sim]# make

至此安装完成。查看书中实例:

root@localhost sim]# ./misc/yis asum.yo
Can't open code file 'asum.yo'
[root@localhost sim]# ./misc/yis ./y86-code/asum.yo
Stopped in 34 steps at PC = 0x13.  Status 'HLT', CC Z=1 S=0 O=0
Changes to registers:
%rax:	0x0000000000000000	0x0000abcdabcdabcd
%rsp:	0x0000000000000000	0x0000000000000200
%rdi:	0x0000000000000000	0x0000000000000038
%r8:	0x0000000000000000	0x0000000000000008
%r9:	0x0000000000000000	0x0000000000000001
%r10:	0x0000000000000000	0x0000a000a000a000

Changes to memory:
0x01f0:	0x0000000000000000	0x0000000000000055
0x01f8:	0x0000000000000000	0x0000000000000013

三、使用Processor Simulators的图形化界面(GUI mode)

由于Processor Simulators默认使用是TTY mode,根据教程,需要在命令中添加 -g 选项:

root@localhost seq]# ./ssim -g ../y86-code/asum.yo
To run in GUI mode, you must recompile with the HAS_GUI constant defined.

然而并没有按照预期打开图形化界面,出现了上述问题。

解决:

查看子目录seq下的README文件,其中包含如下内容:

The simulators run in either TTY or GUI mode:

o TTY mode: A simulator running in TTY mode prints all information
about its runtime behavior on the terminal.  It's hard to understand what's
going on, but useful for automated testing, and doesn't require any
special installation features.

o GUI mode: A simulator running in GUI mode uses a fancy graphical
user interface.  Nice for visualizing and debugging, but requires
installation of Tcl/Tk on your system.

The Makefile has simple instructions for building TTY or GUI
simulators. A TTY simulator runs in TTY mode only. A GUI
simulator can run in either TTY mode or GUI mode, according to
a command line argument.

Once you've configured the Makefile, you can build the different
simulators with commands of the form

        unix> make clean; make ssim VERSION=xxx

where "xxx" is one of the versions listed above.  For example, to build
the version of SEQ described in the CS:APP text based on the control
logic in seq-std.hcl, type

        unix> make clean; make ssim VERSION=std

To save typing, you can also set the Makefile's VERSION variable.

由于我之前对Makefile文件进行了修改,所以使用如下命令,重新生成ssim可执行文件(make clean命令会清除ssim):

make clean
make ssim VERSION=std

修改完毕,验证:

[root@localhost seq]# ./ssim -g ../y86-code/asum.yo

成功出现3个窗口,第一个为Main control panel for SEQ simulator;第二个为Code display window for SEQ simulator;第三个为Memory display window for SEQ simulator:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章