diff --git a/kernel/process.cpp b/kernel/process.cpp index 0a363511..1f229dca 100644 --- a/kernel/process.cpp +++ b/kernel/process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013, 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -1437,6 +1437,7 @@ pid_t sys_tfork(int flags, struct tfork* user_regs) cpuregs.gsbase = regs.gsbase; cpuregs.cr3 = child_process->addrspace; cpuregs.kernel_stack = stack_aligned + stack_aligned_size; + memcpy(&cpuregs.fpuenv, Float::fpu_initialized_regs, 512); #elif defined(__x86_64__) cpuregs.rip = regs.rip; cpuregs.rsp = regs.rsp; @@ -1463,6 +1464,7 @@ pid_t sys_tfork(int flags, struct tfork* user_regs) cpuregs.gsbase = regs.gsbase; cpuregs.cr3 = child_process->addrspace; cpuregs.kernel_stack = stack_aligned + stack_aligned_size; + memcpy(&cpuregs.fpuenv, Float::fpu_initialized_regs, 512); #else #warning "You need to implement initializing the registers of the new thread" #endif diff --git a/kernel/thread.cpp b/kernel/thread.cpp index 2d415e9b..d8bbc23b 100644 --- a/kernel/thread.cpp +++ b/kernel/thread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, 2013, 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -40,6 +40,10 @@ #include #include +#if defined(__i386__) || defined(__x86_64__) +#include "x86-family/float.h" +#endif + void* operator new (size_t /*size*/, void* address) throw() { return address; @@ -191,6 +195,7 @@ static void SetupKernelThreadRegs(struct thread_registers* regs, regs->signal_pending = 0; regs->kernel_stack = stack + stack_size; regs->cr3 = process->addrspace; + memcpy(regs->fpuenv, Float::fpu_initialized_regs, 512); #elif defined(__x86_64__) uintptr_t* stack_values = (uintptr_t*) (stack + stack_size); @@ -225,6 +230,7 @@ static void SetupKernelThreadRegs(struct thread_registers* regs, regs->signal_pending = 0; regs->kernel_stack = stack + stack_size; regs->cr3 = process->addrspace; + memcpy(regs->fpuenv, Float::fpu_initialized_regs, 512); #else #warning "You need to add kernel thread register initialization support" #endif diff --git a/kernel/x64/boot.S b/kernel/x64/boot.S index 4a39db5b..e541b554 100644 --- a/kernel/x64/boot.S +++ b/kernel/x64/boot.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2011, 2014, 2015, 2016 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -204,6 +204,9 @@ __start: mov %cr4, %rax or $0x600, %rax mov %rax, %cr4 + push $0x1F80 + ldmxcsr (%rsp) + addq $8, %rsp # Store a copy of the initialial floating point registers. fxsave fpu_initialized_regs diff --git a/kernel/x86/boot.S b/kernel/x86/boot.S index a6af8db4..acef8104 100644 --- a/kernel/x86/boot.S +++ b/kernel/x86/boot.S @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, 2015 Jonas 'Sortie' Termansen. + * Copyright (c) 2011, 2014, 2015, 2016 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -151,6 +151,9 @@ __start: mov %cr4, %ecx or $0x600, %ecx mov %ecx, %cr4 + push $0x1F80 + ldmxcsr (%esp) + addl $4, %esp # Store a copy of the initialial floating point registers. fxsave fpu_initialized_regs