Giter Site home page Giter Site logo

rustsbi / rustsbi Goto Github PK

View Code? Open in Web Editor NEW
929.0 18.0 75.0 527 KB

RISC-V Supervisor Binary Interface (RISC-V SBI) library in Rust; runs on M or HS mode; good support for embedded Rust ecosystem. For binary download see https://github.com/rustsbi/standalone.

License: MIT License

Rust 100.00%
rust rustsbi rust-embedded riscv sbi sbi-specification bare-metal

rustsbi's Introduction

RustSBI

RISC-V Supervisor Binary Interface (SBI) library in Rust; runs on M-mode or HS mode.

crates.io Documentation License

Binary downloads

Most users would get RustSBI binary download from the RustSBI Prototyping System. Check out the link here to download binary package for your platform.

Boards, SoC vendors and research groups would provide dedicated RustSBI package for supported platforms. There are packages exists on awesome-rustsbi: it is a curated list of awesome things related to RustSBI, which includes some implementation projects maintained by individuals or the community.

Users on commercial boards may visit implementation specific distribution links depending on the platforms they need, or consult vendors if they provide discrete RustSBI package support.

Minimum supported Rust version

To compile RustSBI library, you need at least stable Rust version of rustc 1.65.0.

Build this project

RustSBI is usually used as a library or dependency. If you wish to, you may build RustSBI library itself using the following command:

cargo build

The build should finish without any errors.

Building under native platform will allow development of hypervisors and emulators. To cross-build for a RISC-V platform environment, you may install the target and build onto it instead:

# If you don't have the cross compile target installed, install it first
rustup target add riscv64imac-unknown-none-elf
# Build this project as library
cargo build --target riscv64imac-unknown-none-elf

The target platform of RISC-V platform firmware is usually a bare metal target. Under normal circumstances these targets in Rust would start with riscv??- and end with -none-elf.

Features

  • Feature rich and extensible operating system runtime
  • Empower support, compatibility for machines, hypervisors and emulators
  • Support to and develop with RISC-V SBI specification v2.0 ratified
  • Written in Rust, builds under stable Rust
  • Capable to develop with other firmware ecosystem projects
  • Adapted for operating system kernel models on your choice

Frequently asked questions

  1. How would I build a RustSBI implementation?

RustSBI have extensive documents on such purposes! No matter what you are building with it, you will find some documents about RustSBI on bare-metal environments, hypervisors and emulators.

Check it out at RustSBI document main page.

  1. Can I use RustSBI on C based kernels?

Yes, you can! RustSBI strictly follows RISC-V SBI standard. All features are prepares for all programming languages, as long as they support RISC-V SBI defined calling convention.

If your kernel language supports other SBI implementations, usually it will support RustSBI in the same way.

Talks and documents

This project is originally a part of rCore Summer of Code 2020 activities, inspired by MeowSBI and other similar projects. Now it is capable of running rCore-Tutorial and other OS kernels on wide supported RISC-V devices.

There are multiple talks related to RustSBI dated back to Aug 2020. These talks discuss from design and abstraction of RustSBI modules, to actual production and research usage scenario related to RustSBI and RISC-V bootloaders. Public slides and blog articles of these talks are available at RustSBI/slides page.

Notes on platform implementation

  1. RustSBI should be used as a library. Under normal circumstances, RustSBI platform can be implemented with embedded Rust's embedded-hal libraries.
  2. Contributions are welcomed! We welcome to implement and test RustSBI for both FPGA cores and real cores. Implementations for emulators are also welcomed. If you are ready, start your own binary project and use RustSBI in it!
  3. If there is a bug in RustSBI project itself, fire an issue or pull request to let us know!

License & Copyright

This project is licensed under either of

Documents from RISC-V SBI Specification are used in this project. These documents are (C) RISC-V Foundation under Creative Commons Attribution 4.0 International License (CC-BY 4.0). The full license text is available at https://creativecommons.org/licenses/by/4.0/.

rustsbi's People

Contributors

