From e8a0a36889d9593c4301c328c088cb66ef5d881a Mon Sep 17 00:00:00 2001 From: xamidev Date: Tue, 31 Mar 2026 21:04:44 +0200 Subject: [PATCH] Enable FPU --- src/arch/x86/init.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/arch/x86/init.c b/src/arch/x86/init.c index 040ddf1..e1736c3 100644 --- a/src/arch/x86/init.c +++ b/src/arch/x86/init.c @@ -29,6 +29,26 @@ static void x86_overwrite_pat() wrmsr(0x277, pat); } +/* + * x86_enable_fpu - Enable Floating Point Unit + * + * This function enables the Floating Point Unit, + * which allows the CPU to do floating point + * operations. + * + * Here we do not check for FPU support but we + * should. However most processors support it. + */ +static void x86_enable_fpu() +{ + size_t cr4; + __asm__ volatile("mov %%cr4, %0" : "=r"(cr4)); + cr4 |= 0x200; + __asm__ volatile("mov %0, %%cr4" :: "r"(cr4)); + uint16_t cw = 0x37F; + asm volatile("fldcw %0" :: "m"(cw)); +} + /* * x86_arch_init - Initialize x86 CPU structures * @@ -42,6 +62,7 @@ static void x86_overwrite_pat() void x86_arch_init() { x86_overwrite_pat(); + x86_enable_fpu(); x86_cpu_identification(); idt_init(); gdt_init();