3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
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.
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.
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.
21 * PROJECT: ReactOS kernel
22 * FILE: ntoskrnl/ke/i386/trap.s
23 * PURPOSE: Exception handlers
24 * PROGRAMMER: David Welch <welch@cwcom.net>
27 /* INCLUDES ******************************************************************/
30 #include <ddk/status.h>
31 #include <internal/i386/ke.h>
32 #include <internal/i386/segment.h>
33 #include <internal/ps.h>
34 #include <ddk/defines.h>
36 /* FUNCTIONS *****************************************************************/
39 * Epilog for exception handlers
42 cmpl $1, %eax /* Check for v86 recovery */
46 /* Skip debug information and unsaved registers */
67 /* Restore the old previous mode */
71 movb %bl, %ss:KTHREAD_PREVIOUS_MODE(%esi)
73 /* Restore the old exception handler list */
75 movl %ebx, %fs:KPCR_EXCEPTION_LIST
82 addl $0x4, %esp /* Ignore error code */
88 movl $_KiTrapHandler, %ebx
90 .global _KiTrapProlog2
95 /* Make room for the previous mode and the exception list */
98 /* Save other registers */
107 /* Clear all breakpoint enables in dr7. */
108 andl $0xFFFF0000, %eax
120 leal 0x64(%esp), %eax
121 pushl %eax /* XXX: TempESP */
122 pushl %ss /* XXX: TempSS */
123 pushl $0 /* XXX: DebugPointer */
124 pushl $0 /* XXX: DebugArgMark */
125 movl 0x60(%esp), %eax
126 pushl %eax /* XXX: DebugEIP */
127 pushl %ebp /* XXX: DebugEBP */
129 /* Load the segment registers */
130 movl $KERNEL_DS, %eax
135 /* save the trap frame */
138 /* Load the PCR selector into fs */
139 movl $PCR_SELECTOR, %eax
142 /* Save the old exception list */
143 movl %fs:KPCR_EXCEPTION_LIST, %eax
144 movl %eax, KTRAP_FRAME_EXCEPTION_LIST(%ebp)
146 /* Get a pointer to the current thread */
147 movl %fs:KPCR_CURRENT_THREAD, %edi
149 /* The current thread may be NULL early in the boot process */
153 /* Save the old previous mode */
155 movb KTHREAD_PREVIOUS_MODE(%edi), %al
156 movl %eax, KTRAP_FRAME_PREVIOUS_MODE(%ebp)
158 /* Set the new previous mode based on the saved CS selector */
159 movl KTRAP_FRAME_CS(%ebp), %eax
160 andl $0x0000FFFF, %eax
161 cmpl $KERNEL_CS, %eax
163 movb $KernelMode, KTHREAD_PREVIOUS_MODE(%edi)
166 movb $UserMode, KTHREAD_PREVIOUS_MODE(%edi)
169 /* Save the old trap frame. */
170 movl KTHREAD_TRAP_FRAME(%edi), %edx
173 /* Save a pointer to the trap frame in the current KTHREAD */
174 movl %ebp, KTHREAD_TRAP_FRAME(%edi)
177 /* Call the C exception handler */
183 /* Get a pointer to the current thread */
184 movl %fs:KPCR_CURRENT_THREAD, %esi
186 /* Restore the old trap frame pointer */
190 movl %ebx, KTHREAD_TRAP_FRAME(%esi)
192 /* Return to the caller */
195 /* Handle the no-thread case out of line */
197 movl $0, %eax /* previous mode */
198 movl %eax, KTRAP_FRAME_PREVIOUS_MODE(%ebp)
199 pushl %eax /* old trap frame */
278 call _KiDoubleFaultHandler
328 movl $_KiTrapHandler, %ebx
376 .globl _KiTrapUnknown