Skip to content

Istar-Eldritch/riscv-emu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Running the emulator

Dependencies

You require the riscv toolchain and the rust bindings for it.

sudo apt install binutils-riscv64-unknown-elf
rustup target add riscv32i-unknown-none-elf

Binary Arguments

cargo run --bin riscv-emu --help
Usage: 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 10

Running the examples

You can use the Makefile commands

make run_example example=<example_name>
make run_example example=halt

Memory MAP

            ┌─────────────────────────────────┐
0x0000_0000 │ ┌────────────────────────────┐  │
            │ │                            │  │
            │ │        FLASH MEMORY        │  │
            │ │                            │  │
0x0003_2000 │ └────────────────────────────┘  │
            │ ┌────────────────────────────┐  │
            │ │          RESERVED          │  │
            │ └────────────────────────────┘  │
0x0200_0000 │ ┌────────────────────────────┐  │
            │ │                            │  │
            │ │                            │  │
            │ │            CLINT           │  │
            │ │                            │  │
            │ │                            │  │
0x0200_FFFF │ └────────────────────────────┘  │
            │ ┌────────────────────────────┐  │
            │ │          RESERVED          │  │
            │ └────────────────────────────┘  │
0x0C00_0000 │ ┌────────────────────────────┐  │
            │ │                            │  │
            │ │                            │  │
            │ │            PLIC            │  │
            │ │                            │  │
            │ │                            │  │
0x1000_0000 │ └────────────────────────────┘  │
            │ ┌────────────────────────────┐  │
            │ │          RESERVED          │  │
            │ └────────────────────────────┘  │
0x1001_3000 │ ┌────────────────────────────┐  │
            │ │                            │  │
            │ │                            │  │
            │ │           UART0            │  │
            │ │                            │  │
            │ │                            │  │
0x1001_3FFF │ └────────────────────────────┘  │
            └─────────────────────────────────┘

Limitations

The current implementation doesn't support vectored trap hanlers.

Environment Calls

HALT

You can halt the execution at any time writing 0x8 to the x15 register and executing ecall

li x17, 0x8 // send halt signal
ecall

MEMDUMP

You 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
ecall

Rust on the RV32i

Install the toolchain:

rustup target add rv32i-unknown-none-elf

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published