Crate sbi

source · []
Expand description

This crate provides a safe, pure-Rust implementation of the RISC-V SBI interface to be used in S-mode software, such as operating system kernels. This crate implements the v1.0.0 version of the SBI specification and aims to stay up to date with it as newer versions of the specification are released.

Important safety note

Since this crate is meant to be used by S-mode software, it is assumed that you are executing the provided functions from within S-mode with a spec compliant SBI implementation running in M-mode (or S-mode in the case of VS-mode), and considers execution from any other operating mode out of the scope of this crate, which may bring with it memory safety concerns in those environments. Consider this an implicit contract when using the crate.

SBI extension support

Extension implementation state legend:

✅ - Fully implemented

🚧 - Partially implemented

❌ - Not implemented

Standard SBI extensions

SBI extensions implementation state
Legacy ✅
FunctionExtension IDImplemented
Set timer0
Console putchar1
Console getchar2
Clear IPI3
Send IPI4
Remote FENCE.I5
Remote SFENCE.VMA6
Remote SFENCE.VMA with ASID7
Shutdown8
Base ✅
FunctionFunction IDImplemented
Get SBI specification version0
Get SBI implementation ID1
Get SBI implementation version2
Probe SBI extension3
Get machine vendor ID4
Get machine architecture ID5
Get machine implementation ID6
Timer ✅
FunctionFunction IDImplemented
Set timer0
Interprocessor Interrupt (IPI) ✅
FunctionFunction IDImplemented
Send IPI0
RFENCE ✅
FunctionFunction IDImplemented
Remote FENCE.I0
Remote SFENCE.VMA1
Remote SFENCE.VMA with ASID2
Remote HFENCE.GVMA with VMID3
Remote HFENCE.GVMA4
Remote HFENCE.VVMA with ASID5
Remote HFENCE.VVMA6
Hart State Management ✅
FunctionFunction IDImplemented
Hart start0
Hart stop1
Get hart status2
Hart suspend3
System Reset ✅
FunctionFunction IDImplemented
System reset0
Performance Monitoring Unit ✅
FunctionFunction IDImplemented
Get number of counters0
Get counter information1
Configure matching counters2
Start counters3
Stop counters4
Read firmware counter5

Experimental, vendor-specific, and firmware-specific extensions

Experimental, vendor-specific, and firmware-specific SBI extensions are provided as opt-in crate features.

The currently supported non-standard SBI extensions are:

Experimental

There are currently no supported experimental SBI extensions.

Vendor-specific

There are currently no supported vendor-specific SBI extensions.

Firmware-specific

There are currently no supported firmware-specific SBI extensions.

License

sbi is licensed under the Mozilla Public License 2.0

Re-exports

pub use hart_state_management as hsm;

Modules

Required base SBI functionality

Hart State Management extension

IPI extension

Legacy SBI calls

Performance Monitoring Unit extension

RFENCE extension

System Reset extension

Timer extension

Macros

A convenience macro to help create a HartMask from either one or more hart IDs or a base and a list of hart IDs.

Structs

A SBI hart mask

Enums

Error codes returned by SBI calls

Functions

A zero-argument ecall with the given extension and function IDs.

A one-argument ecall with the given extension and function IDs.

A two-argument ecall with the given extension and function IDs.

A three-argument ecall with the given extension and function IDs.

A four-argument ecall with the given extension and function IDs.

A five-argument ecall with the given extension and function IDs.

A six-argument ecall with the given extension and function IDs.