This repo contains the code for the RISC-V emulator that I presented at Rust Nation 2023.
It is intended as a teaching example to introduce people to the principles behind binary translation, and not a proper production-ready emulator. However, pull requests are still welcome!
A build.sh script is provided in the examples directory to build the assembly code examples used in the presentation. This requires clang and llvm-objcopy to be installed. Pass the name of the assembly file to the script to build it.
The resulting .bin file can be passed as an argument to the emulator:
examples/build.sh examples/hello_word.s
cargo run -- -b interpreter examples/hello_world.bin
The behavior of the ecall and ebreak instructions is defined in syscall.rs. Currently, ebreak will stop the emulator and exit the process. ecall invokes a system call depending on the value of x17:
| System call number (x17) | Name | Description | Arguments | Return value |
|---|---|---|---|---|
| 0 | print | Prints a string | x10: string address x11: string length | |
| 1 | print_int | Prints an integer | x10: integer to print | |
| 2 | get_arg | Returns the Nth argument as an integer, or 0 if absent | x10: argument index | x10: argument value |
You can easily define additional system calls by extending syscall.rs.
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
2 commits
Rust
100.0%
This repo contains the code for the RISC-V emulator that I presented at Rust Nation 2023.
It is intended as a teaching example to introduce people to the principles behind binary translation, and not a proper production-ready emulator. However, pull requests are still welcome!
A build.sh script is provided in the examples directory to build the assembly code examples used in the presentation. This requires clang and llvm-objcopy to be installed. Pass the name of the assembly file to the script to build it.
The resulting .bin file can be passed as an argument to the emulator:
examples/build.sh examples/hello_word.s
cargo run -- -b interpreter examples/hello_world.bin
The behavior of the ecall and ebreak instructions is defined in syscall.rs. Currently, ebreak will stop the emulator and exit the process. ecall invokes a system call depending on the value of x17:
| System call number (x17) | Name | Description | Arguments | Return value |
|---|---|---|---|---|
| 0 | print | Prints a string | x10: string address x11: string length | |
| 1 | print_int | Prints an integer | x10: integer to print | |
| 2 | get_arg | Returns the Nth argument as an integer, or 0 if absent | x10: argument index | x10: argument value |
You can easily define additional system calls by extending syscall.rs.
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
2 commits
Rust
100.0%