riscv-software-src / riscv-tools

RISC-V Tools (ISA Simulator and Tests)
1.14k stars 447 forks source link

RV32 fesrv-device miscommunication #225

Closed Cirromulus closed 6 years ago

Cirromulus commented 6 years ago

Hello there! We are currently trying to develop a riscv32g systemC processor, which should someday run Linux. To build a reference model, I am trying to build an image of bbl+vmlinux as described in the tutorials. Unfortunately, some things seem to work different in the 32Bit version. (Some flags for rv32 are getting ignored in configure scripts, but that is not the problem)

When running the BBL with its dummy_payload, the first print ("bbl loader") fails, directly calling a trap. The main cause is the way the 32Bit version seems to handle the tohost cmd-style. If I enforce the 64Bit version of the TOHOST_CMD (see code below), the bootloader actually prints its signature.

>> htif.h
#if 1==1 || __riscv_xlen == 64
# define TOHOST_CMD(dev, cmd, payload) \
  (((uint64_t)(dev) << 56) | ((uint64_t)(cmd) << 48) | (uint64_t)(payload))
#else
# define TOHOST_CMD(dev, cmd, payload) ({ \
  if ((dev) || (cmd)) __builtin_trap(); \
  (payload); })
# warning funny stuff going on
#endif

This calls the machine abstraction in fesrv, which calls the bcd, that finally prints out the payload.

Unfortunately, prints in the bbl dummy_payload lead to the error

terminate called after throwing an instance of 'trap_load_access_fault'

>> dummy_entry.S
  lbu a0, (s0)
  beqz a0, 1f
  li a7, SBI_CONSOLE_PUTCHAR
  ecall
  add s0, s0, 1
  j 1b

This does not call the bcd-device, but the syscall_proxy, which direktly fails handling the command '0'. The produced value in tohost is not by the format seen in htif.c, but left blank with only the ascii-representation of the char. (note: tohost has the value 00000084, which is the first Letter 'T' of dummy_payload and therefore gets translated to device 0, cmd 0, payload 84 instead of device 1, cmd 1, payload 84 which would print the letter T)

Why is that, and how can I correct this?

Cirromulus commented 6 years ago

Btw: To even get going, I had to rename the mmu name, may this be the source of the Problem?

//File riscv-isa-sim/riscv/dts.cc, line 35 in make_dts()
//mmu-type = \"riscv," << (procs[i]->get_max_xlen() <= 32 ? "sv32" : "sv48") << "\";\n"
mmu-type = \"riscv," << (procs[i]->get_max_xlen() <= 32 ? "sv39" : "sv48") << "\";\n"

This value is expected by the simulator and pk.

Cirromulus commented 6 years ago

This is an example output from my modified fesrv.

syscall_proxy (0) registered command 0 (syscall) bcd (1) registered command 0 (read) bcd (1) registered command 1 (write)

b bcd (device: 1) CMD: 1 Payload: 98 (b) b bcd (device: 1) CMD: 1 Payload: 98 (b) l bcd (device: 1) CMD: 1 Payload: 108 (l) bcd (device: 1) CMD: 1 Payload: 32 ( ) l bcd (device: 1) CMD: 1 Payload: 108 (l) o bcd (device: 1) CMD: 1 Payload: 111 (o) a bcd (device: 1) CMD: 1 Payload: 97 (a) d bcd (device: 1) CMD: 1 Payload: 100 (d) e bcd (device: 1) CMD: 1 Payload: 101 (e) r bcd (device: 1) CMD: 1 Payload: 114 (r) [..] syscall_proxy (device: 0) CMD: 0 Payload: 84 (T) Ignoring failing command. syscall_proxy (device: 0) CMD: 0 Payload: 104 (h) Ignoring failing command. syscall_proxy (device: 0) CMD: 0 Payload: 105 (i) Ignoring failing command. syscall_proxy (device: 0) CMD: 0 Payload: 115 (s) Ignoring failing command. [... rest of dummy_payload string] P bcd (device: 1) CMD: 1 Payload: 80 (P) o bcd (device: 1) CMD: 1 Payload: 111 (o) w bcd (device: 1) CMD: 1 Payload: 119 (w) e bcd (device: 1) CMD: 1 Payload: 101 (e) r bcd (device: 1) CMD: 1 Payload: 114 (r) bcd (device: 1) CMD: 1 Payload: 32 ( ) o bcd (device: 1) CMD: 1 Payload: 111 (o) f bcd (device: 1) CMD: 1 Payload: 102 (f) f bcd (device: 1) CMD: 1 Payload: 102 (f) [..] syscall_proxy (device: 0) CMD: 0 Payload: 1 ()

It seems, that the dummy_payload is using the 32Bit version of the tohost cmd, which is not understood by fesrv.

Running spike pk hello.out works, by the way. PK prints normal text to terminal.

syscall_proxy registered command 0 (syscall) bcd registered command 0 (read) bcd registered command 1 (write) Listening for remote bitbang connection on port 9824. b bcd (device: 1) CMD: 1 Payload: 98 (b) b bcd (device: 1) CMD: 1 Payload: 98 (b) l bcd (device: 1) CMD: 1 Payload: 108 (l) bcd (device: 1) CMD: 1 Payload: 32 ( ) l bcd (device: 1) CMD: 1 Payload: 108 (l) o bcd (device: 1) CMD: 1 Payload: 111 (o) a bcd (device: 1) CMD: 1 Payload: 97 (a) d bcd (device: 1) CMD: 1 Payload: 100 (d) e bcd (device: 1) CMD: 1 Payload: 101 (e) r bcd (device: 1) CMD: 1 Payload: 114 (r) ) cd (device: 1) CMD: 1 Payload: 13 ( bcd (device: 1) CMD: 1 Payload: 10 (

) syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () Hello world 0.834848! syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 () syscall_proxy (device: 0) CMD: 0 Payload: 2147549696 ()

Cirromulus commented 6 years ago

Solution: Just use the freedom-u-sdk.