static uint32_t REGISTER; \
if (REGISTER == 0) \
REGISTER = fetch_##REGISTER(TYPE); \
- return (REGISTER & feature) == feature; \
+ return !!(REGISTER & feature); \
}
DEFINE_FEATURE_FUNC(ecxfeature, ecx, CPUID_PROCINFO_AND_FEATUREBITS)
#undef DEFINE_FEATURE_FUNC
-static const char *const cpuids[] = {
- "Nooooooooone",
- "AMDisbetter!",
- "AuthenticAMD",
- "CentaurHauls",
- "CyrixInstead",
- "GenuineIntel",
- "TransmetaCPU",
- "GeniuneTMx86",
- "Geode by NSC",
- "NexGenDriven",
- "RiseRiseRise",
- "SiS SiS SiS ",
- "UMC UMC UMC ",
- "VIA VIA VIA ",
- "Vortex86 SoC",
- "KVMKVMKVMKVM"
-};
-
cputype_t cpuid_get_cpu_type(void)
{
static cputype_t cputype;
uint32_t i;
___cpuid(CPUID_VENDORID, &i, &u.bufu32[0], &u.bufu32[2], &u.bufu32[1]);
- for (i = 0; i < sizeof(cpuids) / sizeof(cpuids[0]); ++i) {
- if (strncmp(cpuids[i], u.buf, 12) == 0) {
+ for (i = 0; i < sizeof(c_cpunames) / sizeof(c_cpunames); ++i) {
+ if (strncmp(c_cpunames[i], u.buf, sizeof(c_cpunames[0])) == 0) {
cputype = (cputype_t)i;
break;
}
return cputype;
}
-bool cpuid_sprintf_cputype(const cputype_t cputype, char *buf)
-{
- if (cputype == CT_NONE)
- return false;
-
- memcpy(buf, cpuids[(int)cputype], 12);
- buf[12] = '\0';
- return true;
-}
-
uint32_t cpuid_highest_ext_func_supported(void)
{
static uint32_t highest;
return highest;
}
-void cpuid(cpuid_t info, uint32_t *buf)
+void cpuid(cpuid_t request, uint32_t *buf)
{
/* Sanity checks, make sure we're not trying to do something
* invalid or we are trying to get information that isn't supported
* by the CPU. */
- if (info > CPUID_VIRT_PHYS_ADDR_SIZES || (info > CPUID_HIGHEST_EXTENDED_FUNCTION_SUPPORTED
- && !cpuid_test_feature(info)))
+ if (request > CPUID_VIRT_PHYS_ADDR_SIZES || (request > CPUID_HIGHEST_EXTENDED_FUNCTION_SUPPORTED
+ && !cpuid_test_feature(request)))
return;
- if (info == CPUID_PROC_BRAND_STRING) {
+ 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] );
buf = (uint32_t *)cached;
return;
- } else if (info == CPUID_HIGHEST_EXTENDED_FUNCTION_SUPPORTED) {
+ } else if (request == CPUID_HIGHEST_EXTENDED_FUNCTION_SUPPORTED) {
*buf = cpuid_highest_ext_func_supported();
return;
}
uint32_t eax, ebx, ecx, edx;
- ___cpuid(info, &eax, &ebx, &ecx, &edx);
+ ___cpuid(request, &eax, &ebx, &ecx, &edx);
- switch (info) {
+ switch (request) {
case CPUID_VENDORID:
buf[0] = ebx;
buf[1] = edx;
/*
- * Copyright (c) 2013 Ahmed Samy <f.fallen45@gmail.com>
+ * Copyright (c) 2013, 2015 Ahmed Samy <f.fallen45@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
CT_KVM
} cputype_t;
+static char const *const c_cpunames[] = {
+ "Nooooooooone",
+ "AMDisbetter!",
+ "AuthenticAMD",
+ "CentaurHauls",
+ "CyrixInstead",
+ "GenuineIntel",
+ "TransmetaCPU",
+ "GeniuneTMx86",
+ "Geode by NSC",
+ "NexGenDriven",
+ "RiseRiseRise",
+ "SiS SiS SiS ",
+ "UMC UMC UMC ",
+ "VIA VIA VIA ",
+ "Vortex86 SoC",
+ "KVMKVMKVMKVM"
+};
+
#if defined(__i386__) || defined(__i386) || defined(__x86_64) \
|| defined(_M_AMD64) || defined(__M_X64)
*
* See also: cpuid_get_cpu_type_string()
*/
-#define is_intel_cpu() cpuid_get_cpu_type() == CT_INTEL
-#define is_amd_cpu() cpuid_get_cpu_type() == CT_AMDK5 || cpuid_get_cpu_type() == CT_AMD
cputype_t cpuid_get_cpu_type(void);
-/**
- * cpuid_sprintf_cputype - Get CPU Type string
- * @cputype: a char of atleast 12 bytes in it.
- *
- * Returns true on success, false on failure
- */
-bool cpuid_sprintf_cputype(const cputype_t cputype, char *buf);
+static inline bool is_intel_cpu(void)
+{
+ return cpuid_get_cpu_type() == CT_INTEL;
+}
+
+static inline bool is_amd_cpu(void)
+{
+ return cpuid_get_cpu_type() == CT_AMDK5 || cpuid_get_cpu_type() == CT_AMD;
+}
+
+static inline const char *cpuid_get_name(void)
+{
+ return c_cpunames[(int)cpuid_get_cpu_type()];
+}
/**
* cpuid_is_supported - test if the CPUID instruction is supported
*
* If an invalid flag has been passed a 0xbaadf00d is returned in *buf.
*/
-void cpuid(cpuid_t info, uint32_t *buf);
+void cpuid(cpuid_t request, uint32_t *buf);
/**
* cpuid_write_info - Write specified CPU information to a file.