aatomical avatar dependabot[bot] avatar duskmoon314 avatar felixonmars avatar hasheddan avatar jakezhu9 avatar luojia65 avatar mengxi-xu avatar occupymars2025 avatar orangecms avatar placebo27 avatar wyfcyx avatar ydrmaster 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rustsbi's Issues

Software Delegate IllegalInstruction Exception to Supervisor Mode

Now RustSBI just panic if the illegal instruction is not related to platform/privilege spec compatibility. It causes that when an illegal instruction occurs in application(U Mode), the kernel(S Mode) cannot catch and handle it since RustSBI does not delegate the exception to the kernel but just panic.

In my opinion, we can delegate(software) the exception to kernel in RustSBI by setting scause/stval etc. and jumping to the address which stvec points to, although there are plenty of details to be considered...

Page fault delegation

话说根据boot之后sbi输出的medeleg来看,是不是Page fault没有进行委托QAQ

How to work on riscv32?

I am using qemu-system-riscv32 to load rustsbi, and nothing to show.

If possible, please help provide documentation about how to build for riscv32.

rustsbi qemu panic due to invalid instruction

加载 rustsbi 时panic,qemu 5.2.50,我的机器是一台m1 mac,但是据反馈,intel的mac也有此问题,但其降到5.2.0就OK了,m1 的 mac qemu 降到5.2.0暂时无法运行,我这边没法尝试。

我觉得还是和qemu 5.2.50有关。

➜  os git:(main)  qemu-system-riscv64 \
                -machine virt \
                -nographic \
                -bios ../bootloader/rustsbi-qemu.bin
