diff --git a/src/tools/amdcpuid.c b/src/tools/amdcpuid.c deleted file mode 100644 index 9c2500e9d6..0000000000 --- a/src/tools/amdcpuid.c +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2012 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Alexander von Gluck, kallisti5@unixzen.com - */ - -/* - * Pass an AMD CPUID in hex, and get out a CPUID for OS.h - */ - - -#include -#include -#include - - -#define AMD_VENDOR 0x110000 - -#define EXT_FAMILY_MASK 0xF00000 -#define EXT_MODEL_MASK 0x0F0000 -#define FAMILY_MASK 0x000F00 -#define MODEL_MASK 0x0000F0 -#define STEPPING_MASK 0x00000F - - -// Converts a hexadecimal string to integer -static int xtoi(const char* xs, unsigned int* result) -{ - size_t szlen = strlen(xs); - int i, xv, fact; - - if (szlen > 0) { - // Converting more than 32bit hexadecimal value? - if (szlen>8) return 2; // exit - - // Begin conversion here - *result = 0; - fact = 1; - - // Run until no more character to convert - for (i = szlen - 1; i>=0 ;i--) { - if (isxdigit(*(xs+i))) { - if (*(xs+i)>=97) { - xv = ( *(xs+i) - 97) + 10; - } else if ( *(xs+i) >= 65) { - xv = (*(xs+i) - 65) + 10; - } else { - xv = *(xs+i) - 48; - } - *result += (xv * fact); - fact *= 16; - } else { - // Conversion was abnormally terminated - // by non hexadecimal digit, hence - // returning only the converted with - // an error value 4 (illegal hex character) - return 4; - } - } - } - - // Nothing to convert - return 1; -} - - -int -main(int argc, char *argv[]) -{ - if (argc != 2) { - printf("Provide the AMD cpuid in hex, and you will get how we id it\n"); - printf("usage: amdcpuid \n"); - return 1; - } - - unsigned int 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); - - unsigned int amdFamily = 0; - unsigned int amdModel = 0; - if (family == 0xF) { - amdFamily = extFam + family; - amdModel = (extMod << 4) + model; - } else { - amdFamily = family; - amdModel = model; - } - - // Haiku AMD cpuid format: VVFFMM - unsigned int amdHaiku - = AMD_VENDOR + (amdFamily << 8) + amdModel; - - printf("family: 0x%lX\n", amdFamily); - printf("model: 0x%lX\n", amdModel); - printf("stepping: 0x%lX\n", stepping); - printf("Haiku CPUID: 0x%lX\n", amdHaiku); - - return 0; -} diff --git a/src/tools/intelcpuid.c b/src/tools/cpuidtool.c similarity index 69% rename from src/tools/intelcpuid.c rename to src/tools/cpuidtool.c index 44e3e4c926..b7837e832b 100644 --- a/src/tools/intelcpuid.c +++ b/src/tools/cpuidtool.c @@ -16,8 +16,6 @@ #include -#define INTEL_VENDOR 0x100000 - #define EXT_FAMILY_MASK 0xF00000 #define EXT_MODEL_MASK 0x0F0000 #define FAMILY_MASK 0x000F00 @@ -69,14 +67,14 @@ static int xtoi(const char* xs, unsigned int* result) int main(int argc, char *argv[]) { - if (argc != 2) { - printf("Provide the Intel cpuid in hex, and you will get how we id it\n"); - printf("usage: intelcpuid \n"); + if (argc != 3) { + printf("Provide the cpuid in hex, and you will get how we id it\n"); + printf("usage: cpuidhaiku \n"); return 1; } - unsigned int cpuid; - xtoi(argv[1], &cpuid); + unsigned int cpuid = 0; + xtoi(argv[2], &cpuid); printf("cpuid: 0x%X\n", cpuid); @@ -86,11 +84,24 @@ main(int argc, char *argv[]) unsigned int model = (cpuid & MODEL_MASK) >> 4; unsigned int stepping = (cpuid & STEPPING_MASK); - // Haiku INTEL cpuid format: VVEFEM - unsigned int intelHaiku = INTEL_VENDOR + ((extFam & 0xF) << 12) - + (family << 8) + (extMod << 4) + model; + 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", intelHaiku); + printf("Haiku CPUID: 0x%lx\n", cpuidHaiku); return 0; }