sel4/arch/x86/
object.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: MIT
//

use core::ffi::c_uint;

use crate::{
    const_helpers::u32_into_usize, sys, ObjectBlueprint, ObjectBlueprintSeL4Arch, ObjectType,
    ObjectTypeSeL4Arch,
};

pub type ObjectTypeArch = ObjectTypeX86;

pub type ObjectBlueprintArch = ObjectBlueprintX86;

#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ObjectTypeX86 {
    _4k,
    LargePage,
    PageTable,
    PageDirectory,
    SeL4Arch(ObjectTypeSeL4Arch),
}

impl ObjectTypeX86 {
    pub(crate) const fn into_sys(self) -> c_uint {
        match self {
            Self::_4k => sys::_object::seL4_X86_4K,
            Self::LargePage => sys::_object::seL4_X86_LargePageObject,
            Self::PageTable => sys::_object::seL4_X86_PageTableObject,
            Self::PageDirectory => sys::_object::seL4_X86_PageDirectoryObject,
            Self::SeL4Arch(sel4_arch) => sel4_arch.into_sys(),
        }
    }
}

impl From<ObjectTypeSeL4Arch> for ObjectTypeArch {
    fn from(ty: ObjectTypeSeL4Arch) -> Self {
        Self::SeL4Arch(ty)
    }
}

impl From<ObjectTypeSeL4Arch> for ObjectType {
    fn from(ty: ObjectTypeSeL4Arch) -> Self {
        Self::from(ObjectTypeArch::from(ty))
    }
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum ObjectBlueprintX86 {
    _4k,
    LargePage,
    PageTable,
    PageDirectory,
    SeL4Arch(ObjectBlueprintSeL4Arch),
}

impl ObjectBlueprintX86 {
    pub(crate) const fn ty(self) -> ObjectTypeX86 {
        match self {
            Self::_4k => ObjectTypeX86::_4k,
            Self::LargePage => ObjectTypeX86::LargePage,
            Self::PageTable => ObjectTypeX86::PageTable,
            Self::PageDirectory => ObjectTypeX86::PageDirectory,
            Self::SeL4Arch(sel4_arch) => ObjectTypeX86::SeL4Arch(sel4_arch.ty()),
        }
    }

    pub(crate) const fn physical_size_bits(self) -> usize {
        match self {
            Self::_4k => u32_into_usize(sys::seL4_PageBits),
            Self::LargePage => u32_into_usize(sys::seL4_LargePageBits),
            Self::PageTable => u32_into_usize(sys::seL4_PageTableBits),
            Self::PageDirectory => u32_into_usize(sys::seL4_PageDirBits),
            Self::SeL4Arch(sel4_arch) => sel4_arch.physical_size_bits(),
        }
    }
}

impl From<ObjectBlueprintSeL4Arch> for ObjectBlueprintArch {
    fn from(blueprint: ObjectBlueprintSeL4Arch) -> Self {
        Self::SeL4Arch(blueprint)
    }
}

impl From<ObjectBlueprintSeL4Arch> for ObjectBlueprint {
    fn from(ty: ObjectBlueprintSeL4Arch) -> Self {
        Self::from(ObjectBlueprintArch::from(ty))
    }
}