Gem5のインストール方法についてまとめ。
Dhrystoneがどうして動かないのか、デバッグ情報を確認した。
command line: ./build/RISCV/gem5.debug --debug-flags=Exec 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... 0: system.cpu: T0 : 0x80000000 @_start : c_li ra, 0 : IntAlu : D=0x0000000000000000 500: system.cpu: T0 : 0x80000002 @_start+2 : c_li sp, 0 : IntAlu : D=0x0000000000000000 1000: system.cpu: T0 : 0x80000004 @_start+4 : c_li gp, 0 : IntAlu : D=0x0000000000000000 1500: system.cpu: T0 : 0x80000006 @_start+6 : c_li tp, 0 : IntAlu : D=0x0000000000000000 2000: system.cpu: T0 : 0x80000008 @_start+8 : c_li t0, 0 : IntAlu : D=0x0000000000000000 2500: system.cpu: T0 : 0x8000000a @_start+10 : c_li t1, 0 : IntAlu : D=0x0000000000000000 3000: system.cpu: T0 : 0x8000000c @_start+12 : c_li t2, 0 : IntAlu : D=0x0000000000000000 3500: system.cpu: T0 : 0x8000000e @_start+14 : c_li s0, 0 : IntAlu : D=0x0000000000000000 4000: system.cpu: T0 : 0x80000010 @_start+16 : c_li s1, 0 : IntAlu : D=0x0000000000000000 4500: system.cpu: T0 : 0x80000012 @_start+18 : c_li a0, 0 : IntAlu : D=0x0000000000000000 5000: system.cpu: T0 : 0x80000014 @_start+20 : c_li a1, 0 : IntAlu : D=0x0000000000000000 5500: system.cpu: T0 : 0x80000016 @_start+22 : c_li a2, 0 : IntAlu : D=0x0000000000000000 6000: system.cpu: T0 : 0x80000018 @_start+24 : c_li a3, 0 : IntAlu : D=0x0000000000000000 6500: system.cpu: T0 : 0x8000001a @_start+26 : c_li a4, 0 : IntAlu : D=0x0000000000000000 7000: system.cpu: T0 : 0x8000001c @_start+28 : c_li a5, 0 : IntAlu : D=0x0000000000000000 7500: system.cpu: T0 : 0x8000001e @_start+30 : c_li a6, 0 : IntAlu : D=0x0000000000000000 8000: system.cpu: T0 : 0x80000020 @_start+32 : c_li a7, 0 : IntAlu : D=0x0000000000000000 8500: system.cpu: T0 : 0x80000022 @_start+34 : c_li s2, 0 : IntAlu : D=0x0000000000000000 9000: system.cpu: T0 : 0x80000024 @_start+36 : c_li s3, 0 : IntAlu : D=0x0000000000000000 9500: system.cpu: T0 : 0x80000026 @_start+38 : c_li s4, 0 : IntAlu : D=0x0000000000000000 10000: system.cpu: T0 : 0x80000028 @_start+40 : c_li s5, 0 : IntAlu : D=0x0000000000000000 10500: system.cpu: T0 : 0x8000002a @_start+42 : c_li s6, 0 : IntAlu : D=0x0000000000000000 11000: system.cpu: T0 : 0x8000002c @_start+44 : c_li s7, 0 : IntAlu : D=0x0000000000000000 11500: system.cpu: T0 : 0x8000002e @_start+46 : c_li s8, 0 : IntAlu : D=0x0000000000000000 12000: system.cpu: T0 : 0x80000030 @_start+48 : c_li s9, 0 : IntAlu : D=0x0000000000000000 12500: system.cpu: T0 : 0x80000032 @_start+50 : c_li s10, 0 : IntAlu : D=0x0000000000000000 13000: system.cpu: T0 : 0x80000034 @_start+52 : c_li s11, 0 : IntAlu : D=0x0000000000000000 13500: system.cpu: T0 : 0x80000036 @_start+54 : c_li t3, 0 : IntAlu : D=0x0000000000000000 14000: system.cpu: T0 : 0x80000038 @_start+56 : c_li t4, 0 : IntAlu : D=0x0000000000000000 14500: system.cpu: T0 : 0x8000003a @_start+58 : c_li t5, 0 : IntAlu : D=0x0000000000000000 15000: system.cpu: T0 : 0x8000003c @_start+60 : c_li t6, 0 : IntAlu : D=0x0000000000000000 15500: system.cpu: T0 : 0x8000003e @_start+62 : c_lui t0, 30 : IntAlu : D=0x000000000001e000 16000: system.cpu: T0 : 0x80000040 @_start+64 : csrrs ft0, mstatus, t0 : No_OpClass : build/RISCV/arch/riscv/faults.cc:196: panic: Illegal instruction 0x3002a073 at pc (0x80000044=>0x80000048).(0=>1): mstatus is not accessible in 0
CSR命令が実行できていない。権限モードがどうもおかしい。なんでユーザモードから始まっているんだろう?
build/RISCV/arch/riscv/linux/se_workload.cc:60: warn: Unknown operating system; assuming Linux.
なるほど、Linuxを前提として動いているので、それでユーザモードからスタートしているのか。これはCoremarkやらDhrystoneやらLinuxモードデコンパイルしないといけないのかな。
riscv64-unknown-linux-gnu-gcc
を使ってサンプルプログラムをコンパイルしなおした。どうもDynamic Linkを防ぐために-static
オプションを使用する必要があるらしい。
printf.c
#include <stdio.h> int main () { printf("Hello World\n"); return 0; }
$ riscv64-unknown-linux-gnu-gcc printf.c -static -o printf
これならばGem5で実行できた。
./build/RISCV/gem5.debug configs/example/se.py -c /home/msyksphinz/work/gem5/gem5_test/printf/printf 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 13 2022 00:57:06 gem5 executing on ms-x1carbon, pid 23034 command line: ./build/RISCV/gem5.debug configs/example/se.py -c /home/msyksphinz/work/gem5/gem5_test/printf/printf 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) 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/sim/mem_state.cc:443: info: Increasing stack size by one page. build/RISCV/sim/syscall_emul.cc:74: warn: ignoring syscall mprotect(...) Hello World Exiting @ tick 3284000 because exiting with last active thread context