12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937 |
- use core::marker::PhantomData;
- #[derive(Clone, Copy, PartialEq, Eq)]
- #[repr(C)]
- pub struct SbiRet<T = usize> {
-
- pub error: T,
-
- pub value: T,
- }
- #[doc(alias = "SBI_SUCCESS")]
- pub const RET_SUCCESS: usize = <usize as SbiRegister>::RET_SUCCESS;
- #[doc(alias = "SBI_ERR_FAILED")]
- pub const RET_ERR_FAILED: usize = <usize as SbiRegister>::RET_ERR_FAILED;
- #[doc(alias = "SBI_ERR_NOT_SUPPORTED")]
- pub const RET_ERR_NOT_SUPPORTED: usize = <usize as SbiRegister>::RET_ERR_NOT_SUPPORTED;
- #[doc(alias = "SBI_ERR_INVALID_PARAM")]
- pub const RET_ERR_INVALID_PARAM: usize = <usize as SbiRegister>::RET_ERR_INVALID_PARAM;
- #[doc(alias = "SBI_ERR_DENIED")]
- pub const RET_ERR_DENIED: usize = <usize as SbiRegister>::RET_ERR_DENIED;
- #[doc(alias = "SBI_ERR_INVALID_ADDRESS")]
- pub const RET_ERR_INVALID_ADDRESS: usize = <usize as SbiRegister>::RET_ERR_INVALID_ADDRESS;
- #[doc(alias = "SBI_ERR_ALREADY_AVAILABLE")]
- pub const RET_ERR_ALREADY_AVAILABLE: usize = <usize as SbiRegister>::RET_ERR_ALREADY_AVAILABLE;
- #[doc(alias = "SBI_ERR_ALREADY_STARTED")]
- pub const RET_ERR_ALREADY_STARTED: usize = <usize as SbiRegister>::RET_ERR_ALREADY_STARTED;
- #[doc(alias = "SBI_ERR_ALREADY_STOPPED")]
- pub const RET_ERR_ALREADY_STOPPED: usize = <usize as SbiRegister>::RET_ERR_ALREADY_STOPPED;
- #[doc(alias = "SBI_ERR_NO_SHMEM")]
- pub const RET_ERR_NO_SHMEM: usize = <usize as SbiRegister>::RET_ERR_NO_SHMEM;
- #[doc(alias = "SBI_ERR_INVALID_STATE")]
- pub const RET_ERR_INVALID_STATE: usize = <usize as SbiRegister>::RET_ERR_INVALID_STATE;
- #[doc(alias = "SBI_ERR_BAD_RANGE")]
- pub const RET_ERR_BAD_RANGE: usize = <usize as SbiRegister>::RET_ERR_BAD_RANGE;
- #[doc(alias = "SBI_ERR_TIMEOUT")]
- pub const RET_ERR_TIMEOUT: usize = <usize as SbiRegister>::RET_ERR_TIMEOUT;
- #[doc(alias = "SBI_ERR_IO")]
- pub const RET_ERR_IO: usize = <usize as SbiRegister>::RET_ERR_IO;
- pub trait SbiRegister: Copy + Eq + Ord + core::fmt::Debug {
-
- const RET_SUCCESS: Self;
-
- const RET_ERR_FAILED: Self;
-
- const RET_ERR_NOT_SUPPORTED: Self;
-
- const RET_ERR_INVALID_PARAM: Self;
-
- const RET_ERR_DENIED: Self;
-
- const RET_ERR_INVALID_ADDRESS: Self;
-
- const RET_ERR_ALREADY_AVAILABLE: Self;
-
- const RET_ERR_ALREADY_STARTED: Self;
-
- const RET_ERR_ALREADY_STOPPED: Self;
-
- const RET_ERR_NO_SHMEM: Self;
-
- const RET_ERR_INVALID_STATE: Self;
-
- const RET_ERR_BAD_RANGE: Self;
-
- const RET_ERR_TIMEOUT: Self;
-
- const RET_ERR_IO: Self;
-
- const ZERO: Self;
-
-
- const FULL_MASK: Self;
-
- fn into_result(ret: SbiRet<Self>) -> Result<Self, Error<Self>>;
- }
- macro_rules! impl_sbi_register {
- ($ty:ty, $signed:ty) => {
- impl SbiRegister for $ty {
- const RET_SUCCESS: Self = 0;
- const RET_ERR_FAILED: Self = -1 as $signed as $ty;
- const RET_ERR_NOT_SUPPORTED: Self = -2 as $signed as $ty;
- const RET_ERR_INVALID_PARAM: Self = -3 as $signed as $ty;
- const RET_ERR_DENIED: Self = -4 as $signed as $ty;
- const RET_ERR_INVALID_ADDRESS: Self = -5 as $signed as $ty;
- const RET_ERR_ALREADY_AVAILABLE: Self = -6 as $signed as $ty;
- const RET_ERR_ALREADY_STARTED: Self = -7 as $signed as $ty;
- const RET_ERR_ALREADY_STOPPED: Self = -8 as $signed as $ty;
- const RET_ERR_NO_SHMEM: Self = -9 as $signed as $ty;
- const RET_ERR_INVALID_STATE: Self = -10 as $signed as $ty;
- const RET_ERR_BAD_RANGE: Self = -11 as $signed as $ty;
- const RET_ERR_TIMEOUT: Self = -12 as $signed as $ty;
- const RET_ERR_IO: Self = -13 as $signed as $ty;
- const ZERO: Self = 0;
- const FULL_MASK: Self = !0;
- fn into_result(ret: SbiRet<Self>) -> Result<Self, Error<Self>> {
- match ret.error {
- Self::RET_SUCCESS => Ok(ret.value),
- Self::RET_ERR_FAILED => Err(Error::Failed),
- Self::RET_ERR_NOT_SUPPORTED => Err(Error::NotSupported),
- Self::RET_ERR_INVALID_PARAM => Err(Error::InvalidParam),
- Self::RET_ERR_DENIED => Err(Error::Denied),
- Self::RET_ERR_INVALID_ADDRESS => Err(Error::InvalidAddress),
- Self::RET_ERR_ALREADY_AVAILABLE => Err(Error::AlreadyAvailable),
- Self::RET_ERR_ALREADY_STARTED => Err(Error::AlreadyStarted),
- Self::RET_ERR_ALREADY_STOPPED => Err(Error::AlreadyStopped),
- Self::RET_ERR_NO_SHMEM => Err(Error::NoShmem),
- Self::RET_ERR_INVALID_STATE => Err(Error::InvalidState),
- Self::RET_ERR_BAD_RANGE => Err(Error::BadRange),
- Self::RET_ERR_TIMEOUT => Err(Error::Timeout),
- Self::RET_ERR_IO => Err(Error::Io),
- unknown => Err(Error::Custom(unknown as _)),
- }
- }
- }
- };
- }
- impl_sbi_register!(usize, isize);
- impl_sbi_register!(isize, isize);
- impl_sbi_register!(u32, i32);
- impl_sbi_register!(i32, i32);
- impl_sbi_register!(u64, i64);
- impl_sbi_register!(i64, i64);
- impl_sbi_register!(u128, i128);
- impl_sbi_register!(i128, i128);
- impl<T: SbiRegister + core::fmt::LowerHex> core::fmt::Debug for SbiRet<T> {
- fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match T::into_result(*self) {
- Ok(value) => write!(f, "{:?}", value),
- Err(err) => match err {
- Error::Failed => write!(f, "<SBI call failed>"),
- Error::NotSupported => write!(f, "<SBI feature not supported>"),
- Error::InvalidParam => write!(f, "<SBI invalid parameter>"),
- Error::Denied => write!(f, "<SBI denied>"),
- Error::InvalidAddress => write!(f, "<SBI invalid address>"),
- Error::AlreadyAvailable => write!(f, "<SBI already available>"),
- Error::AlreadyStarted => write!(f, "<SBI already started>"),
- Error::AlreadyStopped => write!(f, "<SBI already stopped>"),
- Error::NoShmem => write!(f, "<SBI shared memory not available>"),
- Error::InvalidState => write!(f, "<SBI invalid state>"),
- Error::BadRange => write!(f, "<SBI bad range>"),
- Error::Timeout => write!(f, "<SBI timeout>"),
- Error::Io => write!(f, "<SBI input/output error>"),
- Error::Custom(unknown) => write!(f, "[SBI Unknown error: {:#x}]", unknown),
- },
- }
- }
- }
- #[derive(Debug, Clone, Copy, PartialEq, Eq)]
- pub enum Error<T = usize> {
-
- Failed,
-
- NotSupported,
-
- InvalidParam,
-
- Denied,
-
- InvalidAddress,
-
- AlreadyAvailable,
-
- AlreadyStarted,
-
- AlreadyStopped,
-
- NoShmem,
-
- InvalidState,
-
- BadRange,
-
- Timeout,
-
- Io,
-
- Custom(T),
- }
- impl<T: SbiRegister> SbiRet<T> {
-
- #[inline]
- pub const fn success(value: T) -> Self {
- Self {
- error: T::RET_SUCCESS,
- value,
- }
- }
-
- #[inline]
- pub const fn failed() -> Self {
- Self {
- error: T::RET_ERR_FAILED,
- value: T::ZERO,
- }
- }
-
-
-
- #[inline]
- pub const fn not_supported() -> Self {
- Self {
- error: T::RET_ERR_NOT_SUPPORTED,
- value: T::ZERO,
- }
- }
-
-
-
-
- #[inline]
- pub const fn invalid_param() -> Self {
- Self {
- error: T::RET_ERR_INVALID_PARAM,
- value: T::ZERO,
- }
- }
-
-
- #[inline]
- pub const fn denied() -> Self {
- Self {
- error: T::RET_ERR_DENIED,
- value: T::ZERO,
- }
- }
-
-
-
- #[inline]
- pub const fn invalid_address() -> Self {
- Self {
- error: T::RET_ERR_INVALID_ADDRESS,
- value: T::ZERO,
- }
- }
-
-
- #[inline]
- pub const fn already_available() -> Self {
- Self {
- error: T::RET_ERR_ALREADY_AVAILABLE,
- value: T::ZERO,
- }
- }
-
-
- #[inline]
- pub const fn already_started() -> Self {
- Self {
- error: T::RET_ERR_ALREADY_STARTED,
- value: T::ZERO,
- }
- }
-
-
- #[inline]
- pub const fn already_stopped() -> Self {
- Self {
- error: T::RET_ERR_ALREADY_STOPPED,
- value: T::ZERO,
- }
- }
-
-
- #[inline]
- pub const fn no_shmem() -> Self {
- Self {
- error: T::RET_ERR_NO_SHMEM,
- value: T::ZERO,
- }
- }
-
-
- #[inline]
- pub const fn invalid_state() -> Self {
- Self {
- error: T::RET_ERR_INVALID_STATE,
- value: T::ZERO,
- }
- }
-
-
- #[inline]
- pub const fn bad_range() -> Self {
- Self {
- error: T::RET_ERR_BAD_RANGE,
- value: T::ZERO,
- }
- }
-
-
- #[inline]
- pub const fn timeout() -> Self {
- Self {
- error: T::RET_ERR_TIMEOUT,
- value: T::ZERO,
- }
- }
-
- #[inline]
- pub const fn io() -> Self {
- Self {
- error: T::RET_ERR_IO,
- value: T::ZERO,
- }
- }
- }
- impl<T: SbiRegister> From<Error<T>> for SbiRet<T> {
- #[inline]
- fn from(value: Error<T>) -> Self {
- match value {
- Error::Failed => SbiRet::failed(),
- Error::NotSupported => SbiRet::not_supported(),
- Error::InvalidParam => SbiRet::invalid_param(),
- Error::Denied => SbiRet::denied(),
- Error::InvalidAddress => SbiRet::invalid_address(),
- Error::AlreadyAvailable => SbiRet::already_available(),
- Error::AlreadyStarted => SbiRet::already_started(),
- Error::AlreadyStopped => SbiRet::already_stopped(),
- Error::NoShmem => SbiRet::no_shmem(),
- Error::InvalidState => SbiRet::invalid_state(),
- Error::BadRange => SbiRet::bad_range(),
- Error::Timeout => SbiRet::timeout(),
- Error::Io => SbiRet::io(),
- Error::Custom(error) => SbiRet {
- error,
- value: T::ZERO,
- },
- }
- }
- }
- impl SbiRet {
-
- #[inline]
- pub const fn into_result(self) -> Result<usize, Error> {
- match self.error {
- RET_SUCCESS => Ok(self.value),
- RET_ERR_FAILED => Err(Error::Failed),
- RET_ERR_NOT_SUPPORTED => Err(Error::NotSupported),
- RET_ERR_INVALID_PARAM => Err(Error::InvalidParam),
- RET_ERR_DENIED => Err(Error::Denied),
- RET_ERR_INVALID_ADDRESS => Err(Error::InvalidAddress),
- 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),
- RET_ERR_INVALID_STATE => Err(Error::InvalidState),
- RET_ERR_BAD_RANGE => Err(Error::BadRange),
- RET_ERR_TIMEOUT => Err(Error::Timeout),
- RET_ERR_IO => Err(Error::Io),
- unknown => Err(Error::Custom(unknown as _)),
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"]
- #[inline]
- pub const fn is_ok(&self) -> bool {
- matches!(self.error, RET_SUCCESS)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[must_use]
- #[inline]
- pub fn is_ok_and(self, f: impl FnOnce(usize) -> bool) -> bool {
- self.into_result().is_ok_and(f)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[must_use = "if you intended to assert that this is err, consider `.unwrap_err()` instead"]
- #[inline]
- pub const fn is_err(&self) -> bool {
- !self.is_ok()
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[must_use]
- #[inline]
- pub fn is_err_and(self, f: impl FnOnce(Error) -> bool) -> bool {
- self.into_result().is_err_and(f)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn ok(self) -> Option<usize> {
- self.into_result().ok()
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn err(self) -> Option<Error> {
- self.into_result().err()
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn map<U, F: FnOnce(usize) -> U>(self, op: F) -> Result<U, Error> {
- self.into_result().map(op)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn map_or<U, F: FnOnce(usize) -> U>(self, default: U, f: F) -> U {
- self.into_result().map_or(default, f)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn map_or_else<U, D: FnOnce(Error) -> U, F: FnOnce(usize) -> U>(
- self,
- default: D,
- f: F,
- ) -> U {
- self.into_result().map_or_else(default, f)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn map_err<F, O: FnOnce(Error) -> F>(self, op: O) -> Result<usize, F> {
- self.into_result().map_err(op)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn inspect<F: FnOnce(&usize)>(self, f: F) -> Self {
- if let Ok(ref t) = self.into_result() {
- f(t);
- }
- self
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn inspect_err<F: FnOnce(&Error)>(self, f: F) -> Self {
- if let Err(ref e) = self.into_result() {
- f(e);
- }
- self
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn expect(self, msg: &str) -> usize {
- self.into_result().expect(msg)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn unwrap(self) -> usize {
- self.into_result().unwrap()
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn expect_err(self, msg: &str) -> Error {
- self.into_result().expect_err(msg)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn unwrap_err(self) -> Error {
- self.into_result().unwrap_err()
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn and<U>(self, res: Result<U, Error>) -> Result<U, Error> {
- self.into_result().and(res)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn and_then<U, F: FnOnce(usize) -> Result<U, Error>>(self, op: F) -> Result<U, Error> {
- self.into_result().and_then(op)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn or<F>(self, res: Result<usize, F>) -> Result<usize, F> {
- self.into_result().or(res)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn or_else<F, O: FnOnce(Error) -> Result<usize, F>>(self, op: O) -> Result<usize, F> {
- self.into_result().or_else(op)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn unwrap_or(self, default: usize) -> usize {
- self.into_result().unwrap_or(default)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub fn unwrap_or_else<F: FnOnce(Error) -> usize>(self, op: F) -> usize {
- self.into_result().unwrap_or_else(op)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub unsafe fn unwrap_unchecked(self) -> usize {
- unsafe { self.into_result().unwrap_unchecked() }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- pub unsafe fn unwrap_err_unchecked(self) -> Error {
- unsafe { self.into_result().unwrap_err_unchecked() }
- }
- }
- impl IntoIterator for SbiRet {
- type Item = usize;
- type IntoIter = core::result::IntoIter<usize>;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #[inline]
- fn into_iter(self) -> Self::IntoIter {
- self.into_result().into_iter()
- }
- }
- #[inline]
- pub(crate) const fn valid_bit(base: usize, bit: usize) -> bool {
- if bit < base {
-
- false
- } else if (bit - base) >= usize::BITS as usize {
-
- false
- } else {
- true
- }
- }
- #[inline]
- pub(crate) const fn has_bit(mask: usize, base: usize, ignore: usize, bit: usize) -> bool {
- if base == ignore {
-
- true
- } else if !valid_bit(base, bit) {
- false
- } else {
-
- mask & (1 << (bit - base)) != 0
- }
- }
- #[repr(C)]
- #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
- pub struct HartMask<T = usize> {
- hart_mask: T,
- hart_mask_base: T,
- }
- impl<T: SbiRegister> HartMask<T> {
-
- pub const IGNORE_MASK: T = T::FULL_MASK;
-
- #[inline]
- pub const fn from_mask_base(hart_mask: T, hart_mask_base: T) -> Self {
- Self {
- hart_mask,
- hart_mask_base,
- }
- }
-
-
-
-
-
-
- #[inline]
- pub const fn all() -> Self {
- Self {
- hart_mask: T::ZERO,
- hart_mask_base: T::FULL_MASK,
- }
- }
-
- #[inline]
- pub const fn ignore_mask(&self) -> T {
- Self::IGNORE_MASK
- }
-
- #[inline]
- pub const fn into_inner(self) -> (T, T) {
- (self.hart_mask, self.hart_mask_base)
- }
- }
- impl HartMask<usize> {
-
- #[inline]
- pub const fn has_bit(self, hart_id: usize) -> bool {
- has_bit(
- self.hart_mask,
- self.hart_mask_base,
- Self::IGNORE_MASK,
- hart_id,
- )
- }
-
-
-
- #[inline]
- pub const fn insert(&mut self, hart_id: usize) -> Result<(), MaskError> {
- if self.hart_mask_base == Self::IGNORE_MASK {
- Ok(())
- } else if valid_bit(self.hart_mask_base, hart_id) {
- self.hart_mask |= 1usize << (hart_id - self.hart_mask_base);
- Ok(())
- } else {
- Err(MaskError::InvalidBit)
- }
- }
-
-
-
- #[inline]
- pub const fn remove(&mut self, hart_id: usize) -> Result<(), MaskError> {
- if self.hart_mask_base == Self::IGNORE_MASK {
- Err(MaskError::Ignored)
- } else if valid_bit(self.hart_mask_base, hart_id) {
- self.hart_mask &= !(1usize << (hart_id - self.hart_mask_base));
- Ok(())
- } else {
- Err(MaskError::InvalidBit)
- }
- }
-
- #[inline]
- pub const fn iter(&self) -> HartIds {
- HartIds {
- inner: match self.hart_mask_base {
- Self::IGNORE_MASK => UnvisitedMask::Range(0, usize::MAX),
- _ => UnvisitedMask::MaskBase(self.hart_mask, self.hart_mask_base),
- },
- }
- }
- }
- impl IntoIterator for HartMask {
- type Item = usize;
- type IntoIter = HartIds;
- #[inline]
- fn into_iter(self) -> Self::IntoIter {
- self.iter()
- }
- }
- #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
- pub struct HartIds {
- inner: UnvisitedMask,
- }
- #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
- enum UnvisitedMask {
- MaskBase(usize, usize),
- Range(usize, usize),
- }
- impl Iterator for HartIds {
- type Item = usize;
- #[inline]
- fn next(&mut self) -> Option<Self::Item> {
- match &mut self.inner {
- UnvisitedMask::MaskBase(0, _base) => None,
- UnvisitedMask::MaskBase(unvisited_mask, base) => {
- let low_bit = unvisited_mask.trailing_zeros();
- let hart_id = usize::try_from(low_bit).unwrap() + *base;
- *unvisited_mask &= !(1usize << low_bit);
- Some(hart_id)
- }
- UnvisitedMask::Range(start, end) => {
- assert!(start <= end);
- if *start < *end {
- let ans = *start;
- *start += 1;
- Some(ans)
- } else {
- None
- }
- }
- }
- }
- #[inline]
- fn size_hint(&self) -> (usize, Option<usize>) {
- match self.inner {
- UnvisitedMask::MaskBase(unvisited_mask, _base) => {
- let exact_popcnt = usize::try_from(unvisited_mask.count_ones()).unwrap();
- (exact_popcnt, Some(exact_popcnt))
- }
- UnvisitedMask::Range(start, end) => {
- assert!(start <= end);
- let exact_num_harts = end - start;
- (exact_num_harts, Some(exact_num_harts))
- }
- }
- }
- #[inline]
- fn count(self) -> usize {
- self.size_hint().0
- }
- #[inline]
- fn last(mut self) -> Option<Self::Item> {
- self.next_back()
- }
- #[inline]
- fn min(mut self) -> Option<Self::Item> {
- self.next()
- }
- #[inline]
- fn max(mut self) -> Option<Self::Item> {
- self.next_back()
- }
- #[inline]
- fn is_sorted(self) -> bool {
- true
- }
-
-
-
- }
- impl DoubleEndedIterator for HartIds {
- #[inline]
- fn next_back(&mut self) -> Option<Self::Item> {
- match &mut self.inner {
- UnvisitedMask::MaskBase(0, _base) => None,
- UnvisitedMask::MaskBase(unvisited_mask, base) => {
- let high_bit = unvisited_mask.leading_zeros();
- let hart_id = usize::try_from(usize::BITS - high_bit - 1).unwrap() + *base;
- *unvisited_mask &= !(1usize << (usize::BITS - high_bit - 1));
- Some(hart_id)
- }
- UnvisitedMask::Range(start, end) => {
- assert!(start <= end);
- if *start < *end {
- let ans = *end;
- *end -= 1;
- Some(ans)
- } else {
- None
- }
- }
- }
- }
-
-
-
- }
- impl ExactSizeIterator for HartIds {}
- impl core::iter::FusedIterator for HartIds {}
- #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
- pub enum MaskError {
-
- Ignored,
-
- InvalidBit,
- }
- #[repr(C)]
- #[derive(Debug, Copy, Clone, Eq, PartialEq)]
- pub struct CounterMask<T = usize> {
- counter_idx_mask: T,
- counter_idx_base: T,
- }
- impl<T: SbiRegister> CounterMask<T> {
-
- pub const IGNORE_MASK: T = T::FULL_MASK;
-
- #[inline]
- pub const fn from_mask_base(counter_idx_mask: T, counter_idx_base: T) -> Self {
- Self {
- counter_idx_mask,
- counter_idx_base,
- }
- }
-
- #[inline]
- pub const fn ignore_mask(&self) -> T {
- Self::IGNORE_MASK
- }
-
- #[inline]
- pub const fn into_inner(self) -> (T, T) {
- (self.counter_idx_mask, self.counter_idx_base)
- }
- }
- impl CounterMask<usize> {
-
- #[inline]
- pub const fn has_bit(self, counter: usize) -> bool {
- has_bit(
- self.counter_idx_mask,
- self.counter_idx_base,
- Self::IGNORE_MASK,
- counter,
- )
- }
- }
- #[repr(C)]
- #[derive(Debug, Copy, Clone, Eq, PartialEq)]
- pub struct TriggerMask<T = usize> {
- trig_idx_base: T,
- trig_idx_mask: T,
- }
- impl<T: SbiRegister> TriggerMask<T> {
-
-
-
-
- #[inline]
- pub const fn from_mask_base(trig_idx_mask: T, trig_idx_base: T) -> Self {
- Self {
- trig_idx_mask,
- trig_idx_base,
- }
- }
-
- #[inline]
- pub const fn into_inner(self) -> (T, T) {
- (self.trig_idx_mask, self.trig_idx_base)
- }
- }
- #[derive(Clone, Copy)]
- pub struct Physical<P> {
- num_bytes: usize,
- phys_addr_lo: usize,
- phys_addr_hi: usize,
- _marker: PhantomData<P>,
- }
- impl<P> Physical<P> {
-
- #[inline]
- pub const fn new(num_bytes: usize, phys_addr_lo: usize, phys_addr_hi: usize) -> Self {
- Self {
- num_bytes,
- phys_addr_lo,
- phys_addr_hi,
- _marker: core::marker::PhantomData,
- }
- }
-
- #[inline]
- pub const fn num_bytes(&self) -> usize {
- self.num_bytes
- }
-
- #[inline]
- pub const fn phys_addr_lo(&self) -> usize {
- self.phys_addr_lo
- }
-
- #[inline]
- pub const fn phys_addr_hi(&self) -> usize {
- self.phys_addr_hi
- }
- }
- pub struct SharedPtr<T> {
- phys_addr_lo: usize,
- phys_addr_hi: usize,
- _marker: PhantomData<*mut T>,
- }
- impl<T> SharedPtr<T> {
-
- #[inline]
- pub const fn new(phys_addr_lo: usize, phys_addr_hi: usize) -> Self {
- Self {
- phys_addr_lo,
- phys_addr_hi,
- _marker: PhantomData,
- }
- }
-
- #[inline]
- pub const fn phys_addr_lo(self) -> usize {
- self.phys_addr_lo
- }
-
- #[inline]
- pub const fn phys_addr_hi(self) -> usize {
- self.phys_addr_hi
- }
- }
- impl<T> Clone for SharedPtr<T> {
- #[inline(always)]
- fn clone(&self) -> Self {
- *self
- }
- }
- impl<T> Copy for SharedPtr<T> {}
- #[cfg(test)]
- mod tests {
- use super::*;
- #[test]
- #[rustfmt::skip]
- fn rustsbi_sbi_ret_constructors() {
- assert_eq!(SbiRet::success(0), SbiRet { value: 0, error: 0 });
- assert_eq!(SbiRet::success(1037), SbiRet { value: 1037, error: 0 });
- assert_eq!(SbiRet::success(usize::MAX), SbiRet { value: usize::MAX, error: 0 });
- assert_eq!(SbiRet::failed(), SbiRet { value: 0, error: usize::MAX - 1 + 1 });
- assert_eq!(SbiRet::not_supported(), SbiRet { value: 0, error: usize::MAX - 2 + 1 });
- assert_eq!(SbiRet::invalid_param(), SbiRet { value: 0, error: usize::MAX - 3 + 1 });
- assert_eq!(SbiRet::denied(), SbiRet { value: 0, error: usize::MAX - 4 + 1 });
- assert_eq!(SbiRet::invalid_address(), SbiRet { value: 0, error: usize::MAX - 5 + 1 });
- assert_eq!(SbiRet::already_available(), SbiRet { value: 0, error: usize::MAX - 6 + 1 });
- assert_eq!(SbiRet::already_started(), SbiRet { value: 0, error: usize::MAX - 7 + 1 });
- assert_eq!(SbiRet::already_stopped(), SbiRet { value: 0, error: usize::MAX - 8 + 1 });
- assert_eq!(SbiRet::no_shmem(), SbiRet { value: 0, error: usize::MAX - 9 + 1 });
- assert_eq!(SbiRet::invalid_state(), SbiRet { value: 0, error: usize::MAX - 10 + 1 });
- assert_eq!(SbiRet::bad_range(), SbiRet { value: 0, error: usize::MAX - 11 + 1 });
- assert_eq!(SbiRet::timeout(), SbiRet { value: 0, error: usize::MAX - 12 + 1 });
- assert_eq!(SbiRet::io(), SbiRet { value: 0, error: usize::MAX - 13 + 1 });
- }
- #[test]
- fn rustsbi_hart_mask() {
- let mask = HartMask::from_mask_base(0b1, 400);
- assert!(!mask.has_bit(0));
- assert!(mask.has_bit(400));
- assert!(!mask.has_bit(401));
- let mask = HartMask::from_mask_base(0b110, 500);
- assert!(!mask.has_bit(0));
- assert!(!mask.has_bit(500));
- assert!(mask.has_bit(501));
- assert!(mask.has_bit(502));
- assert!(!mask.has_bit(500 + (usize::BITS as usize)));
- let max_bit = 1 << (usize::BITS - 1);
- let mask = HartMask::from_mask_base(max_bit, 600);
- assert!(mask.has_bit(600 + (usize::BITS as usize) - 1));
- assert!(!mask.has_bit(600 + (usize::BITS as usize)));
- let mask = HartMask::from_mask_base(0b11, usize::MAX - 1);
- assert!(!mask.has_bit(usize::MAX - 2));
- assert!(mask.has_bit(usize::MAX - 1));
- assert!(mask.has_bit(usize::MAX));
- assert!(!mask.has_bit(0));
-
-
- let mask = HartMask::from_mask_base(0, usize::MAX);
- for i in 0..5 {
- assert!(mask.has_bit(i));
- }
- assert!(mask.has_bit(usize::MAX));
- let mut mask = HartMask::from_mask_base(0, 1);
- assert!(!mask.has_bit(1));
- assert!(mask.insert(1).is_ok());
- assert!(mask.has_bit(1));
- assert!(mask.remove(1).is_ok());
- assert!(!mask.has_bit(1));
- }
- #[test]
- fn rustsbi_hart_ids_iterator() {
- let mask = HartMask::from_mask_base(0b101011, 1);
-
- let mut hart_ids = mask.iter();
- assert_eq!(hart_ids.next(), Some(1));
- assert_eq!(hart_ids.next(), Some(2));
- assert_eq!(hart_ids.next(), Some(4));
- assert_eq!(hart_ids.next(), Some(6));
- assert_eq!(hart_ids.next(), None);
-
- assert_eq!(hart_ids.next(), None);
-
- let mut ans = [0; 4];
- let mut idx = 0;
- for hart_id in mask {
- ans[idx] = hart_id;
- idx += 1;
- }
- assert_eq!(ans, [1, 2, 4, 6]);
-
- let mut hart_ids = mask.iter();
- assert_eq!(hart_ids.size_hint(), (4, Some(4)));
- let _ = hart_ids.next();
- assert_eq!(hart_ids.size_hint(), (3, Some(3)));
- let _ = hart_ids.next();
- let _ = hart_ids.next();
- assert_eq!(hart_ids.size_hint(), (1, Some(1)));
- let _ = hart_ids.next();
- assert_eq!(hart_ids.size_hint(), (0, Some(0)));
- let _ = hart_ids.next();
- assert_eq!(hart_ids.size_hint(), (0, Some(0)));
- let mut hart_ids = mask.iter();
- assert_eq!(hart_ids.count(), 4);
- let _ = hart_ids.next();
- assert_eq!(hart_ids.count(), 3);
- let _ = hart_ids.next();
- let _ = hart_ids.next();
- let _ = hart_ids.next();
- assert_eq!(hart_ids.count(), 0);
- let _ = hart_ids.next();
- assert_eq!(hart_ids.count(), 0);
- let hart_ids = mask.iter();
- assert_eq!(hart_ids.last(), Some(6));
- let mut hart_ids = mask.iter();
- assert_eq!(hart_ids.nth(2), Some(4));
- let mut hart_ids = mask.iter();
- assert_eq!(hart_ids.nth(0), Some(1));
- let mut iter = mask.iter().step_by(2);
- assert_eq!(iter.next(), Some(1));
- assert_eq!(iter.next(), Some(4));
- assert_eq!(iter.next(), None);
- let mask_2 = HartMask::from_mask_base(0b1001101, 64);
- let mut iter = mask.iter().chain(mask_2);
- assert_eq!(iter.next(), Some(1));
- assert_eq!(iter.next(), Some(2));
- assert_eq!(iter.next(), Some(4));
- assert_eq!(iter.next(), Some(6));
- assert_eq!(iter.next(), Some(64));
- assert_eq!(iter.next(), Some(66));
- assert_eq!(iter.next(), Some(67));
- assert_eq!(iter.next(), Some(70));
- assert_eq!(iter.next(), None);
- let mut iter = mask.iter().zip(mask_2);
- assert_eq!(iter.next(), Some((1, 64)));
- assert_eq!(iter.next(), Some((2, 66)));
- assert_eq!(iter.next(), Some((4, 67)));
- assert_eq!(iter.next(), Some((6, 70)));
- assert_eq!(iter.next(), None);
- fn to_plic_context_id(hart_id_machine: usize) -> usize {
- hart_id_machine * 2
- }
- let mut iter = mask.iter().map(to_plic_context_id);
- assert_eq!(iter.next(), Some(2));
- assert_eq!(iter.next(), Some(4));
- assert_eq!(iter.next(), Some(8));
- assert_eq!(iter.next(), Some(12));
- assert_eq!(iter.next(), None);
- let mut channel_received = [0; 4];
- let mut idx = 0;
- let mut channel_send = |hart_id| {
- channel_received[idx] = hart_id;
- idx += 1;
- };
- mask.iter().for_each(|value| channel_send(value));
- assert_eq!(channel_received, [1, 2, 4, 6]);
- let is_in_cluster_1 = |hart_id: &usize| *hart_id >= 4 && *hart_id < 7;
- let mut iter = mask.iter().filter(is_in_cluster_1);
- assert_eq!(iter.next(), Some(4));
- assert_eq!(iter.next(), Some(6));
- assert_eq!(iter.next(), None);
- let if_in_cluster_1_get_plic_context_id = |hart_id: usize| {
- if hart_id >= 4 && hart_id < 7 {
- Some(hart_id * 2)
- } else {
- None
- }
- };
- let mut iter = mask.iter().filter_map(if_in_cluster_1_get_plic_context_id);
- assert_eq!(iter.next(), Some(8));
- assert_eq!(iter.next(), Some(12));
- assert_eq!(iter.next(), None);
- let mut iter = mask.iter().enumerate();
- assert_eq!(iter.next(), Some((0, 1)));
- assert_eq!(iter.next(), Some((1, 2)));
- assert_eq!(iter.next(), Some((2, 4)));
- assert_eq!(iter.next(), Some((3, 6)));
- assert_eq!(iter.next(), None);
- let mut ans = [(0, 0); 4];
- let mut idx = 0;
- for (i, hart_id) in mask.iter().enumerate() {
- ans[idx] = (i, hart_id);
- idx += 1;
- }
- assert_eq!(ans, [(0, 1), (1, 2), (2, 4), (3, 6)]);
- let mut iter = mask.iter().peekable();
- assert_eq!(iter.peek(), Some(&1));
- assert_eq!(iter.next(), Some(1));
- assert_eq!(iter.peek(), Some(&2));
- assert_eq!(iter.next(), Some(2));
- assert_eq!(iter.peek(), Some(&4));
- assert_eq!(iter.next(), Some(4));
- assert_eq!(iter.peek(), Some(&6));
- assert_eq!(iter.next(), Some(6));
- assert_eq!(iter.peek(), None);
- assert_eq!(iter.next(), None);
-
- assert!(mask.iter().is_sorted());
- assert!(mask.iter().is_sorted_by(|a, b| a <= b));
-
- let mut iter = mask.iter().rev();
- assert_eq!(iter.next(), Some(6));
- assert_eq!(iter.next(), Some(4));
- assert_eq!(iter.next(), Some(2));
- assert_eq!(iter.next(), Some(1));
- assert_eq!(iter.next(), None);
-
- let nothing = HartMask::from_mask_base(0, 1000);
- assert!(nothing.iter().eq([]));
- let all_mask_bits_set = HartMask::from_mask_base(usize::MAX, 1000);
- let range = 1000..(1000 + usize::BITS as usize);
- assert!(all_mask_bits_set.iter().eq(range));
- let all_harts = HartMask::all();
- let mut iter = all_harts.iter();
- assert_eq!(iter.size_hint(), (usize::MAX, Some(usize::MAX)));
-
-
- assert_eq!(iter.next(), Some(0));
- assert_eq!(iter.size_hint(), (usize::MAX - 1, Some(usize::MAX - 1)));
- assert_eq!(iter.next(), Some(1));
- assert_eq!(iter.next(), Some(2));
-
- let _ = iter.nth(500 - 1);
- assert_eq!(iter.next(), Some(503));
- assert_eq!(iter.size_hint(), (usize::MAX - 504, Some(usize::MAX - 504)));
- assert_eq!(iter.next_back(), Some(usize::MAX));
- assert_eq!(iter.next_back(), Some(usize::MAX - 1));
- assert_eq!(iter.size_hint(), (usize::MAX - 506, Some(usize::MAX - 506)));
-
- let environment_available_hart_ids = 4..128;
-
- let hart_mask_iter = all_harts.iter().skip(64);
- let filtered_iter = environment_available_hart_ids.filter(|&x| {
- hart_mask_iter
- .clone()
- .find(|&y| y >= x)
- .map_or(false, |y| y == x)
- });
- assert!(filtered_iter.eq(64..128));
-
- let all_harts = HartMask::all();
- assert_eq!(all_harts.iter().count(), usize::MAX);
- assert_eq!(all_harts.iter().last(), Some(usize::MAX));
- assert_eq!(all_harts.iter().min(), Some(0));
- assert_eq!(all_harts.iter().max(), Some(usize::MAX));
- assert!(all_harts.iter().is_sorted());
- let partial_all_harts = {
- let mut ans = HartMask::all().iter();
- let _ = ans.nth(65536 - 1);
- let _ = ans.nth_back(4096 - 1);
- ans
- };
- assert_eq!(partial_all_harts.clone().count(), usize::MAX - 65536 - 4096);
- assert_eq!(partial_all_harts.clone().last(), Some(usize::MAX - 4096));
- assert_eq!(partial_all_harts.clone().min(), Some(65536));
- assert_eq!(partial_all_harts.clone().max(), Some(usize::MAX - 4096));
- assert!(partial_all_harts.is_sorted());
- let nothing = HartMask::from_mask_base(0, 1000);
- assert_eq!(nothing.iter().count(), 0);
- assert_eq!(nothing.iter().last(), None);
- assert_eq!(nothing.iter().min(), None);
- assert_eq!(nothing.iter().max(), None);
- assert!(nothing.iter().is_sorted());
- let mask = HartMask::from_mask_base(0b101011, 1);
- assert_eq!(mask.iter().count(), 4);
- assert_eq!(mask.iter().last(), Some(6));
- assert_eq!(mask.iter().min(), Some(1));
- assert_eq!(mask.iter().max(), Some(6));
- assert!(mask.iter().is_sorted());
- let all_mask_bits_set = HartMask::from_mask_base(usize::MAX, 1000);
- let last = 1000 + usize::BITS as usize - 1;
- assert_eq!(all_mask_bits_set.iter().count(), usize::BITS as usize);
- assert_eq!(all_mask_bits_set.iter().last(), Some(last));
- assert_eq!(all_mask_bits_set.iter().min(), Some(1000));
- assert_eq!(all_mask_bits_set.iter().max(), Some(last));
- assert!(all_mask_bits_set.iter().is_sorted());
- }
- #[test]
- fn rustsbi_counter_index_mask() {
- let mask = CounterMask::from_mask_base(0b1, 400);
- assert!(!mask.has_bit(0));
- assert!(mask.has_bit(400));
- assert!(!mask.has_bit(401));
- let mask = CounterMask::from_mask_base(0b110, 500);
- assert!(!mask.has_bit(0));
- assert!(!mask.has_bit(500));
- assert!(mask.has_bit(501));
- assert!(mask.has_bit(502));
- assert!(!mask.has_bit(500 + (usize::BITS as usize)));
- let max_bit = 1 << (usize::BITS - 1);
- let mask = CounterMask::from_mask_base(max_bit, 600);
- assert!(mask.has_bit(600 + (usize::BITS as usize) - 1));
- assert!(!mask.has_bit(600 + (usize::BITS as usize)));
- let mask = CounterMask::from_mask_base(0b11, usize::MAX - 1);
- assert!(!mask.has_bit(usize::MAX - 2));
- assert!(mask.has_bit(usize::MAX - 1));
- assert!(mask.has_bit(usize::MAX));
- assert!(!mask.has_bit(0));
- let mask = CounterMask::from_mask_base(0, usize::MAX);
- let null_mask = CounterMask::from_mask_base(0, 0);
- (0..=usize::BITS as usize).for_each(|i| {
- assert!(mask.has_bit(i));
- assert!(!null_mask.has_bit(i));
- });
- assert!(mask.has_bit(usize::MAX));
- }
- #[test]
- fn rustsbi_mask_non_usize() {
- assert_eq!(CounterMask::<i32>::IGNORE_MASK, -1);
- assert_eq!(CounterMask::<i64>::IGNORE_MASK, -1);
- assert_eq!(CounterMask::<i128>::IGNORE_MASK, -1);
- assert_eq!(CounterMask::<u32>::IGNORE_MASK, u32::MAX);
- assert_eq!(CounterMask::<u64>::IGNORE_MASK, u64::MAX);
- assert_eq!(CounterMask::<u128>::IGNORE_MASK, u128::MAX);
- assert_eq!(HartMask::<i32>::IGNORE_MASK, -1);
- assert_eq!(HartMask::<i64>::IGNORE_MASK, -1);
- assert_eq!(HartMask::<i128>::IGNORE_MASK, -1);
- assert_eq!(HartMask::<u32>::IGNORE_MASK, u32::MAX);
- assert_eq!(HartMask::<u64>::IGNORE_MASK, u64::MAX);
- assert_eq!(HartMask::<u128>::IGNORE_MASK, u128::MAX);
- assert_eq!(HartMask::<i32>::all(), HartMask::from_mask_base(0, -1));
- }
- }
|