3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ke/i386/trap.s
5 * PURPOSE: Exception handlers
6 * PROGRAMMER: David Welch <welch@cwcom.net>
9 /* INCLUDES ******************************************************************/
13 #include <internal/i386/ke.h>
18 /* FUNCTIONS *****************************************************************/
21 * Epilog for exception handlers
24 cmpl $1, %eax /* Check for v86 recovery */
28 /* Skip debug information and unsaved registers */
50 /* Restore the old exception handler list */
52 movl %ebx, %fs:KPCR_EXCEPTION_LIST
59 addl $0x4, %esp /* Ignore error code */
65 movl $_KiTrapHandler, %ebx
67 .global _KiTrapProlog2
72 /* Make room for the previous mode and the exception list */
75 /* Save other registers */
84 /* Clear all breakpoint enables in dr7. */
85 andl $0xFFFF0000, %eax
98 pushl %eax /* XXX: TempESP */
99 pushl %ss /* XXX: TempSS */
100 pushl $0 /* XXX: DebugPointer */
101 pushl $0 /* XXX: DebugArgMark */
102 movl 0x60(%esp), %eax
103 pushl %eax /* XXX: DebugEIP */
104 pushl %ebp /* XXX: DebugEBP */
106 /* Load the segment registers */
107 movl $KGDT_R0_DATA, %eax
112 /* save the trap frame */
115 /* Load the PCR selector into fs */
116 movl $KGDT_R0_PCR, %eax
119 /* Save the old exception list */
120 movl %fs:KPCR_EXCEPTION_LIST, %eax
121 movl %eax, KTRAP_FRAME_EXCEPTION_LIST(%ebp)
123 /* Get a pointer to the current thread */
124 movl %fs:KPCR_CURRENT_THREAD, %edi
126 /* The current thread may be NULL early in the boot process */
130 /* Save the old previous mode */
132 movb KTHREAD_PREVIOUS_MODE(%edi), %al
133 movl %eax, KTRAP_FRAME_PREVIOUS_MODE(%ebp)
135 /* Set the new previous mode based on the saved CS selector */
136 movl KTRAP_FRAME_CS(%ebp), %eax
137 andl $0x0000FFFF, %eax
139 /* Save the old trap frame. */
140 movl KTHREAD_TRAP_FRAME(%edi), %edx
143 /* Save a pointer to the trap frame in the current KTHREAD */
144 movl %ebp, KTHREAD_TRAP_FRAME(%edi)
147 /* Call the C exception handler */
153 /* Get a pointer to the current thread */
154 movl %fs:KPCR_CURRENT_THREAD, %esi
156 /* Restore the old trap frame pointer */
160 movl %ebx, KTHREAD_TRAP_FRAME(%esi)
162 /* Return to the caller */
165 /* Handle the no-thread case out of line */
167 movl $0, %eax /* previous mode */
168 movl %eax, KTRAP_FRAME_PREVIOUS_MODE(%ebp)
169 pushl %eax /* old trap frame */
248 call _KiDoubleFaultHandler
298 movl $_KiPageFaultHandler, %ebx
346 .globl _KiTrapUnknown
355 .intel_syntax noprefix
356 .globl _KiCoprocessorError@0
357 _KiCoprocessorError@0:
359 /* Get the NPX Thread's Initial stack */
360 mov eax, [fs:KPCR_NPX_THREAD]
361 mov eax, [eax+KTHREAD_INITIAL_STACK]
363 /* Make space for the FPU Save area */
364 sub eax, SIZEOF_FX_SAVE_AREA
366 /* Set the CR0 State */
367 mov dword ptr [eax+FN_CR0_NPX_STATE], 8
374 /* Return to caller */
377 .globl _Ki386AdjustEsp0@4
380 /* Get the current thread */
381 mov eax, [fs:KPCR_CURRENT_THREAD]
383 /* Get trap frame and stack */
385 mov eax, [eax+KTHREAD_INITIAL_STACK]
388 test dword ptr [edx+KTRAP_FRAME_EFLAGS], X86_EFLAGS_VM
392 sub eax, KTRAP_FRAME_V86_GS - KTRAP_FRAME_SS
395 /* Skip FX Save Area */
396 sub eax, SIZEOF_FX_SAVE_AREA
398 /* Disable interrupts */
403 mov edx, [fs:KPCR_TSS]
404 mov ss:[edx+KTSS_ESP0], eax
406 /* Enable interrupts and return */