1、编译之前,首先安装库文件:
以ubuntu1201系统为例,安装库文件如下:
$:sudo apt-get mercurial scons swig gcc m4 python python-dev libgoogle-perftools-dev g++
2、然后下载gem5源码:
$: hg clone http://repo.gem5.org/gem5
3、编译gem5的各个架构:
在根目录下运行:$:scons build/ARM/gem5.opt
其中ARM可以换成X86,MIPS等等,编译完成后就可以运行测试程序。
4、运行测试程序:
$: cd ~/gem5 //进入gem5源码根目录
$:build/ARM/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/arm/linux/hello
打印出如下信息:
gem5 Simulator System. http://gem5.org
gem5 is copyrighted software; use the --copyright option for details.
gem5 compiled Nov 16 2012 10:27:19
gem5 started Nov 28 2012 14:36:59
gem5 executing on slave0
command line: build/ARM/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/arm/linux/hello
Global frequency set at 1000000000000 ticks per second
0: system.remote_gdb.listener: listening for remote gdb #0 on port 7002
**** REAL SIMULATION ****
info: Entering event queue @ 0. Starting simulation...
Hello world!
hack: be nice to actually delete the event here
Exiting @ tick 3107500 because target called exit()
以上红色部分就是程序执行的结果。
5、看下测试程序的源码:
$:cd ~/gem5
$: gedit tests/test-progs/hello/src/hello.c
打开可以看到,就是一个helloworld测试程序。
NOTE:如果你想重新写个测试程序,注意想在什么架构下运行,如果在ARM架构下运行,需要用ARM toolchain ,如果想运行MIPS架构的测试程序,需要用MIPS的交叉工具链编译测试程序。
有朋友反映运行程序出问题,有几点需要注意:
gem5有SE(系统调用模拟)模式和FS(全系统)模式,SE是单独运行测试程序的模式,要运行的程序必须静态链接。
FS是全系统模式,运行linux操作系统才用的。如果没有特别需求,不建议用FS模式,因为巨慢!