blob: 0c9403fd80b109a2b74364d8c0214c7879c8df3c (
plain)
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
|
#include "cpu.h"
#include <stdlib.h>
static_assert(sizeof(CPU::features_t) == 2 * sizeof(uint32_t));
CPU::CPU() {
static_assert(sizeof(CPU::version_t) == sizeof(uint32_t));
struct {
uint32_t d;
uint32_t c;
uint32_t b;
uint32_t a;
} __attribute__((packed)) r;
size_t highest_param = 0;
for (int i = 0; i <= highest_param; ++i) {
asm volatile("cpuid" : "=a"(r.a), "=b"(r.b), "=c"(r.c), "=d"(r.d) : "a"(i));
switch (i) {
case 0:
highest_param = static_cast<size_t>(r.a);
memcpy(&m_manufacturer[0], &r.b, sizeof(r.b));
memcpy(&m_manufacturer[4], &r.d, sizeof(r.d));
memcpy(&m_manufacturer[8], &r.c, sizeof(r.c));
break;
case 1:
memcpy(&m_info, &r.a, sizeof(r.a));
memcpy(&m_features, &r.d, sizeof(CPU::features_t));
break;
default:
return;
}
}
}
|