diff options
author | 2016-06-26 18:49:50 -0700 | |
---|---|---|
committer | 2016-06-26 18:49:50 -0700 | |
commit | b071258ae864f869cf578fd2a47c80af3edce15a (patch) | |
tree | 2a326321a1ac902b9ba2b6e75896d4b6a509ce23 /src | |
parent | 32257991aaa3700620f1d6c180cfec3e2d65a360 (diff) | |
download | rust-x86-b071258ae864f869cf578fd2a47c80af3edce15a.tar.gz rust-x86-b071258ae864f869cf578fd2a47c80af3edce15a.tar.zst rust-x86-b071258ae864f869cf578fd2a47c80af3edce15a.zip |
Use upstream bitflags now that no_std issues were resolved
Diffstat (limited to 'src')
-rw-r--r-- | src/bitflags.rs | 163 | ||||
-rw-r--r-- | src/irq.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/paging.rs | 12 | ||||
-rw-r--r-- | src/rflags.rs | 2 | ||||
-rw-r--r-- | src/segmentation.rs | 12 |
6 files changed, 11 insertions, 184 deletions
diff --git a/src/bitflags.rs b/src/bitflags.rs deleted file mode 100644 index 8d16e41..0000000 --- a/src/bitflags.rs +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -macro_rules! bitflags { - ($(#[$attr:meta])* flags $BitFlags:ident: $T:ty { - $($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+ - }) => { - #[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)] - $(#[$attr])* - pub struct $BitFlags { - bits: $T, - } - - $($(#[$Flag_attr])* pub const $Flag: $BitFlags = $BitFlags { bits: $value };)+ - - impl $BitFlags { - /// Returns an empty set of flags. - #[inline] - pub fn empty() -> $BitFlags { - $BitFlags { bits: 0 } - } - - /// Returns the set containing all flags. - #[inline] - pub fn all() -> $BitFlags { - $BitFlags { bits: $($value)|+ } - } - - /// Returns the raw value of the flags currently stored. - #[inline] - pub fn bits(&self) -> $T { - self.bits - } - - /// Convert from underlying bit representation, unless that - /// representation contains bits that do not correspond to a flag. - #[inline] - pub fn from_bits(bits: $T) -> ::std::option::Option<$BitFlags> { - if (bits & !$BitFlags::all().bits()) != 0 { - ::std::option::Option::None - } else { - ::std::option::Option::Some($BitFlags { bits: bits }) - } - } - - /// Convert from underlying bit representation, dropping any bits - /// that do not correspond to flags. - #[inline] - pub fn from_bits_truncate(bits: $T) -> $BitFlags { - $BitFlags { bits: bits } & $BitFlags::all() - } - - /// Returns `true` if no flags are currently stored. - #[inline] - pub fn is_empty(&self) -> bool { - *self == $BitFlags::empty() - } - - /// Returns `true` if all flags are currently set. - #[inline] - pub fn is_all(&self) -> bool { - *self == $BitFlags::all() - } - - /// Returns `true` if there are flags common to both `self` and `other`. - #[inline] - pub fn intersects(&self, other: $BitFlags) -> bool { - !(*self & other).is_empty() - } - - /// Returns `true` all of the flags in `other` are contained within `self`. - #[inline] - pub fn contains(&self, other: $BitFlags) -> bool { - (*self & other) == other - } - - /// Inserts the specified flags in-place. - #[inline] - pub fn insert(&mut self, other: $BitFlags) { - self.bits |= other.bits; - } - - /// Removes the specified flags in-place. - #[inline] - pub fn remove(&mut self, other: $BitFlags) { - self.bits &= !other.bits; - } - - /// Toggles the specified flags in-place. - #[inline] - pub fn toggle(&mut self, other: $BitFlags) { - self.bits ^= other.bits; - } - } - - impl ::std::ops::BitOr for $BitFlags { - type Output = $BitFlags; - - /// Returns the union of the two sets of flags. - #[inline] - fn bitor(self, other: $BitFlags) -> $BitFlags { - $BitFlags { bits: self.bits | other.bits } - } - } - - impl ::std::ops::BitXor for $BitFlags { - type Output = $BitFlags; - - /// Returns the left flags, but with all the right flags toggled. - #[inline] - fn bitxor(self, other: $BitFlags) -> $BitFlags { - $BitFlags { bits: self.bits ^ other.bits } - } - } - - impl ::std::ops::BitAnd for $BitFlags { - type Output = $BitFlags; - - /// Returns the intersection between the two sets of flags. - #[inline] - fn bitand(self, other: $BitFlags) -> $BitFlags { - $BitFlags { bits: self.bits & other.bits } - } - } - - impl ::std::ops::Sub for $BitFlags { - type Output = $BitFlags; - - /// Returns the set difference of the two sets of flags. - #[inline] - fn sub(self, other: $BitFlags) -> $BitFlags { - $BitFlags { bits: self.bits & !other.bits } - } - } - - impl ::std::ops::Not for $BitFlags { - type Output = $BitFlags; - - /// Returns the complement of this set of flags. - #[inline] - fn not(self) -> $BitFlags { - $BitFlags { bits: !self.bits } & $BitFlags::all() - } - } - }; - ($(#[$attr:meta])* flags $BitFlags:ident: $T:ty { - $($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+, - }) => { - bitflags! { - $(#[$attr])* - flags $BitFlags: $T { - $($(#[$Flag_attr])* const $Flag = $value),+ - } - } - }; -} @@ -267,7 +267,7 @@ impl IdtEntry { bitflags!{ // Taken from Intel Manual Section 4.7 Page-Fault Exceptions. - flags PageFaultError: u32 { + pub flags PageFaultError: u32 { /// 0: The fault was caused by a non-present page. /// 1: The fault was caused by a page-level protection violation const PFAULT_ERROR_P = bit!(0), @@ -296,7 +296,7 @@ bitflags!{ } } -impl fmt::Debug for PageFaultError { +impl fmt::Display for PageFaultError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let p = match self.contains(PFAULT_ERROR_P) { false => "The fault was caused by a non-present page.", @@ -7,7 +7,7 @@ #![crate_type = "lib"] #[macro_use] -mod bitflags; +extern crate bitflags; #[macro_use] extern crate raw_cpuid; diff --git a/src/paging.rs b/src/paging.rs index 22d9526..cc519b2 100644 --- a/src/paging.rs +++ b/src/paging.rs @@ -140,8 +140,7 @@ pub fn pt_index(addr: VAddr) -> usize { /// PML4 Entry bits description. bitflags! { - #[derive(Debug)] - flags PML4Entry: u64 { + pub flags PML4Entry: u64 { /// Present; must be 1 to reference a page-directory-pointer table const PML4_P = bit!(0), /// Read/write; if 0, writes may not be allowed to the 512-GByte region @@ -200,8 +199,7 @@ impl PML4Entry { /// PDPT Entry bits description. bitflags! { - #[derive(Debug)] - flags PDPTEntry: u64 { + pub flags PDPTEntry: u64 { /// Present; must be 1 to map a 1-GByte page or reference a page directory. const PDPT_P = bit!(0), /// Read/write; if 0, writes may not be allowed to the 1-GByte region controlled by this entry @@ -269,8 +267,7 @@ impl PDPTEntry { /// PD Entry bits description. bitflags! { - #[derive(Debug)] - flags PDEntry: u64 { + pub flags PDEntry: u64 { /// Present; must be 1 to map a 2-MByte page or reference a page table. const PD_P = bit!(0), /// Read/write; if 0, writes may not be allowed to the 2-MByte region controlled by this entry @@ -345,8 +342,7 @@ impl PDEntry { /// PT Entry bits description. bitflags! { - #[derive(Debug)] - flags PTEntry: u64 { + pub flags PTEntry: u64 { /// Present; must be 1 to map a 4-KByte page. const PT_P = bit!(0), /// Read/write; if 0, writes may not be allowed to the 4-KByte region controlled by this entry diff --git a/src/rflags.rs b/src/rflags.rs index 6af25b1..7cf4bbd 100644 --- a/src/rflags.rs +++ b/src/rflags.rs @@ -2,7 +2,7 @@ /// RFLAGS description. bitflags! { - flags RFlags: u64 { + pub flags RFlags: u64 { /// ID Flag (ID) const RFLAGS_ID = 1 << 21, /// Virtual Interrupt Pending (VIP) diff --git a/src/segmentation.rs b/src/segmentation.rs index e3c259e..e46b333 100644 --- a/src/segmentation.rs +++ b/src/segmentation.rs @@ -6,7 +6,7 @@ use core::fmt; /// descriptor tables (i.e., is a index to LDT or GDT table /// with some additional flags). bitflags! { - flags SegmentSelector: u16 { + pub flags SegmentSelector: u16 { /// Requestor Privilege Level const RPL_0 = 0b00, const RPL_1 = 0b01, @@ -35,7 +35,7 @@ impl SegmentSelector { } } -impl fmt::Debug for SegmentSelector { +impl fmt::Display for SegmentSelector { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let r0 = match self.contains(RPL_0) { false => "", @@ -73,7 +73,7 @@ impl fmt::Debug for SegmentSelector { /// Entry for GDT or LDT. Provides size and location of a segment. bitflags! { - flags SegmentDescriptor: u64 { + pub flags SegmentDescriptor: u64 { /// Descriptor type (0 = system; 1 = code or data). const DESC_S = 1 << (32+12), /// Descriptor privilege level 0. @@ -162,12 +162,6 @@ impl SegmentDescriptor { } } -impl fmt::Debug for SegmentDescriptor { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "SD: 0x{:x}", self.bits) - } -} - /// Reload stack segment register. pub unsafe fn load_ss(sel: SegmentSelector) { asm!("movw $0, %ss " :: "r" (sel) : "memory"); |