Fix floating point registers of new threads.

This commit is contained in:
Jonas 'Sortie' Termansen 2016-03-26 16:04:05 +01:00
parent e770766cc8
commit 9f77beaea6
4 changed files with 18 additions and 4 deletions

View File

@ -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

View File

@ -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 <sortix/kernel/thread.h>
#include <sortix/kernel/time.h>
#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

View File

@ -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

View File

@ -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