Created
September 1, 2020 13:34
-
-
Save kivikakk/c3e16e5bc1370987b2026952017ccb08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn cpuid(leaf_id: u32) [16]u8 { | |
var result: [16]u8 = undefined; | |
asm volatile ( | |
\\ cpuid | |
\\ movl %%eax, 0(%[leaf_ptr]) | |
\\ movl %%ebx, 4(%[leaf_ptr]) | |
\\ movl %%ecx, 8(%[leaf_ptr]) | |
\\ movl %%edx, 12(%[leaf_ptr]) | |
: | |
: [leaf_id] "{eax}" (leaf_id), | |
[subid] "{ecx}" (@as(u32, 0)), | |
[leaf_ptr] "r" (&result) | |
: "eax", "ebx", "ecx", "edx" | |
); | |
return result; | |
} | |
pub fn main() !void { | |
@import("std").debug.print("{}{}{}\n", .{ | |
cpuid(0x80000002), | |
cpuid(0x80000003), | |
cpuid(0x80000004), | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment