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
use core::fmt;
use crate::i386::PrivilegeLevel;
use bit_field::BitField;
#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct SegmentSelector(pub u16);
impl SegmentSelector {
pub const fn new(index: u16, rpl: PrivilegeLevel) -> SegmentSelector {
SegmentSelector(index << 3 | (rpl as u16))
}
pub fn index(self) -> u16 {
self.0 >> 3
}
pub fn rpl(self) -> PrivilegeLevel {
PrivilegeLevel::from_u8(self.0.get_bits(0..2) as u8)
}
pub fn is_ldt(self) -> bool {
self.0.get_bit(2)
}
}
impl fmt::Debug for SegmentSelector {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut s = f.debug_struct("SegmentSelector");
s.field("index", &self.index());
s.field("rpl", &self.rpl());
s.field("is_ldt", &self.is_ldt());
s.finish()
}
}