2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Alexander von Gluck, kallisti5@unixzen.com
10 * Pass a standard CPUID in hex, and get out a CPUID for cpu_type.h
19 #define EXT_FAMILY_MASK 0xF00000
20 #define EXT_MODEL_MASK 0x0F0000
21 #define FAMILY_MASK 0x000F00
22 #define MODEL_MASK 0x0000F0
23 #define STEPPING_MASK 0x00000F
26 // Converts a hexadecimal string to integer
28 xtoi(const char* xs
, unsigned int* result
)
30 size_t szlen
= strlen(xs
);
36 // Converting more than 32bit hexadecimal value?
40 // Begin conversion here
44 // Run until no more character to convert
45 for (i
= szlen
- 1; i
>=0; i
--) {
46 if (isxdigit(*(xs
+ i
))) {
48 xv
= (*(xs
+ i
) - 97) + 10;
49 else if (*(xs
+ i
) >= 65)
50 xv
= (*(xs
+ i
) - 65) + 10;
54 *result
+= (xv
* fact
);
57 // Conversion was abnormally terminated
58 // by non hexadecimal digit, hence
59 // returning only the converted with
60 // an error value 4 (illegal hex character)
72 main(int argc
, char *argv
[])
75 printf("Provide the cpuid in hex, and you will get how we id it\n");
76 printf("usage: cpuidhaiku <cpuid_hex>\n");
80 unsigned int cpuid
= 0;
81 xtoi(argv
[1], &cpuid
);
83 printf("cpuid: 0x%X\n", cpuid
);
85 int family
= ((cpuid
>> 8) & 0xf) | ((cpuid
>> 16) & 0xff0);
86 int model
= ((cpuid
>> 4) & 0xf) | ((cpuid
>> 12) & 0xf0);
87 int stepping
= cpuid
& 0xf;
89 printf("Haiku CPUID: Family: 0x%x, Model: 0x%x, Stepping: 0x%x\n", family
,