[rustsbi] RustSBI version 0.1.1
.______       __    __      _______.___________.  _______..______   __
|   _  \     |  |  |  |    /       |           | /       ||   _  \ |  |
|  |_)  |    |  |  |  |   |   (----`---|  |----`|   (----`|  |_)  ||  |
|      /     |  |  |  |    \   \       |  |      \   \    |   _  < |  |
|  |\  \----.|  `--'  |.----)   |      |  |  .----)   |   |  |_)  ||  |
| _| `._____| \______/ |_______/       |__|  |_______/    |______/ |__|

[rustsbi] Platform: QEMU (Version 0.1.0)
[rustsbi] misa: RV64ACDFIMSU
[rustsbi] mideleg: 0x222
[rustsbi] medeleg: 0xb1ab
[rustsbi-dtb] Hart count: cluster0 with 1 cores
[rustsbi] Kernel entry: 0x80200000
[rustsbi-panic] hart 0 panicked at 'invalid instruction, mepc: 0000000080003eba, instruction: 0000000030200073', platform\qemu\src\main.rs:458:17
[rustsbi-panic] system shutdown scheduled due to RustSBI panic

安装问题

下载安装包之后,得到两个文件, rustsbi-qemu, rustsbi-qemu.bin, 然后该怎么按照rustsbi呢

RustSBI的浮点指令支持

我在用fmv.w.x指令时,发现被RustSBI视为非法指令
请问RustSBI没有提供浮点指令的支持吗?

能否限定 RustSBI 的实现通过 &‘static dyn 传入模块的实现对象?

现在各个模块的 init 都使用一般的泛型,并且传入转移所有权的实现对象。然而这样的对象由于无法在库编译时确定尺寸,实际上无法存储,只能放在堆上,这要求 SBI 的实现必须提供堆,这对于某些嵌入式设备似乎不够友好。

既然目前 RustSBI 已经以全局的方式提供服务,基本上已经在事实上要求实现对象是静态的。能否直接要求实现传入 &'static dyn 来初始化各模块?RustSBI 本体不再负责保存这些对象,只是通过指针访问它们。

这样还有个好处是设置对象可以是原子操作更新指针,更快更安全。

Why is the symbol not found?

= note: rust-lld: error: /root/rustsbi/target/riscv64gc-unknown-none-elf/debug/deps/libriscv-d89f58cca82b1706.rlib(riscv.o): cannot link object files with different floating-point ABI
rust-lld: error: undefined symbol: _max_hart_id
>>> referenced by main.rs:76 (platform/k210/src/main.rs:76)
>>> /root/rustsbi/target/riscv64gc-unknown-none-elf/debug/deps/rustsbi_k210-fa3b824066eafffd.1hd3n18pcrelb196.rcgu.o:(_start)
>>> referenced by main.rs:76 (platform/k210/src/main.rs:76)
>>> /root/rustsbi/target/riscv64gc-unknown-none-elf/debug/deps/rustsbi_k210-fa3b824066eafffd.1hd3n18pcrelb196.rcgu.o:(_start)

      rust-lld: error: undefined symbol: _stack_start
      >>> referenced by main.rs:76 (platform/k210/src/main.rs:76)
      >>>               /root/rustsbi/target/riscv64gc-unknown-none-elf/debug/deps/rustsbi_k210-fa3b824066eafffd.1hd3n18pcrelb196.rcgu.o:(_start)
      
      rust-lld: error: undefined symbol: _hart_stack_size
      >>> referenced by main.rs:76 (platform/k210/src/main.rs:76)
      >>>               /root/rustsbi/target/riscv64gc-unknown-none-elf/debug/deps/rustsbi_k210-fa3b824066eafffd.1hd3n18pcrelb196.rcgu.o:(_start)
      >>> referenced by main.rs:76 (platform/k210/src/main.rs:76)
      >>>               /root/rustsbi/target/riscv64gc-unknown-none-elf/debug/deps/rustsbi_k210-fa3b824066eafffd.1hd3n18pcrelb196.rcgu.o:(_start)
      
      rust-lld: error: undefined symbol: _sbss
      >>> referenced by main.rs:118 (platform/k210/src/main.rs:118)
      >>>               /root/rustsbi/target/riscv64gc-unknown-none-elf/debug/deps/rustsbi_k210-fa3b824066eafffd.1hd3n18pcrelb196.rcgu.o:(_start)
      
      rust-lld: error: undefined symbol: _ebss
      >>> referenced by main.rs:118 (platform/k210/src/main.rs:118)
      >>>               /root/rustsbi/target/riscv64gc-unknown-none-elf/debug/deps/rustsbi_k210-fa3b824066eafffd.1hd3n18pcrelb196.rcgu.o:(_start)
      
      rust-lld: error: undefined symbol: _sdata
      >>> referenced by main.rs:119 (platform/k210/src/main.rs:119)
      >>>               /root/rustsbi/target/riscv64gc-unknown-none-elf/debug/deps/rustsbi_k210-fa3b824066eafffd.1hd3n18pcrelb196.rcgu.o:(_start)
      
      rust-lld: error: undefined symbol: _sidata
      >>> referenced by main.rs:119 (platform/k210/src/main.rs:119)
      >>>               /root/rustsbi/target/riscv64gc-unknown-none-elf/debug/deps/rustsbi_k210-fa3b824066eafffd.1hd3n18pcrelb196.rcgu.o:(_start)

为什么会找不到这些符号
target = riscv64gc-unknown-none-elf

More build guidance in README.md

For someone who isn't using Rust for cross compilation on a daily basis, I found the README a bit lacking in how to build this. I tried

$ rustup target add riscv64gc-unknown-linux-gnu
$ cargo build --target riscv64gc-unknown-linux-gnu

but that crashed out with:

    Updating crates.io index
   Compiling memchr v2.4.1
   Compiling regex-syntax v0.6.25
   Compiling lazy_static v1.4.0
   Compiling nb v1.0.0
   Compiling bare-metal v1.0.0
   Compiling bit_field v0.10.1
   Compiling void v1.0.2
   Compiling nb v0.1.3
   Compiling embedded-hal v0.2.6
   Compiling aho-corasick v0.7.18
   Compiling regex v1.5.4
   Compiling riscv-target v0.1.2
   Compiling riscv v0.7.0
error: failed to run custom build command for `riscv v0.7.0`

Caused by:
  process didn't exit successfully: `/home/tommy/projects/chipsalliance/workloads/rustsbi/target/debug/build/riscv-c23973cdc9c82cbb/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', /home/tommy/.cargo.x86_64-linux/registry/src/github.com-1ecc6299db9ec823/riscv-0.7.0/build.rs:22:10
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.