From 43a915a7d0280d8cea632c768fee1b9dfb5e7fcd Mon Sep 17 00:00:00 2001 From: Pawel Wieczorkiewicz Date: Mon, 8 Feb 2021 14:01:04 +0100 Subject: [PATCH] lib: add write_cr0() and enable_sse() helper functions Signed-off-by: Pawel Wieczorkiewicz --- include/lib.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/lib.h b/include/lib.h index 4d32c2ff..63c24028 100644 --- a/include/lib.h +++ b/include/lib.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #define min(a, b) \ @@ -232,6 +233,10 @@ static inline unsigned long read_cr0(void) { return cr0; } +static inline void write_cr0(unsigned long cr0) { + asm volatile("mov %0, %%cr0" ::"r"(cr0)); +} + static inline unsigned long read_cr2(void) { unsigned long cr2; @@ -395,6 +400,11 @@ static inline unsigned long ipow(int base, unsigned int exp) { return result; } +static inline void enable_sse(void) { + write_cr0((read_cr0() & ~X86_CR0_EM) | X86_CR0_MP); + write_cr4(read_cr4() | X86_CR4_OSFXSR | X86_CR4_OSXMMEXCPT); +} + /* External declarations */ extern void halt(void);