學習《深入理解計算機系統》安裝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:

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