2 * PROJECT: ReactOS kernel
3 * FILE: ntoskrnl/ke/i386/trap.s
4 * PURPOSE: Exception handlers
5 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
6 * David Welch <welch@cwcom.net>
9 /* INCLUDES ******************************************************************/
14 * The prologue is currently a duplication of the trap enter code in KiDebugService.
15 * It will be made a macro and shared later.
18 /* FUNCTIONS *****************************************************************/
21 * Epilog for exception handlers
24 cmpl $1, %eax /* Check for v86 recovery */
30 movl $_KiTrapHandler, %ebx
32 .global _KiTrapProlog2
37 .intel_syntax noprefix
38 /* Load the PCR selector into fs */
42 /* Push exception list and previous mode (invalid) */
43 push fs:[KPCR_EXCEPTION_LIST]
46 /* Push volatiles and segments */
54 /* Set the R3 data segment */
55 mov ax, KGDT_R3_DATA + RPL_MASK
57 /* Skip debug registers and debug stuff */
60 /* Load the segment registers */
67 /* Check if this was from V86 Mode */
68 test dword ptr [ebp+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
71 /* Get current thread */
72 mov ecx, [fs:KPCR_CURRENT_THREAD]
76 and dword ptr [ebp+KTRAP_FRAME_DR7], 0
78 /* Check if the thread was being debugged */
79 //test byte ptr [ecx+KTHREAD_DEBUG_ACTIVE], 0xFF
82 /* Get the Debug Trap Frame EBP/EIP */
83 mov ecx, [ebp+KTRAP_FRAME_EBP]
84 mov edi, [ebp+KTRAP_FRAME_EIP]
86 /* Write the debug data */
87 mov [ebp+KTRAP_FRAME_DEBUGPOINTER], edx
88 mov dword ptr [ebp+KTRAP_FRAME_DEBUGARGMARK], 0xBADB0D00
89 mov [ebp+KTRAP_FRAME_DEBUGEBP], ecx
90 mov [ebp+KTRAP_FRAME_DEBUGEIP], edi
95 /* Call the C exception handler */
101 /* Return to the caller */
180 call _KiDoubleFaultHandler
230 movl $_KiPageFaultHandler, %ebx
278 .globl _KiTrapUnknown
287 .intel_syntax noprefix
288 .globl _KiCoprocessorError@0
289 _KiCoprocessorError@0:
291 /* Get the NPX Thread's Initial stack */
292 mov eax, [fs:KPCR_NPX_THREAD]
293 mov eax, [eax+KTHREAD_INITIAL_STACK]
295 /* Make space for the FPU Save area */
296 sub eax, SIZEOF_FX_SAVE_AREA
298 /* Set the CR0 State */
299 mov dword ptr [eax+FN_CR0_NPX_STATE], 8
306 /* Return to caller */
309 .globl _Ki386AdjustEsp0@4
312 /* Get the current thread */
313 mov eax, [fs:KPCR_CURRENT_THREAD]
315 /* Get trap frame and stack */
317 mov eax, [eax+KTHREAD_INITIAL_STACK]
320 test dword ptr [edx+KTRAP_FRAME_EFLAGS], EFLAGS_V86_MASK
324 sub eax, KTRAP_FRAME_V86_GS - KTRAP_FRAME_SS
327 /* Skip FX Save Area */
328 sub eax, SIZEOF_FX_SAVE_AREA
330 /* Disable interrupts */
335 mov edx, [fs:KPCR_TSS]
336 mov ss:[edx+KTSS_ESP0], eax
338 /* Enable interrupts and return */