You require the riscv toolchain and the rust bindings for it.
sudo apt install binutils-riscv64-unknown-elfrustup target add riscv32i-unknown-none-elfcargo run --bin riscv-emu --helpUsage: riscv-emu [OPTIONS] <FLASH>
Arguments:
<FLASH> the binary to flash
Options:
-d, --dump-folder <DUMP_FOLDER>
-s, --speed <SPEED>
-l, --log <LOG>
-h, --help Print help information
-V, --version Print version information
cargo run --bin riscv-emu -- target/examples/uart_hello_world.bin --speed 10You can use the Makefile commands
make run_example example=<example_name>make run_example example=halt ┌─────────────────────────────────┐
0x0000_0000 │ ┌────────────────────────────┐ │
│ │ │ │
│ │ FLASH MEMORY │ │
│ │ │ │
0x0003_2000 │ └────────────────────────────┘ │
│ ┌────────────────────────────┐ │
│ │ RESERVED │ │
│ └────────────────────────────┘ │
0x0200_0000 │ ┌────────────────────────────┐ │
│ │ │ │
│ │ │ │
│ │ CLINT │ │
│ │ │ │
│ │ │ │
0x0200_FFFF │ └────────────────────────────┘ │
│ ┌────────────────────────────┐ │
│ │ RESERVED │ │
│ └────────────────────────────┘ │
0x0C00_0000 │ ┌────────────────────────────┐ │
│ │ │ │
│ │ │ │
│ │ PLIC │ │
│ │ │ │
│ │ │ │
0x1000_0000 │ └────────────────────────────┘ │
│ ┌────────────────────────────┐ │
│ │ RESERVED │ │
│ └────────────────────────────┘ │
0x1001_3000 │ ┌────────────────────────────┐ │
│ │ │ │
│ │ │ │
│ │ UART0 │ │
│ │ │ │
│ │ │ │
0x1001_3FFF │ └────────────────────────────┘ │
└─────────────────────────────────┘
The current implementation doesn't support vectored trap hanlers.
You can halt the execution at any time writing 0x8 to the x15 register and executing ecall
li x17, 0x8 // send halt signal
ecallYou can dump a section of memory to a a writer at any time writing the from to x10 the to to x11 and 254 to x17. The default emulator will write dumps to a file and provides the argument --dump-folder to define the location of the dumps, if not provided it will use the current directory.
// Dumps the flash memory
li x10, 0
li x11, 0x0003_2000
li x17, 254
ecallInstall the toolchain:
rustup target add rv32i-unknown-none-elf