riscv-software-src / riscv-isa-sim

Spike, a RISC-V ISA Simulator
Other
2.44k stars 857 forks source link

"firmware" mode #465

Open kovalexpro opened 4 years ago

kovalexpro commented 4 years ago

Hi, I'm trying to run simple ELF payload on Spike without PK desirably without any MMU. I'm using rv32i ISA and built gnu-toolchain, pk and spike locally. All tests with PK works fine.

Now, minimal test (i.e. echo "void _start(void) {}" compiled with -nostdlib can't start even:

terminate called after throwing an instance of 'trap_load_access_fault' 

#5  0x00007ffff76bbd54 in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00005555555b9b58 in mmu_t::load_slow_path (this=this@entry=0x555555a40c00, addr=67600, len=len@entry=8, bytes=bytes@entry=0x7fffffffc880 "") at ../riscv/mmu.cc:140
#7  0x00005555555ac114 in mmu_t::load_uint64 (addr=<optimized out>, this=<optimized out>) at ../riscv/mmu.h:121
#8  sim_t::read_chunk (this=<optimized out>, taddr=<optimized out>, len=<optimized out>, dst=0x7fffffffc8b0) at ../riscv/sim.cc:312
#9  0x0000555555783f40 in memif_t::write (this=0x7fffffffcaf0, addr=65536, len=<optimized out>, bytes=0x7ffff7ff3000) at ../fesvr/memif.cc:65
#10 0x000055555578cbcb in load_elf[abi:cxx11](char const*, memif_t*, unsigned long*) (fn=<optimized out>, memif=memif@entry=0x7fffffffcaf0, entry=entry@entry=0x7fffffffd658) at ../fesvr/elfloader.cc:87
#11 0x0000555555780a2d in htif_t::load_payload (this=0x7fffffffd640, payload="stream.elf", entry=0x7fffffffd658) at ../fesvr/htif.cc:119
#12 0x0000555555781818 in htif_t::load_program (this=0x7fffffffd640) at ../fesvr/htif.cc:124
#13 0x000055555577fdf9 in htif_t::start (this=0x7fffffffd640) at ../fesvr/htif.cc:81
#14 0x0000555555780c8d in htif_t::run (this=0x7fffffffd640) at ../fesvr/htif.cc:184
#15 0x000055555559338b in main (argc=<optimized out>, argv=<optimized out>) at ../spike_main/spike.cc:384

Looks like then running without PK the device map has no memory object mapped and thus sim_t::addr_to_mem() fails to translate 0x10000 (start of ELF payload I guess) to the host memory.

$2 = std::map with 3 elements = {[0] = 0x7fffffffd9e0, [33554432] = 0x555555a85740, [2147483648] = 0x555555a24dc0}
kovalexpro commented 4 years ago

BTW, I tried to disable MMU by instantiating all mmu_t() objects with proc=NULL. This did not help as well and I guess the reason is the same - bus.find_device() finds single object mapped at zero address and it's not mem_t (memory).