Gem5のインストール方法についてまとめ。
WSL2上のUbuntu 20.04LTSで試行したが、だいたい以下のページの通りに進めばいける。
sudo apt install build-essential git m4 scons zlib1g zlib1g-dev \ libprotobuf-dev protobuf-compiler libprotoc-dev libgoogle-perftools-dev \ python3-dev python-is-python3 libboost-all-dev pkg-config
git clone https://gem5.googlesource.com/public/gem5
ビルドはX86、RISC-Vで実行してみた。結構時間がかかる。
scons build/X86/gem5.debug -j20 scons build/RISCV/gem5.debug -j20
ビルドできたら、一応確認してみよう。
$ ./build/RISCV/gem5.debug
gem5 Simulator System. https://www.gem5.org gem5 is copyrighted software; use the --copyright option for details. gem5 version 22.0.0.2 gem5 compiled Aug 12 2022 22:42:22 gem5 started Aug 12 2022 22:47:17 gem5 executing on ms-x1carbon, pid 32595 command line: ./build/RISCV/gem5.debug Usage ===== gem5.debug [gem5 options] script.py [script options] gem5 is copyrighted software; use the --copyright option for details. Options ======= --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, -d DIR 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 --silent-redirect Suppress printing a message when redirecting stdout or stderr --stdout-file=FILE Filename for -r redirection [Default: simout] --stderr-file=FILE Filename for -e redirection [Default: simerr] --listener-mode={on,off,auto} Port (e.g., gdb) listener mode (auto: Enable if running interactively) [Default: auto] --allow-remote-connections Port listeners will accept connections from anywhere ... --debug-end=TICK End debug output at TICK --debug-file=FILE Sets the output file for debug. Append '.gz' to the name for it to be compressed automatically [Default: cout] --debug-ignore=EXPR Ignore EXPR sim objects --remote-gdb-port=REMOTE_GDB_PORT Remote gdb base port (set to 0 to disable listening) Help Options ------------ --list-sim-objects List all built-in SimObjects, their params and default values
Dhrystoneは動くかな。
$ ./build/RISCV/gem5.debug configs/example/se.py -c /home/msyksphinz/riscv64/riscv64-unknown-elf/share/riscv-tests/benchmarks/dhrystone.riscv
Global frequency set at 1000000000000 ticks per second warn: No dot file generated. Please install pydot to generate the dot file and pdf. build/RISCV/mem/dram_interface.cc:690: warn: DRAM device capacity (8192 Mbytes) does not match the address range assigned (512 Mbytes) build/RISCV/arch/riscv/linux/se_workload.cc:60: warn: Unknown operating system; assuming Linux. 0: system.remote_gdb: listening for remote gdb on port 7000 **** REAL SIMULATION **** build/RISCV/sim/simulate.cc:194: info: Entering event queue @ 0. Starting simulation... build/RISCV/arch/riscv/faults.cc:196: panic: Illegal instruction 0x3002a073 at pc (0x80000044=>0x80000048).(0=>1): mstatus is not accessible in 0 Memory Usage: 629980 KBytes Program aborted at tick 16000
あれー動かんな。CSRS
命令で死んでいるんだけど、ユーザモードで動いているのかな。
Helloのテストバイナリは動くようだ。
./build/RISCV/gem5.debug configs/example/se.py -c tests/test-progs/hello/bin/riscv/linux/hello
**** REAL SIMULATION **** build/RISCV/sim/simulate.cc:194: info: Entering event queue @ 0. Starting simulation... build/RISCV/sim/mem_state.cc:443: info: Increasing stack size by one page. Hello world! Exiting @ tick 3306500 because exiting with last active thread context
なるほど、--debug-flags=Exec
で命令トレースを出力することができるらしい。
./build/RISCV/gem5.debug --debug-flags=Exec configs/example/se.py -c tests/test-progs/hello/bin/riscv/linux/hello
**** REAL SIMULATION **** :194: info: Entering event queue @ 0. Starting simulation... 0: system.cpu: T0 : 0x102a4 @_start : jal ra, 44 : IntAlu : D=0x00000000000102a8 500: system.cpu: T0 : 0x102d0 @_start+44 : auipc gp, 108 : IntAlu : D=0x000000000007c2d0 1000: system.cpu: T0 : 0x102d4 @_start+48 : addi gp, gp, -480 : IntAlu : D=0x000000000007c0f0 1500: system.cpu: T0 : 0x102d8 @_start+52 : c_jr ra : IntAlu : 2000: system.cpu: T0 : 0x102a8 @_start+4 : c_mv a5, a0 : IntAlu : D=0x0000000000000000 3000: system.cpu: T0 : 0x102aa @_start+6 : auipc a0, 0 : IntAlu : D=0x00000000000102aa 4000: system.cpu: T0 : 0x102ae @_start+10 : addi a0, a0, 232 : IntAlu : D=0x0000000000010392 4500: system.cpu: T0 : 0x102b2 @_start+14 : c_ldsp a1, 0(sp) : MemRead : D=0x0000000000000001 A=0x7fffffffffffff20 5000: system.cpu: T0 : 0x102b4 @_start+16 : c_addi4spn a2, sp, 8 : IntAlu : D=0x7fffffffffffff28 6000: system.cpu: T0 : 0x102b6 @_start+18 : andi sp, sp, 18446744073709551600 : IntAlu : D=0x7fffffffffffff20 7000: system.cpu: T0 : 0x102ba @_start+22 : auipc a3, 0 : IntAlu : D=0x00000000000102ba 8000: system.cpu: T0 : 0x102be @_start+26 : addi a3, a3, 1504 : IntAlu : D=0x000000000001089a 9000: system.cpu: T0 : 0x102c2 @_start+30 : auipc a4, 0 : IntAlu : D=0x00000000000102c2 10000: system.cpu: T0 : 0x102c6 @_start+34 : addi a4, a4, 1640 : IntAlu : D=0x000000000001092a 10500: system.cpu: T0 : 0x102ca @_start+38 : c_mv a6, sp : IntAlu : D=0x7fffffffffffff20 11000: system.cpu: T0 : 0x102cc @_start+40 : jal ft0, 230 : IntAlu : D=0x00000000000102d0 11500: system.cpu: T0 : 0x103b2 @__libc_start_main : c_addi16sp sp, -320 : IntAlu : D=0x7ffffffffffffde0 12000: system.cpu: T0 : 0x103b4 @__libc_start_main+2 : lui a7, 0 : IntAlu : D=0x0000000000000000 12500: system.cpu: T0 : 0x103b8 @__libc_start_main+6 : c_sdsp s0, 304(sp) : MemWrite : D=0x0000000000000000 A=0x7fffffffffffff10 13000: system.cpu: T0 : 0x103ba @__libc_start_main+8 : c_sdsp s1, 296(sp) : MemWrite : D=0x0000000000000000 A=0x7fffffffffffff08 13500: system.cpu: T0 : 0x103bc @__libc_start_main+10 : c_sdsp s2, 288(sp) : MemWrite : D=0x0000000000000000 A=0x7fffffffffffff00