forked from seL4/rust-sel4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crates/sel4-supervising/types: Split out
- Loading branch information
Showing
8 changed files
with
150 additions
and
92 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# | ||
# Copyright 2024, Colias Group, LLC | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
|
||
{ mk, versions }: | ||
|
||
mk { | ||
package.name = "sel4-supervising-types"; | ||
dependencies = { | ||
inherit (versions) zerocopy; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# Copyright 2023, Colias Group, LLC | ||
# | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
# | ||
# | ||
# This file is generated from './Cargo.nix'. You can edit this file directly | ||
# if you are not using this project's Cargo manifest management tools. | ||
# See 'hacking/cargo-manifest-management/README.md' for more information. | ||
# | ||
|
||
[package] | ||
name = "sel4-supervising-types" | ||
version = "0.1.0" | ||
authors = ["Nick Spinale <[email protected]>"] | ||
edition = "2021" | ||
license = "BSD-2-Clause" | ||
|
||
[dependencies] | ||
zerocopy = "0.7.32" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// | ||
// Copyright 2024, Colias Group, LLC | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// | ||
|
||
#![no_std] | ||
|
||
use zerocopy::AsBytes; | ||
|
||
#[cfg(target_pointer_width = "64")] | ||
type Word = u64; | ||
|
||
#[cfg(target_pointer_width = "32")] | ||
type Word = u32; | ||
|
||
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] | ||
pub enum MemoryAccessWidth { | ||
U8, | ||
U16, | ||
U32, | ||
#[cfg(target_pointer_width = "64")] | ||
U64, | ||
} | ||
|
||
impl MemoryAccessWidth { | ||
pub fn mask(self) -> Word { | ||
match self { | ||
Self::U8 => 0xff, | ||
Self::U16 => 0xffff, | ||
Self::U32 => 0xffff_ffff, | ||
#[cfg(target_pointer_width = "64")] | ||
Self::U64 => 0xffff_ffff_ffff_ffff, | ||
} | ||
} | ||
|
||
pub fn truncate(self, val: Word) -> MemoryAccessData { | ||
match self { | ||
Self::U8 => MemoryAccessData::U8(val as u8), | ||
Self::U16 => MemoryAccessData::U16(val as u16), | ||
Self::U32 => MemoryAccessData::U32(val as u32), | ||
#[cfg(target_pointer_width = "64")] | ||
Self::U64 => MemoryAccessData::U64(val as u64), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Eq, PartialEq, Debug)] | ||
pub enum MemoryAccessData { | ||
U8(u8), | ||
U16(u16), | ||
U32(u32), | ||
#[cfg(target_pointer_width = "64")] | ||
U64(u64), | ||
} | ||
|
||
impl MemoryAccessData { | ||
pub fn width(&self) -> MemoryAccessWidth { | ||
match self { | ||
Self::U8(_) => MemoryAccessWidth::U8, | ||
Self::U16(_) => MemoryAccessWidth::U16, | ||
Self::U32(_) => MemoryAccessWidth::U32, | ||
#[cfg(target_pointer_width = "64")] | ||
Self::U64(_) => MemoryAccessWidth::U64, | ||
} | ||
} | ||
|
||
pub fn zero_extend(&self) -> Word { | ||
match self { | ||
Self::U8(raw) => *raw as Word, | ||
Self::U16(raw) => *raw as Word, | ||
Self::U32(raw) => *raw as Word, | ||
#[cfg(target_pointer_width = "64")] | ||
Self::U64(raw) => *raw as Word, | ||
} | ||
} | ||
|
||
pub fn bytes(&self) -> &[u8] { | ||
match self { | ||
Self::U8(raw) => raw.as_bytes(), | ||
Self::U16(raw) => raw.as_bytes(), | ||
Self::U32(raw) => raw.as_bytes(), | ||
#[cfg(target_pointer_width = "64")] | ||
Self::U64(raw) => raw.as_bytes(), | ||
} | ||
} | ||
|
||
pub fn bytes_mut(&mut self) -> &mut [u8] { | ||
match self { | ||
Self::U8(raw) => raw.as_bytes_mut(), | ||
Self::U16(raw) => raw.as_bytes_mut(), | ||
Self::U32(raw) => raw.as_bytes_mut(), | ||
#[cfg(target_pointer_width = "64")] | ||
Self::U64(raw) => raw.as_bytes_mut(), | ||
} | ||
} | ||
|
||
pub fn set(&self, old_val: Word) -> Word { | ||
(old_val & !self.width().mask()) | self.zero_extend() | ||
} | ||
} |