From 54066ddbb70fa4b8f2344300f91dd1c69a4e1d99 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Sun, 12 Mar 2017 14:46:02 -0500 Subject: [PATCH] OS.h: Add AMD Ryzen CPU name identification. * Update cpuidtool.c to new post-smp rework name calculation --- headers/private/shared/cpu_type.h | 12 ++++++++++- src/tools/cpuidtool.c | 36 ++++++++----------------------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/headers/private/shared/cpu_type.h b/headers/private/shared/cpu_type.h index be64e2be98..478fbd0989 100644 --- a/headers/private/shared/cpu_type.h +++ b/headers/private/shared/cpu_type.h @@ -255,6 +255,15 @@ get_cpu_model_string(enum cpu_platform platform, enum cpu_vendor cpuVendor, if (platform != B_CPU_x86 && platform != B_CPU_x86_64) return NULL; + // XXX: This *really* isn't accurate. There is differing math + // based on the CPU vendor.. Don't use these numbers anywhere + // except "fast and dumb" identification of processor names. + // + // see cpuidtool.c to decode cpuid signatures (sysinfo) into a + // value for this function. + // + // sysinfo has code in it which obtains the proper fam/mod/step ids + uint16 family = ((cpuModel >> 8) & 0xf) | ((cpuModel >> 16) & 0xff0); uint16 model = ((cpuModel >> 4) & 0xf) | ((cpuModel >> 12) & 0xf0); uint8 stepping = cpuModel & 0xf; @@ -315,7 +324,8 @@ get_cpu_model_string(enum cpu_platform platform, enum cpu_vendor cpuVendor, return "FX-Series"; if (model == 0x10 || model == 0x13) return "A-Series"; - } + } else if (family == 0x8f) + return "Ryzen 7" // Fallback to manual parsing of the model string get_cpuid_model_string(cpuidName); diff --git a/src/tools/cpuidtool.c b/src/tools/cpuidtool.c index 570fd79be9..326c3a98a8 100644 --- a/src/tools/cpuidtool.c +++ b/src/tools/cpuidtool.c @@ -7,7 +7,7 @@ */ /* - * Pass a standard CPUID in hex, and get out a CPUID for OS.h + * Pass a standard CPUID in hex, and get out a CPUID for cpu_type.h */ @@ -71,41 +71,23 @@ xtoi(const char* xs, unsigned int* result) int main(int argc, char *argv[]) { - if (argc != 3) { + if (argc != 2) { printf("Provide the cpuid in hex, and you will get how we id it\n"); - printf("usage: cpuidhaiku \n"); + printf("usage: cpuidhaiku \n"); return 1; } unsigned int cpuid = 0; - xtoi(argv[2], &cpuid); + xtoi(argv[1], &cpuid); printf("cpuid: 0x%X\n", cpuid); - unsigned int extFam = (cpuid & EXT_FAMILY_MASK) >> 20; - unsigned int extMod = (cpuid & EXT_MODEL_MASK) >> 16; - unsigned int family = (cpuid & FAMILY_MASK) >> 8; - unsigned int model = (cpuid & MODEL_MASK) >> 4; - unsigned int stepping = (cpuid & STEPPING_MASK); + int family = ((cpuid >> 8) & 0xf) | ((cpuid >> 16) & 0xff0); + int model = ((cpuid >> 4) & 0xf) | ((cpuid >> 12) & 0xf0); + int stepping = cpuid & 0xf; - unsigned int cpuidHaiku; - if (strncmp(argv[1], "AMD", 3) == 0) { - if (family == 0xF) { - cpuidHaiku = (extFam << 20) + (extMod << 16) - + (family << 4) + model; - } else - cpuidHaiku = (family << 4) + model; - cpuidHaiku += 0x1100; // AMD vendor id - } else if (strncmp(argv[1], "INTEL", 5) == 0) { - cpuidHaiku = (extFam << 20) + (extMod << 16) - + (family << 4) + model; - cpuidHaiku += 0x1000; // Intel vendor id - } else { - printf("Vendor should be AMD or INTEL\n"); - return 1; - } - - printf("Haiku CPUID: 0x%lx\n", cpuidHaiku); + printf("Haiku CPUID: Family: 0x%x, Model: 0x%x, Stepping: 0x%x\n", family, + model, stepping); return 0; }