rustsbi/rustsbi-qemu

QEMU support using RustSBI

When running cargo qemu, the test kernel will build and run

Compile and run with:

cargo qemu

When running cargo qemu, the test kernel will build and run. Expected output should be:

xtask: mode: Debug
   Compiling rustsbi-qemu v0.1.0 (D:\RustProjects\rustsbi-qemu\rustsbi-qemu)
    Finished dev [unoptimized + debuginfo] target(s) in 1.09s
    Finished dev [unoptimized + debuginfo] target(s) in 0.23s
[rustsbi] RustSBI version 0.2.0-alpha.3
.______       __    __      _______.___________.  _______..______   __
|   _  \     |  |  |  |    /       |           | /       ||   _  \ |  |
|  |_)  |    |  |  |  |   |   (----`---|  |----`|   (----`|  |_)  ||  |
|      /     |  |  |  |    \   \       |  |      \   \    |   _  < |  |
|  |\  \----.|  `--'  |.----)   |      |  |  .----)   |   |  |_)  ||  |
| _| `._____| \______/ |_______/       |__|  |_______/    |______/ |__|

[rustsbi] Implementation: RustSBI-QEMU Version 0.0.1
[rustsbi-dtb] Hart count: cluster0 with 1 cores
[rustsbi] misa: RV64ACDFIMSU
[rustsbi] mideleg: ssoft, stimer, sext (0x222)
[rustsbi] medeleg: ima, ia, bkpt, la, sa, uecall, ipage, lpage, spage (0xb1ab)
[rustsbi] pmp0: 0x80000000 ..= 0x800fffff (rwx)
[rustsbi] pmp1: 0x80200000 ..= 0x802fffff (rwx)
[rustsbi] pmp2: 0x0 ..= 0xfffffffffffffffc (---)
[rustsbi] enter supervisor 0x80200000
<< Test-kernel: Hart id = 0, DTB physical address = 0x87e00000
>> Test-kernel: Testing base extension
<< Test-kernel: Base extension version: 1
<< Test-kernel: SBI specification version: 2
<< Test-kernel: SBI implementation Id: 4
<< Test-kernel: SBI implementation version: 200
<< Test-kernel: Device mvendorid: 0
<< Test-kernel: Device marchid: 0
<< Test-kernel: Device mimpid: 0
>> Test-kernel: Testing SBI instruction emulation
<< Test-kernel: Current time: 31918a
>> Test-kernel: Trigger illegal exception
<< Test-kernel: Value of scause: Exception(IllegalInstruction)
<< Test-kernel: Illegal exception delegate success
<< Test-kernel: SBI test SUCCESS, shutdown

Run test kernel

Requirements

cargo-binutils and llvm-tools-preview are needed

cargo install cargo-binutils
rustup component add llvm-tools-preview

Run

Run with:

cargo test

It will run RustSBI-QEMU with a test kernel. The test kernel will test all SBI functions, its command emulation and other features. If it succeeds, there would be output like:

running 1 test
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
   Compiling test-kernel v0.1.0 (D:\RustProjects\rustsbi-qemu\test-kernel)
    Finished dev [unoptimized + debuginfo] target(s) in 0.61s
test run_test_kernel ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.31s

License

This project is licensed under Mulan PSL v2.

Copyright (c) 2021 Wuxiang Zhi Feng Team
RustSBI-QEMU is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
         http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
Issues

Collection of the latest Issues

yztz

yztz

Comment Icon1

在现有的处理中: https://github.com/rustsbi/rustsbi-qemu/blob/96704cf4373b9eb804145268862ba92700e46b27/rustsbi-qemu/src/feature/transfer_trap.rs#L23 仅仅设置SPP为S态似乎有些草率。比如在xv6中,若是在用户态触发了非法指令异常,那么在异常处理函数中会判断该异常是否来自于用户态:

若按上述设置,那么将会触发panic,这对于debug来说颇具误导性...

比较合适的设置方法应该是根据现有的MPP来设置SPP:

wyfcyx

wyfcyx

Comment Icon5

The Rustsbi binary was downloaded from https://github.com/rustsbi/rustsbi-qemu/releases/download/v0.1.1/rustsbi-qemu-release.zip.

The PMP output was not correct. Actually, the expected output is:

It was very weird that when I tested using cargo qemu under the rustsbi-qemu root directory, the output was correct. I did not know what happened.


Another question is that rCore-Tutorial-v3 cannot work normally using rustsbi-qemu version 0.1.1 if the tutorial is built in debug mode. However, it works under release mode. Therefore, I decide not to upgrade rustsbi for a while...

Gallium70

Gallium70

Comment Icon3

目前rustsbi-qemu在收到M态软件中断时,只会判断上一个HSM命令,如果不存在就直接 panic ,导致S态软件无论是通过SBI s-IPI扩展还是直接访问Clint都无法使用IPI功能(除非是ACLINT)。

一个最直接的hack就是发现没有HSM命令时,把软件中断直接转发给S态;不过这样可能处理不了rfence扩展,应该得再加一套或者两套命令接口。

duskmoon314

duskmoon314

help wanted
Comment Icon2

Now rustsbi-qemu doesn't allow S mode software use devices provided by qemu because we havn't set pmp registers for them.

Noticed that qemu provides more than one board, and they have different MMIO. We need to discuss how to set pmp registers properly.

现在 rustsbi-qemu 不允许 S 态软件使用 qemu 提供的设备,因为我们没有为它们设置 pmp 寄存器。

注意到 qemu 提供了不止一种板子,而且它们有不同的 MMIO。我们需要讨论如何正确设置 pmp 寄存器。


If anyone who wonder how to use devices in qemu, here is an example of using uart0 (uart0_mmio base 0x10000000 lenth 0x100) in virt machine:

如果任何人想知道如何使用 qemu 的外设,下面是使用 virt 的 uart0 (uart0_mmio 基址 0x10000000 长度 0x100) 的一个例子:

retrhelo

retrhelo

help wanted
Comment Icon6

注意到作为测试用例的test-kernel目前是作为该项目以及rustsbi-k210项目的一部分存在的。考虑到其作为测试用例而言对这两个sbi实现具有普适性,是否可以将test-kernel独立出来?这样还可以方便其他的SBI实现使用其作为测试用例。

D0ot

D0ot

Comment Icon4

Rustsbi version: at commit 269d1d32b4c0fd4900e6db1f070e7a2ce983dd14 QEMU version: 5.2.0

Minimalist test case:

When i use the legacy sbi_legacy_set_timer(), the code works as expected, outputs a lot.

When i use the new sbi_set_time(), it seems that timer interrupt was never triggered..

I have traced the code, the params were properly passed.

image image

Is the difference an expected behavior?

Thanks ~~~

Versions

Find the latest versions by id

v0.1.1 - Mar 29, 2022

This update contains:

Added

  • Adapts to RustSBI version 0.2.2, RISC-V SBI version 1.0.0 ratified
  • Handle possible failure of deref virtual address by machine trap detection

Modified

  • Use Rust Edition 2021
  • Modify test kernel message

Each zip archive contains an ELF file and a binary file. Install the binary into target, and use the ELF to help debugging if needed.

v0.1.0 - Feb 13, 2022

This update contains:

  • Adapts to RustSBI version 0.2.0
  • Implement SBI non-retentive resume procedure
  • PMP updates, use stabilized core::arch::asm! macro, thanks to @wyfcyx
  • Fixes on usage of CLINT peripheral, thanks to @duskmoon314
  • Numerous fixes to HSM module implementation, more documents

Each zip archive contains an ELF file and a binary file. Install the binary into target, and use the ELF to help debugging if needed.

v0.0.2 - Nov 26, 2021

This update contains:

  • Supports RISC-V Privileged Specification v1.12, adapts to SBI specification version 0.3
  • Retentive and non-retentive hart suspend function, providing convenience for multi-core kernel system boot
  • SBI HSM standard hart start and stop function
  • Migrate to RustSBI v0.2.0-alpha.7
  • Prevent cargo check error in Visual Studio Code IDE
  • PMP module settings, support virtio0 in pmp config (@wyfcyx)
  • Delegate U interrupt to S, delegate MTI to S via set_stip (@duskmoon314)
  • Add toolchain check for xtask (@SKTT1Ryze)
  • Set rust build toolchain to nightly (@duskmoon314)
  • Small fixes

Each zip archive contains an ELF file and a binary file. Install the binary into target, and use the ELF to help debugging if needed.

v0.0.1 - May 23, 2021

This is the first release of rearranged RustSBI-QEMU project. It fully supports RISC-V Privileged Specification v1.11, and adapts to RISC-V SBI specification v0.2.

This project targets to provide an SBI environment and a test suite on QEMU, hereby provided as an example for further RustSBI implementations.

Each release contains an ELF file and a binary file. Install the binary into target, and use the ELF to help debugging if needed.

Information - Updated Jun 20, 2022

Stars: 46
Forks: 15
Issues: 8

rust_embedded_starter

Boilerplate für Embedded Entwicklung mit Rust mit Flash und Debug automatik

rust_embedded_starter

Embedded rust HAL (hardware abstraction layer) for the STM32WL

This is a work in progress, it is unstable, incomplete, and (mostly) untested

Embedded rust HAL (hardware abstraction layer) for the STM32WL

Embedded Rust Template

This template is based on stm32f4xx-hal

Embedded Rust Template

A Rust embedded-hal HAL for all MCUs in the STM32 F7 family

This crate is largely inspired by the awesome work done here:

A Rust embedded-hal HAL for all MCUs in the STM32 F7 family

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony...

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony Romano's docs

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony...

embedded-rust-H2AL

Hardware abstraction layer - abstraction layer

embedded-rust-H2AL

cargo-pio = Cargo + PlatformIO

Build Rust embedded projects with PlatformIO!

cargo-pio = Cargo + PlatformIO

Embedded rust HAL (hardware abstraction layer) for the STM32WL series

This is still in development, the code that exists today covers basic usage of:

Embedded rust HAL (hardware abstraction layer) for the STM32WL series

Microchip MCP4725 DAC Driver for Rust Embedded HAL

This is a driver crate for embedded Rust

Microchip MCP4725 DAC Driver for Rust Embedded HAL

An async embedded rust no_std driver for the QMC5883L magnetometer chip based on this driver

An async embedded rust no_std driver for the QMC5883L magnetometer chip based on embassy example

An async embedded rust no_std driver for the QMC5883L magnetometer chip based on this driver
Facebook Instagram Twitter GitHub Dribbble
Privacy