-
Notifications
You must be signed in to change notification settings - Fork 142
Add CPUID instruction #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Nope, it's mostly just figuring out the correct abstraction around the instruction. CPUID does a lot of things, and returns a bunch of different types of data. We will likely need a combination of a "raw" and "non-raw" CPUID function. |
Tbh, I was just thinking of a low level function like this one use core::arch::asm;
/// Runs the CPUID instruction with the provided `eax` register.
///
/// # Returns
///
/// A 4-tuple (eax, ebx, ecx, edx). It's up to the user to interpret these values based on the
/// input.
pub fn cpuid(mut eax: u32) -> (u32, u32, u32, u32) {
let ebx: u32;
let ecx: u32;
let edx: u32;
unsafe {
asm!(
"push rbx",
"cpuid",
"mov esi, ebx",
"pop rbx",
out("esi") ebx,
inout("eax") eax,
out("ecx") ecx,
out("edx") edx
);
}
(eax, ebx, ecx, edx)
} Even this I think would be useful as it's non-trivial given that LLVM uses rbx. |
So they're already are some functions related to CPUID in the standard library
I would want to make sure we're doing something more then just reimplementing them. That could just be providing a safe and/or stable API. Regardless, we should reuse the |
Just wanted to point out that there's already a very good crate that implements abstractions over cpuid: |
@Freax13 That's a really good point. Should we just add a note to the README mentioning that crate? It could be in a "other helper crates" section. |
@Freax13 Thank you for the info. I agree that having that linked in the README would be sufficient in my opinion. |
Fixes #372 Signed-off-by: Joe Richey <[email protected]>
Not sure why this isn't already part of the API, it seems like a very natural instruction to have. Am I missing something?
The text was updated successfully, but these errors were encountered: