Created
December 16, 2015 17:48
-
-
Save strangeglyph/67b425f2263222202c47 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
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 |
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
#[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