From 27e2cc6e7e472aec45336b3635530802cf1aa4f4 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 28 Dec 2020 14:30:51 +0100 Subject: [PATCH 1/2] Make `DescriptorTablePointer::base` a `VirtAddr` Makes it clear that segmentation is applied before paging. --- src/structures/gdt.rs | 7 +++++-- src/structures/idt.rs | 2 +- src/structures/mod.rs | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/structures/gdt.rs b/src/structures/gdt.rs index a071982f9..97c43a2fb 100644 --- a/src/structures/gdt.rs +++ b/src/structures/gdt.rs @@ -1,7 +1,10 @@ //! Types for the Global Descriptor Table and segment selectors. -use crate::structures::{tss::TaskStateSegment, DescriptorTablePointer}; use crate::PrivilegeLevel; +use crate::{ + structures::{tss::TaskStateSegment, DescriptorTablePointer}, + VirtAddr, +}; use bit_field::BitField; use bitflags::bitflags; use core::fmt; @@ -169,7 +172,7 @@ impl GlobalDescriptorTable { fn pointer(&self) -> DescriptorTablePointer { use core::mem::size_of; DescriptorTablePointer { - base: self.table.as_ptr() as u64, + base: VirtAddr::new(self.table.as_ptr() as u64), limit: (self.next_free * size_of::() - 1) as u16, } } diff --git a/src/structures/idt.rs b/src/structures/idt.rs index 06cbe3265..dd605f20a 100644 --- a/src/structures/idt.rs +++ b/src/structures/idt.rs @@ -440,7 +440,7 @@ impl InterruptDescriptorTable { fn pointer(&self) -> DescriptorTablePointer { use core::mem::size_of; DescriptorTablePointer { - base: self as *const _ as u64, + base: VirtAddr::new(self as *const _ as u64), limit: (size_of::() - 1) as u16, } } diff --git a/src/structures/mod.rs b/src/structures/mod.rs index cdddce2ee..79801c245 100644 --- a/src/structures/mod.rs +++ b/src/structures/mod.rs @@ -1,5 +1,7 @@ //! Representations of various x86 specific structures and descriptor tables. +use crate::VirtAddr; + pub mod gdt; // idt needs `feature(abi_x86_interrupt)`, which is not available on stable rust @@ -18,5 +20,5 @@ pub struct DescriptorTablePointer { /// Size of the DT. pub limit: u16, /// Pointer to the memory region containing the DT. - pub base: u64, + pub base: VirtAddr, } From b7588c7868391121df9a70f1db7190b5a538d52d Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Mon, 28 Dec 2020 14:32:56 +0100 Subject: [PATCH 2/2] Update changelog for #215 --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 47812e5e1..734983217 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ - `ExceptionStackFrame` - `VirtAddr::new_unchecked` - `interrupts::enable_interrupts_and_hlt` +- **Breaking:** Make `DescriptorTablePointer::base` a `VirtAddr` ([#215](https://github.com/rust-osdev/x86_64/pull/215)) - Relaxe `Sized` requirement for `FrameAllocator` in `Mapper::map_to` ([204](https://github.com/rust-osdev/x86_64/pull/204)) # 0.12.3 – 2020-10-31