Crate sbi

Source
Expand description

This crate provides a safe, pure-Rust implementation of the RISC-V Supervisor Binary Interface (SBI) to be used in S-mode software, such as operating system kernels. This crate implements the v2.0-rc5 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โœ…
ยงDebug Console โœ…
FunctionFunction IDImplemented
Console write0โœ…
Console read1โœ…
Console write byte2โœ…
ยงSystem Suspend โœ…
FunctionFunction IDImplemented
System suspend0โœ…
ยงCollaborative Processor Performance Control โœ…
FunctionFunction IDImplemented
Probe CPPC register0โœ…
Read CPPC register1โœ…
Read CPPC register high bits2โœ…
Write CPPC register3โœ…
ยงNested Acceleration Extension โŒ
FunctionFunction IDImplemented
Probe nested acceleration feature0โŒ
Set nested acceleration shared memory1โŒ
Synchronize shared memory CSRs2โŒ
Synchronize shared memory HFENCEs3โŒ
Synchronize shared memory and emulate SRET4โŒ
ยงSteal-Time Accounting โŒ
FunctionFunction IDImplemented
Set steal-time shared memory address0โŒ

ยง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 collaborative_processor_performance_control as cbbc;
pub use hart_state_management as hsm;
pub use performance_monitoring_unit as pmu;

Modulesยง

base
Required base SBI functionality
collaborative_processor_performance_control
Collaborative Processor Performance Control
debug_console
Debug Console extension
hart_state_management
Hart State Management extension
ipi
IPI extension
legacy
Legacy SBI calls
performance_monitoring_unit
Performance Monitoring Unit extension
rfence
RFENCE extension
system_reset
System Reset extension
system_suspend
System Suspend extension
timer
Timer extension

Macrosยง

hart_mask
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ยง

HartMask
A SBI hart mask
PhysicalAddress
Representation of a physical address
RestrictedRange
A value restricted to a given range
SbiError
Error codes returned by SBI calls

Functionsยง

ecall0โš 
A zero-argument ecall with the given extension and function IDs.
ecall1โš 
A one-argument ecall with the given extension and function IDs.
ecall2โš 
A two-argument ecall with the given extension and function IDs.
ecall3โš 
A three-argument ecall with the given extension and function IDs.
ecall4โš 
A four-argument ecall with the given extension and function IDs.
ecall5โš 
A five-argument ecall with the given extension and function IDs.
ecall6โš 
A six-argument ecall with the given extension and function IDs.