sel4/arch/x86/
object.rs
1use core::ffi::c_uint;
8
9use crate::{
10 const_helpers::u32_into_usize, sys, ObjectBlueprint, ObjectBlueprintSeL4Arch, ObjectType,
11 ObjectTypeSeL4Arch,
12};
13
14pub type ObjectTypeArch = ObjectTypeX86;
15
16pub type ObjectBlueprintArch = ObjectBlueprintX86;
17
18#[derive(Debug, Clone, Eq, PartialEq)]
19pub enum ObjectTypeX86 {
20 _4k,
21 LargePage,
22 PageTable,
23 PageDirectory,
24 SeL4Arch(ObjectTypeSeL4Arch),
25}
26
27impl ObjectTypeX86 {
28 pub(crate) const fn into_sys(self) -> c_uint {
29 match self {
30 Self::_4k => sys::_object::seL4_X86_4K,
31 Self::LargePage => sys::_object::seL4_X86_LargePageObject,
32 Self::PageTable => sys::_object::seL4_X86_PageTableObject,
33 Self::PageDirectory => sys::_object::seL4_X86_PageDirectoryObject,
34 Self::SeL4Arch(sel4_arch) => sel4_arch.into_sys(),
35 }
36 }
37}
38
39impl From<ObjectTypeSeL4Arch> for ObjectTypeArch {
40 fn from(ty: ObjectTypeSeL4Arch) -> Self {
41 Self::SeL4Arch(ty)
42 }
43}
44
45impl From<ObjectTypeSeL4Arch> for ObjectType {
46 fn from(ty: ObjectTypeSeL4Arch) -> Self {
47 Self::from(ObjectTypeArch::from(ty))
48 }
49}
50
51#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
52pub enum ObjectBlueprintX86 {
53 _4k,
54 LargePage,
55 PageTable,
56 PageDirectory,
57 SeL4Arch(ObjectBlueprintSeL4Arch),
58}
59
60impl ObjectBlueprintX86 {
61 pub(crate) const fn ty(self) -> ObjectTypeX86 {
62 match self {
63 Self::_4k => ObjectTypeX86::_4k,
64 Self::LargePage => ObjectTypeX86::LargePage,
65 Self::PageTable => ObjectTypeX86::PageTable,
66 Self::PageDirectory => ObjectTypeX86::PageDirectory,
67 Self::SeL4Arch(sel4_arch) => ObjectTypeX86::SeL4Arch(sel4_arch.ty()),
68 }
69 }
70
71 pub(crate) const fn physical_size_bits(self) -> usize {
72 match self {
73 Self::_4k => u32_into_usize(sys::seL4_PageBits),
74 Self::LargePage => u32_into_usize(sys::seL4_LargePageBits),
75 Self::PageTable => u32_into_usize(sys::seL4_PageTableBits),
76 Self::PageDirectory => u32_into_usize(sys::seL4_PageDirBits),
77 Self::SeL4Arch(sel4_arch) => sel4_arch.physical_size_bits(),
78 }
79 }
80}
81
82impl From<ObjectBlueprintSeL4Arch> for ObjectBlueprintArch {
83 fn from(blueprint: ObjectBlueprintSeL4Arch) -> Self {
84 Self::SeL4Arch(blueprint)
85 }
86}
87
88impl From<ObjectBlueprintSeL4Arch> for ObjectBlueprint {
89 fn from(ty: ObjectBlueprintSeL4Arch) -> Self {
90 Self::from(ObjectBlueprintArch::from(ty))
91 }
92}