};
#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. */
#else
#include <intrin.h>
-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);
} 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;
}
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
}
uint32_t eax, ebx, ecx, edx;
- ___cpuid(request, &eax, &ebx, &ecx, &edx);
+ get_cpuid(request, &eax, &ebx, &ecx, &edx);
switch (request) {
case CPUID_VENDORID:
}
}
-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());
}
#undef YON
- fclose(file);
return true;
}