-
Notifications
You must be signed in to change notification settings - Fork 149
Add variable privilege to gdt #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)) | ||
| } | ||
|
|
||
| /// Loads the GDT in the CPU using the `lgdt` instruction. | ||
|
|
@@ -148,8 +148,8 @@ impl Descriptor { | |
| Descriptor::UserSegment(flags.bits()) | ||
| } | ||
|
|
||
| /// Creates a TSS system descriptor for the given TSS. | ||
| pub fn tss_segment(tss: &'static TaskStateSegment) -> Descriptor { | ||
| /// Creates a TSS system descriptor for the given TSS and IO permissions bitmap size. | ||
| pub fn tss_segment(tss: &'static TaskStateSegment, iomap_size: u16) -> Descriptor { | ||
| use self::DescriptorFlags as Flags; | ||
| use core::mem::size_of; | ||
|
|
||
|
|
@@ -159,8 +159,11 @@ impl Descriptor { | |
| // base | ||
| low.set_bits(16..40, ptr.get_bits(0..24)); | ||
| low.set_bits(56..64, ptr.get_bits(24..32)); | ||
| // limit (the `-1` in needed since the bound is inclusive) | ||
| low.set_bits(0..16, (size_of::<TaskStateSegment>() - 1) as u64); | ||
| // limit (the `-1` is needed since the bound is inclusive) | ||
| low.set_bits( | ||
| 0..16, | ||
| (size_of::<TaskStateSegment>() + (tss.iomap_base + iomap_size) as usize - 1) as u64 | ||
| ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code only works if the To solve this, we could create an internal (non-public) Now we can create a new What do you think about this?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that it should work for the TSS anywhere (so long as it is within a 16 bit pointer)? That's why
Sounds good. Will do.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, missed that!
Thanks! |
||
| // type (0b1001 = available 64-bit tss) | ||
| low.set_bits(40..44, 0b1001); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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) -> PrivilegeLevelmethod toDescriptor? Then we could keep the bit shifts at one place. Also, we could use theget_bitsmethod instead of doing the shift and logical AND ourselves.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, will do.