1 // SPDX-License-Identifier: GPL-2.0
8 #include "../../util/header.h"
11 cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c,
14 __asm__ __volatile__ (".byte 0x53\n\tcpuid\n\t"
15 "movl %%ebx, %%esi\n\t.byte 0x5b"
24 __get_cpuid(char *buffer, size_t sz, const char *fmt)
26 unsigned int a, b, c, d, lvl;
27 int family = -1, model = -1, step = -1;
31 cpuid(0, &lvl, &b, &c, &d);
32 strncpy(&vendor[0], (char *)(&b), 4);
33 strncpy(&vendor[4], (char *)(&d), 4);
34 strncpy(&vendor[8], (char *)(&c), 4);
38 cpuid(1, &a, &b, &c, &d);
40 family = (a >> 8) & 0xf; /* bits 11 - 8 */
41 model = (a >> 4) & 0xf; /* Bits 7 - 4 */
46 family += (a >> 20) & 0xff;
50 model += ((a >> 16) & 0xf) << 4;
52 nb = scnprintf(buffer, sz, fmt, vendor, family, model, step);
54 /* look for end marker to ensure the entire data fit */
55 if (strchr(buffer, '$')) {
63 get_cpuid(char *buffer, size_t sz)
65 return __get_cpuid(buffer, sz, "%s,%u,%u,%u$");
71 char *buf = malloc(128);
73 if (buf && __get_cpuid(buf, 128, "%s-%u-%X$") < 0) {