|
For the latest stable version, please use Supervisor Binary Interface v3.0! |
2.1. Binary Encoding
2.1. Binary Encoding
All SBI functions share a single binary encoding, which facilitates the mixing of SBI extensions. The SBI specification follows the below calling convention.
-
An
ECALLis used as the control transfer instruction between the supervisor and the SEE. -
a7encodes the SBI extension ID (EID), -
a6encodes the SBI function ID (FID) for a given extension ID encoded ina7for any SBI extension defined in or after SBI v0.2. -
All registers except
a0&a1must be preserved across an SBI call by the callee. -
SBI functions must return a pair of values in
a0anda1, witha0returning an error code. This is analogous to returning the C structure
struct sbiret {
long error;
long value;
};
In the name of compatibility, SBI extension IDs (EIDs) and SBI function IDs (FIDs) are encoded as signed 32-bit integers. When passed in registers these follow the standard above calling convention rules.
The Table 1 below provides a list of Standard SBI error codes.
| Error Type | Value |
|---|---|
SBI_SUCCESS |
0 |
SBI_ERR_FAILED |
-1 |
SBI_ERR_NOT_SUPPORTED |
-2 |
SBI_ERR_INVALID_PARAM |
-3 |
SBI_ERR_DENIED |
-4 |
SBI_ERR_INVALID_ADDRESS |
-5 |
SBI_ERR_ALREADY_AVAILABLE |
-6 |
SBI_ERR_ALREADY_STARTED |
-7 |
SBI_ERR_ALREADY_STOPPED |
-8 |
An ECALL with an unsupported SBI extension ID (EID) or an unsupported SBI
function ID (FID) must return the error code SBI_ERR_NOT_SUPPORTED.
Every SBI function should prefer unsigned long as the data type. It keeps
the specification simple and easily adaptable for all RISC-V ISA types.
In case the data is defined as 32bit wide, higher privilege software must
ensure that it only uses 32 bit data only.
If an SBI function needs to pass a list of harts to the higher privilege mode, it must use a hart mask as defined below. This is applicable to any extensions defined in or after v0.2.
Any function, requiring a hart mask, need to pass following two arguments.
-
unsigned long hart_maskis a scalar bit-vector containing hartids -
unsigned long hart_mask_baseis the starting hartid from which bit-vector must be computed.
In a single SBI function call, maximum number harts that can be set is
always XLEN. If a lower privilege mode needs to pass information about more
than XLEN harts, it should invoke multiple instances of the SBI function
call. hart_mask_base can be set to -1 to indicate that hart_mask can
be ignored and all available harts must be considered.
Any function using hart mask may return error values listed in the Table 1 below which are in addition to function specific error values.
| Error code | Description |
|---|---|
SBI_ERR_INVALID_PARAM |
Either |