Architectural Support: x86_64 (#37)
[lunaix-os.git] / lunaix-os / arch / x86 / includes / sys / crx.h
1 #ifndef __LUNAIX_CRX_H
2 #define __LUNAIX_CRX_H
3
4 #define CR4_PSE36           ( 1UL << 4  )
5 #define CR4_OSXMMEXCPT      ( 1UL << 10 )
6 #define CR4_OSFXSR          ( 1UL << 9  )
7 #define CR4_PCIDE           ( 1UL << 17 )
8 #define CR4_PGE             ( 1UL << 7  )
9 #define CR4_LA57            ( 1UL << 12 )
10
11 #define CR0_PG              ( 1UL << 31 )
12 #define CR0_WP              ( 1UL << 16 )
13 #define CR0_EM              ( 1UL << 2  )
14 #define CR0_MP              ( 1UL << 1  )
15
16 #ifdef CONFIG_ARCH_X86_64
17
18 #define crx_addflag(crx, flag)      \
19     asm(                            \
20         "movq %%" #crx ", %%rax\n"  \
21         "orq  %0,    %%rax\n"       \
22         "movq %%rax, %%" #crx "\n"  \
23         ::"r"(flag)                 \
24         :"rax"                      \
25     );
26
27 #define crx_rmflag(crx, flag)       \
28     asm(                            \
29         "movq %%" #crx ", %%rax\n"  \
30         "andq  %0,    %%rax\n"      \
31         "movq %%rax, %%" #crx "\n"  \
32         ::"r"(~(flag))              \
33         :"rax"                      \
34     );
35
36 #else
37
38 #define crx_addflag(crx, flag)      \
39     asm(                            \
40         "movl %%" #crx ", %%eax\n"  \
41         "orl  %0,    %%eax\n"       \
42         "movl %%eax, %%" #crx "\n"  \
43         ::"r"(flag)                 \
44         :"eax"                      \
45     );
46
47 #define crx_rmflag(crx, flag)       \
48     asm(                            \
49         "movl %%" #crx ", %%eax\n"  \
50         "andl  %0,    %%eax\n"      \
51         "movl %%eax, %%" #crx "\n"  \
52         ::"r"(~(flag))              \
53         :"eax"                      \
54     );
55
56 #endif
57
58 static inline void
59 cr4_setfeature(unsigned long feature)
60 {
61     crx_addflag(cr4, feature);
62 }
63
64 static inline void
65 cr0_setfeature(unsigned long feature)
66 {
67     crx_addflag(cr0, feature);
68 }
69
70 static inline void
71 cr0_unsetfeature(unsigned long feature)
72 {
73     crx_rmflag(cr0, feature);
74 }
75
76 #endif /* __LUNAIX_CR4_H */