Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #18 from hwk2077/main
Browse files Browse the repository at this point in the history
feat: add new SBI error `NoShmem`
  • Loading branch information
luojia65 authored Dec 4, 2023
2 parents d6415b6 + 5869ee6 commit a0efa4c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -52,6 +54,7 @@ impl core::fmt::Debug for SbiRet {
RET_ERR_ALREADY_AVAILABLE => write!(f, "<SBI already available>"),
RET_ERR_ALREADY_STARTED => write!(f, "<SBI already started>"),
RET_ERR_ALREADY_STOPPED => write!(f, "<SBI already stopped>"),
RET_ERR_NO_SHMEM => write!(f, "<SBI shared memory not available>"),
unknown => write!(f, "[SBI Unknown error: {unknown:#x}]"),
}
}
Expand All @@ -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),
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 _)),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit a0efa4c

Please sign in to comment.