aboutsummaryrefslogtreecommitdiff
path: root/arch/i686/include/sys/cpuid.h
blob: f2ffe37794a2a905d4c3f68e973f594512555e8f (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
#pragma once

#include <cpuid.h>

struct CPUVersion {
  unsigned int stepping : 4;
  unsigned int model : 4;
  unsigned int family : 4;
  unsigned int type : 2;
  unsigned int __unused_1 : 2;
  unsigned int model_ex : 4;
  unsigned int family_ex : 8;
  unsigned int __unused_2 : 4;
} __attribute__((packed, aligned(__alignof__(unsigned int))));
_Static_assert(sizeof(struct CPUVersion) == sizeof(unsigned int));

unsigned int
family(const struct CPUVersion v)
{
  if (v.family == 0x0f) return v.family + v.family_ex;
  else
    return v.family;
}

unsigned int
model(const struct CPUVersion v)
{
  switch (v.family) {
  case 0x06:
  case 0x0f:
    return ((unsigned int)v.model_ex << 4) | v.model;
  default:
    return v.model;
  }
}