Xen Test Framework
cpuid.h
Go to the documentation of this file.
1#ifndef XTF_X86_CPUID_H
2#define XTF_X86_CPUID_H
3
4#include <xtf/types.h>
5#include <xtf/numbers.h>
6
8
9typedef void (*cpuid_fn_t)(uint32_t leaf,
10 uint32_t *eax, uint32_t *ebx,
11 uint32_t *ecx, uint32_t *edx);
12typedef void (*cpuid_count_fn_t)(uint32_t leaf, uint32_t subleaf,
13 uint32_t *eax, uint32_t *ebx,
14 uint32_t *ecx, uint32_t *edx);
15
17{
21};
22
23extern enum x86_vendor x86_vendor;
24extern unsigned int max_leaf, max_extd_leaf;
25extern unsigned int x86_family, x86_model, x86_stepping;
26extern unsigned int maxphysaddr, maxvirtaddr;
27
28static inline bool vendor_is(enum x86_vendor v)
29{
30 return x86_vendor == v;
31}
32
33#define vendor_is_intel vendor_is(X86_VENDOR_INTEL)
34#define vendor_is_amd vendor_is(X86_VENDOR_AMD)
35
36
37#define cpufeat_word(idx) ((idx) / 32)
38#define cpufeat_bit(idx) ((idx) % 32)
39#define cpufeat_mask(idx) (_AC(1, U) << cpufeat_bit(idx))
40
41#define FEATURESET_1d cpufeat_word(X86_FEATURE_FPU)
42#define FEATURESET_1c cpufeat_word(X86_FEATURE_SSE3)
43#define FEATURESET_e1d cpufeat_word(X86_FEATURE_SYSCALL)
44#define FEATURESET_e1c cpufeat_word(X86_FEATURE_LAHF_LM)
45#define FEATURESET_Da1 cpufeat_word(X86_FEATURE_XSAVEOPT)
46#define FEATURESET_7b0 cpufeat_word(X86_FEATURE_FSGSBASE)
47#define FEATURESET_7c0 cpufeat_word(X86_FEATURE_PREFETCHWT1)
48#define FEATURESET_e7d cpufeat_word(X86_FEATURE_ITSC)
49#define FEATURESET_e8b cpufeat_word(X86_FEATURE_CLZERO)
50#define FEATURESET_7d0 cpufeat_word(X86_FEATURE_RTM_ALWAYS_ABORT)
51
52#define FSCAPINTS (FEATURESET_7d0 + 1)
53
55
56static inline bool cpu_has(unsigned int feature)
57{
58 return x86_features[cpufeat_word(feature)] & cpufeat_mask(feature);
59}
60
61#define cpu_has_fpu cpu_has(X86_FEATURE_FPU)
62#define cpu_has_vme cpu_has(X86_FEATURE_VME)
63#define cpu_has_de cpu_has(X86_FEATURE_DE)
64#define cpu_has_pse cpu_has(X86_FEATURE_PSE)
65#define cpu_has_tsc cpu_has(X86_FEATURE_TSC)
66#define cpu_has_pae cpu_has(X86_FEATURE_PAE)
67#define cpu_has_mce cpu_has(X86_FEATURE_MCE)
68#define cpu_has_pge cpu_has(X86_FEATURE_PGE)
69#define cpu_has_mca cpu_has(X86_FEATURE_MCA)
70#define cpu_has_pat cpu_has(X86_FEATURE_PAT)
71#define cpu_has_pse36 cpu_has(X86_FEATURE_PSE36)
72#define cpu_has_ds cpu_has(X86_FEATURE_DS)
73#define cpu_has_mmx cpu_has(X86_FEATURE_MMX)
74#define cpu_has_fxsr cpu_has(X86_FEATURE_FXSR)
75
76#define cpu_has_sse cpu_has(X86_FEATURE_SSE)
77#define cpu_has_sse2 cpu_has(X86_FEATURE_SSE2)
78#define cpu_has_vmx cpu_has(X86_FEATURE_VMX)
79#define cpu_has_smx cpu_has(X86_FEATURE_SMX)
80#define cpu_has_pcid cpu_has(X86_FEATURE_PCID)
81#define cpu_has_x2apic cpu_has(X86_FEATURE_X2APIC)
82#define cpu_has_xsave cpu_has(X86_FEATURE_XSAVE)
83#define cpu_has_avx cpu_has(X86_FEATURE_AVX)
84
85#define cpu_has_syscall cpu_has(X86_FEATURE_SYSCALL)
86#define cpu_has_nx cpu_has(X86_FEATURE_NX)
87#define cpu_has_page1gb cpu_has(X86_FEATURE_PAGE1GB)
88#define cpu_has_lm cpu_has(X86_FEATURE_LM)
89
90#define cpu_has_svm cpu_has(X86_FEATURE_SVM)
91#define cpu_has_dbext cpu_has(X86_FEATURE_DBEXT)
92
93#define cpu_has_fsgsbase cpu_has(X86_FEATURE_FSGSBASE)
94#define cpu_has_hle cpu_has(X86_FEATURE_HLE)
95#define cpu_has_smep cpu_has(X86_FEATURE_SMEP)
96#define cpu_has_rtm cpu_has(X86_FEATURE_RTM)
97#define cpu_has_smap cpu_has(X86_FEATURE_SMAP)
98
99#define cpu_has_umip cpu_has(X86_FEATURE_UMIP)
100#define cpu_has_pku cpu_has(X86_FEATURE_PKU)
101
102#define cpu_has_rtm_always_abort cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)
103
104#endif /* XTF_X86_CPUID_H */
105
106/*
107 * Local variables:
108 * mode: C
109 * c-file-style: "BSD"
110 * c-basic-offset: 4
111 * tab-width: 4
112 * indent-tabs-mode: nil
113 * End:
114 */
unsigned int x86_family
Definition: setup.c:27
void(* cpuid_count_fn_t)(uint32_t leaf, uint32_t subleaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
Definition: cpuid.h:12
#define cpufeat_word(idx)
Definition: cpuid.h:37
#define cpufeat_mask(idx)
Definition: cpuid.h:39
unsigned int max_leaf
Definition: setup.c:26
uint32_t x86_features[FSCAPINTS]
Definition: setup.c:24
unsigned int x86_stepping
Definition: cpuid.h:25
void(* cpuid_fn_t)(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
Definition: cpuid.h:9
static bool cpu_has(unsigned int feature)
Definition: cpuid.h:56
unsigned int x86_model
Definition: cpuid.h:25
unsigned int maxvirtaddr
Definition: cpuid.h:26
x86_vendor
Definition: cpuid.h:17
@ X86_VENDOR_AMD
Definition: cpuid.h:20
@ X86_VENDOR_INTEL
Definition: cpuid.h:19
@ X86_VENDOR_UNKNOWN
Definition: cpuid.h:18
#define FSCAPINTS
Definition: cpuid.h:52
static bool vendor_is(enum x86_vendor v)
Definition: cpuid.h:28
unsigned int maxphysaddr
Definition: setup.c:28
unsigned int max_extd_leaf
Definition: cpuid.h:24
Primatives for number manipulation.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:16
Common declarations for all tests.