Skip to content

Commit

Permalink
return ring enum instead of u16
Browse files Browse the repository at this point in the history
  • Loading branch information
elbiazo committed Nov 30, 2023
1 parent 1a77405 commit 10d125a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/segmentation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Functionality to manipulate segment registers, build segement
//! descriptors and selectors.
use _core::convert::TryInto;

Check warning on line 3 in src/segmentation.rs

View workflow job for this annotation

GitHub Actions / ci (nightly)

unused import: `_core::convert::TryInto`
use bitflags::*;

use core::arch::asm;
Expand Down Expand Up @@ -45,8 +46,14 @@ impl SegmentSelector {
}

/// Returns the requested privilege level of the selector.
pub fn rpl(&self) -> u16 {
self.bits & 0b11
pub fn rpl(&self) -> Ring {
match self.bits & 0b11 {
0b00 => Ring::Ring0,
0b01 => Ring::Ring1,
0b10 => Ring::Ring2,
0b11 => Ring::Ring3,
_ => unreachable!(),
}
}

/// Returns the table indicator (TI) bit.
Expand All @@ -67,7 +74,13 @@ impl fmt::Display for SegmentSelector {
true => "LDT Table",
};

write!(f, "Index {} in {}, RPL = {}", self.index(), tbl, self.rpl())
write!(
f,
"Index {} in {}, {:?} segment selector.",
self.index(),
tbl,
self.rpl()
)
}
}

Expand Down

0 comments on commit 10d125a

Please sign in to comment.