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.
19 /* $Id: trap.s,v 1.10 2001/03/28 14:24:05 dwelch Exp $
21 * PROJECT: ReactOS kernel
22 * FILE: ntoskrnl/ke/i386/trap.s
23 * PURPOSE: Exception handlers
24 * PROGRAMMER: David Welch <welch@cwcom.net>
27 /* INCLUDES ******************************************************************/
29 #include <ddk/status.h>
30 #include <internal/i386/segment.h>
31 #include <internal/ps.h>
32 #include <ddk/defines.h>
34 /* FUNCTIONS *****************************************************************/
37 * Epilog for exception handlers
40 cmpl $1, %eax /* Check for v86 recovery */
44 /* Get a pointer to the current thread */
47 /* Restore the old trap frame pointer */
49 movl %ebx, KTHREAD_TRAP_FRAME(%esi)
51 /* Skip debug information and unsaved registers */
60 /* Restore the old previous mode */
62 movb %bl, %ss:KTHREAD_PREVIOUS_MODE(%esi)
64 /* Restore the old exception handler list */
66 movl %ebx, %fs:KPCR_EXCEPTION_LIST
73 addl $0x4, %esp /* Ignore error code */
83 * Check that the PCR exists, very early in the boot process it may
86 cmpl $0, %ss:_KiPcrInitDone
89 /* Load the PCR selector into fs */
90 movl $PCR_SELECTOR, %ebx
93 /* Save the old exception list */
94 movl %fs:KPCR_EXCEPTION_LIST, %ebx
97 /* Put the exception handler chain terminator */
98 movl $0xffffffff, %fs:KPCR_EXCEPTION_LIST
100 /* Get a pointer to the current thread */
101 movl %fs:KPCR_CURRENT_THREAD, %edi
103 /* The current thread may be NULL early in the boot process */
107 /* Save the old previous mode */
109 movb %ss:KTHREAD_PREVIOUS_MODE(%edi), %bl
112 /* Set the new previous mode based on the saved CS selector */
113 movl 0x24(%esp), %ebx
114 cmpl $KERNEL_CS, %ebx
116 movb $KernelMode, %ss:KTHREAD_PREVIOUS_MODE(%edi)
119 movb $UserMode, %ss:KTHREAD_PREVIOUS_MODE(%edi)
122 /* Save other registers */
135 pushl $0 /* XXX: TempESP */
136 pushl $0 /* XXX: TempCS */
137 pushl $0 /* XXX: DebugPointer */
138 pushl $0 /* XXX: DebugArgMark */
139 pushl $0 /* XXX: DebugEIP */
140 pushl $0 /* XXX: DebugEBP */
142 /* Load the segment registers */
143 movl $KERNEL_DS, %ebx
148 /* Set ES to kernel segment */
152 /* Call the C exception handler */
160 /* Return to the caller */
163 /* Handle the no-pcr case out of line */
167 /* Handle the no-thread case out of line */
248 call _KiDoubleFaultHandler
316 .globl _KiTrapUnknown