forked from dankamongmen/x86info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_model_name.c
52 lines (44 loc) · 1.16 KB
/
get_model_name.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Licensed under the terms of the GNU GPL License version 2.
*
* Get CPU name string from cpuid.
*/
#include <stdio.h>
#include <string.h>
#include <x86info.h>
#include <amd.h>
void get_model_name(struct cpudata *cpu)
{
unsigned int i, j;
unsigned int eax, ebx, ecx, edx;
char namestring[49], *cp;
if (cpu->maxei < 0x80000004)
return;
cp = namestring;
for (j = 0x80000002; j <= 0x80000004; j++) {
cpuid(cpu->number, j, &eax, &ebx, &ecx, &edx);
if (eax == 0)
return;
for (i = 0; i < 4; i++)
*cp++ = eax >> (8 * i);
for (i = 0; i < 4; i++)
*cp++ = ebx >> (8 * i);
for (i = 0; i < 4; i++)
*cp++ = ecx >> (8 * i);
for (i = 0; i < 4; i++)
*cp++ = edx >> (8 * i);
}
cp = namestring;
while(*cp == ' ')
cp++;
/* Broken BIOS? Try to determine the model name ourselves. */
if (strstr(cp, "unknown") != NULL) {
unsigned int vendor;
cpuid(cpu->number, 0, NULL, &vendor, NULL, NULL);
if (vendor == 0x68747541 && cpu->cpuid_level >= 1 && cpu->maxei >= 0x80000001) { /* AMD defined flags */
cp = namestring;
fix_amd_model_name(cpu, cp, sizeof(namestring));
}
}
printf("Processor name string (BIOS programmed): %s\n", cp);
}