X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/32b9a6d76790c73d3d2d36d9081a2581cc65d184..28c176b668c841a3b7fb093faccf0efa39257603:/lunaix-os/arch/x86/includes/sys/crx.h diff --git a/lunaix-os/arch/x86/includes/sys/crx.h b/lunaix-os/arch/x86/includes/sys/crx.h new file mode 100644 index 0000000..4eb56e0 --- /dev/null +++ b/lunaix-os/arch/x86/includes/sys/crx.h @@ -0,0 +1,76 @@ +#ifndef __LUNAIX_CRX_H +#define __LUNAIX_CRX_H + +#define CR4_PSE36 ( 1UL << 4 ) +#define CR4_OSXMMEXCPT ( 1UL << 10 ) +#define CR4_OSFXSR ( 1UL << 9 ) +#define CR4_PCIDE ( 1UL << 17 ) +#define CR4_PGE ( 1UL << 7 ) +#define CR4_LA57 ( 1UL << 12 ) + +#define CR0_PG ( 1UL << 31 ) +#define CR0_WP ( 1UL << 16 ) +#define CR0_EM ( 1UL << 2 ) +#define CR0_MP ( 1UL << 1 ) + +#ifdef CONFIG_ARCH_X86_64 + +#define crx_addflag(crx, flag) \ + asm( \ + "movq %%" #crx ", %%rax\n" \ + "orq %0, %%rax\n" \ + "movq %%rax, %%" #crx "\n" \ + ::"r"(flag) \ + :"rax" \ + ); + +#define crx_rmflag(crx, flag) \ + asm( \ + "movq %%" #crx ", %%rax\n" \ + "andq %0, %%rax\n" \ + "movq %%rax, %%" #crx "\n" \ + ::"r"(~(flag)) \ + :"rax" \ + ); + +#else + +#define crx_addflag(crx, flag) \ + asm( \ + "movl %%" #crx ", %%eax\n" \ + "orl %0, %%eax\n" \ + "movl %%eax, %%" #crx "\n" \ + ::"r"(flag) \ + :"eax" \ + ); + +#define crx_rmflag(crx, flag) \ + asm( \ + "movl %%" #crx ", %%eax\n" \ + "andl %0, %%eax\n" \ + "movl %%eax, %%" #crx "\n" \ + ::"r"(~(flag)) \ + :"eax" \ + ); + +#endif + +static inline void +cr4_setfeature(unsigned long feature) +{ + crx_addflag(cr4, feature); +} + +static inline void +cr0_setfeature(unsigned long feature) +{ + crx_addflag(cr0, feature); +} + +static inline void +cr0_unsetfeature(unsigned long feature) +{ + crx_rmflag(cr0, feature); +} + +#endif /* __LUNAIX_CR4_H */