From c9aa7a84623cf107450b9281d2fe93eedfe66a89 Mon Sep 17 00:00:00 2001 From: guido Date: Sun, 15 Sep 2002 13:49:57 +0000 Subject: [PATCH] Initialisation of debugging and floating point registers in PsBeginThread*. svn path=/trunk/; revision=3504 --- reactos/ntoskrnl/include/internal/i386/fpu.h | 4 +- reactos/ntoskrnl/ke/i386/bthread.S | 75 ++++++++++++++------ reactos/ntoskrnl/ke/i386/fpu.c | 2 +- reactos/ntoskrnl/ke/i386/thread.c | 16 ++--- 4 files changed, 62 insertions(+), 35 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/i386/fpu.h b/reactos/ntoskrnl/include/internal/i386/fpu.h index fec8ba10169..9c38d532f11 100644 --- a/reactos/ntoskrnl/include/internal/i386/fpu.h +++ b/reactos/ntoskrnl/include/internal/i386/fpu.h @@ -20,7 +20,9 @@ #ifndef __NTOSKRNL_INCLUDE_INTERNAL_I386_FPU_H #define __NTOSKRNL_INCLUDE_INTERNAL_I386_FPU_H -VOID +extern ULONG HardwareMathSupport; + +VOID KiCheckFPU(VOID); #endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_FPU_H */ diff --git a/reactos/ntoskrnl/ke/i386/bthread.S b/reactos/ntoskrnl/ke/i386/bthread.S index 997be090e73..b43384b7f43 100644 --- a/reactos/ntoskrnl/ke/i386/bthread.S +++ b/reactos/ntoskrnl/ke/i386/bthread.S @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: bthread.S,v 1.5 2002/09/08 10:23:29 chorns Exp $ +/* $Id: bthread.S,v 1.6 2002/09/15 13:49:57 guido Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -38,10 +38,10 @@ * */ - .globl _PsBeginThreadWithContextInternal +.globl _PsBeginThreadWithContextInternal .globl _PsBeginThread -_PsBeginThread: +_PsBeginThread: /* * This isn't really a function, we are called as the return address * of the context switch function @@ -52,6 +52,25 @@ _PsBeginThread: */ call _PiBeforeBeginThread + /* + * Initialize debugging registers + */ + movl $0, %eax /* set to 0 */ + movl %eax, %dr0 + movl %eax, %dr1 + movl %eax, %dr2 + movl %eax, %dr3 + movl %eax, %dr6 + movl %eax, %dr7 + + /* + * Initialize floating point registers + */ + movl (_HardwareMathSupport), %eax + jz nofpu + fninit +nofpu: + /* * Call the actual start of the thread */ @@ -74,41 +93,51 @@ _PsBeginThread: pushl $0 call _KeBugCheck@4 addl $4, %esp - + /* * And if that fails then loop */ .1: jmp .1 - - + + _PsBeginThreadWithContextInternal: /* * This isn't really a function, we are called as the return * address of a context switch */ - + /* * Do the necessary prolog before the context switch - */ + */ call _PiBeforeBeginThread - - /* FIXME: Don't ignore the debugging registers. */ - popl %eax /* Dr0 */ - popl %eax /* Dr1 */ - popl %eax /* Dr2 */ - popl %eax /* Dr3 */ - popl %eax /* Dr6 */ - popl %eax /* Dr7 */ - /* FIXME: Don't ignore the floating point registers. */ - addl $112,%esp /* FloatSave */ + /* + * Load the debugging registers + */ + popl %eax /* Dr0 */ + movl %eax, %dr0 + popl %eax /* Dr1 */ + movl %eax, %dr1 + popl %eax /* Dr2 */ + movl %eax, %dr2 + popl %eax /* Dr3 */ + movl %eax, %dr3 + popl %eax /* Dr6 */ + movl %eax, %dr6 + popl %eax /* Dr7 */ + movl %eax, %dr7 + + /* + * Load the floating point registers + */ + movl (_HardwareMathSupport), %eax + jz nofpu2 + frstor 0(%esp) +nofpu2: + addl $4, %esp /* Load the rest of the thread's user mode context. */ - movl $0,%eax + movl $0, %eax jmp KeReturnFromSystemCallWithHook - - - - diff --git a/reactos/ntoskrnl/ke/i386/fpu.c b/reactos/ntoskrnl/ke/i386/fpu.c index 30e8cbc3887..44472db4df3 100644 --- a/reactos/ntoskrnl/ke/i386/fpu.c +++ b/reactos/ntoskrnl/ke/i386/fpu.c @@ -37,7 +37,7 @@ /* GLOBALS *******************************************************************/ -static ULONG HardwareMathSupport; +ULONG HardwareMathSupport; /* FUNCTIONS *****************************************************************/ diff --git a/reactos/ntoskrnl/ke/i386/thread.c b/reactos/ntoskrnl/ke/i386/thread.c index 3cbdd0d0432..78ac3a4b284 100644 --- a/reactos/ntoskrnl/ke/i386/thread.c +++ b/reactos/ntoskrnl/ke/i386/thread.c @@ -103,8 +103,8 @@ Ke386InitThreadWithContext(PKTHREAD Thread, PCONTEXT Context) /* * Setup a stack frame for exit from the task switching routine */ - - InitSize = 5 * sizeof(DWORD) + 6 * sizeof(DWORD) + + + InitSize = 5 * sizeof(DWORD) + 6 * sizeof(DWORD) + sizeof(FLOATING_SAVE_AREA) + sizeof(KTRAP_FRAME); KernelStack = (PULONG)(Thread->KernelStack - InitSize); @@ -124,12 +124,10 @@ Ke386InitThreadWithContext(PKTHREAD Thread, PCONTEXT Context) KernelStack[10] = Context->Dr7; /* Set up the initial floating point state. */ - memcpy((PVOID)&KernelStack[11], (PVOID)&Context->FloatSave, - sizeof(FLOATING_SAVE_AREA)); + KernelStack[11] = (ULONG)&Context->FloatSave; /* Set up a trap frame from the context. */ - TrapFrame = (PKTRAP_FRAME) - ((PBYTE)KernelStack + 11 * sizeof(DWORD) + sizeof(FLOATING_SAVE_AREA)); + TrapFrame = (PKTRAP_FRAME)((PBYTE)KernelStack + 12 * sizeof(DWORD)); TrapFrame->DebugEbp = (PVOID)Context->Ebp; TrapFrame->DebugEip = (PVOID)Context->Eip; TrapFrame->DebugArgMark = 0; @@ -163,8 +161,8 @@ Ke386InitThreadWithContext(PKTHREAD Thread, PCONTEXT Context) } NTSTATUS -Ke386InitThread(PKTHREAD Thread, - PKSTART_ROUTINE StartRoutine, +Ke386InitThread(PKTHREAD Thread, + PKSTART_ROUTINE StartRoutine, PVOID StartContext) /* * Initialize a thread @@ -177,8 +175,6 @@ Ke386InitThread(PKTHREAD Thread, */ KernelStack = (PULONG)(Thread->KernelStack - (8*4)); - /* FIXME: Add initial floating point information */ - /* FIXME: Add initial debugging information */ KernelStack[0] = 0; /* EDI */ KernelStack[1] = 0; /* ESI */ KernelStack[2] = 0; /* EBX */