Writing a RISC-V Emulator from Scratch in 10 Steps

Introduction

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

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

Step

Content

Step 1

Setup and Implement Two Instructions

Step 2

RV64I ISA

Step 3

Exceptions

Step 4

A part of CSRs

Step 5

Supervisor ISA

Step 6

UART (a universal asynchronous receiver-transmitter)

Step 7

PLIC (a platform-level interrupt controller)

Step 8

Interrupts

Step 9

CLINT (a core-local interruptor)

Step 10

Virtio

Congratulations🎉 Now you can run xv6 in your emulator!

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