Simple RISC-V emulator presented at Rust Nation 2023

Overview

A tale of binary translation

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!

Building the examples

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

System calls

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.

License

Licensed under either of:

at your option.

Contribution

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.

You might also like...
Repository containing schedules, slides/talk and user submissions for the 2023 devconnect hackerhouse

2023 DevConnect Hacker House Content Schedule Hackathon Tracks xChain dapps - Total Prize pool of USD 12k (5k, 4k, 3k) Fully on-chain dapps - Total Pr

🎄Solutions for Advent of Code 2023
🎄Solutions for Advent of Code 2023

🎄 Advent of Code 2023 Solutions for Advent of Code in Rust. 2023 Results Day Part 1 Part 2 Day 1 ⭐ ⭐ Day 2 ⭐ ⭐ Day 3 ⭐ ⭐ Day 4 ⭐ ⭐ Day 5 ⭐ ⭐ Day 6 ⭐

My solutions for the Advent of Code 2023.

🎄 Advent Of Code 2023 Hi! These are my Rust solutions for the Advent of Code 2023. Day Name Source Part 1 Part 2 Time 1 Time 2 1 Trebuchet?! 01.rs ⭐

🎄🎅 My Advent of Code 2023 solutions 🎁⛄
🎄🎅 My Advent of Code 2023 solutions 🎁⛄

🎄🎁 My AOC 2023 solutions 🎅⛄ 🎄 Table of contents 🎁 Table of the days 🎅 Goals ⛄ Quickstart 🎁 Table of the days Day Part 1 Part 2 Language 01 Toki

Advent of Code 2023 solutions - #15 on global leaderboard

My solutions for Advent of Code 2023, written in Rust. The code requires Rust nightly to run. Sample inputs from each day are provided. To run with ac

Blink program on RISC L106 80Mhz 32bit CPU

esp8266-blink Blink program on RISC L106 80Mhz 32bit CPU Flashing Running rust on ESP* is sort of hard... We won't cover the installation process, ins

Following "ZK HACK III - Building On-chain Apps Off-chain Using RISC Zero"

RISC Zero Rust Starter Template Welcome to the RISC Zero Rust Starter Template! This template is intended to give you a starting point for building a

A fast, efficient emulator for the osu! Bancho protocol written in Rust

rosu. A fast, efficient emulator for the osu! Bancho protocol written in Rust. Setup Git clone rosu, setup your nginx (example config is in the ext fo

My terminal emulator
My terminal emulator

Miro A GPU-accelerated terminal emulator written in Rust. miro -t pika miro -t kirby miro -t mario miro -t sonic Building from source

Owner
Amanieu d'Antras
Amanieu d'Antras
rust-rustlings-2023-autumn-CAIMEOX created by GitHub Classroom

2023秋冬季操作系统训练营 第一阶段训练安排 rustlings Rust编程训练教室 rustlings ??❤️ Greetings and welcome to rustlings. This project contains small exercises to get you used

The Learning&Training Hub of OS Kernel 2 Oct 31, 2023
DevNot Summit 2023 etkinliğindeki Programcıdan Programcıya Rust konulu sunuma ait örnek kodları içerir.

DevNot Summit 2023 - Programcıdan Programcıya Rust DevNot Summit 2023 etkinliğindeki Programcıdan Programcıya Rust konulu sunuma ait örnek kodları içe

Burak Selim Senyurt 8 Oct 12, 2023
Solutions of Advent-of-Code 2023 in Rust

Advent of Code 2023 in Rust If you've never heard of Advent of Code, you're missing out. Check it out now at adventofcode.com! I mostly do AoC puzzles

Aurélien Geron 4 Dec 8, 2023
Solutions to Advent of Code 2023 in Rust 🎄

Advent of Code 2023 Solutions to Advent of Code 2023 in Rust ?? Day Part 1 Part 2 Thoughts 1 ⭐ ⭐ As with most early advent of code challenges, it's mo

Pedro Godinho 6 Dec 6, 2023
Solutions to Advent of Code 2023 in Rust! :crab:

AdventOfCode2023 ?? Solutions to AoC 2023 in Rust ?? Usage # to be able to download inputs (see fetch.sh) export AOC_SESSION=[value from session cooki

Axel Lindeberg 27 Dec 17, 2023
My Advent of Code 2023 solutions in the Rust programming language.

Advent of Code 2023 in Rust My Advent of Code 2023 solutions in the Rust programming language. This repository holds a separate Rust project for each

Tim Visée 65 Dec 17, 2023
Contains challenges, write-ups, and deployment configurations from b01lersCTF 2023.

CTF Name A template repository for a CTF competition. This is a description of the CTF event. CTFTime Link Structure Challenges are organized by categ

null 7 Mar 29, 2023
Sky Island Showdown: CSE 125 Spring 2023 Group 5 Project, a Multiplayer, 3D Game

As the Wind Blows ?? Project for CSE 125 Spring 2023, Group 5 Homepage » As the Wind Blows is a 3D multiplayer game, created with Rust, WGPU, and a to

null 5 May 1, 2023
a hack implementation of CCS generic arithmetization, won a prize at Zuzalu hackathon 2023 despite incompleteness

ccs-hack CCS (Customized Constraint System) is a generic constraints representation system can simultaneously capture R1CS, Plonkish, and AIR: $$\sum_

Thor 27 Jun 1, 2023
GraphQL Summit 2023 Workshop Demo for Federated Subscriptions in GraphOS.

Kahoot Clone Demo App - Subgraphs Welcome to the project for GraphQL Summit 2023 "Federated Subscriptions in GraphOS" workshop! ⚠️ Before the workshop

Apollo GraphQL 4 Oct 10, 2023