用 Rust 编写 RISC-V 模拟器
Writing a RISC-V Emulator in Rust

原始链接: https://book.rvemu.app/

本书指导读者使用Rust构建一个64位RISC-V模拟器,最终能够运行类Unix操作系统xv6。这是一个实践性的学习过程,涵盖了计算机体系结构的基础概念。 该项目目前正在开发中,详细介绍了CPU、内存、系统总线、控制/状态寄存器等关键硬件组件的实现,以及操作系统功能所必需的元素——包括中断控制器(PLIC & CLINT)、UART和虚拟内存系统。它还涵盖了必要的指令集架构(ISA)实现。 源代码可在GitHub上找到(d0iasm/rvemu-for-book),作者(@d0iasm)鼓励通过Twitter或GitHub issues提供反馈和建议。成功完成本书将得到一个能够运行xv6的完整模拟器。

## 黑客新闻上的RISC-V模拟器讨论 最近一篇黑客新闻文章介绍了新的基于Rust的RISC-V模拟器(rvemu.app),引发了关于RISC-V指令集架构(ISA)的争论。一个关键的争论点是大端序支持的包含。许多评论者,包括Linus Torvalds等知名人士,质疑其必要性,认为它增加了复杂性,但实际益处不大。 最初为大端序支持的理由源于一种小众的网络场景,但批评者认为这是一个微不足道的理由,会使规范和软件堆栈复杂化。人们对维护开销、由于缺乏广泛使用而导致的潜在数据腐坏,以及小端序已基本成为标准这一事实表示担忧。 讨论还涉及了替代的模拟器实现方法,一些人提倡使用汇编语言以提高性能和寿命,而另一些人则支持使用Rust等高级语言,甚至使用Sail等工具从规范本身进行自动翻译。最终,该帖子展示了RISC-V不断发展过程中关于设计选择和权衡的活跃交流。
相关文章

原文

NOTE: This project is actively ongoing. Pages are not perfect yet and it possible to change dramatically.

This is the book for writing a 64-bit RISC-V emulator from scratch in Rust. You can run xv6, a simple Unix-like OS, in your emulator once you finish the book.

You'll learn the basic computer architecture such as ISA, previleged architecture, exceptions, interrupts, peripheral devices, and virtual memory system from making an emulator.

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

Chapter 1 shows all hardward components we need to implement for running xv6.

  1. CPU with Two Instructions
  2. Memory and System Bus
  3. Control and Status Registers
  4. Privileged Architecture
  5. Exceptions
  6. PLIC (a platform-level interrupt controller) and CLINT (a core-local interrupter)
  7. UART (a universal asynchronous receiver-transmitter)
  8. Interrupts
  9. Virtio
  10. Virtual Memory System

Chapter 2 shows all ISAs we need to implement for running xv6.

Once you read this book and implement the emulator, you will be able to run xv6 in your emulator!

Demo for running xv6 on the emulator

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

联系我们 contact @ memedata.com