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 */
69 movb %bl, %ss:KTHREAD_PREVIOUS_MODE(%esi)
71 /* Restore the old exception handler list */
73 movl %ebx, %fs:KPCR_EXCEPTION_LIST
80 addl $0x4, %esp /* Ignore error code */
91 * Check that the PCR exists, very early in the boot process it may
94 cmpl $0, %ss:_KiPcrInitDone
97 /* Load the PCR selector into fs */
98 movl $PCR_SELECTOR, %ebx
101 /* Save the old exception list */
102 movl %fs:KPCR_EXCEPTION_LIST, %ebx
105 /* Get a pointer to the current thread */
106 movl %fs:KPCR_CURRENT_THREAD, %edi
108 /* The current thread may be NULL early in the boot process */
112 /* Save the old previous mode */
114 movb %ss:KTHREAD_PREVIOUS_MODE(%edi), %bl
117 /* Set the new previous mode based on the saved CS selector */
118 movl 0x24(%esp), %ebx
119 andl $0x0000FFFF, %ebx
120 cmpl $KERNEL_CS, %ebx
122 movb $KernelMode, %ss:KTHREAD_PREVIOUS_MODE(%edi)
125 movb $UserMode, %ss:KTHREAD_PREVIOUS_MODE(%edi)
128 /* Save other registers */
137 /* Clear all breakpoint enables in dr7. */
138 andl $0xFFFF0000, %eax
150 leal 0x64(%esp), %eax
151 pushl %eax /* XXX: TempESP */
152 pushl %ss /* XXX: TempSS */
153 pushl $0 /* XXX: DebugPointer */
154 pushl $0 /* XXX: DebugArgMark */
155 movl 0x60(%esp), %ebx
156 pushl %ebx /* XXX: DebugEIP */
157 pushl %ebp /* XXX: DebugEBP */
159 /* Load the segment registers */
160 movl $KERNEL_DS, %ebx
165 /* Set ES to kernel segment */
172 /* Save the old trap frame. */
175 movl %ss:KTHREAD_TRAP_FRAME(%edi), %edx
182 /* Save a pointer to the trap frame in the current KTHREAD */
185 movl %ebx, %ss:KTHREAD_TRAP_FRAME(%edi)
188 /* Call the C exception handler */
195 /* Get a pointer to the current thread */
196 movl %fs:KPCR_CURRENT_THREAD, %esi
198 /* Restore the old trap frame pointer */
200 movl %ebx, KTHREAD_TRAP_FRAME(%esi)
202 /* Return to the caller */
205 /* Handle the no-pcr case out of line */
209 /* Handle the no-thread case out of line */
290 call _KiDoubleFaultHandler
387 .globl _KiTrapUnknown