Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1.  
  2.  
  3. static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
  4. unsigned int *ecx, unsigned int *edx)
  5. {
  6. /* ecx is often an input as well as an output. */
  7. asm volatile("cpuid": "=a" (*eax),"=b" (*ebx),"=c" (*ecx),"=d" (*edx): "0" (*eax), "2" (*ecx): "memory");
  8. }
  9. int main(int argc, char **argv) {
  10. // Code snippet
  11. unsigned eax, ebx, ecx, edx;
  12. // for obtaining the features
  13. eax = 0; /* processor info and feature bits */
  14. native_cpuid(&eax, &ebx, &ecx, &edx);
  15. printf("Vendor ID ");
  16. printf("%c%c%c%c", (ebx) & 0xFF, (ebx>>8) & 0xFF, (ebx>>16) & 0xFF, (ebx>>24) &0xFF);
  17. printf("%c%c%c%c", (edx) & 0xFF, (edx>>8) & 0xFF, (edx>>16) & 0xFF, (edx>>24) &0xFF);
  18. printf("%c%c%c%c", (ecx) & 0xFF, (ecx>>8) & 0xFF, (ecx>>16) & 0xFF, (ecx>>24) &0xFF);
  19. printf("\n");
  20. // for obtaining the features
  21. eax = 1; /* processor info and feature bits */
  22. native_cpuid(&eax, &ebx, &ecx, &edx);
  23. printf("stepping %d\n", eax & 0xF);
  24. printf("model %d\n", (eax >> 4) & 0xF);
  25. printf("family %d\n", (eax >> 8) & 0xF);
  26. printf("processor type %d\n", (eax >> 12) & 0x3);
  27. printf("extended model %d\n", (eax >> 16) & 0xF);
  28. printf("extended family %d\n", (eax >> 20) & 0xFF);
  29. // for obtaining the serial number
  30. eax = 3; /* processor serial number */
  31. native_cpuid(&eax, &ebx, &ecx, &edx);
  32. printf("serial number 0x%08x%08x\n", edx, ecx);
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement