coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
cr.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef CPU_X86_CR_H
4 #define CPU_X86_CR_H
5 
6 #if !defined(__ASSEMBLER__)
7 
8 #include <stdint.h>
9 
10 #define COMPILER_BARRIER "memory"
11 
12 #if ENV_X86_64
13 #define CRx_TYPE uint64_t
14 #define CRx_IN "q"
15 #define CRx_RET "=q"
16 #else
17 #define CRx_TYPE uint32_t
18 #define CRx_IN "r"
19 #define CRx_RET "=r"
20 #endif
22 {
24  __asm__ __volatile__ (
25  "mov %%cr0, %0"
26  : CRx_RET(value)
27  :
29  );
30  return value;
31 }
32 
34 {
35  __asm__ __volatile__ (
36  "mov %0, %%cr0"
37  :
38  : CRx_IN(data)
40  );
41 }
42 
44 {
46  __asm__ __volatile__ (
47  "mov %%cr2, %0"
48  : CRx_RET(value)
49  :
51  );
52  return value;
53 }
54 
56 {
58  __asm__ __volatile__ (
59  "mov %%cr3, %0"
60  : CRx_RET(value)
61  :
63  );
64  return value;
65 }
66 
68 {
69  __asm__ __volatile__ (
70  "mov %0, %%cr3"
71  :
72  : CRx_IN(data)
74  );
75 }
77 {
79  __asm__ __volatile__ (
80  "mov %%cr4, %0"
81  : CRx_RET(value)
82  :
84  );
85  return value;
86 }
87 
89 {
90  __asm__ __volatile__ (
91  "mov %0, %%cr4"
92  :
93  : CRx_IN(data)
95  );
96 }
97 
98 #endif /* !defined(__ASSEMBLER__) */
99 
100 /* CR0 flags */
101 #define CR0_PE (1 << 0)
102 #define CR0_MP (1 << 1)
103 #define CR0_EM (1 << 2)
104 #define CR0_TS (1 << 3)
105 #define CR0_ET (1 << 4)
106 #define CR0_NE (1 << 5)
107 #define CR0_WP (1 << 16)
108 #define CR0_AM (1 << 18)
109 #define CR0_NW (1 << 29)
110 #define CR0_CD (1 << 30)
111 #define CR0_PG (1 << 31)
112 
113 /* CR4 flags */
114 #define CR4_VME (1 << 0)
115 #define CR4_PVI (1 << 1)
116 #define CR4_TSD (1 << 2)
117 #define CR4_DE (1 << 3)
118 #define CR4_PSE (1 << 4)
119 #define CR4_PAE (1 << 5)
120 #define CR4_MCE (1 << 6)
121 #define CR4_PGE (1 << 7)
122 #define CR4_PCE (1 << 8)
123 #define CR4_OSFXSR (1 << 9)
124 #define CR4_OSXMMEXCPT (1 << 10)
125 #define CR4_VMXE (1 << 13)
126 #define CR4_SMXE (1 << 14)
127 #define CR4_FSGSBASE (1 << 16)
128 #define CR4_PCIDE (1 << 17)
129 #define CR4_OSXSAVE (1 << 18)
130 #define CR4_SMEP (1 << 20)
131 
132 #endif /* CPU_X86_CR_H */
pte_t value
Definition: mmu.c:91
#define __always_inline
Definition: compiler.h:35
static __always_inline void write_cr3(CRx_TYPE data)
Definition: cr.h:67
static __always_inline CRx_TYPE read_cr3(void)
Definition: cr.h:55
static __always_inline void write_cr4(CRx_TYPE data)
Definition: cr.h:88
#define COMPILER_BARRIER
Definition: cr.h:10
static __always_inline CRx_TYPE read_cr4(void)
Definition: cr.h:76
#define CRx_RET
Definition: cr.h:19
#define CRx_TYPE
Definition: cr.h:17
static __always_inline void write_cr0(CRx_TYPE data)
Definition: cr.h:33
static __always_inline CRx_TYPE read_cr2(void)
Definition: cr.h:43
#define CRx_IN
Definition: cr.h:18
static __always_inline CRx_TYPE read_cr0(void)
Definition: cr.h:21