1、运行gem5(查看帮助命令):
./build/ARM/gem5.opt –h
=====
gem5.opt [gem5 options] script.py [scriptoptions]
gem5 is copyrightedsoftware; use the --copyright option for details.
Options
=======
--version show program's version numberand exit
--help, -h show this help message and exit
--build-info, -B Show build information
--copyright, -C Show full copyright information
--readme, -R Show the readme
--outdir=DIR, -dDIR Set the output directory to DIR [Default:m5out]
--redirect-stdout,-r Redirect stdout (& stderr,without -e) to file
--redirect-stderr,-e Redirect stderr to file
--stdout-file=FILE Filename for -r redirection [Default:simout]
--stderr-file=FILE Filename for -e redirection [Default:simerr]
--interactive,-i Invoke the interactiveinterpreter after running the
script
--pdb Invoke the python debuggerbefore running the script
--path=PATH[:PATH],-p PATH[:PATH]
Prepend PATH to the system path wheninvoking the
2、选择两种仿真类型
全系统仿真:
- Full system (FS) :./configs/example/fs.py
* For bootingoperating systems
* Models barehardware, including devices
* Interrupts,exceptions, privileged instructions, fault handlers
* Simulated UARToutput
* Simulated framebuffer output
调用仿真:
- Syscall emulation(SE) :./configs/example/se.py
* For runningindividual applications, or set of applications on MP
* Models user-visibleISA plus common system calls
* System callsemulated, typically by calling host OS
* Simplified addresstranslation model, no scheduling
3、运行一个调用仿真:
./build/ARM/gem5.opt configs/example/se.py -c tests/test-progs/hello/bin/arm/linux/hello
4、运行一个全系统仿真的过程:
A、首先获取操作系统镜像:
可以自己编译定制的linux内核,编译linux内核的例子在后边的文章中有介绍,源码:(git clone https://github.com/gem5/linux-arm64-gem5.git);
也可是使用gem5官网给的编译好的例子做测试,下载地址:http://www.gem5.org/Download;
B、将其解压到gem5目录下的一个自建的文件夹fullsystem中(这里假设已经下载了官网上的ARM full-system files,自己制作的话需要将其制作成类似的格式);
C、将解压fullsystem添加环境变量:
Export M5_PATH=$M5_PATH:/…/gem5/fullsystem>> ~/.bashrc;
Source ~/.bashrc(重新加载bashrc);
4、运行全系统模拟
./build/ARM/gem5.optconfigs/example/fs.py --disk-image=/$PWD/fullsystem/disks/linux-aarch32-ael.img
运行起来相当于一个服务器,正常运行后会弹出一些警告无需理会,正常情况下会停止在某个阶段然后等待客户端的链接;
5、
1)另打开一个客户端,使用telnet连接模拟器:
telnet 127.0.0.1 3456
等一会,输入用户名:root 没有密码
连接上了仿真系统,,在服务器端会打印出来一条有用户登录的信息。测试:输入命令: time ps ,会看到一系列输出。
2)使用gem5自带的连接器m5term
A、在gem5根目录目录下
cd /util/term
make
sudo install -o root –m 555 m5term /usr/local/bin
意思是安装m5term软件到/usr/local/bin/目录下,软件所有者是root,权限是555.
在全系统模拟已经打开的情况下,
m5term localhost 3456
连接上模拟器,测试:time ps 会看到一系列输出。
使用:
设立检查点:m5 checkpoint 在系统端可以看到有:Writing checkpoint.
退出:m5 exit
5、追踪程序执行过程:
./build/ARM/gem5.opt--debug-flags=Exec,ExecTicks configs/example/se.py -ctests/test-progs/hello/bin/arm/linux/hello | more
将追踪的记录写入一个文件中:
./build/ARM/gem5.opt--debug-flags=Exec,ExecTicks --trace-file=hello.arm.trace.outconfigs/example/se.py -c tests/test-progs/hello/bin/arm/linux/hello
静态的统计文件:/opt/gem5/m5out/stats.txt
可以直接将追踪文件压缩:
./build/ARM/gem5.opt--debug-flags=Exec,ExecTicks --trace-file=hello1.arm.trace.out.gzconfigs/example/se.py -c tests/test-progs/hello/bin/arm/linux/hello