Writing a RISC-V Emulator from Scratch in 10 Steps


This is the book for writing a 64-bit RISC-V emulator from scratch in Rust. It shows us how to implement an emulator in 10 steps. You can run xv6, a simple Unix-like OS, in your emulator in the final step.

You'll learn the following basic computer architecture from making an emulator in Rust:

  • Basic RISC-V architecture

  • How to write code in Rust language

  • Privilege levels

  • Exceptions

  • Interrupts

  • Peripheral devices

  • Virtual memory system

The source code is available at d0iasm/rvemu-for-book.



Step 1

Setup and Implement Two Instructions

Step 2

RV64I Base Integer Instruction Set

Step 3

Control and Status Registers

Step 4

Privileged Instruction Set

Step 5


Step 6

UART (a universal asynchronous receiver-transmitter)

Step 7

PLIC (a platform-level interrupt controller) and CLINT (a core-local interrupter)

Step 8


Step 9


Step 10

Virtual Memory System

Congratulations🎉 Now you can run xv6 in your emulator!

The author is @d0iasm and please feel free to ask and request anything to me via Twitter or GitHub issues!