Giter VIP home page Giter VIP logo

xv6-riscv-rust's Introduction

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

xv6-riscv-rust's People

Contributors

jaic1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

xv6-riscv-rust's Issues

Cannot make it to run

I have followed the instructions in README.md to compile this project, it ended up no errors while compiling but there is a file fs.img missing so that qemu cannot be started. Did I miss anything?

Problem with `feature removed`

When I run the command in the repo

cargo +nightly run

It shows that

error[E0557]: feature has been removed
 --> src/lib.rs:4:12
  |
4 | #![feature(const_in_array_repeat_expressions)]
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ feature has been removed
  |
  = note: removed due to causing promotable bugs

And I comment on this line and cargo run again, it shows that

#![no_std]
error[E0277]: the trait bound `PageTableEntry: core::marker::Copy` is not satisfied
  --> src/mm/pagetable.rs:76:19
   |
76 |             data: [PageTableEntry { data: 0 }; 512],
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::marker::Copy` is not implemented for `PageTableEntry`
   |
   = note: the `Copy` trait is required because the repeated element will be copied

error: aborting due to previous error; 1 warning emitted

Could you please tell me how to solve this problem?

Looking forward to your reply.

Lori

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.