Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/structures/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ impl GlobalDescriptorTable {
///
/// Panics if the GDT has no free entries left.
pub fn add_entry(&mut self, entry: Descriptor) -> SegmentSelector {
let index = match entry {
Descriptor::UserSegment(value) => self.push(value),
let (index, privilege) = match entry {
Descriptor::UserSegment(value) => (self.push(value), (value >> 45) & 0b11),
Descriptor::SystemSegment(value_low, value_high) => {
let index = self.push(value_low);
self.push(value_high);
index
(index, (value_low >> 45) & 0b11)
}
};
SegmentSelector::new(index as u16, PrivilegeLevel::Ring0)
SegmentSelector::new(index as u16, PrivilegeLevel::from_u16(privilege as u16))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a privilege_level(&self) -> PrivilegeLevel method to Descriptor? Then we could keep the bit shifts at one place. Also, we could use the get_bits method instead of doing the shift and logical AND ourselves.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, will do.

}

/// Loads the GDT in the CPU using the `lgdt` instruction.
Expand Down