Advertisement
pasholnahuy

1

Nov 20th, 2023
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <cpuid.h>
  2. #include <stdio.h>
  3.  
  4. enum {
  5. CONST4b = 0b1111,
  6. CONST4 = 4,
  7. CONST2b = 0b11,
  8. CONST8b = 0b11111111,
  9. CONST8 = 8,
  10. CONST6 = 6,
  11. CONST15 = 15
  12. };
  13.  
  14. int main() {
  15. int v1, v2, v3;
  16. __asm__("mov $1, %%eax\n\t"
  17. "cpuid"
  18. : "=a"(v1), "=c"(v2), "=d"(v3)
  19. :
  20. : "ebx");
  21. // int stepping_id = v1 && CONST4b;
  22. v1 = (v1 >> CONST4);
  23. int model = v1 & CONST4b;
  24. v1 = (v1 >> CONST4);
  25. int family_id = v1 & CONST4b;
  26. v1 = (v1 >> CONST4);
  27. // int processor_type = v1 & CONST2b;
  28. v1 = (v1 >> CONST4);
  29. int extended_model_id = v1 & CONST4b;
  30. v1 = (v1 >> CONST4);
  31. // int extended_family_id = v1 & CONST8b;
  32. v1 = (v1 >> CONST8);
  33. int processor_model = 0;
  34. if (family_id == CONST6 || family_id == CONST15) {
  35. processor_model = (extended_model_id << CONST4) + model;
  36. } else {
  37. processor_model = model;
  38. }
  39. printf("family=%d model=%d ecx=0x%x edx=0x%x\n", family_id, processor_model,
  40. v2, v3);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement