sel4/arch/riscv/
object.rs

1//
2// Copyright 2023, Colias Group, LLC
3//
4// SPDX-License-Identifier: MIT
5//
6
7use core::ffi::c_uint;
8
9use sel4_config::{sel4_cfg_enum, sel4_cfg_wrap_match};
10
11use crate::{const_helpers::u32_into_usize, sys};
12
13pub type ObjectTypeArch = ObjectTypeRISCV;
14
15pub type ObjectBlueprintArch = ObjectBlueprintRiscV;
16
17#[sel4_cfg_enum]
18#[derive(Debug, Clone, Eq, PartialEq)]
19pub enum ObjectTypeRISCV {
20    _4kPage,
21    MegaPage,
22    PageTable,
23    #[sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))]
24    GigaPage,
25}
26
27impl ObjectTypeRISCV {
28    pub(crate) const fn into_sys(self) -> c_uint {
29        sel4_cfg_wrap_match! {
30            match self {
31                Self::_4kPage => sys::_object::seL4_RISCV_4K_Page,
32                Self::MegaPage => sys::_object::seL4_RISCV_Mega_Page,
33                #[sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))]
34                Self::GigaPage => sys::_mode_object::seL4_RISCV_Giga_Page,
35                Self::PageTable => sys::_object::seL4_RISCV_PageTableObject,
36            }
37        }
38    }
39}
40
41#[sel4_cfg_enum]
42#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
43pub enum ObjectBlueprintRiscV {
44    _4kPage,
45    MegaPage,
46    #[sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))]
47    GigaPage,
48    PageTable,
49}
50
51impl ObjectBlueprintRiscV {
52    pub(crate) const fn ty(self) -> ObjectTypeRISCV {
53        sel4_cfg_wrap_match! {
54            match self {
55                Self::_4kPage => ObjectTypeRISCV::_4kPage,
56                Self::MegaPage => ObjectTypeRISCV::MegaPage,
57                #[sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))]
58                Self::GigaPage => ObjectTypeRISCV::GigaPage,
59                Self::PageTable => ObjectTypeRISCV::PageTable,
60            }
61        }
62    }
63
64    pub(crate) const fn physical_size_bits(self) -> usize {
65        sel4_cfg_wrap_match! {
66            match self {
67                Self::_4kPage => u32_into_usize(sys::seL4_PageBits),
68                Self::MegaPage => u32_into_usize(sys::seL4_LargePageBits),
69                #[sel4_cfg(any(PT_LEVELS = "3", PT_LEVELS = "4"))]
70                Self::GigaPage => u32_into_usize(sys::seL4_HugePageBits),
71                Self::PageTable => u32_into_usize(sys::seL4_PageTableBits),
72            }
73        }
74    }
75}