3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
5 * Moved to MSVC-compatible inline assembler by Mike Nordell, 2003-12-26
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.
22 * FILE: ntoskrnl/ke/i386/vm86_sup.S
23 * PURPOSE: V86 mode support
24 * PROGRAMMER: David Welch (welch@cwcom.net)
29 /* INCLUDES ******************************************************************/
33 #include <ddk/ntddk.h>
34 #include <ddk/status.h>
35 #include <internal/i386/segment.h>
36 #include <internal/i386/fpu.h>
37 #include <internal/ps.h>
38 #include <ddk/defines.h>
39 #include <internal/v86m.h>
41 //#include <ntos/service.h>
42 #include <internal/trap.h>
43 #include <internal/ps.h>
46 #include <internal/ntoskrnl.h>
47 #include <internal/i386/segment.h>
50 extern KSPIN_LOCK PiThreadListLock
;
51 extern ULONG PiNrThreadsAwaitingReaping
;
52 extern ULONG MmGlobalKernelPageDirectory
[1024];
54 VOID STDCALL
PiWakeupReaperThread(VOID
);
55 VOID
KeSetBaseGdtSelector(ULONG Entry
, PVOID Base
);
59 * FUNCTIONS: Switches to another thread's context
61 * Thread = Thread to switch to
62 * OldThread = Thread to switch from
66 Ki386ContextSwitch(struct _KTHREAD
* NewThread
, struct _KTHREAD
* OldThread
)
73 /* Save callee save registers. */
78 cli
/* This is a critical section for this processor. */
80 /* Get the pointer to the new thread. */
84 * Set the base of the TEB selector to the base of the TEB for
90 call KeSetBaseGdtSelector
95 * Load the PCR selector.
101 * Set the current thread information in the PCR.
103 mov fs
:KPCR_CURRENT_THREAD
, ebx
106 * Set the current LDT
109 mov edi
, ETHREAD_THREADS_PROCESS
[ebx
]
110 test word ptr KPROCESS_LDT_DESCRIPTOR0
[edi
], 0xFFFF
113 push KPROCESS_LDT_DESCRIPTOR1
[edi
]
114 push KPROCESS_LDT_DESCRIPTOR0
[edi
]
116 call KeSetGdtSelector
119 mov eax
, LDT_SELECTOR
125 * Load up the iomap offset for this thread in
126 * preparation for setting it below.
128 mov eax
, KPROCESS_IOPM_OFFSET
[edi
]
131 * FIXME: Save debugging state.
135 * FIXME: Save floating point state.
142 mov KTHREAD_KERNEL_STACK
[ebx
], esp
144 mov esp
, KTHREAD_KERNEL_STACK
[ebx
]
145 mov edi
, KTHREAD_STACK_LIMIT
[ebx
]
148 * Set the stack pointer in this processors TSS
153 * Set current IOPM offset in the TSS
155 mov KTSS_IOMAPBASE
[esi
], ax
157 mov eax
, KTHREAD_INITIAL_STACK
[ebx
]
158 mov KTSS_ESP0
[esi
], eax
161 * Change the address space
163 mov ebx
, ETHREAD_THREADS_PROCESS
[ebx
]
164 mov eax
, KPROCESS_DIRECTORY_TABLE_BASE
[ebx
]
168 * Set up the PDE for the top of the new stack.
174 mov eax
, 0xF03C0000[esi
*4]
177 mov eax
, MmGlobalKernelPageDirectory
[esi
*4]
178 mov
0xF03C0000[esi
*4], eax
182 cmp ebx
, (MM_STACK_SIZE
/ 4096)
186 * FIXME: Restore floating point state
190 * FIXME: Restore debugging state
194 * Exit the critical section
199 KeReleaseSpinLockFromDpcLevel(&PiThreadListLock
);
201 if (PiNrThreadsAwaitingReaping
) {
202 PiWakeupReaperThread();
208 * Restore the saved register and exit