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 ******************************************************************/
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 /* Skip debug information and unsaved registers */
65 /* Restore the old previous mode */
67 movb %bl, %ss:KTHREAD_PREVIOUS_MODE(%esi)
69 /* Restore the old exception handler list */
71 movl %ebx, %fs:KPCR_EXCEPTION_LIST
78 addl $0x4, %esp /* Ignore error code */
88 * Check that the PCR exists, very early in the boot process it may
91 cmpl $0, %ss:_KiPcrInitDone
94 /* Load the PCR selector into fs */
95 movl $PCR_SELECTOR, %ebx
98 /* Save the old exception list */
99 movl %fs:KPCR_EXCEPTION_LIST, %ebx
102 /* Get a pointer to the current thread */
103 movl %fs:KPCR_CURRENT_THREAD, %edi
105 /* The current thread may be NULL early in the boot process */
109 /* Save the old previous mode */
111 movb %ss:KTHREAD_PREVIOUS_MODE(%edi), %bl
114 /* Set the new previous mode based on the saved CS selector */
115 movl 0x24(%esp), %ebx
116 andl $0x0000FFFF, %ebx
117 cmpl $KERNEL_CS, %ebx
119 movb $KernelMode, %ss:KTHREAD_PREVIOUS_MODE(%edi)
122 movb $UserMode, %ss:KTHREAD_PREVIOUS_MODE(%edi)
125 /* Save other registers */
134 /* Clear all breakpoint enables in dr7. */
135 andl $0xFFFF0000, %eax
147 pushl $0 /* XXX: TempESP */
148 pushl $0 /* XXX: TempCS */
149 pushl $0 /* XXX: DebugPointer */
150 pushl $0 /* XXX: DebugArgMark */
151 movl 0x60(%esp), %ebx
152 pushl %ebx /* XXX: DebugEIP */
153 pushl %ebp /* XXX: DebugEBP */
155 /* Load the segment registers */
156 movl $KERNEL_DS, %ebx
161 /* Set ES to kernel segment */
168 /* Save the old trap frame. */
171 movl %ss:KTHREAD_TRAP_FRAME(%edi), %edx
178 /* Save a pointer to the trap frame in the current KTHREAD */
181 movl %ebx, %ss:KTHREAD_TRAP_FRAME(%edi)
184 /* Call the C exception handler */
191 /* Get a pointer to the current thread */
192 movl %fs:KPCR_CURRENT_THREAD, %esi
194 /* Restore the old trap frame pointer */
196 movl %ebx, KTHREAD_TRAP_FRAME(%esi)
198 /* Return to the caller */
201 /* Handle the no-pcr case out of line */
205 /* Handle the no-thread case out of line */
286 call _KiDoubleFaultHandler
383 .globl _KiTrapUnknown