aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Gerd Zellweger <mail@gerdzellweger.com> 2015-07-19 17:44:22 -0700
committerGravatar Gerd Zellweger <mail@gerdzellweger.com> 2015-07-19 17:44:22 -0700
commitfa51a23a6560dd0efca36ef976163f05e7f6fc12 (patch)
tree93917cb1c43861e492feabf03eafed147851c8b3
parent8ec4efcabce0f669facdfe04172552d2a5004544 (diff)
downloadrust-x86-fa51a23a6560dd0efca36ef976163f05e7f6fc12.tar.gz
rust-x86-fa51a23a6560dd0efca36ef976163f05e7f6fc12.tar.zst
rust-x86-fa51a23a6560dd0efca36ef976163f05e7f6fc12.zip
Update documentation, use raw_cpuid crate.
-rw-r--r--Cargo.toml12
-rw-r--r--LICENSE26
-rw-r--r--README.md13
-rw-r--r--src/cpuid.rs79
-rw-r--r--src/lib.rs7
5 files changed, 39 insertions, 98 deletions
diff --git a/Cargo.toml b/Cargo.toml
index cde4b5c..4c84647 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,15 +1,19 @@
[package]
name = "x86"
-version = "0.1.1"
+version = "0.2.0"
authors = ["Gerd Zellweger <mail@gerdzellweger.com>"]
-description = "Library to program x86 (amd64) hardware. Contains x86 specific data structure descriptions, as well as convenience function to call assembly instructions typically not exposed in higher level languages."
+description = "Library to program x86 (amd64) hardware. Contains x86 specific data structure descriptions, data-tables, as well as convenience function to call assembly instructions typically not exposed in higher level languages."
+
+homepage = "https://github.com/gz/rust-x86"
repository = "https://github.com/gz/rust-x86"
+documentation = "http://gz.github.io/rust-x86/x86/"
readme = "README.md"
-keywords = ["ia32", "os", "amd64", "x86"]
-license = "WTFPL"
+keywords = ["ia32", "os", "amd64", "x86", "x86-64"]
+license = "MIT"
[dependencies]
bitflags = "0.1.0"
+raw-cpuid = "1.*" \ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 9031bba..e734b14 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,11 +1,21 @@
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- Version 2, December 2004
+The MIT License (MIT)
-Everyone is permitted to copy and distribute verbatim or modified
-copies of this license document, and changing it is allowed as long
-as the name is changed.
+Copyright (c) 2015 Gerd Zellweger
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+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:
- 0. You just DO WHAT THE FUCK YOU WANT TO. \ No newline at end of file
+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/README.md b/README.md
index 74f5749..32bfca5 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,6 @@
-# x86 / amd64 library
+# x86 / amd64 library [![Build Status](https://travis-ci.org/gz/rust-x86.svg)](https://travis-ci.org/gz/rust-x86) [![Crates.io](https://img.shields.io/crates/v/x86.svg)](https://crates.io/crates/x86)
-[![Build Status](https://travis-ci.org/gz/rust-x86.svg)](https://travis-ci.org/gz/rust-x86)
-
-This is a low level library that provides only the most basic wrapper functions
-for assembly instructions, defines etc. for x86 hardware.
+Library to program x86 (amd64) hardware. Contains x86 specific data structure descriptions, data-tables, as well as convenience function to call assembly instructions typically not exposed in higher level languages.
Currently supports
* I/O registers
@@ -14,5 +11,9 @@ Currently supports
* IA32-e page table layout
* Interrupts
* Task state
+ * Querying CPUID (uses [raw_cpuid](https://github.com/gz/rust-cpuid) library)
+
+This library depends on libcore so it can be used in kernel level code.
-This only depends on libcore so it can be used in kernel level code.
+## Documentation
+ * [API Documentation](http://gz.github.io/rust-x86/x86/) \ No newline at end of file
diff --git a/src/cpuid.rs b/src/cpuid.rs
deleted file mode 100644
index 3aee708..0000000
--- a/src/cpuid.rs
+++ /dev/null
@@ -1,79 +0,0 @@
-pub use core::prelude::*;
-
-const MAX_ENTRIES: usize = 32;
-
-#[derive(Debug)]
-pub struct CpuId {
- values: [CpuIdResult; MAX_ENTRIES]
-}
-
-#[derive(Debug, Copy, Clone)]
-pub struct CpuIdResult {
- pub eax: u32,
- pub ebx: u32,
- pub ecx: u32,
- pub edx: u32
-}
-
-impl CpuId {
- pub fn new() -> CpuId {
- let mut cpu = CpuId{ values: [ CpuIdResult{ eax: 0, ebx: 0, ecx: 0, edx: 0}; MAX_ENTRIES] };
-
- unsafe {
- cpu.values[0] = cpuid(0x0);
- assert!( (cpu.values[0].eax as usize) < MAX_ENTRIES);
- for i in 1..(cpu.values[0].eax as usize) {
- cpu.values[i] = cpuid(i as u32);
- }
- }
-
- cpu
- }
-
- pub fn get(&self, eax: usize) -> &CpuIdResult {
- return &self.values[eax];
- }
-}
-
-pub unsafe fn cpuid(eax: u32) -> CpuIdResult {
- asm!("movl $0, %eax" : : "r" (eax) : "eax");
-
- let mut res = CpuIdResult{eax: 0, ebx: 0, ecx: 0, edx: 0};
- asm!("cpuid" : "={eax}"(res.eax) "={ebx}"(res.ebx) "={ecx}"(res.ecx) "={edx}"(res.edx)
- :
- : "eax", "ebx", "ecx", "edx");
-
- res
-}
-
-#[cfg(test)]
-fn to_bytes(val: u32) -> [u8; 4] {
- let mut res: [u8; 4] = [0; 4];
-
- res[0] = val as u8;
- res[1] = (val >> 8) as u8;
- res[2] = (val >> 16) as u8;
- res[3] = (val >> 24) as u8;
- res
-}
-
-#[cfg(test)]
-fn to_str(t: [u8; 4]) -> [char; 4] {
- let mut arr: [char; 4] = ['\0'; 4];
- for i in 0..4 {
- arr[i] = t[i] as char;
- }
-
- arr
-}
-
-#[test]
-fn genuine_intel() {
- let cpu: CpuId = CpuId::new();
-
- let b = to_str(to_bytes(cpu.values[0].ebx));
- assert!(b[0] == 'G');
- assert!(b[1] == 'e');
- assert!(b[2] == 'n');
- assert!(b[3] == 'u');
-} \ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
index 393e346..f4f4e6d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -13,6 +13,9 @@ extern crate core;
#[macro_use]
extern crate bitflags;
+#[macro_use]
+extern crate raw_cpuid;
+
#[cfg(test)]
extern crate std;
@@ -33,4 +36,6 @@ pub mod segmentation;
pub mod task;
pub mod dtables;
pub mod syscall;
-pub mod cpuid; \ No newline at end of file
+pub mod cpuid {
+ pub use raw_cpuid::*;
+} \ No newline at end of file