diff options
author | 2016-06-29 15:49:33 -0700 | |
---|---|---|
committer | 2016-06-29 15:49:33 -0700 | |
commit | fffa3ae71951c3b8f4b2a441764a44ab8e55416e (patch) | |
tree | 9a9897b863c845d7679bebeb3c46a774ecb5e33c | |
parent | aaf26598addf1ef47fd8422d688965f89302d21b (diff) | |
download | rust-x86-fffa3ae71951c3b8f4b2a441764a44ab8e55416e.tar.gz rust-x86-fffa3ae71951c3b8f4b2a441764a44ab8e55416e.tar.zst rust-x86-fffa3ae71951c3b8f4b2a441764a44ab8e55416e.zip |
Crudely throw everything together
-rw-r--r-- | LICENSE | 1 | ||||
-rw-r--r-- | build.rs | 2 | ||||
-rw-r--r-- | src/bits32/mod.rs (renamed from tobba/src/x86.rs) | 6 | ||||
-rw-r--r-- | src/bits64/controlregs.rs (renamed from src/controlregs.rs) | 0 | ||||
-rw-r--r-- | src/bits64/dtables.rs (renamed from src/dtables.rs) | 0 | ||||
-rw-r--r-- | src/bits64/io.rs (renamed from src/io.rs) | 0 | ||||
-rw-r--r-- | src/bits64/irq.rs (renamed from src/irq.rs) | 2 | ||||
-rw-r--r-- | src/bits64/mod.rs | 52 | ||||
-rw-r--r-- | src/bits64/msr.rs (renamed from src/msr.rs) | 0 | ||||
-rw-r--r-- | src/bits64/paging.rs (renamed from src/paging.rs) | 0 | ||||
-rw-r--r-- | src/bits64/perfcnt/intel/counters.rs (renamed from src/perfcnt/intel/counters.rs) | 0 | ||||
-rw-r--r-- | src/bits64/perfcnt/intel/description.rs (renamed from src/perfcnt/intel/description.rs) | 0 | ||||
-rw-r--r-- | src/bits64/perfcnt/intel/mod.rs (renamed from src/perfcnt/intel/mod.rs) | 0 | ||||
-rw-r--r-- | src/bits64/perfcnt/mod.rs (renamed from src/perfcnt/mod.rs) | 0 | ||||
-rw-r--r-- | src/bits64/rflags.rs (renamed from src/rflags.rs) | 0 | ||||
-rw-r--r-- | src/bits64/segmentation.rs (renamed from src/segmentation.rs) | 0 | ||||
-rw-r--r-- | src/bits64/sgx.rs (renamed from src/sgx.rs) | 10 | ||||
-rw-r--r-- | src/bits64/syscall.rs (renamed from src/syscall.rs) | 0 | ||||
-rw-r--r-- | src/bits64/task.rs (renamed from src/task.rs) | 2 | ||||
-rw-r--r-- | src/bits64/time.rs (renamed from src/time.rs) | 0 | ||||
-rw-r--r-- | src/bits64/tlb.rs (renamed from src/tlb.rs) | 2 | ||||
-rw-r--r-- | src/bits64/tobba.rs (renamed from tobba/src/x86_64.rs) | 4 | ||||
-rw-r--r-- | src/lib.rs | 61 | ||||
-rw-r--r-- | src/shared/mod.rs (renamed from tobba/src/x86_shared.rs) | 9 | ||||
-rw-r--r-- | tobba/.gitignore | 2 | ||||
-rw-r--r-- | tobba/Cargo.toml | 7 | ||||
-rw-r--r-- | tobba/LICENSE | 19 | ||||
-rw-r--r-- | tobba/README.md | 6 | ||||
-rw-r--r-- | tobba/src/lib.rs | 21 |
29 files changed, 84 insertions, 122 deletions
@@ -1,6 +1,7 @@ The MIT License (MIT) Copyright (c) 2015 Gerd Zellweger +Copyright (c) 2015 The libcpu Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -23,7 +23,7 @@ mod performance_counter { use self::serde_json::Value; - include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/perfcnt/intel/description.rs")); + include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/bits64/perfcnt/intel/description.rs")); /// HACK: We need to convert parsed strings to static because we're reusing /// the struct definition which declare strings as static in the generated code. diff --git a/tobba/src/x86.rs b/src/bits32/mod.rs index d307dd1..acb73c7 100644 --- a/tobba/src/x86.rs +++ b/src/bits32/mod.rs @@ -1,11 +1,11 @@ +//! Data structures and functions used by Protected Mode but not IA-32e. + #![allow(non_upper_case_globals)] -pub use self::x86_shared::*; +pub use shared::*; use core::mem::size_of; -mod x86_shared; - bitflags! { pub flags GdtAccess: u8 { const Accessed = 1 << 0, diff --git a/src/controlregs.rs b/src/bits64/controlregs.rs index c243caf..c243caf 100644 --- a/src/controlregs.rs +++ b/src/bits64/controlregs.rs diff --git a/src/dtables.rs b/src/bits64/dtables.rs index d2e3413..d2e3413 100644 --- a/src/dtables.rs +++ b/src/bits64/dtables.rs diff --git a/src/io.rs b/src/bits64/io.rs index bb7cfb0..bb7cfb0 100644 --- a/src/io.rs +++ b/src/bits64/io.rs diff --git a/src/irq.rs b/src/bits64/irq.rs index bd92834..a1b6d12 100644 --- a/src/irq.rs +++ b/src/bits64/irq.rs @@ -1,7 +1,7 @@ //! Interrupt description and set-up code. use core::fmt; -use paging::VAddr; +use super::paging::VAddr; /// x86 Exception description (see also Intel Vol. 3a Chapter 6). #[derive(Debug)] diff --git a/src/bits64/mod.rs b/src/bits64/mod.rs new file mode 100644 index 0000000..315af02 --- /dev/null +++ b/src/bits64/mod.rs @@ -0,0 +1,52 @@ +//! Data structures and functions used by IA-32e but not Protected Mode. + +macro_rules! bit { + ( $x:expr ) => { + 1 << $x + }; +} + +macro_rules! check_flag { + ($doc:meta, $fun:ident, $flag:ident) => ( + #[$doc] + pub fn $fun(&self) -> bool { + self.contains($flag) + } + ) +} + +macro_rules! is_bit_set { + ($field:expr, $bit:expr) => ( + $field & (1 << $bit) > 0 + ) +} + +macro_rules! check_bit_fn { + ($doc:meta, $fun:ident, $field:ident, $bit:expr) => ( + #[$doc] + pub fn $fun(&self) -> bool { + is_bit_set!(self.$field, $bit) + } + ) +} + +pub mod io; +pub mod controlregs; +pub mod msr; +pub mod time; +pub mod irq; +pub mod rflags; +pub mod paging; +pub mod segmentation; +pub mod task; +pub mod dtables; +pub mod syscall; +pub mod sgx; +#[cfg(feature = "performance-counter")] +pub mod perfcnt; +pub mod cpuid { + pub use raw_cpuid::*; +} +pub mod tlb; + +pub mod tobba; diff --git a/src/msr.rs b/src/bits64/msr.rs index 6b4613a..6b4613a 100644 --- a/src/msr.rs +++ b/src/bits64/msr.rs diff --git a/src/paging.rs b/src/bits64/paging.rs index cc519b2..cc519b2 100644 --- a/src/paging.rs +++ b/src/bits64/paging.rs diff --git a/src/perfcnt/intel/counters.rs b/src/bits64/perfcnt/intel/counters.rs index e2987cc..e2987cc 100644 --- a/src/perfcnt/intel/counters.rs +++ b/src/bits64/perfcnt/intel/counters.rs diff --git a/src/perfcnt/intel/description.rs b/src/bits64/perfcnt/intel/description.rs index f64426d..f64426d 100644 --- a/src/perfcnt/intel/description.rs +++ b/src/bits64/perfcnt/intel/description.rs diff --git a/src/perfcnt/intel/mod.rs b/src/bits64/perfcnt/intel/mod.rs index 960e0c6..960e0c6 100644 --- a/src/perfcnt/intel/mod.rs +++ b/src/bits64/perfcnt/intel/mod.rs diff --git a/src/perfcnt/mod.rs b/src/bits64/perfcnt/mod.rs index 74b80a2..74b80a2 100644 --- a/src/perfcnt/mod.rs +++ b/src/bits64/perfcnt/mod.rs diff --git a/src/rflags.rs b/src/bits64/rflags.rs index 7cf4bbd..7cf4bbd 100644 --- a/src/rflags.rs +++ b/src/bits64/rflags.rs diff --git a/src/segmentation.rs b/src/bits64/segmentation.rs index e46b333..e46b333 100644 --- a/src/segmentation.rs +++ b/src/bits64/segmentation.rs diff --git a/src/sgx.rs b/src/bits64/sgx.rs index e611620..c705e47 100644 --- a/src/sgx.rs +++ b/src/bits64/sgx.rs @@ -6,13 +6,13 @@ /// * Function needs to be executed in ring 0. macro_rules! encls { ($rax:expr, $rbx:expr) - => ( $crate::sgx::encls2($rax as u64, $rbx as u64) ); + => ( $crate::bits64::sgx::encls2($rax as u64, $rbx as u64) ); ($rax:expr, $rbx:expr, $rcx:expr) - => ( $crate::sgx::encls3($rax as u64, $rbx as u64, $rcx as u64) ); + => ( $crate::bits64::sgx::encls3($rax as u64, $rbx as u64, $rcx as u64) ); ($rax:expr, $rbx:expr, $rcx:expr, $rdx:expr) - => ( $crate::sgx::encls4($rax as u64, $rbx as u64, $rcx as u64, $rdx as u64) ); + => ( $crate::bits64::sgx::encls4($rax as u64, $rbx as u64, $rcx as u64, $rdx as u64) ); } /// encls with two arguments -- consider calling the encls! macro instead! @@ -226,10 +226,10 @@ pub unsafe fn encls_ewb(pageinfo: u64, epc_page: u64, va_slot: u64) -> u32 { /// * Function needs to be executed in ring 3. macro_rules! enclu { ($rax:expr, $rbx:expr, $rcx:expr) - => ( $crate::sgx::enclu3($rax as u64, $rbx as u64, $rcx as u64) ); + => ( $crate::bits64::sgx::enclu3($rax as u64, $rbx as u64, $rcx as u64) ); ($rax:expr, $rbx:expr, $rcx:expr, $rdx:expr) - => ( $crate::sgx::enclu4($rax as u64, $rbx as u64, $rcx as u64, $rdx as u64) ); + => ( $crate::bits64::sgx::enclu4($rax as u64, $rbx as u64, $rcx as u64, $rdx as u64) ); } /// enclu with three arguments -- consider calling the enclu! macro instead! diff --git a/src/syscall.rs b/src/bits64/syscall.rs index c554177..c554177 100644 --- a/src/syscall.rs +++ b/src/bits64/syscall.rs diff --git a/src/task.rs b/src/bits64/task.rs index f37bd8d..97d3341 100644 --- a/src/task.rs +++ b/src/bits64/task.rs @@ -1,6 +1,6 @@ //! Helpers to program the task state segment. -use segmentation; +use super::segmentation; pub type TaskStateDescriptorLow = segmentation::SegmentDescriptor; pub type TaskStateDescriptorHigh = u64; diff --git a/src/time.rs b/src/bits64/time.rs index eff567d..eff567d 100644 --- a/src/time.rs +++ b/src/bits64/time.rs diff --git a/src/tlb.rs b/src/bits64/tlb.rs index ec39e3e..6b27e8c 100644 --- a/src/tlb.rs +++ b/src/bits64/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 controlregs::{cr3, cr3_write}; + use super::controlregs::{cr3, cr3_write}; cr3_write(cr3()) } diff --git a/tobba/src/x86_64.rs b/src/bits64/tobba.rs index 64c0efd..2243098 100644 --- a/tobba/src/x86_64.rs +++ b/src/bits64/tobba.rs @@ -1,8 +1,6 @@ #![allow(non_upper_case_globals)] -pub use self::x86_shared::*; - -mod x86_shared; +pub use shared::*; #[inline(always)] pub fn get_flags() -> Flags { @@ -1,11 +1,11 @@ +#![cfg(any(target_arch="x86", target_arch="x86_64"))] + #![feature(const_fn)] #![feature(asm)] +#![feature(associated_consts)] #![no_std] #![cfg_attr(test, allow(unused_features))] -#![crate_name = "x86"] -#![crate_type = "lib"] - #[macro_use] extern crate bitflags; @@ -16,57 +16,14 @@ extern crate raw_cpuid; #[macro_use] extern crate phf; +#[cfg(target_arch="x86")] +pub mod bits32; +#[cfg(target_arch="x86_64")] +pub mod bits64; +pub mod shared; + mod std { pub use core::fmt; pub use core::ops; pub use core::option; } - -macro_rules! bit { - ( $x:expr ) => { - 1 << $x - }; -} - -macro_rules! check_flag { - ($doc:meta, $fun:ident, $flag:ident) => ( - #[$doc] - pub fn $fun(&self) -> bool { - self.contains($flag) - } - ) -} - -macro_rules! is_bit_set { - ($field:expr, $bit:expr) => ( - $field & (1 << $bit) > 0 - ) -} - -macro_rules! check_bit_fn { - ($doc:meta, $fun:ident, $field:ident, $bit:expr) => ( - #[$doc] - pub fn $fun(&self) -> bool { - is_bit_set!(self.$field, $bit) - } - ) -} - -pub mod io; -pub mod controlregs; -pub mod msr; -pub mod time; -pub mod irq; -pub mod rflags; -pub mod paging; -pub mod segmentation; -pub mod task; -pub mod dtables; -pub mod syscall; -pub mod sgx; -#[cfg(feature = "performance-counter")] -pub mod perfcnt; -pub mod cpuid { - pub use raw_cpuid::*; -} -pub mod tlb; diff --git a/tobba/src/x86_shared.rs b/src/shared/mod.rs index 4c1169f..9e5face 100644 --- a/tobba/src/x86_shared.rs +++ b/src/shared/mod.rs @@ -1,3 +1,12 @@ +//! 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)] bitflags! { diff --git a/tobba/.gitignore b/tobba/.gitignore deleted file mode 100644 index 2c96eb1..0000000 --- a/tobba/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target/ -Cargo.lock diff --git a/tobba/Cargo.toml b/tobba/Cargo.toml deleted file mode 100644 index 52a4375..0000000 --- a/tobba/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[project] -name = "cpu" -version = "0.0.1-pre" -authors = [] - -[dependencies] -bitflags = "0.7" diff --git a/tobba/LICENSE b/tobba/LICENSE deleted file mode 100644 index 95521d8..0000000 --- a/tobba/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2015 The libcpu Developers - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE.
\ No newline at end of file diff --git a/tobba/README.md b/tobba/README.md deleted file mode 100644 index 8d46f8e..0000000 --- a/tobba/README.md +++ /dev/null @@ -1,6 +0,0 @@ -libcpu -====== - -Abstracts the messier guts of interfacing with the CPU on a low level in Rust. - -Currently only supports x86, but x86_64 support isn't that far off. diff --git a/tobba/src/lib.rs b/tobba/src/lib.rs deleted file mode 100644 index f18a44d..0000000 --- a/tobba/src/lib.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![cfg(any(target_arch="x86", target_arch="x86_64"))] - -#![no_std] -#![crate_name="cpu"] -#![crate_type="rlib"] -#![feature(asm)] -#![feature(associated_consts)] - -#[macro_use] -extern crate bitflags; - -pub use cpu::*; - -#[cfg(target_arch="x86")] -#[path = "x86.rs"] -mod cpu; -#[cfg(target_arch="x86_64")] -#[path = "x86_64.rs"] -mod cpu; - -pub mod std { pub use core::*; } |