aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers/fpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/drivers/fpu.c')
-rw-r--r--kernel/drivers/fpu.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/kernel/drivers/fpu.c b/kernel/drivers/fpu.c
new file mode 100644
index 0000000..d8a2b79
--- /dev/null
+++ b/kernel/drivers/fpu.c
@@ -0,0 +1,24 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#include <def.h>
+
+void set_fpu_cw(const u16 cw)
+{
+ __asm__ volatile("fldcw %0" ::"m"(cw));
+}
+
+void fpu_install()
+{
+ __asm__ volatile("clts");
+ u32 t;
+ __asm__ volatile("mov %%cr0, %0" : "=r"(t));
+ t &= ~(1 << 2);
+ t |= (1 << 1);
+ __asm__ volatile("mov %0, %%cr0" ::"r"(t));
+
+ __asm__ volatile("mov %%cr4, %0" : "=r"(t));
+ t |= 3 << 9;
+ __asm__ volatile("mov %0, %%cr4" ::"r"(t));
+
+ __asm__ volatile("fninit");
+}