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 <internal/trap.h>
42 #include <internal/ps.h>
45 #include <internal/ntoskrnl.h>
46 #include <internal/i386/segment.h>
49 void KiV86Complete(void);
50 void KiTrapHandler(void);
51 void KiDoubleFaultHandler(void);
53 extern int KiPcrInitDone
;
56 * Epilog for exception handlers
63 cmp eax
, 1 /* Check for v86 recovery */
67 /* Skip debug information and unsaved registers */
76 /* Restore the old previous mode */
78 mov ss
:KTHREAD_PREVIOUS_MODE
[esi
], bl
80 /* Restore the old exception handler list */
82 mov fs
:KPCR_EXCEPTION_LIST
, ebx
89 add esp
, 4 /* Ignore error code */
104 * Check that the PCR exists, very early in the boot process it may
107 cmp ss
:KiPcrInitDone
, 0
110 /* Load the PCR selector into fs */
111 mov ebx
, PCR_SELECTOR
114 /* Save the old exception list */
115 mov ebx
, fs
:KPCR_EXCEPTION_LIST
118 /* Put the exception handler chain terminator */
119 mov dword ptr fs
:KPCR_EXCEPTION_LIST
, 0xffffffff
121 /* Get a pointer to the current thread */
122 mov edi
, fs
:KPCR_CURRENT_THREAD
124 /* The current thread may be NULL early in the boot process */
128 /* Save the old previous mode */
130 mov bl
, ss
:KTHREAD_PREVIOUS_MODE
[edi
]
133 /* Set the new previous mode based on the saved CS selector */
138 mov ss
:KTHREAD_PREVIOUS_MODE
[edi
], KernelMode
141 mov ss
:KTHREAD_PREVIOUS_MODE
[edi
], UserMode
144 /* Save other registers */
157 push
0 /* XXX: TempESP */
158 push
0 /* XXX: TempCS */
159 push
0 /* XXX: DebugPointer */
160 push
0 /* XXX: DebugArgMark */
162 push ebx
/* XXX: DebugEIP */
163 push ebp
/* XXX: DebugEBP */
165 /* Load the segment registers */
171 /* Set ES to kernel segment */
178 /* Save the old trap frame. */
181 mov edx
, ss
:KTHREAD_TRAP_FRAME
[edi
]
188 /* Save a pointer to the trap frame in the current KTHREAD */
191 mov ss
:KTHREAD_TRAP_FRAME
[edi
], ebx
194 /* Call the C exception handler */
200 /* Get a pointer to the current thread */
201 mov esi
, fs
:KPCR_CURRENT_THREAD
203 /* Restore the old trap frame pointer */
205 mov KTHREAD_TRAP_FRAME
[esi
], ebx
207 /* Return to the caller */
210 /* Handle the no-pcr case out of line */
214 /* Handle the no-thread case out of line */
219 } // end of __asm block
342 call KiDoubleFaultHandler