Skip to content

Jaic1/xv6-riscv-rust

Repository files navigation

xv6-riscv-rust

This is a project intending to port xv6-riscv using Rust.
It is now runnable.

Usage

  1. Follow 6.S081 2021/6.S081 2020 to install tools.

    We may need to build qemu from source depending on the machine.

  2. Build fs:

make fs.img
  1. Run:
cargo run

Misc Options/Features

Objdump:

cargo objdump --bin xv6-riscv-rust -- -d > kernel.asm

// recommended, some instructions is unknown when using rust-objdump/llvm-objdump
// in target/riscv64gc-unknown-none-elf/debug
riscv64-unknown-elf-objdump -S xv6-riscv-rust > kernel.asm

trace system call:

cargo run --features "trace_syscall"

Verbose init info:

cargo run --features "verbose_init_info"

Unit Test(deprecated):

cargo run --features "unit_test"

target spec:

rustc -Z unstable-options --print target-spec-json --target riscv64gc-unknown-none-elf

Path

  • porting console and uart to support printf, p.s., smp = 1
  • add register abstraction to support start using mret to return to rust_main
  • cpu abstraction and spinlock, add unit_test feature as temp solution
  • us spin e lock to synchronize con print sole's ln, and refactor PRINT
  • add kernel frame allocator(kalloc), fix writing bug in timerinit
  • use Unique in self-implemented Box to provide ownership, see this for example
  • add Addr and PageTable
  • add kvm for kernel, i.e., kernel paging
  • cpu and proc basic abstraction(hard time playing around lock and borrow checker)
  • add kernel trap handler(panic at fork_ret)
  • add user trap returner and way to user space
  • add user code space(initcode) and ecall handing in user_trap
  • add virtio disk driver, plic, buffer cache, inode
  • refactor Proc into several parts, one need lock to protect, the other is private
  • separate Buf into two parts, one guarded by bcache's lock, the guarded by its own sleeplock
  • update bio and virtio disk
  • replace linked list allocator with buddy system, remove self-implemented Box
  • add log layer in fs
  • add inode layer in fs
  • complete sys_exec and add elf loader
  • add console, refactor uart and print
  • add file layer and sys_open, sys_dup, sys_write
  • add several sys_* func
  • add pipe in fs and also sys_unlink, sys_chdir, sys_pipe
  • port user library
  • add several sys_* func and handle some OOM cases
  • enable all harts

TODO

  • recycle pgt for uvm(no need to recycle pgt for kvm now)
  • remove ConstAddr and PhysAddr?
  • stack size need to be 8192 bytes?
  • meta data portion of buddy system is too high
  • may be too much UB
  • one-time init, like Once
  • some assertions can switch to debug_assert, compile time assert
  • remove VirtAddr and PhysAddr
  • refactor superblock
  • refactor begin_op and end_op
  • compare raw pointer's get_mut method with null-unchecked version &mut *
  • new_uninit
  • OOM
  • unexpected external interrupt irq=0

Useful Reference

Why implementing Send trait for Mutex?
Explicitly drop
fixed-size linked list allocator
take ownership from nothing
Unique issue
out of memory
integrate Mutex and MutexGuard
lld linker script
Rust Memory layout
rustc codegen options
Consider deprecation of UB-happy static mut
non-reentrant function
Cpp's Relaxed ordering
Rust build profile

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published