3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
5 * Moved to MSVC-compatible inline assembler by Mike Nordell, 2003-12-25
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* $Id: ke_i386_bthread.c,v 1.1 2004/02/06 08:21:56 fireball Exp $
23 * COPYRIGHT: See COPYING in the top level directory
24 * PROJECT: ReactOS kernel
25 * FILE: ntoskrnl/ke/i386/bthread.S
26 * PURPOSE: Trap handlers
27 * PROGRAMMER: David Welch (david.welch@seh.ox.ac.uk)
30 /* INCLUDES ******************************************************************/
32 #include <ddk/ntddk.h>
33 #include <ddk/status.h>
34 #include <internal/i386/segment.h>
35 #include <internal/i386/fpu.h>
36 #include <internal/ps.h>
37 #include <ddk/defines.h>
39 /* Values for contextflags */
40 #define CONTEXT_i386 0x10000
41 #ifndef CONTEXT_CONTROL
42 #define CONTEXT_CONTROL (CONTEXT_i386 | 1)
44 #ifndef CONTEXT_INTEGER
45 #define CONTEXT_INTEGER (CONTEXT_i386 | 2)
47 #ifndef CONTEXT_SEGMENTS
48 #define CONTEXT_SEGMENTS (CONTEXT_i386 | 4)
50 #ifndef CONTEXT_FLOATING_POINT
51 #define CONTEXT_FLOATING_POINT (CONTEXT_i386 | 8)
53 #ifndef CONTEXT_DEBUG_REGISTERS
54 #define CONTEXT_DEBUG_REGISTERS (CONTEXT_i386 | 0x10)
57 #define CONTEXT_FULL (CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS)
60 /* FUNCTIONS *****************************************************************/
62 void KeReturnFromSystemCallWithHook();
64 VOID
PiBeforeBeginThread(CONTEXT c
);
71 VOID
PsBeginThread(PKSTART_ROUTINE StartRoutine
, PVOID StartContext
)
74 * This isn't really a function, we are called as the return address
75 * of the context switch function
79 * Do the necessary prolog after a context switch
83 call PiBeforeBeginThread
86 * Call the actual start of the thread
88 // We must NOT use the arguments by name. VC then uses EBP-relative
89 // addressing, and with an EBP of 0 you can imagine what happens.
90 mov ebx
, 4[esp
] // StartRoutine
91 mov eax
, 8[esp
] // StartContext
93 call ebx
/* Call the start routine */
97 * Terminate the thread
100 call PsTerminateSystemThread
105 /* If that fails then bug check */
108 /* And if that fails then loop */
115 VOID
PsBeginThreadWithContextInternal(VOID
)
118 * This isn't really a function, we are called as the return
119 * address of a context switch
123 * Do the necessary prolog before the context switch
127 call PiBeforeBeginThread
130 * Load the context flags.
135 * Load the debugging registers
137 test ebx
, (CONTEXT_DEBUG_REGISTERS
& ~CONTEXT_i386
)
139 pop eax __asm mov dr0
, eax
140 pop eax __asm mov dr1
, eax
141 pop eax __asm mov dr2
, eax
142 pop eax __asm mov dr3
, eax
143 pop eax __asm mov dr6
, eax
144 pop eax __asm mov dr7
, eax
151 * Load the floating point registers
153 mov eax
, HardwareMathSupport
156 test ebx
, (CONTEXT_FLOATING_POINT
& ~CONTEXT_i386
)
162 /* Load the rest of the thread's user mode context. */
164 jmp KeReturnFromSystemCallWithHook