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
#![cfg_attr(not(test), no_std)]
#![cfg_attr(feature = "const_fn", feature(const_fn))]
#![cfg_attr(feature = "const_fn", feature(const_panic))]
#![cfg_attr(feature = "const_fn", feature(const_mut_refs))]
#![cfg_attr(feature = "const_fn", feature(const_fn_fn_ptr_basics))]
#![cfg_attr(feature = "const_fn", feature(const_in_array_repeat_expressions))]
#![cfg_attr(feature = "inline_asm", feature(asm))]
#![cfg_attr(feature = "abi_x86_interrupt", feature(abi_x86_interrupt))]
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![cfg_attr(feature = "deny-warnings", deny(missing_docs))]
#![cfg_attr(not(feature = "deny-warnings"), warn(missing_docs))]
#![deny(missing_debug_implementations)]
pub use crate::addr::{align_down, align_up, PhysAddr, VirtAddr};
macro_rules! const_fn {
(
$(#[$attr:meta])*
$sv:vis fn $($fn:tt)*
) => {
$(#[$attr])*
#[cfg(feature = "const_fn")]
$sv const fn $($fn)*
$(#[$attr])*
#[cfg(not(feature = "const_fn"))]
$sv fn $($fn)*
};
(
$(#[$attr:meta])*
$sv:vis unsafe fn $($fn:tt)*
) => {
$(#[$attr])*
#[cfg(feature = "const_fn")]
$sv const unsafe fn $($fn)*
$(#[$attr])*
#[cfg(not(feature = "const_fn"))]
$sv unsafe fn $($fn)*
};
}
#[cfg(all(feature = "instructions", feature = "external_asm"))]
pub(crate) mod asm;
pub mod addr;
pub mod instructions;
pub mod registers;
pub mod structures;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
pub enum PrivilegeLevel {
Ring0 = 0,
Ring1 = 1,
Ring2 = 2,
Ring3 = 3,
}
impl PrivilegeLevel {
#[inline]
pub fn from_u16(value: u16) -> PrivilegeLevel {
match value {
0 => PrivilegeLevel::Ring0,
1 => PrivilegeLevel::Ring1,
2 => PrivilegeLevel::Ring2,
3 => PrivilegeLevel::Ring3,
i => panic!("{} is not a valid privilege level", i),
}
}
}