X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fcpuid%2Fcpuid.c;h=4510def85b2dc0cb87fb0c780615a70da87fdd60;hp=df215eef616a26a45227d0fac7783d51032d5633;hb=29490fe08d33d35f1ac037d905d68028e6e1a075;hpb=ea830cd11ee1f05fd510ea0f97b7c6020d0387df diff --git a/ccan/cpuid/cpuid.c b/ccan/cpuid/cpuid.c index df215eef..4510def8 100644 --- a/ccan/cpuid/cpuid.c +++ b/ccan/cpuid/cpuid.c @@ -37,7 +37,7 @@ enum { }; #ifndef _MSC_VER -static void ___cpuid(cpuid_t info, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) +static void get_cpuid(cpuid_t info, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { __asm__( "xchg %%ebx, %%edi\n\t" /* 32bit PIC: Don't clobber ebx. */ @@ -50,7 +50,7 @@ static void ___cpuid(cpuid_t info, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, #else #include -static void ___cpuid(cpuid_t info, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) +static void get_cpuid(cpuid_t info, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { uint32_t registers[4]; __cpuid(registers, info); @@ -236,9 +236,9 @@ cputype_t cpuid_get_cpu_type(void) } u; uint32_t i; - ___cpuid(CPUID_VENDORID, &i, &u.bufu32[0], &u.bufu32[2], &u.bufu32[1]); - for (i = 0; i < sizeof(c_cpunames) / sizeof(c_cpunames); ++i) { - if (strncmp(c_cpunames[i], u.buf, sizeof(c_cpunames[0])) == 0) { + get_cpuid(CPUID_VENDORID, &i, &u.bufu32[0], &u.bufu32[2], &u.bufu32[1]); + for (i = 0; i < sizeof(c_cpunames) / sizeof(c_cpunames[0]); ++i) { + if (strncmp(c_cpunames[i], u.buf, 12) == 0) { cputype = (cputype_t)i; break; } @@ -283,9 +283,9 @@ void cpuid(cpuid_t request, uint32_t *buf) if (request == CPUID_PROC_BRAND_STRING) { static char cached[48] = { 0 }; if (cached[0] == '\0') { - ___cpuid(CPUID_PROC_BRAND_STRING, &buf[0], &buf[1], &buf[2], &buf[3] ); - ___cpuid(CPUID_PROC_BRAND_STRING_INTERNAL0, &buf[4], &buf[5], &buf[6], &buf[7] ); - ___cpuid(CPUID_PROC_BRAND_STRING_INTERNAL1, &buf[8], &buf[9], &buf[10], &buf[11]); + get_cpuid(CPUID_PROC_BRAND_STRING, &buf[0], &buf[1], &buf[2], &buf[3] ); + get_cpuid(CPUID_PROC_BRAND_STRING_INTERNAL0, &buf[4], &buf[5], &buf[6], &buf[7] ); + get_cpuid(CPUID_PROC_BRAND_STRING_INTERNAL1, &buf[8], &buf[9], &buf[10], &buf[11]); memcpy(cached, buf, sizeof cached); } else @@ -298,7 +298,7 @@ void cpuid(cpuid_t request, uint32_t *buf) } uint32_t eax, ebx, ecx, edx; - ___cpuid(request, &eax, &ebx, &ecx, &edx); + get_cpuid(request, &eax, &ebx, &ecx, &edx); switch (request) { case CPUID_VENDORID: @@ -368,32 +368,12 @@ void cpuid(cpuid_t request, uint32_t *buf) } } -bool cpuid_write_info(uint32_t info, uint32_t featureset, const char *outfile) +bool cpuid_write_info(uint32_t info, uint32_t featureset, FILE *file) { - FILE *file; - char filename[256]; - char cpu_information[64]; - - if (!cpuid_sprintf_cputype(cpuid_get_cpu_type(), cpu_information)) - return false; - char brand[48]; cpuid(CPUID_PROC_BRAND_STRING, (uint32_t *)brand); - cpu_information[12] = '_'; - memcpy(&cpu_information[13], brand, sizeof brand); - - if (!outfile) - strncpy(filename, cpu_information, sizeof cpu_information); - else - strncpy(filename, outfile, sizeof filename); - - file = fopen(filename, "w"); - if (!file) - return false; - - fprintf(file, "-- CPU Information for CPU: %s --\n\n", cpu_information); - + fprintf(file, "-- CPU Information for: %s_%s --\n\n", cpuid_get_name(), brand); if (info & CPUID_HIGHEST_EXTENDED_FUNCTION_SUPPORTED) fprintf(file, "Highest extended function supported: %#010x\n\n", cpuid_highest_ext_func_supported()); @@ -675,7 +655,6 @@ bool cpuid_write_info(uint32_t info, uint32_t featureset, const char *outfile) } #undef YON - fclose(file); return true; }