diff options
Diffstat (limited to 'x86_64')
-rw-r--r-- | x86_64/Cargo.toml | 4 | ||||
-rw-r--r-- | x86_64/build.rs | 7 | ||||
-rw-r--r-- | x86_64/host_cpuid.c | 11 | ||||
-rw-r--r-- | x86_64/src/cpuid.rs | 70 |
4 files changed, 15 insertions, 77 deletions
diff --git a/x86_64/Cargo.toml b/x86_64/Cargo.toml index e5d5e14..3f5ba3e 100644 --- a/x86_64/Cargo.toml +++ b/x86_64/Cargo.toml @@ -3,7 +3,6 @@ name = "x86_64" version = "0.1.0" authors = ["The Chromium OS Authors"] edition = "2018" -build = "build.rs" [dependencies] arch = { path = "../arch" } @@ -20,6 +19,3 @@ remain = "*" resources = { path = "../resources" } sync = { path = "../sync" } sys_util = { path = "../sys_util" } - -[build-dependencies] -cc = "=1.0.25" diff --git a/x86_64/build.rs b/x86_64/build.rs deleted file mode 100644 index 5f2c1eb..0000000 --- a/x86_64/build.rs +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2018 The Chromium OS Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -fn main() { - cc::Build::new().file("host_cpuid.c").compile("host_cpuid"); -} diff --git a/x86_64/host_cpuid.c b/x86_64/host_cpuid.c deleted file mode 100644 index 3230c90..0000000 --- a/x86_64/host_cpuid.c +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2018 The Chromium OS Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include <stdint.h> - -void host_cpuid(uint32_t func, uint32_t func2, uint32_t *pEax, - uint32_t *pEbx, uint32_t *pEcx, uint32_t *pEdx) { - asm volatile("cpuid" : "=a"(*pEax), "=b"(*pEbx), "=c"(*pEcx), "=d"(*pEdx) : - "0"(func), "2"(func2) : "cc"); -} diff --git a/x86_64/src/cpuid.rs b/x86_64/src/cpuid.rs index a42b662..46294b2 100644 --- a/x86_64/src/cpuid.rs +++ b/x86_64/src/cpuid.rs @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +use std::arch::x86_64::{__cpuid, __cpuid_count}; use std::fmt::{self, Display}; use std::result; @@ -28,19 +29,6 @@ impl Display for Error { } } -// This function is implemented in C because stable rustc does not -// support inline assembly. -extern "C" { - fn host_cpuid( - func: u32, - func2: u32, - rEax: *mut u32, - rEbx: *mut u32, - rEcx: *mut u32, - rEdx: *mut u32, - ) -> (); -} - // CPUID bits in ebx, ecx, and edx. const EBX_CLFLUSH_CACHELINE: u32 = 8; // Flush a cache line size. const EBX_CLFLUSH_SIZE_SHIFT: u32 = 8; // Bytes flushed when executing CLFLUSH. @@ -77,25 +65,19 @@ fn filter_cpuid( } } 2 | 0x80000005 | 0x80000006 => unsafe { - host_cpuid( - entry.function, - 0, - &mut entry.eax as *mut u32, - &mut entry.ebx as *mut u32, - &mut entry.ecx as *mut u32, - &mut entry.edx as *mut u32, - ); + let result = __cpuid(entry.function); + entry.eax = result.eax; + entry.ebx = result.ebx; + entry.ecx = result.ecx; + entry.edx = result.edx; }, 4 => { unsafe { - host_cpuid( - entry.function, - entry.index, - &mut entry.eax as *mut u32, - &mut entry.ebx as *mut u32, - &mut entry.ecx as *mut u32, - &mut entry.edx as *mut u32, - ); + let result = __cpuid_count(entry.function, entry.index); + entry.eax = result.eax; + entry.ebx = result.ebx; + entry.ecx = result.ecx; + entry.edx = result.edx; } entry.eax &= !0xFC000000; } @@ -132,34 +114,12 @@ pub fn setup_cpuid(kvm: &kvm::Kvm, vcpu: &kvm::Vcpu, cpu_id: u64, nrcpus: u64) - /// get host cpu max physical address bits pub fn phy_max_address_bits() -> u32 { - let mut eax: u32 = 0; - let mut ebx: u32 = 0; - let mut ecx: u32 = 0; - let mut edx: u32 = 0; let mut phys_bits: u32 = 36; - unsafe { - host_cpuid( - 0x80000000, - 0, - &mut eax as *mut u32, - &mut ebx as *mut u32, - &mut ecx as *mut u32, - &mut edx as *mut u32, - ); - } - if eax >= 0x80000008 { - unsafe { - host_cpuid( - 0x80000008, - 0, - &mut eax as *mut u32, - &mut ebx as *mut u32, - &mut ecx as *mut u32, - &mut edx as *mut u32, - ); - } - phys_bits = eax & 0xff; + let highest_ext_function = unsafe { __cpuid(0x80000000) }; + if highest_ext_function.eax >= 0x80000008 { + let addr_size = unsafe { __cpuid(0x80000008) }; + phys_bits = addr_size.eax & 0xff; } phys_bits |