Skip to content

Instantly share code, notes, and snippets.

@strangeglyph
Created December 16, 2015 17:48
Show Gist options
  • Save strangeglyph/67b425f2263222202c47 to your computer and use it in GitHub Desktop.
Save strangeglyph/67b425f2263222202c47 to your computer and use it in GitHub Desktop.
global internal_cpuid
section .text
bits 64
; params:
; rdi - cpuid call
; rsi - pointer to a continous 16 bytes of memory
; which will be filled
internal_cpuid:
; save frame pointer and callee-save ebx
push rbp
mov rbp, rsp
push rbx
; cpuid call - 0 = vendor id
mov eax, rdi
cpuid
mov dword [rsi], eax
mov dword [rsi+4], ebx
mov dword [rsi+8], ecx
mov dword [rsi+12], edx
pop rbx
pop rbp
ret
#[repr(C, packed)]
struct CpuIdResult {
eax: u32,
ebx: u32,
ecx: u32,
edx: u32
}
fn cpuid(id: u32) -> CpuIdResult {
let mut result = CpuIdResult {
eax: 0,
ebx: 0,
ecx: 0,
edx: 0,
};
unsafe {
internal_cpuid(&mut result);
}
result;
}
#[link(name = "cpuid")]
extern {
pub fn internal_cpuid(ptr: *mut CpuIdResult);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment