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,

Chris
  • 3,827
  • 22
  • 30
Younghwan Oh
  • 137
  • 1
  • 8

1 Answers1

0

You compiled your hello-world using newlib, which requires that you run on top of a kernel.

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

The above command is telling the Rocket-chip emulator to load and execute the program "pk" (proxy-kernel) with the argument "hello". The Proxy kernel will then load in the program "hello" and jump to its _start address (0x10000).

If you want to write your own bare-metal hello world, then you can consult with this SO answer here:

(How can I compile C code to get a bare-metal skeleton of a minimal RISC-V assembly program?)


To answer your specific question: you need to find the "pk" in your $RISCV install location $RISCV/riscv64-unknown-elf/bin/pk, and then generate a hex file for the pk (pk.hex). Then you can feed this hex file to the Rocket-chip emulator.


More info: to explain the behavior of the output log you are seeing, the processor boots up at 0x2000. It then cache misses and takes many cycles to fetch the first instruction. Since your hello world is located at the wrong address (0x10000), the processor only sees "00000000" as the instruction.

Community
  • 1
  • 1
Chris
  • 3,827
  • 22
  • 30