diff --git a/helper_functions.c b/helper_functions.c index f16c060..3503035 100644 --- a/helper_functions.c +++ b/helper_functions.c @@ -87,41 +87,38 @@ print_family_info (struct family_info *proc_info) // printf(" Extended Family %d\n", proc_info->extended_family); } +static inline void cpuid (unsigned int info, unsigned int *eax, unsigned int *ebx, + unsigned int *ecx, unsigned int *edx) +{ + unsigned int _eax = info, _ebx, _ecx, _edx; + asm volatile ("mov %%ebx, %%edi;" // save ebx (for PIC) + "cpuid;" + "mov %%ebx, %%esi;" // pass to caller + "mov %%edi, %%ebx;" // restore ebx + :"+a" (_eax), "=S" (_ebx), "=c" (_ecx), "=d" (_edx)); + if (eax) *eax = _eax; + if (ebx) *ebx = _ebx; + if (ecx) *ecx = _ecx; + if (edx) *edx = _edx; +} -#ifdef x64_BIT void get_vendor (char *vendor_string) { //get vendor name - unsigned int b, c, d, e; - // int i; - asm volatile ("mov %4, %%eax; " // 0 into eax - "cpuid;" "mov %%eax, %0;" // eeax into b - "mov %%ebx, %1;" // eebx into c - "mov %%edx, %2;" // eeax into d - "mov %%ecx, %3;" // eeax into e - :"=r" (b), "=r" (c), "=r" (d), "=r" (e) /* output */ - :"r" (0) /* input */ - :"%eax", "%ebx", "%ecx", "%edx" /* clobbered register, will be modifying inside the asm routine so dont use them */ - ); - memcpy (vendor_string, &c, 4); + unsigned int a, b, c, d; + cpuid (0, &a, &b, &c, &d); + memcpy (vendor_string, &b, 4); memcpy (vendor_string + 4, &d, 4); - memcpy (vendor_string + 8, &e, 4); + memcpy (vendor_string + 8, &c, 4); vendor_string[12] = '\0'; // printf("Vendor %s\n",vendor_string); } -#endif int turbo_status () { //turbo state flag unsigned int eax; - // int i; - asm volatile ("mov %1, %%eax; " // 0 into eax - "cpuid;" "mov %%eax, %0;" // eeax into b - :"=r" (eax) /* output */ - :"r" (6) /* input */ - :"%eax" /* clobbered register, will be modifying inside the asm routine so dont use them */ - ); + cpuid (6, &eax, NULL, NULL, NULL); //printf("eax %d\n",(eax&0x2)>>1); @@ -132,12 +129,7 @@ void get_familyinformation (struct family_info *proc_info) { //get info about CPU unsigned int b; - asm volatile ("mov %1, %%eax; " // 0 into eax - "cpuid;" "mov %%eax, %0;" // eeax into b - :"=r" (b) /* output */ - :"r" (1) /* input */ - :"%eax" /* clobbered register, will be modifying inside the asm routine so dont use them */ - ); + cpuid (1, &b, NULL, NULL, NULL); // printf ("eax %x\n", b); proc_info->stepping = b & 0x0000000F; //bits 3:0 proc_info->model = (b & 0x000000F0) >> 4; //bits 7:4 @@ -348,7 +340,6 @@ void Print_Information_Processor(bool* nehalem, bool* sandy_bridge) { struct family_info proc_info; -#ifdef x64_BIT char vendor_string[13]; get_vendor (vendor_string); if (strcmp (vendor_string, "GenuineIntel") == 0) @@ -359,14 +350,6 @@ void Print_Information_Processor(bool* nehalem, bool* sandy_bridge) ("this was designed to be a intel proc utility. You can perhaps mod it for your machine?\n"); exit (1); } -#endif - -#ifndef x64_BIT - //anecdotal evidence: get_vendor doesnt seem to work on 32-bit - printf - ("I dont know the CPUID code to check on 32-bit OS, so i will assume that you have an Intel processor\n"); - printf ("Don't worry if i don't find a nehalem next, i'll quit anyways\n"); -#endif get_familyinformation (&proc_info); print_family_info (&proc_info); diff --git a/i7z b/i7z index a590622..f82d8b4 100755 Binary files a/i7z and b/i7z differ diff --git a/i7z.h b/i7z.h index b088e6c..a7da910 100644 --- a/i7z.h +++ b/i7z.h @@ -106,9 +106,7 @@ __asm__ __volatile__ ("rdtsc":"=a" (lo), "=d" (hi)); void print_family_info (struct family_info *proc_info); -#ifdef x64_BIT void get_vendor (char *vendor_string); -#endif int turbo_status (); double cpufreq_info();