1

I've been trying to simulate small binary file (translated to hex) using the cycle-accurate RISC-V Rocket-chip C++ emulator. The build process of emulator was successful and make run generates correct test/benchmark results.

However, when I compiled a custom source code and simulated it, it just printed lots of 000000... in log file. Surely, I checked those logs with enough cycle counts and there weren't any changes as it runs. It just kept printing 0000.. in operand number, inst, DASM and so on without stopping simulation. Some of exceptions are the first few lines, see below.

C0:          0 [0] pc=[00000002000] W[r 0=0000000000000048][0] R[r13=00000000003741c8] R[r28=36f000000000006c] inst=[a3c6f23b] DASM(a3c6f23b)
C0:          1 [0] pc=[00000002000] W[r 0=0000000000000048][0] R[r13=00000000003741c8] R[r28=36f000000000006c] inst=[a3c6f23b] DASM(a3c6f23b)
C0:          2 [0] pc=[00000002000] W[r 0=0000000000000048][0] R[r13=00000000003741c8] R[r28=36f000000000006c] inst=[a3c6f23b] DASM(a3c6f23b)
C0:          3 [0] pc=[00000002000] W[r 0=0000000000000048][0] R[r13=00000000003741c8] R[r28=36f000000000006c] inst=[a3c6f23b] DASM(a3c6f23b)
C0:          4 [0] pc=[00000002000] W[r 0=0000000000000048][0] R[r13=00000000003741c8] R[r28=36f000000000006c] inst=[a3c6f23b] DASM(a3c6f23b)
C0:          5 [0] pc=[00000002000] W[r 0=0000000000000000][0] R[r 0=0000000000000000] R[r 0=0000000000000000] inst=[00000000] DASM(00000000)
repeating the last line 0000....

In the middle of simulations, pc eventually increases but it still prints 0000.. over and over again, it didn't stop. Here is the C source code and process I've tried. (Also, I tried many other sources.)

int main(){
    int a=0, i;
    for (i=0; i<100; i++){
        a += 1;
    }
    return 0;
}

And, command lists.

riscv-unknown-elf-gcc hello.c -o hello
elf2hex 16 16384 hello > hello.hex
emulator-DefaultCPPConfig +dramsim +max-cycles=100000000 +verbose +loadmem=hello.hex none 2> hello.out

I think the simulator doesn't correctly recognize the translated hex format. So, it cannot triggers correct instruction streams. Can anyone help?

Thanks,

4

1 回答 1

0

您使用 newlib 编译了您的 hello-world,这要求您在内核之上运行。

riscv-unknown-elf-gcc hello.c -o hello
emulator-DefaultCPPConfig +dramsim +max-cycles=100000000 +verbose pk hello 2> hello.out

上面的命令告诉 Rocket-chip 仿真器加载并执行带有参数“hello”的程序“pk”(代理内核)。然后代理内核将加载程序“hello”并跳转到它的_start地址(0x10000)。

如果您想编写自己的裸机 hello world,则可以在此处咨询此 SO 答案:

如何编译 C 代码以获得最小 RISC-V 汇编程序的裸机骨架?


要回答您的具体问题:您需要在 $RISCV 安装位置找到“pk” $RISCV/riscv64-unknown-elf/bin/pk,然后hex为 pk (pk.hex) 生成一个文件。然后您可以将此十六进制文件提供给 Rocket-chip 仿真器。


更多信息:为了解释您看到的输出日志的行为,处理器在 0x2000 处启动。然后它缓存未命中并花费许多周期来获取第一条指令。由于您的 hello world 位于错误的地址 (0x10000),因此处理器只会将“00000000”视为指令。

于 2015-07-21T20:02:14.637 回答