diff options
author | 2017-11-14 11:33:08 +0100 | |
---|---|---|
committer | 2017-11-14 11:33:08 +0100 | |
commit | 2b6d77154f01e835d32d44c2e7f05c54b01f901a (patch) | |
tree | 4018c48c164e5c7567e1e245a6b78f1b4a0d96b7 /src | |
parent | 305d41d88fa2dcc961b2c9a258e6b657d237b475 (diff) | |
parent | d714769d04ec732529135a61df0b1ec5dfe867f1 (diff) | |
download | rust-x86-2b6d77154f01e835d32d44c2e7f05c54b01f901a.tar.gz rust-x86-2b6d77154f01e835d32d44c2e7f05c54b01f901a.tar.zst rust-x86-2b6d77154f01e835d32d44c2e7f05c54b01f901a.zip |
Merge pull request #35 from ColinFinck/dtables
GDT, LDT, and IDT all expect the limit to be set to "one less". So do…
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/dtables.rs | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/src/shared/dtables.rs b/src/shared/dtables.rs index c5337fb..5ec2117 100644 --- a/src/shared/dtables.rs +++ b/src/shared/dtables.rs @@ -17,8 +17,11 @@ pub struct DescriptorTablePointer<Entry> { } impl<T> DescriptorTablePointer<T> { - fn new(slice: &[T]) -> Self { - let len = slice.len() * size_of::<T>(); + pub fn new(slice: &[T]) -> Self { + // GDT, LDT, and IDT all expect the limit to be set to "one less". + // See Intel 3a, Section 3.5.1 "Segment Descriptor Tables" and + // Section 6.10 "Interrupt Descriptor Table (IDT)". + let len = slice.len() * size_of::<T>() - 1; assert!(len < 0x10000); DescriptorTablePointer { base: slice.as_ptr(), @@ -27,23 +30,6 @@ impl<T> DescriptorTablePointer<T> { } } -impl DescriptorTablePointer<SegmentDescriptor> { - pub fn new_gdtp(gdt: &[SegmentDescriptor]) -> Self { - let mut p = Self::new(gdt); - p.limit -= 1; - p - } - pub fn new_ldtp(ldt: &[SegmentDescriptor]) -> Self { - Self::new(ldt) - } -} - -impl DescriptorTablePointer<IdtEntry> { - pub fn new_idtp(idt: &[IdtEntry]) -> Self { - Self::new(idt) - } -} - /// Load GDT table. pub unsafe fn lgdt(gdt: &DescriptorTablePointer<SegmentDescriptor>) { |