| 1 |
#include "stdio.h" |
| 2 |
#include "memory.h" |
| 3 |
|
| 4 |
static inline void cpuid (unsigned int info, unsigned int *eax, unsigned int *ebx, |
| 5 |
unsigned int *ecx, unsigned int *edx) |
| 6 |
{ |
| 7 |
unsigned int _eax = info, _ebx, _ecx, _edx; |
| 8 |
asm volatile ("mov %%ebx, %%edi;" // save ebx (for PIC) |
| 9 |
"cpuid;" |
| 10 |
"mov %%ebx, %%esi;" // pass to caller |
| 11 |
"mov %%edi, %%ebx;" // restore ebx |
| 12 |
:"+a" (_eax), "=S" (_ebx), "=c" (_ecx), "=d" (_edx) |
| 13 |
: /* inputs: eax is handled above */ |
| 14 |
:"edi" /* clobbers: we hit edi directly */); |
| 15 |
if (eax) *eax = _eax; |
| 16 |
if (ebx) *ebx = _ebx; |
| 17 |
if (ecx) *ecx = _ecx; |
| 18 |
if (edx) *edx = _edx; |
| 19 |
} |
| 20 |
|
| 21 |
void get_familyinformation () |
| 22 |
{ |
| 23 |
unsigned int a, b, c, d; |
| 24 |
// earlier i thought that NULL was the issue but |
| 25 |
cpuid (1, &b, NULL, NULL, NULL); |
| 26 |
//cpuid (1, &b, &a, &c, &d); |
| 27 |
// printf ("eax %x\n", b); |
| 28 |
/* |
| 29 |
proc_info->stepping = b & 0x0000000F; //bits 3:0 |
| 30 |
proc_info->model = (b & 0x000000F0) >> 4; //bits 7:4 |
| 31 |
proc_info->family = (b & 0x00000F00) >> 8; //bits 11:8 |
| 32 |
proc_info->processor_type = (b & 0x00007000) >> 12; //bits 13:12 |
| 33 |
proc_info->extended_model = (b & 0x000F0000) >> 16; //bits 19:16 |
| 34 |
proc_info->extended_family = (b & 0x0FF00000) >> 20; //bits 27:20 |
| 35 |
*/ |
| 36 |
} |
| 37 |
void get_vendor (char *vendor_string) |
| 38 |
{ |
| 39 |
//get vendor name |
| 40 |
unsigned int a, b, c, d; |
| 41 |
cpuid (0, &a, &b, &c, &d); |
| 42 |
memcpy (vendor_string, &b, 4); |
| 43 |
memcpy (&vendor_string[4], &d, 4); |
| 44 |
memcpy (&vendor_string[8], &c, 4); |
| 45 |
vendor_string[12] = '\0'; |
| 46 |
// printf("Vendor %s\n",vendor_string); |
| 47 |
} |
| 48 |
|
| 49 |
int main() |
| 50 |
{ |
| 51 |
printf("i will print success on quitting\n"); |
| 52 |
fflush(stdout); |
| 53 |
|
| 54 |
char vendor_string[13]; |
| 55 |
get_vendor(vendor_string); |
| 56 |
|
| 57 |
if ((strcmp (vendor_string, "GenuineIntel") == 0)) { |
| 58 |
printf ("i7z DEBUG: Found Intel Processor\n"); |
| 59 |
} else { |
| 60 |
printf |
| 61 |
("this was designed to be a intel proc utility. You can perhaps mod it for your machine?\n"); |
| 62 |
} |
| 63 |
|
| 64 |
get_familyinformation(); |
| 65 |
|
| 66 |
printf("working\n"); |
| 67 |
fflush(stdout); |
| 68 |
} |