diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a5f1ae..17645a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - Support to PMU events in Chapter 11 - Support `NACL` extension in Chapter 15 - Support `STA` extension in Chapter 16 +- Add new SBI error `NoShmem` ### Modified diff --git a/src/binary.rs b/src/binary.rs index 935f105..4147124 100644 --- a/src/binary.rs +++ b/src/binary.rs @@ -39,6 +39,8 @@ pub const RET_ERR_ALREADY_AVAILABLE: usize = -6isize as _; pub const RET_ERR_ALREADY_STARTED: usize = -7isize as _; /// Error for resource already stopped. pub const RET_ERR_ALREADY_STOPPED: usize = -8isize as _; +/// Error for shared memory not available. +pub const RET_ERR_NO_SHMEM: usize = -9isize as _; impl core::fmt::Debug for SbiRet { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { @@ -52,6 +54,7 @@ impl core::fmt::Debug for SbiRet { RET_ERR_ALREADY_AVAILABLE => write!(f, ""), RET_ERR_ALREADY_STARTED => write!(f, ""), RET_ERR_ALREADY_STOPPED => write!(f, ""), + RET_ERR_NO_SHMEM => write!(f, ""), unknown => write!(f, "[SBI Unknown error: {unknown:#x}]"), } } @@ -76,6 +79,8 @@ pub enum Error { AlreadyStarted, /// Error for resource already stopped. AlreadyStopped, + /// Error for shared memory not available. + NoShmem, /// Custom error code. Custom(isize), } @@ -175,6 +180,16 @@ impl SbiRet { value: 0, } } + + /// SBI call failed for shared memory is not available, + /// e.g. Nested acceleration shared memory is not available. + #[inline] + pub const fn no_shmem() -> Self { + Self { + error: RET_ERR_NO_SHMEM, + value: 0, + } + } } impl SbiRet { @@ -191,6 +206,7 @@ impl SbiRet { RET_ERR_ALREADY_AVAILABLE => Err(Error::AlreadyAvailable), RET_ERR_ALREADY_STARTED => Err(Error::AlreadyStarted), RET_ERR_ALREADY_STOPPED => Err(Error::AlreadyStopped), + RET_ERR_NO_SHMEM => Err(Error::NoShmem), unknown => Err(Error::Custom(unknown as _)), } } diff --git a/src/lib.rs b/src/lib.rs index 055a976..dc5353d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,6 +83,7 @@ mod tests { const_assert_eq!(-6, RET_ERR_ALREADY_AVAILABLE as isize); const_assert_eq!(-7, RET_ERR_ALREADY_STARTED as isize); const_assert_eq!(-8, RET_ERR_ALREADY_STOPPED as isize); + const_assert_eq!(-9, RET_ERR_NO_SHMEM as isize); } // ยง4 #[test]