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 */
53 /* Restore the old previous mode */
55 movb %bl, %ss:KTHREAD_PREVIOUS_MODE(%esi)
57 /* Restore the old exception handler list */
59 movl %ebx, %fs:KPCR_EXCEPTION_LIST
66 addl $0x4, %esp /* Ignore error code */
76 * Check that the PCR exists, very early in the boot process it may
79 cmpl $0, %ss:_KiPcrInitDone
82 /* Load the PCR selector into fs */
83 movl $PCR_SELECTOR, %ebx
86 /* Save the old exception list */
87 movl %fs:KPCR_EXCEPTION_LIST, %ebx
90 /* Put the exception handler chain terminator */
91 movl $0xffffffff, %fs:KPCR_EXCEPTION_LIST
93 /* Get a pointer to the current thread */
94 movl %fs:KPCR_CURRENT_THREAD, %edi
96 /* The current thread may be NULL early in the boot process */
100 /* Save the old previous mode */
102 movb %ss:KTHREAD_PREVIOUS_MODE(%edi), %bl
105 /* Set the new previous mode based on the saved CS selector */
106 movl 0x24(%esp), %ebx
107 andl $0x0000FFFF, %ebx
108 cmpl $KERNEL_CS, %ebx
110 movb $KernelMode, %ss:KTHREAD_PREVIOUS_MODE(%edi)
113 movb $UserMode, %ss:KTHREAD_PREVIOUS_MODE(%edi)
116 /* Save other registers */
129 pushl $0 /* XXX: TempESP */
130 pushl $0 /* XXX: TempCS */
131 pushl $0 /* XXX: DebugPointer */
132 pushl $0 /* XXX: DebugArgMark */
133 movl 0x60(%esp), %ebx
134 pushl %ebx /* XXX: DebugEIP */
135 pushl %ebp /* XXX: DebugEBP */
137 /* Load the segment registers */
138 movl $KERNEL_DS, %ebx
143 /* Set ES to kernel segment */
150 /* Save the old trap frame. */
153 movl %ss:KTHREAD_TRAP_FRAME(%edi), %edx
160 /* Save a pointer to the trap frame in the current KTHREAD */
163 movl %ebx, %ss:KTHREAD_TRAP_FRAME(%edi)
166 /* Call the C exception handler */
173 /* Get a pointer to the current thread */
174 movl %fs:KPCR_CURRENT_THREAD, %esi
176 /* Restore the old trap frame pointer */
178 movl %ebx, KTHREAD_TRAP_FRAME(%esi)
180 /* Return to the caller */
183 /* Handle the no-pcr case out of line */
187 /* Handle the no-thread case out of line */
268 call _KiDoubleFaultHandler
338 .globl _KiTrapUnknown