aboutsummaryrefslogtreecommitdiff
path: root/src/shared/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/mod.rs')
-rw-r--r--src/shared/mod.rs102
1 files changed, 3 insertions, 99 deletions
diff --git a/src/shared/mod.rs b/src/shared/mod.rs
index 04bc5e0..e9c8084 100644
--- a/src/shared/mod.rs
+++ b/src/shared/mod.rs
@@ -1,14 +1,7 @@
-//! Data structures and functions used by both protected mode and IA-32e.
-
-// In a few rare-cases this module includes mode-specific
-// *implementations*. This is usually because we cannot trust the LLVM inline
-// assembler to infer instruction variants from argument size, and thus we add
-// size-suffixes wherever possible.
-//
-// That said, *interfaces* must always be mode-portable
-
#![allow(non_upper_case_globals)]
+pub mod control_regs;
+
bitflags! {
pub flags Flags: usize {
const CarryFlag = 1 << 0,
@@ -32,44 +25,6 @@ bitflags! {
}
}
-bitflags! {
- pub flags Cr0: usize {
- const ProtectedMode = 1 << 0,
- const MonitorCoprocessor = 1 << 1,
- const EmulateCoprocessor = 1 << 2,
- const TaskSwitched = 1 << 3,
- const ExtensionType = 1 << 4,
- const NumericError = 1 << 5,
- const WriteProtect = 1 << 16,
- const AlignmentMask = 1 << 18,
- const NotWriteThrough = 1 << 29,
- const CacheDisable = 1 << 30,
- const EnablePaging = 1 << 31
- }
-}
-
-bitflags! {
- pub flags Cr4: usize {
- const EnableVme = 1 << 0,
- const VirtualInterrupts = 1 << 1,
- const TimeStampDisable = 1 << 2,
- const DebuggingExtensions = 1 << 3,
- const EnablePse = 1 << 4,
- const EnablePae = 1 << 5,
- const EnableMachineCheck = 1 << 6,
- const EnableGlobalPages = 1 << 7,
- const EnablePpmc = 1 << 8,
- const EnableSse = 1 << 9,
- const UnmaskedSse = 1 << 10,
- const EnableVmx = 1 << 13,
- const EnableSmx = 1 << 14,
- const EnablePcid = 1 << 17,
- const EnableOsXSave = 1 << 18,
- const EnableSmep = 1 << 20,
- const EnableSmap = 1 << 21
- }
-}
-
bitflags!(
pub flags Features: u64 {
const Fpu = 1 << 0,
@@ -184,7 +139,7 @@ impl Exception {
19 => Exception::Simd,
20 => Exception::Virtualization,
30 => Exception::Security,
-
+
_ => return None
})
}
@@ -285,57 +240,6 @@ pub unsafe fn set_cs(selector: SegmentSelector) {
}
#[inline(always)]
-pub fn get_cr0() -> Cr0 {
- unsafe {
- let r: usize;
- asm!("mov $0, cr0" : "=r"(r) ::: "intel");
- Cr0::from_bits_truncate(r)
- }
-}
-
-#[inline(always)]
-pub fn get_cr2() -> usize {
- unsafe {
- let r: usize;
- asm!("mov $0, cr2" : "=r"(r) ::: "intel");
- r
- }
-}
-
-#[inline(always)]
-pub fn get_cr3() -> usize {
- unsafe {
- let r: usize;
- asm!("mov $0, cr3" : "=r"(r) ::: "intel");
- r
- }
-}
-
-#[inline(always)]
-pub fn get_cr4() -> Cr4 {
- unsafe {
- let r: usize;
- asm!("mov $0, cr4" : "=r"(r) ::: "intel");
- Cr4::from_bits_truncate(r)
- }
-}
-
-#[inline(always)]
-pub unsafe fn set_cr0(flags: Cr0) {
- asm!("mov cr0, $0" :: "r"(flags.bits()) :: "volatile", "intel");
-}
-
-#[inline(always)]
-pub unsafe fn set_cr3(val: usize) {
- asm!("mov cr3, $0" :: "r"(val) :: "volatile", "intel");
-}
-
-#[inline(always)]
-pub unsafe fn set_cr4(flags: Cr4) {
- asm!("mov cr4, $0" :: "r"(flags.bits()) :: "volatile", "intel");
-}
-
-#[inline(always)]
pub unsafe fn enable_interrupts() {
asm!("sti" :::: "volatile", "intel");
}