diff options
author | 2015-07-19 17:44:22 -0700 | |
---|---|---|
committer | 2015-07-19 17:44:22 -0700 | |
commit | fa51a23a6560dd0efca36ef976163f05e7f6fc12 (patch) | |
tree | 93917cb1c43861e492feabf03eafed147851c8b3 /src | |
parent | 8ec4efcabce0f669facdfe04172552d2a5004544 (diff) | |
download | rust-x86-fa51a23a6560dd0efca36ef976163f05e7f6fc12.tar.gz rust-x86-fa51a23a6560dd0efca36ef976163f05e7f6fc12.tar.zst rust-x86-fa51a23a6560dd0efca36ef976163f05e7f6fc12.zip |
Update documentation, use raw_cpuid crate.
Diffstat (limited to 'src')
-rw-r--r-- | src/cpuid.rs | 79 | ||||
-rw-r--r-- | src/lib.rs | 7 |
2 files changed, 6 insertions, 80 deletions
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 @@ -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 |