sel4/arch/riscv/
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
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: MIT
//

use core::ffi::c_uint;

use sel4_config::{sel4_cfg_enum, sel4_cfg_wrap_match};

use crate::{const_helpers::u32_into_usize, sys};

pub type ObjectTypeArch = ObjectTypeRISCV;

pub type ObjectBlueprintArch = ObjectBlueprintRiscV;

#[sel4_cfg_enum]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ObjectTypeRISCV {
    _4kPage,
    MegaPage,
    PageTable,
    #[sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))]
    GigaPage,
}

impl ObjectTypeRISCV {
    pub(crate) const fn into_sys(self) -> c_uint {
        sel4_cfg_wrap_match! {
            match self {
                Self::_4kPage => sys::_object::seL4_RISCV_4K_Page,
                Self::MegaPage => sys::_object::seL4_RISCV_Mega_Page,
                #[sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))]
                Self::GigaPage => sys::_mode_object::seL4_RISCV_Giga_Page,
                Self::PageTable => sys::_object::seL4_RISCV_PageTableObject,
            }
        }
    }
}

#[sel4_cfg_enum]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum ObjectBlueprintRiscV {
    _4kPage,
    MegaPage,
    #[sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))]
    GigaPage,
    PageTable,
}

impl ObjectBlueprintRiscV {
    pub(crate) const fn ty(self) -> ObjectTypeRISCV {
        sel4_cfg_wrap_match! {
            match self {
                Self::_4kPage => ObjectTypeRISCV::_4kPage,
                Self::MegaPage => ObjectTypeRISCV::MegaPage,
                #[sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))]
                Self::GigaPage => ObjectTypeRISCV::GigaPage,
                Self::PageTable => ObjectTypeRISCV::PageTable,
            }
        }
    }

    pub(crate) const fn physical_size_bits(self) -> usize {
        sel4_cfg_wrap_match! {
            match self {
                Self::_4kPage => u32_into_usize(sys::seL4_PageBits),
                Self::MegaPage => u32_into_usize(sys::seL4_LargePageBits),
                #[sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))]
                Self::GigaPage => u32_into_usize(sys::seL4_HugePageBits),
                Self::PageTable => u32_into_usize(sys::seL4_PageTableBits),
            }
        }
    }
}