diff options
author | 2018-04-20 10:45:30 -0700 | |
---|---|---|
committer | 2018-04-20 10:45:30 -0700 | |
commit | 91583f100ffe4efa343babd15bf3e96d9e405971 (patch) | |
tree | 0fe8fd3b137b801918230b9208a7586940134a1b /src | |
parent | 1e2efb6b7a0d76d9b672e09862515f5ac2541d9f (diff) | |
download | rust-x86-91583f100ffe4efa343babd15bf3e96d9e405971.tar.gz rust-x86-91583f100ffe4efa343babd15bf3e96d9e405971.tar.zst rust-x86-91583f100ffe4efa343babd15bf3e96d9e405971.zip |
Refactoring removed the unnecessary shared hierarchy.
Signed-off-by: Gerd Zellweger <mail@gerdzellweger.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/bits32/irq.rs | 6 | ||||
-rw-r--r-- | src/bits32/segmentation.rs | 7 | ||||
-rw-r--r-- | src/bits64/irq.rs | 6 | ||||
-rw-r--r-- | src/bits64/paging.rs | 2 | ||||
-rw-r--r-- | src/bits64/segmentation.rs | 6 | ||||
-rw-r--r-- | src/control_regs.rs (renamed from src/shared/control_regs.rs) | 0 | ||||
-rw-r--r-- | src/descriptor.rs (renamed from src/shared/descriptor.rs) | 4 | ||||
-rw-r--r-- | src/dtables.rs (renamed from src/shared/dtables.rs) | 9 | ||||
-rw-r--r-- | src/flags.rs (renamed from src/shared/flags.rs) | 2 | ||||
-rw-r--r-- | src/io.rs (renamed from src/shared/io.rs) | 0 | ||||
-rw-r--r-- | src/irq.rs (renamed from src/shared/irq.rs) | 0 | ||||
-rw-r--r-- | src/lib.rs | 38 | ||||
-rw-r--r-- | src/msr.rs (renamed from src/shared/msr.rs) | 0 | ||||
-rw-r--r-- | src/paging.rs (renamed from src/shared/paging.rs) | 0 | ||||
-rw-r--r-- | src/perfcnt/intel/counters.rs (renamed from src/shared/perfcnt/intel/counters.rs) | 0 | ||||
-rw-r--r-- | src/perfcnt/intel/description.rs (renamed from src/shared/perfcnt/intel/description.rs) | 0 | ||||
-rw-r--r-- | src/perfcnt/intel/mod.rs (renamed from src/shared/perfcnt/intel/mod.rs) | 0 | ||||
-rw-r--r-- | src/perfcnt/mod.rs (renamed from src/shared/perfcnt/mod.rs) | 0 | ||||
-rw-r--r-- | src/segmentation.rs (renamed from src/shared/segmentation.rs) | 4 | ||||
-rw-r--r-- | src/shared/mod.rs | 33 | ||||
-rw-r--r-- | src/task.rs (renamed from src/shared/task.rs) | 2 | ||||
-rw-r--r-- | src/time.rs (renamed from src/shared/time.rs) | 0 | ||||
-rw-r--r-- | src/tlb.rs (renamed from src/shared/tlb.rs) | 2 |
23 files changed, 63 insertions, 58 deletions
diff --git a/src/bits32/irq.rs b/src/bits32/irq.rs index 5d6eb0d..7affeb5 100644 --- a/src/bits32/irq.rs +++ b/src/bits32/irq.rs @@ -1,8 +1,8 @@ //! Interrupt description and set-up code. -use shared::descriptor::*; -use shared::paging::VAddr; -use shared::PrivilegeLevel; +use ::descriptor::*; +use ::paging::VAddr; +use ::PrivilegeLevel; /// An interrupt gate or trap gate descriptor. /// diff --git a/src/bits32/segmentation.rs b/src/bits32/segmentation.rs index 31547b0..fe95141 100644 --- a/src/bits32/segmentation.rs +++ b/src/bits32/segmentation.rs @@ -1,9 +1,10 @@ use core::mem::size_of; +use ::descriptor; +use ::PrivilegeLevel; +pub use ::segmentation::*; + use bits32::task::*; -use shared::descriptor; -use shared::PrivilegeLevel; -pub use shared::segmentation::*; /// Reload code segment register. /// Note this is special since we can not directly move diff --git a/src/bits64/irq.rs b/src/bits64/irq.rs index 0f8f9ce..8fbbf48 100644 --- a/src/bits64/irq.rs +++ b/src/bits64/irq.rs @@ -2,10 +2,10 @@ use core::fmt; +use ::descriptor::*; +use ::paging::VAddr; +use ::PrivilegeLevel; use bits64::segmentation::SegmentSelector; -use shared::descriptor::*; -use shared::paging::VAddr; -use shared::PrivilegeLevel; /// An interrupt gate descriptor. /// diff --git a/src/bits64/paging.rs b/src/bits64/paging.rs index 8858de8..4ec8485 100644 --- a/src/bits64/paging.rs +++ b/src/bits64/paging.rs @@ -2,7 +2,7 @@ use core::fmt; -use shared::paging::*; +use ::paging::*; /// Represents a physical memory address #[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] diff --git a/src/bits64/segmentation.rs b/src/bits64/segmentation.rs index 529efb9..93ac2aa 100644 --- a/src/bits64/segmentation.rs +++ b/src/bits64/segmentation.rs @@ -1,9 +1,9 @@ use core::mem::size_of; +use ::descriptor; +use ::PrivilegeLevel; +pub use ::segmentation::*; use bits64::task::*; -use shared::descriptor; -use shared::PrivilegeLevel; -pub use shared::segmentation::*; /// Reload code segment register. /// Note this is special since we can not directly move diff --git a/src/shared/control_regs.rs b/src/control_regs.rs index 1a1f6a3..1a1f6a3 100644 --- a/src/shared/control_regs.rs +++ b/src/control_regs.rs diff --git a/src/shared/descriptor.rs b/src/descriptor.rs index 231e7b6..aff4f0e 100644 --- a/src/shared/descriptor.rs +++ b/src/descriptor.rs @@ -1,7 +1,7 @@ //! Fields which are common to all segment-section and gate descriptors -use shared::PrivilegeLevel; -use shared::segmentation; +use ::PrivilegeLevel; +use ::segmentation; /// System-Segment and Gate-Descriptor Types for IA32e mode. When the `S` /// (descriptor type) flag in a segment descriptor is clear, the descriptor type diff --git a/src/shared/dtables.rs b/src/dtables.rs index 5ec2117..5f2b17a 100644 --- a/src/shared/dtables.rs +++ b/src/dtables.rs @@ -1,13 +1,13 @@ //! Functions and data-structures to load descriptor tables. +use core::fmt; use core::mem::size_of; use current::irq::IdtEntry; -use shared::segmentation::SegmentDescriptor; +use segmentation::SegmentDescriptor; /// A struct describing a pointer to a descriptor table (GDT / IDT). /// This is in a format suitable for giving to 'lgdt' or 'lidt'. -#[derive(Debug)] #[repr(C, packed)] pub struct DescriptorTablePointer<Entry> { /// Size of the DT. @@ -30,6 +30,11 @@ impl<T> DescriptorTablePointer<T> { } } +impl<T> fmt::Debug for DescriptorTablePointer<T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + unsafe { write!(f, "DescriptorTablePointer ({} {:?})", self.limit, self.base) } + } +} /// Load GDT table. pub unsafe fn lgdt(gdt: &DescriptorTablePointer<SegmentDescriptor>) { diff --git a/src/shared/flags.rs b/src/flags.rs index 55dad6d..46013a8 100644 --- a/src/shared/flags.rs +++ b/src/flags.rs @@ -1,6 +1,6 @@ //! Processor state stored in the FLAGS, EFLAGS, or RFLAGS register. -use shared::PrivilegeLevel; +use ::PrivilegeLevel; /// The RFLAGS register. All variants are backwards compatable so only one /// bitflags struct needed. diff --git a/src/shared/io.rs b/src/io.rs index 16f641c..16f641c 100644 --- a/src/shared/io.rs +++ b/src/io.rs diff --git a/src/shared/irq.rs b/src/irq.rs index 4654ad3..4654ad3 100644 --- a/src/shared/irq.rs +++ b/src/irq.rs @@ -7,18 +7,32 @@ #[macro_use] extern crate bitflags; - extern crate raw_cpuid; - #[cfg(feature = "performance-counter")] #[macro_use] extern crate phf; #[cfg(target_arch="x86")] pub mod bits32; + #[cfg(target_arch="x86_64")] pub mod bits64; -pub mod shared; + +pub mod control_regs; +pub mod descriptor; +pub mod dtables; +pub mod io; +pub mod irq; +pub mod msr; +pub mod paging; +pub mod flags; +pub mod segmentation; +pub mod task; +pub mod tlb; +pub mod time; + +#[cfg(feature = "performance-counter")] +pub mod perfcnt; pub mod current { #[cfg(target_arch="x86")] @@ -27,8 +41,26 @@ pub mod current { pub use bits64::*; } +pub mod cpuid { + pub use raw_cpuid::*; +} + mod std { pub use core::fmt; pub use core::ops; pub use core::option; } + +#[derive(Copy, Clone, PartialEq, Eq)] +#[repr(u8)] +pub enum PrivilegeLevel { + Ring0 = 0, + Ring1 = 1, + Ring2 = 2, + Ring3 = 3, +} + +#[inline(always)] +pub unsafe fn halt() { + asm!("hlt" :::: "volatile"); +} diff --git a/src/shared/msr.rs b/src/msr.rs index 1520232..1520232 100644 --- a/src/shared/msr.rs +++ b/src/msr.rs diff --git a/src/shared/paging.rs b/src/paging.rs index 41705a9..41705a9 100644 --- a/src/shared/paging.rs +++ b/src/paging.rs diff --git a/src/shared/perfcnt/intel/counters.rs b/src/perfcnt/intel/counters.rs index f99a3fb..f99a3fb 100644 --- a/src/shared/perfcnt/intel/counters.rs +++ b/src/perfcnt/intel/counters.rs diff --git a/src/shared/perfcnt/intel/description.rs b/src/perfcnt/intel/description.rs index 5e1b66f..5e1b66f 100644 --- a/src/shared/perfcnt/intel/description.rs +++ b/src/perfcnt/intel/description.rs diff --git a/src/shared/perfcnt/intel/mod.rs b/src/perfcnt/intel/mod.rs index f038055..f038055 100644 --- a/src/shared/perfcnt/intel/mod.rs +++ b/src/perfcnt/intel/mod.rs diff --git a/src/shared/perfcnt/mod.rs b/src/perfcnt/mod.rs index dec5d2a..dec5d2a 100644 --- a/src/shared/perfcnt/mod.rs +++ b/src/perfcnt/mod.rs diff --git a/src/shared/segmentation.rs b/src/segmentation.rs index 8aafd31..7672d4a 100644 --- a/src/shared/segmentation.rs +++ b/src/segmentation.rs @@ -1,7 +1,7 @@ use core::fmt; -use shared::descriptor; -use shared::PrivilegeLevel; +use ::descriptor; +use ::PrivilegeLevel; /// Specifies which element to load into a segment from /// descriptor tables (i.e., is a index to LDT or GDT table diff --git a/src/shared/mod.rs b/src/shared/mod.rs deleted file mode 100644 index 6ea7633..0000000 --- a/src/shared/mod.rs +++ /dev/null @@ -1,33 +0,0 @@ -pub mod control_regs; -pub mod descriptor; -pub mod dtables; -pub mod io; -pub mod irq; -pub mod msr; -pub mod paging; -pub mod flags; -pub mod segmentation; -pub mod task; -pub mod tlb; -pub mod time; - -pub mod cpuid { - pub use raw_cpuid::*; -} - -#[derive(Copy, Clone, PartialEq, Eq)] -#[repr(u8)] -pub enum PrivilegeLevel { - Ring0 = 0, - Ring1 = 1, - Ring2 = 2, - Ring3 = 3, -} - -#[cfg(feature = "performance-counter")] -pub mod perfcnt; - -#[inline(always)] -pub unsafe fn halt() { - asm!("hlt" :::: "volatile"); -} diff --git a/src/shared/task.rs b/src/task.rs index 27fd0bc..b0dd2ff 100644 --- a/src/shared/task.rs +++ b/src/task.rs @@ -1,7 +1,7 @@ //! Helpers to program the task state segment. //! See Intel 3a, Chapter 7 -pub use shared::segmentation; +pub use ::segmentation; /// Load the task state register. pub unsafe fn load_tr(sel: segmentation::SegmentSelector) { diff --git a/src/shared/time.rs b/src/time.rs index eff567d..eff567d 100644 --- a/src/shared/time.rs +++ b/src/time.rs diff --git a/src/shared/tlb.rs b/src/tlb.rs index f99604f..99558fd 100644 --- a/src/shared/tlb.rs +++ b/src/tlb.rs @@ -15,6 +15,6 @@ pub unsafe fn flush(addr: usize) { /// This function is unsafe as it causes a general protection fault (GP) if the current privilege /// level is not 0. pub unsafe fn flush_all() { - use shared::control_regs::{cr3, cr3_write}; + use ::control_regs::{cr3, cr3_write}; cr3_write(cr3()) } |