From bc8ae069109a0cb429199f64a1db2744b0eff242 Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Wed, 4 Oct 2023 08:05:10 +0000 Subject: [PATCH] crates/sel4/bitfield-types: Move Bitfield type into sel4-sys Signed-off-by: Nick Spinale --- crates/sel4/bitfield-types/src/lib.rs | 41 -------------------- crates/sel4/sys/src/{bf.rs => bf/mod.rs} | 4 +- crates/sel4/sys/src/bf/types.rs | 42 +++++++++++++++++++++ crates/sel4/sys/src/ipc_buffer.rs | 6 +-- crates/sel4/sys/src/syscalls/helpers/mod.rs | 2 +- 5 files changed, 49 insertions(+), 46 deletions(-) rename crates/sel4/sys/src/{bf.rs => bf/mod.rs} (73%) create mode 100644 crates/sel4/sys/src/bf/types.rs 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};