Skip to content

Instantly share code, notes, and snippets.

@kivikakk
Created September 1, 2020 13:34
Show Gist options
  • Save kivikakk/c3e16e5bc1370987b2026952017ccb08 to your computer and use it in GitHub Desktop.
Save kivikakk/c3e16e5bc1370987b2026952017ccb08 to your computer and use it in GitHub Desktop.
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