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