diff --git a/crates/sel4/bitfield-types/src/lib.rs b/crates/sel4/bitfield-types/src/lib.rs index c8caef60a..e4fc6c4fa 100644 --- a/crates/sel4/bitfield-types/src/lib.rs +++ b/crates/sel4/bitfield-types/src/lib.rs @@ -231,47 +231,6 @@ where // // // -#[repr(C)] -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] -pub struct Bitfield { - arr: [T; N], -} - -impl Bitfield -where - T: UnsignedPrimInt, -{ - pub fn from_arr(arr: [T; N]) -> Self { - Self { arr } - } - - pub fn into_arr(self) -> [T; N] { - self.arr - } - - pub fn as_arr(&self) -> &[T; N] { - &self.arr - } - - pub fn as_mut_arr(&mut self) -> &mut [T; N] { - &mut self.arr - } - - pub fn zeroed() -> Self { - Self::from_arr([T::zero(); N]) - } - - pub fn get_bits(&self, range: Range) -> T { - get_bits(&self.arr, range) - } - - pub fn set_bits(&mut self, range: Range, bits: T) { - set_bits(&mut self.arr, range, bits) - } -} - -// // // - #[cfg(test)] mod test { #![allow(unused_imports)] diff --git a/crates/sel4/sys/src/bf.rs b/crates/sel4/sys/src/bf/mod.rs similarity index 73% rename from crates/sel4/sys/src/bf.rs rename to crates/sel4/sys/src/bf/mod.rs index 1c9e08188..bdc8bf272 100644 --- a/crates/sel4/sys/src/bf.rs +++ b/crates/sel4/sys/src/bf/mod.rs @@ -1,6 +1,8 @@ use core::fmt; -use sel4_bitfield_types::Bitfield; +pub(crate) mod types; + +use types::Bitfield; include!(concat!(env!("OUT_DIR"), "/types.rs")); include!(concat!(env!("OUT_DIR"), "/shared_types.rs")); diff --git a/crates/sel4/sys/src/bf/types.rs b/crates/sel4/sys/src/bf/types.rs new file mode 100644 index 000000000..306dd044e --- /dev/null +++ b/crates/sel4/sys/src/bf/types.rs @@ -0,0 +1,42 @@ +use core::ops::Range; + +use sel4_bitfield_types::{get_bits, set_bits, UnsignedPrimInt}; + +#[repr(C)] +#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)] +pub struct Bitfield { + arr: [T; N], +} + +impl Bitfield +where + T: UnsignedPrimInt, +{ + pub fn from_arr(arr: [T; N]) -> Self { + Self { arr } + } + + pub fn into_arr(self) -> [T; N] { + self.arr + } + + pub fn as_arr(&self) -> &[T; N] { + &self.arr + } + + pub fn as_mut_arr(&mut self) -> &mut [T; N] { + &mut self.arr + } + + pub fn zeroed() -> Self { + Self::from_arr([T::zero(); N]) + } + + pub fn get_bits(&self, range: Range) -> T { + get_bits(&self.arr, range) + } + + pub fn set_bits(&mut self, range: Range, bits: T) { + set_bits(&mut self.arr, range, bits) + } +} diff --git a/crates/sel4/sys/src/ipc_buffer.rs b/crates/sel4/sys/src/ipc_buffer.rs index 09cf12775..8ecf4e03e 100644 --- a/crates/sel4/sys/src/ipc_buffer.rs +++ b/crates/sel4/sys/src/ipc_buffer.rs @@ -2,7 +2,7 @@ use core::mem; use core::ops::Range; use core::slice; -use sel4_bitfield_types::{get_bits_maybe_signed, set_bits_maybe_signed, PrimInt}; +use sel4_bitfield_types::{get_bits, set_bits, PrimInt}; use crate::{seL4_CPtr, seL4_IPCBuffer, seL4_Word}; @@ -20,7 +20,7 @@ impl seL4_IPCBuffer { T: PrimInt, T::Unsigned: TryFrom, { - get_bits_maybe_signed(&self.msg, range) + T::cast_from_unsigned(get_bits(&self.msg, range)) } pub(crate) fn set_mr_bits(&mut self, range: Range, value: T) @@ -28,7 +28,7 @@ impl seL4_IPCBuffer { T: PrimInt, T::Unsigned: TryInto, { - set_bits_maybe_signed(&mut self.msg, range, value) + set_bits(&mut self.msg, range, T::cast_to_unsigned(value)) } pub(crate) fn msg_bytes_mut(&mut self) -> &'static mut [u8] { diff --git a/crates/sel4/sys/src/syscalls/helpers/mod.rs b/crates/sel4/sys/src/syscalls/helpers/mod.rs index 7b3fad444..f701f7596 100644 --- a/crates/sel4/sys/src/syscalls/helpers/mod.rs +++ b/crates/sel4/sys/src/syscalls/helpers/mod.rs @@ -1,4 +1,4 @@ -use sel4_bitfield_types::Bitfield; +use crate::bf::types::Bitfield; use crate::{seL4_MessageInfo, seL4_Word};