From f18285205c73f038bffb16711c3ee1a045a7286e Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Tue, 21 May 2019 16:17:39 +0200 Subject: [PATCH] hw: enable FPU during CPU startup on x86 Also disable TS (task switch) flag in cr0 during kernel initialization, so FPU faults are not raised. This became necessary since GCC lately aggressively generates FPU instructions at arbitrary places and also at early kernel-bootstrapping stages. fixes #3365 --- repos/base-hw/src/bootstrap/spec/x86_64/crt0.s | 17 +++++++++++++++++ repos/base-hw/src/core/spec/x86_64/fpu.cc | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/repos/base-hw/src/bootstrap/spec/x86_64/crt0.s b/repos/base-hw/src/bootstrap/spec/x86_64/crt0.s index 0e75f38c9..cf2a97512 100644 --- a/repos/base-hw/src/bootstrap/spec/x86_64/crt0.s +++ b/repos/base-hw/src/bootstrap/spec/x86_64/crt0.s @@ -157,6 +157,23 @@ __gdt: movq (%rax), %rsp addq %rcx, %rsp + /* + * Enable paging and FPU: + * PE, MP, NE, WP, PG + */ + mov $0x80010023, %rax + mov %rax, %cr0 + + /* + * OSFXSR and OSXMMEXCPT for SSE FPU support + */ + mov %cr4, %rax + bts $9, %rax + bts $10, %rax + mov %rax, %cr4 + + fninit + /* kernel-initialization */ call init diff --git a/repos/base-hw/src/core/spec/x86_64/fpu.cc b/repos/base-hw/src/core/spec/x86_64/fpu.cc index bd2ee20d8..3e7d64db7 100644 --- a/repos/base-hw/src/core/spec/x86_64/fpu.cc +++ b/repos/base-hw/src/core/spec/x86_64/fpu.cc @@ -21,7 +21,12 @@ void Genode::Fpu::init() Cpu::Cr0::Mp::set(cr0_value); Cpu::Cr0::Em::clear(cr0_value); - Cpu::Cr0::Ts::set(cr0_value); + + /* + * Clear task switched so we do not gnerate FPU faults during kernel + * initialisation, it will be turned on by Fpu::disable + */ + Cpu::Cr0::Ts::clear(cr0_value); Cpu::Cr0::Ne::set(cr0_value); Cpu::Cr0::write(cr0_value);