Created
August 20, 2018 15:49
-
-
Save colesbury/68ce5ededb6b48998af8a41ca326246b 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
#include <stdio.h> | |
static inline void native_cpuid(unsigned int *eax, unsigned int *ebx, | |
unsigned int *ecx, unsigned int *edx) | |
{ | |
/* ecx is often an input as well as an output. */ | |
asm volatile("cpuid" | |
: "=a" (*eax), | |
"=b" (*ebx), | |
"=c" (*ecx), | |
"=d" (*edx) | |
: "0" (*eax), "2" (*ecx)); | |
} | |
int main(int argc, char **argv) | |
{ | |
unsigned eax, ebx, ecx, edx; | |
eax = 1; /* processor info and feature bits */ | |
native_cpuid(&eax, &ebx, &ecx, &edx); | |
printf("stepping %d\n", eax & 0xF); | |
printf("model %d\n", (eax >> 4) & 0xF); | |
printf("family %d\n", (eax >> 8) & 0xF); | |
printf("processor type %d\n", (eax >> 12) & 0x3); | |
printf("extended model %d\n", (eax >> 16) & 0xF); | |
printf("extended family %d\n", (eax >> 20) & 0xFF); | |
eax = 3; /* processor serial number */ | |
native_cpuid(&eax, &ebx, &ecx, &edx); | |
/** see the CPUID Wikipedia article on which models return the serial | |
number in which registers. The example here is for | |
Pentium III */ | |
printf("serial number 0x%08x%08x\n", edx, ecx); | |
eax = 3; /* processor serial number */ | |
native_cpuid(&eax, &ebx, &ecx, &edx); | |
/** see the CPUID Wikipedia article on which models return the serial | |
number in which registers. The example here is for | |
Pentium III */ | |
printf("serial number 0x%08x%08x\n", edx, ecx); | |
eax = 0x80000000; /* Get Highest Extended Function Supported */ | |
native_cpuid(&eax, &ebx, &ecx, &edx); | |
printf("extended support: 0x%08x\n", eax); | |
eax = 0x80000001; /* Extended Processor Info and Feature Bits */ | |
native_cpuid(&eax, &ebx, &ecx, &edx); | |
printf("extended support: ecx 0x%08x edx 0x%08x\n", ecx, edx); | |
printf("FMA4 support: %d\n", (ecx & (1 << 16)) != 0); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment