Skip to content

Commit

Permalink
crates/sel4/bitfield-types: Move Bitfield type into sel4-sys
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Oct 4, 2023
1 parent b4088ba commit 99b70f3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 46 deletions.
41 changes: 0 additions & 41 deletions crates/sel4/bitfield-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,47 +231,6 @@ where

// // //

#[repr(C)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct Bitfield<T, const N: usize> {
arr: [T; N],
}

impl<T, const N: usize> Bitfield<T, N>
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<usize>) -> T {
get_bits(&self.arr, range)
}

pub fn set_bits(&mut self, range: Range<usize>, bits: T) {
set_bits(&mut self.arr, range, bits)
}
}

// // //

#[cfg(test)]
mod test {
#![allow(unused_imports)]
Expand Down
4 changes: 3 additions & 1 deletion crates/sel4/sys/src/bf.rs → crates/sel4/sys/src/bf/mod.rs
Original file line number Diff line number Diff line change
@@ -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"));
42 changes: 42 additions & 0 deletions crates/sel4/sys/src/bf/types.rs
Original file line number Diff line number Diff line change
@@ -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<T, const N: usize> {
arr: [T; N],
}

impl<T, const N: usize> Bitfield<T, N>
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<usize>) -> T {
get_bits(&self.arr, range)
}

pub fn set_bits(&mut self, range: Range<usize>, bits: T) {
set_bits(&mut self.arr, range, bits)
}
}
6 changes: 3 additions & 3 deletions crates/sel4/sys/src/ipc_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -20,15 +20,15 @@ impl seL4_IPCBuffer {
T: PrimInt,
T::Unsigned: TryFrom<seL4_Word>,
{
get_bits_maybe_signed(&self.msg, range)
T::cast_from_unsigned(get_bits(&self.msg, range))
}

pub(crate) fn set_mr_bits<T>(&mut self, range: Range<usize>, value: T)
where
T: PrimInt,
T::Unsigned: TryInto<seL4_Word>,
{
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] {
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4/sys/src/syscalls/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sel4_bitfield_types::Bitfield;
use crate::bf::types::Bitfield;

use crate::{seL4_MessageInfo, seL4_Word};

Expand Down

0 comments on commit 99b70f3

Please sign in to comment.