From b8f00b77e965c73a047e71193c8c6e2d7488f34d Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 4 Sep 2020 15:50:21 +0200 Subject: Added mandelbrot demo and fpu driver --- kernel/drivers/fpu.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 kernel/drivers/fpu.c (limited to 'kernel/drivers/fpu.c') 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 + +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"); +} -- cgit v1.2.3