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
93
94
95
96
97
98
99
100
101
102
103
104
//
// Copyright 2023, Colias Group, LLC
//
// SPDX-License-Identifier: MIT
//

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

mod arch;
mod invocations;
mod object;
mod vm_attributes;
mod vspace;

pub(crate) mod fault;

pub(crate) mod top_level {
    pub use super::{
        arch::top_level::*,
        object::{ObjectBlueprintArch, ObjectBlueprintArm, ObjectTypeArch, ObjectTypeArm},
        vm_attributes::VmAttributes,
        vspace::{FrameObjectType, TranslationTableObjectType},
        NUM_FAST_MESSAGE_REGISTERS,
    };
}

pub(crate) use vspace::vspace_levels;

/// The number of message registers which are passed in architectural registers.
pub const NUM_FAST_MESSAGE_REGISTERS: usize = u32_into_usize(sys::seL4_FastMessageRegisters);

pub(crate) mod cap_type_arch {
    use crate::{declare_cap_type_for_object_of_fixed_size, sel4_cfg};

    #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)]
    declare_cap_type_for_object_of_fixed_size! {
        /// Corresponds to `seL4_ARM_VCPU`.
        VCpu { ObjectTypeArch, ObjectBlueprintArch }
    }

    declare_cap_type_for_object_of_fixed_size! {
        /// Corresponds to `seL4_ARM_Page` with `size_bits = 12`.
        SmallPage { ObjectTypeArch, ObjectBlueprintArch }
    }

    declare_cap_type_for_object_of_fixed_size! {
        /// Corresponds to `seL4_ARM_Page` with `size_bits = 21`.
        LargePage { ObjectTypeArch, ObjectBlueprintArch }
    }

    #[sel4_cfg(ARCH_AARCH64)]
    declare_cap_type_for_object_of_fixed_size! {
        /// Corresponds to `seL4_ARM_Page` with `size_bits = 30`.
        HugePage { ObjectTypeSeL4Arch, ObjectBlueprintSeL4Arch }
    }

    #[sel4_cfg(ARCH_AARCH32)]
    declare_cap_type_for_object_of_fixed_size! {
        /// Corresponds to `seL4_ARM_Page` with `size_bits = 16`.
        Section { ObjectTypeSeL4Arch, ObjectBlueprintSeL4Arch }
    }

    #[sel4_cfg(ARCH_AARCH64)]
    declare_cap_type_for_object_of_fixed_size! {
        /// Corresponds to `seL4_ARM_VSpace`.
        VSpace { ObjectTypeSeL4Arch, ObjectBlueprintSeL4Arch }
    }

    #[sel4_cfg(ARCH_AARCH32)]
    declare_cap_type_for_object_of_fixed_size! {
        /// Corresponds to `seL4_ARM_PD`.
        PD { ObjectTypeSeL4Arch, ObjectBlueprintSeL4Arch }
    }

    declare_cap_type_for_object_of_fixed_size! {
        /// Corresponds to `seL4_ARM_PageTable`.
        PT { ObjectTypeArch, ObjectBlueprintArch }
    }

    /// Alias for [`cap_type::SmallPage`](SmallPage).
    pub type Granule = SmallPage;

    #[sel4_cfg(ARCH_AARCH32)]
    /// Alias for [`cap_type::PD`](PD).
    pub type VSpace = PD;
}

pub(crate) mod cap_arch {
    use crate::{declare_cap_alias, sel4_cfg};

    #[sel4_cfg(ARM_HYPERVISOR_SUPPORT)]
    declare_cap_alias!(VCpu);

    declare_cap_alias!(SmallPage);
    declare_cap_alias!(LargePage);

    #[sel4_cfg(ARCH_AARCH64)]
    declare_cap_alias!(HugePage);

    #[sel4_cfg(ARCH_AARCH32)]
    declare_cap_alias!(PD);

    declare_cap_alias!(PT);
}