Initialisation of debugging and floating point registers in
[reactos.git] / reactos / ntoskrnl / ke / i386 / bthread.S
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: bthread.S,v 1.6 2002/09/15 13:49:57 guido Exp $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: ntoskrnl/ke/i386/bthread.S
24 * PURPOSE: Trap handlers
25 * PROGRAMMER: David Welch (david.welch@seh.ox.ac.uk)
26 */
27
28 /* INCLUDES ******************************************************************/
29
30 #include <ddk/status.h>
31 #include <internal/i386/segment.h>
32 #include <internal/ps.h>
33 #include <ddk/defines.h>
34
35 /* FUNCTIONS *****************************************************************/
36
37 /*
38 *
39 */
40
41 .globl _PsBeginThreadWithContextInternal
42 .globl _PsBeginThread
43
44 _PsBeginThread:
45 /*
46 * This isn't really a function, we are called as the return address
47 * of the context switch function
48 */
49
50 /*
51 * Do the necessary prolog after a context switch
52 */
53 call _PiBeforeBeginThread
54
55 /*
56 * Initialize debugging registers
57 */
58 movl $0, %eax /* set to 0 */
59 movl %eax, %dr0
60 movl %eax, %dr1
61 movl %eax, %dr2
62 movl %eax, %dr3
63 movl %eax, %dr6
64 movl %eax, %dr7
65
66 /*
67 * Initialize floating point registers
68 */
69 movl (_HardwareMathSupport), %eax
70 jz nofpu
71 fninit
72 nofpu:
73
74 /*
75 * Call the actual start of the thread
76 */
77 movl 4(%esp), %ebx /* Start routine */
78 movl 8(%esp), %eax /* Start context */
79 pushl %eax
80 call *%ebx /* Call the start routine */
81 addl $4, %esp
82
83 /*
84 * Terminate the thread
85 */
86 pushl %eax
87 call _PsTerminateSystemThread@4
88 addl $4, %esp
89
90 /*
91 * If that fails then bug check
92 */
93 pushl $0
94 call _KeBugCheck@4
95 addl $4, %esp
96
97 /*
98 * And if that fails then loop
99 */
100 .1:
101 jmp .1
102
103
104 _PsBeginThreadWithContextInternal:
105 /*
106 * This isn't really a function, we are called as the return
107 * address of a context switch
108 */
109
110 /*
111 * Do the necessary prolog before the context switch
112 */
113 call _PiBeforeBeginThread
114
115 /*
116 * Load the debugging registers
117 */
118 popl %eax /* Dr0 */
119 movl %eax, %dr0
120 popl %eax /* Dr1 */
121 movl %eax, %dr1
122 popl %eax /* Dr2 */
123 movl %eax, %dr2
124 popl %eax /* Dr3 */
125 movl %eax, %dr3
126 popl %eax /* Dr6 */
127 movl %eax, %dr6
128 popl %eax /* Dr7 */
129 movl %eax, %dr7
130
131 /*
132 * Load the floating point registers
133 */
134 movl (_HardwareMathSupport), %eax
135 jz nofpu2
136 frstor 0(%esp)
137 nofpu2:
138 addl $4, %esp
139
140 /* Load the rest of the thread's user mode context. */
141 movl $0, %eax
142 jmp KeReturnFromSystemCallWithHook
143