Author: tkreuzer
Date: Fri Sep 16 17:47:32 2011
New Revision: 53723
URL:
http://svn.reactos.org/svn/reactos?rev=53723&view=rev
Log:
[NTOSKRNL/AMD64]
- Update the trap code to use the new macros and cleanup a little
Modified:
trunk/reactos/ntoskrnl/ke/amd64/trap.S
Modified: trunk/reactos/ntoskrnl/ke/amd64/trap.S
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/amd64/trap.S?r…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/amd64/trap.S [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/amd64/trap.S [iso-8859-1] Fri Sep 16 17:47:32 2011
@@ -8,8 +8,8 @@
/* INCLUDES ******************************************************************/
#include <asm.inc>
-
#include <ksamd64.inc>
+#include <trapamd64.inc>
EXTERN KiDispatchException:PROC
EXTERN FrLdrDbgPrint:DWORD
@@ -28,232 +28,23 @@
MsgUnimplemented:
.asciz "WARNING: %s at %s:%d is UNIMPLEMENTED!\n"
-MsgPageFault:
-.asciz "Page fault! Code = 0x%x, RIP = %p, FaultingAddress = %p\n"
-
-MsgGeneralProtFault:
-.asciz "General protection fault at %p!\n"
-
-MsgBreakpointTrap:
-.asciz "BreakpointTrap at %p\n"
-
-MsgUnexpectedInterrupt:
-.asciz "UnexpectedInterrupt Vector=0x%02lx\n"
-
-MsgInvalidOpcodeFault:
-.asciz "Invalid opcode fault at %p!\n"
-
-MsgDoubleFault:
-.asciz "Double fault at %p, rbp=%p!\n"
-
-MsgTrapInfo:
-.asciz "Trap: %s at %p\n"
-
-MACRO(TRAPINFO, func)
-LOCAL label1, label2
-#if 0
- jmp label2
-label1: .asciz "\func"
-label2:
- sub rsp, 32
- lea rcx, MsgTrapInfo[rip]
- lea rdx, 1b[rip]
- mov r8, [rbp + KTRAP_FRAME_Rip]
- call qword ptr FrLdrDbgPrint[rip]
- add rsp, 32
-#endif
+
+/* Helper Macros *************************************************************/
+
+MACRO(DispatchException, Status, Number, P1, P2, P3)
+ mov eax, Status
+ mov edx, Number
+ mov r9, P1
+ mov r10, P2
+ mov r11, P3
+ call InternalDispatchException
ENDM
-/* Helper Macros *************************************************************/
-
-#define TRAPFLAG_VOLATILES HEX(01)
-#define TRAPFLAG_NONVOLATILES HEX(02)
-#define TRAPFLAG_XMM HEX(04)
-#define TRAPFLAG_SEGMENTS HEX(08)
-#define TRAPFLAG_DEBUG HEX(10)
-#define TRAPFLAG_HAS_ERRORCODE HEX(100)
-
-#define TRAPFLAG_SYSTEMSERVICE (TRAPFLAG_VOLATILES|TRAPFLAG_DEBUG)
-#define TRAPFLAG_ALL HEX(ff)
-
-/*
- * Stack Layout:
- * |-------------------|
- * | KTRAP_FRAME |
- * |-------------------| <- rbp
- * | EXCEPTION_RECORD |
- * |-------------------|
- * | KEXCEPTION_FRAME |
- * |-------------------| <- rsp
- *
- */
-
-/*
- * ENTER_TRAP_FRAME - Allocate KTRAP_FRAME_LENGTH and save registers to it
- */
-MACRO(ENTER_TRAP_FRAME, Flags)
-LOCAL dont_swap
-
- /* Save the trap flags for this trap */
- TRAPFLAGS = VAL(Flags)
-
- /* Size of hardware trap frame */
-if (TRAPFLAGS AND TRAPFLAG_HAS_ERRORCODE)
- .pushframe code
- SIZE_INITIAL_FRAME = 6 * 8
-else
- .pushframe
- SIZE_INITIAL_FRAME = 5 * 8
-endif
-
- /* Make room for a KTRAP_FRAME */
- sub rsp, (KTRAP_FRAME_LENGTH - SIZE_INITIAL_FRAME)
- .allocstack (KTRAP_FRAME_LENGTH - SIZE_INITIAL_FRAME)
- .endprolog
-
- /* Save rbp */
- mov [rsp + KTRAP_FRAME_Rbp], rbp
-
- /* Point rbp to the KTRAP_FRAME */
- lea rbp, [rsp]
-
-if (TRAPFLAGS AND TRAPFLAG_NONVOLATILES)
- /* Save non-volatile registers */
- mov [rbp + KTRAP_FRAME_Rbx], rbx
- mov [rbp + KTRAP_FRAME_Rdi], rdi
- mov [rbp + KTRAP_FRAME_Rsi], rsi
-endif
-
-if (TRAPFLAGS AND TRAPFLAG_VOLATILES)
- /* Save volatile registers */
- mov [rbp + KTRAP_FRAME_Rax], rax
- mov [rbp + KTRAP_FRAME_Rcx], rcx
- mov [rbp + KTRAP_FRAME_Rdx], rdx
- mov [rbp + KTRAP_FRAME_R8], r8
- mov [rbp + KTRAP_FRAME_R9], r9
- mov [rbp + KTRAP_FRAME_R10], r10
- mov [rbp + KTRAP_FRAME_R11], r11
-endif
-
-if (TRAPFLAGS AND TRAPFLAG_XMM)
- /* Save xmm registers */
- movdqa [rbp + KTRAP_FRAME_Xmm0], xmm0
- movdqa [rbp + KTRAP_FRAME_Xmm1], xmm1
- movdqa [rbp + KTRAP_FRAME_Xmm2], xmm2
- movdqa [rbp + KTRAP_FRAME_Xmm3], xmm3
- movdqa [rbp + KTRAP_FRAME_Xmm4], xmm4
- movdqa [rbp + KTRAP_FRAME_Xmm5], xmm5
-endif
-
-if (TRAPFLAGS AND TRAPFLAG_SEGMENTS)
- /* Save segment selectors */
- mov ax, ds
- mov [rbp + KTRAP_FRAME_SegDs], ax
- mov ax, es
- mov [rbp + KTRAP_FRAME_SegEs], ax
- mov ax, fs
- mov [rbp + KTRAP_FRAME_SegFs], ax
- mov ax, gs
- mov [rbp + KTRAP_FRAME_SegGs], ax
-endif
-
- /* Save previous mode and swap gs when it was UserMode */
- mov ax, [rbp + KTRAP_FRAME_SegCs]
- and al, 1
- mov [rbp + KTRAP_FRAME_PreviousMode], al
- jz dont_swap
- swapgs
-dont_swap:
-
- /* Save previous irql */
- mov rax, cr8
- mov [rbp + KTRAP_FRAME_PreviousIrql], al
-
-// KTRAP_FRAME_FaultIndicator
-// KTRAP_FRAME_ExceptionActive
-// KTRAP_FRAME_MxCsr
-
-if (TRAPFLAGS AND TRAPFLAG_DEBUG)
- /* Save debug registers */
- mov rax, dr0
- mov [rbp + KTRAP_FRAME_Dr0], rax
- mov rax, dr1
- mov [rbp + KTRAP_FRAME_Dr1], rax
- mov rax, dr2
- mov [rbp + KTRAP_FRAME_Dr2], rax
- mov rax, dr3
- mov [rbp + KTRAP_FRAME_Dr3], rax
- mov rax, dr6
- mov [rbp + KTRAP_FRAME_Dr6], rax
- mov rax, dr7
- mov [rbp + KTRAP_FRAME_Dr7], rax
-endif
-
-// KTRAP_FRAME_DebugControl
-// KTRAP_FRAME_LastBranchToRip
-// KTRAP_FRAME_LastBranchFromRip
-// KTRAP_FRAME_LastExceptionToRip
-// KTRAP_FRAME_LastExceptionFromRip
-// KTRAP_FRAME_TrapFrame
-
- /* Make sure the direction flag is cleared */
- cld
-ENDM
-
-
-/*
- * LEAVE_TRAP_FRAME - Restore registers and free stack space
- */
-MACRO(LEAVE_TRAP_FRAME)
-LOCAL dont_swap_back
-if (TRAPFLAGS AND TRAPFLAG_SEGMENTS)
- /* Restore segment selectors */
- mov ax, [rbp + KTRAP_FRAME_SegDs]
- mov ds, ax
- mov ax, [rbp + KTRAP_FRAME_SegEs]
- mov es, ax
- mov ax, [rbp + KTRAP_FRAME_SegFs]
- mov fs, ax
-endif
-
- test byte ptr [rbp + KTRAP_FRAME_PreviousMode], 1
- jz dont_swap_back
- swapgs
-dont_swap_back:
-
-if (TRAPFLAGS AND TRAPFLAG_NONVOLATILES)
- /* Restore non-volatile registers */
- mov rbx, [rbp + KTRAP_FRAME_Rbx]
- mov rdi, [rbp + KTRAP_FRAME_Rdi]
- mov rsi, [rbp + KTRAP_FRAME_Rsi]
-endif
-
-if (TRAPFLAGS AND TRAPFLAG_VOLATILES)
- /* Restore volatile registers */
- mov rax, [rbp + KTRAP_FRAME_Rax]
- mov rcx, [rbp + KTRAP_FRAME_Rcx]
- mov rdx, [rbp + KTRAP_FRAME_Rdx]
- mov r8, [rbp + KTRAP_FRAME_R8]
- mov r9, [rbp + KTRAP_FRAME_R9]
- mov r10, [rbp + KTRAP_FRAME_R10]
- mov r11, [rbp + KTRAP_FRAME_R11]
-endif
-
-if (TRAPFLAGS AND TRAPFLAG_XMM)
- /* Restore xmm registers */
- movdqa xmm0, [rbp + KTRAP_FRAME_Xmm0]
- movdqa xmm1, [rbp + KTRAP_FRAME_Xmm1]
- movdqa xmm2, [rbp + KTRAP_FRAME_Xmm2]
- movdqa xmm3, [rbp + KTRAP_FRAME_Xmm3]
- movdqa xmm4, [rbp + KTRAP_FRAME_Xmm4]
- movdqa xmm5, [rbp + KTRAP_FRAME_Xmm5]
-endif
-
- /* Restore rbp */
- mov rbp, [rbp + KTRAP_FRAME_Rbp]
-
- /* Adjust stack pointer */
- add rsp, KTRAP_FRAME_Rip
+MACRO(Fatal, BugcheckCode)
+ /* Bugcheck */
+ mov ecx, BugcheckCode
+ mov rdx, rbp
+ call KiSystemFatalException
ENDM
@@ -348,33 +139,25 @@
/* SOFTWARE INTERRUPT SERVICES ***********************************************/
PUBLIC KiDivideErrorFault
-.PROC KiDivideErrorFault
+FUNC KiDivideErrorFault
/* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
+ EnterTrap TF_SAVE_ALL
/* Enable interrupts */
sti
/* Dispatch the exception */
- mov eax, STATUS_INTEGER_DIVIDE_BY_ZERO
- mov edx, 0
- mov r9, 0
- mov r10, 0
- mov r11, 0
- call InternalDispatchException
-
- /* Return */
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiDivideErrorFault
+ DispatchException STATUS_INTEGER_DIVIDE_BY_ZERO, 0, 0, 0, 0
+
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiDivideErrorFault
PUBLIC KiDebugTrapOrFault
-.PROC KiDebugTrapOrFault
+FUNC KiDebugTrapOrFault
/* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
-
- TRAPINFO KiDebugTrapOrFault
+ EnterTrap TF_SAVE_ALL
/* Check if the frame was from kernelmode */
test word ptr [rbp + KTRAP_FRAME_SegCs], 3
@@ -384,125 +167,84 @@
sti
KiDebugTrapOrFaultKMode:
-
- /* Dispatch the exception */
- mov eax, STATUS_SINGLE_STEP
- mov edx, 0
- mov r9, 0
- mov r10, 0
- mov r11, 0
- call InternalDispatchException
-
- /* Return */
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiDebugTrapOrFault
+ /* Dispatch the exception */
+ DispatchException STATUS_SINGLE_STEP, 0, 0, 0, 0
+
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiDebugTrapOrFault
PUBLIC KiNmiInterrupt
-.PROC KiNmiInterrupt
+FUNC KiNmiInterrupt
/* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
+ EnterTrap TF_SAVE_ALL
UNIMPLEMENTED KiNmiInterrupt
-
- jmp $
-
- /* Return */
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiNmiInterrupt
+ int 3
+
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiNmiInterrupt
PUBLIC KiBreakpointTrap
-.PROC KiBreakpointTrap
+FUNC KiBreakpointTrap
/* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
-
- TRAPINFO KiBreakpointTrap
-
-// lea rcx, MsgBreakpointTrap[rip]
-// mov rdx, rsp
-// call qword ptr FrLdrDbgPrint[rip]
-
- /* Dispatch the exception */
- mov eax, STATUS_BREAKPOINT
- mov edx, 3
- mov r9, 0
- mov r10, 0
- mov r11, 0
- call InternalDispatchException
-
- /* Return */
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiBreakpointTrap
+ EnterTrap TF_SAVE_ALL
+
+ /* Dispatch the exception */
+ DispatchException STATUS_BREAKPOINT, 3, 0, 0, 0
+
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiBreakpointTrap
PUBLIC KiOverflowTrap
-.PROC KiOverflowTrap
+FUNC KiOverflowTrap
/* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
+ EnterTrap TF_SAVE_ALL
/* Enable interrupts */
sti
/* Dispatch the exception */
- mov eax, STATUS_INTEGER_OVERFLOW
- mov edx, 3
- mov r9, 0
- mov r10, 0
- mov r11, 0
- call InternalDispatchException
-
- /* Return */
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiOverflowTrap
+ DispatchException STATUS_INTEGER_OVERFLOW, 3, 0, 0, 0
+
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiOverflowTrap
PUBLIC KiBoundFault
-.PROC KiBoundFault
- /* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
+FUNC KiBoundFault
+ /* No error code */
+ EnterTrap TF_SAVE_ALL
/* Check if the frame was from kernelmode */
test word ptr [rbp + KTRAP_FRAME_SegCs], 3
- jnz KiBoundFaltUserMode
-
- /* Bugcheck */
- mov ecx, EXCEPTION_BOUND_CHECK
- mov rdx, rbp
- call KiSystemFatalException
-
-KiBoundFaltUserMode:
+ jnz KiBoundFaultUserMode
+
+ /* Bugcheck */
+ Fatal EXCEPTION_BOUND_CHECK
+
+KiBoundFaultUserMode:
/* Enable interrupts for user-mode */
sti
/* Dispatch the exception */
- mov eax, STATUS_INTEGER_OVERFLOW
- mov edx, 3
- mov r9, 0
- mov r10, 0
- mov r11, 0
- call InternalDispatchException
-
- /* Return */
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiBoundFault
+ DispatchException STATUS_ARRAY_BOUNDS_EXCEEDED, 0, 0, 0, 0
+
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiBoundFault
PUBLIC KiInvalidOpcodeFault
-.PROC KiInvalidOpcodeFault
- /* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
-
- TRAPINFO KiInvalidOpcodeFault
-
- mov rdx, [rbp + KTRAP_FRAME_Rip]
- lea rcx, MsgInvalidOpcodeFault[rip]
- call qword ptr FrLdrDbgPrint[rip]
+FUNC KiInvalidOpcodeFault
+ /* No error code */
+ EnterTrap TF_SAVE_ALL
/* Enable interrupts */
sti
@@ -517,23 +259,17 @@
/* Kernel mode fault */
/* Dispatch the exception */
- mov eax, STATUS_ILLEGAL_INSTRUCTION
- mov edx, 3
- mov r9, 0
- mov r10, 0
- mov r11, 0
- call InternalDispatchException
-
- /* Return */
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiInvalidOpcodeFault
+ DispatchException STATUS_ILLEGAL_INSTRUCTION, 3, 0, 0, 0
+
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiInvalidOpcodeFault
PUBLIC KiNpxNotAvailableFault
-.PROC KiNpxNotAvailableFault
- /* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
+FUNC KiNpxNotAvailableFault
+ /* No error code */
+ EnterTrap TF_SAVE_ALL
/* Call the C handler */
mov rcx, rbp
@@ -544,103 +280,73 @@
jz KiNpxNotAvailableFaultExit
/* Dispatch the exception */
- mov edx, 3
- mov r9, 0
- mov r10, 0
- mov r11, 0
- call InternalDispatchException
+ DispatchException eax, 3, 0, 0, 0
KiNpxNotAvailableFaultExit:
/* Return */
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiNpxNotAvailableFault
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiNpxNotAvailableFault
PUBLIC KiDoubleFaultAbort
-.PROC KiDoubleFaultAbort
- /* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
-
- lea rcx, MsgDoubleFault[rip]
- mov rdx, [rbp + KTRAP_FRAME_FaultAddress]
- mov r8, rbp
- call qword ptr FrLdrDbgPrint[rip]
-
- /* Bugcheck */
- mov ecx, 8 // EXCEPTION_DOUBLE_FAULT
- mov rdx, rbp
- call KiSystemFatalException
-
- jmp $
-.ENDP KiDoubleFaultAbort
+FUNC KiDoubleFaultAbort
+ /* No error code */
+ EnterTrap TF_SAVE_ALL
+
+ /* Bugcheck */
+ Fatal 8 // EXCEPTION_DOUBLE_FAULT
+ jmp $
+ENDFUNC KiDoubleFaultAbort
PUBLIC KiNpxSegmentOverrunAbort
-.PROC KiNpxSegmentOverrunAbort
- /* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
-
- /* Bugcheck */
- mov ecx, EXCEPTION_NPX_OVERRUN
- mov rdx, rbp
- call KiSystemFatalException
-
- jmp $
-.ENDP KiNpxSegmentOverrunAbort
+FUNC KiNpxSegmentOverrunAbort
+ /* No error code */
+ EnterTrap TF_SAVE_ALL
+
+ /* Bugcheck */
+ Fatal EXCEPTION_NPX_OVERRUN
+ jmp $
+ENDFUNC KiNpxSegmentOverrunAbort
PUBLIC KiInvalidTssFault
-.PROC KiInvalidTssFault
- /* We have an error code */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
-
- /* Bugcheck */
- mov ecx, EXCEPTION_INVALID_TSS
- mov rdx, rbp
- call KiSystemFatalException
-
- jmp $
-.ENDP KiInvalidTssFault
+FUNC KiInvalidTssFault
+ /* We have an error code */
+ EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
+
+ /* Bugcheck */
+ Fatal EXCEPTION_INVALID_TSS
+ jmp $
+ENDFUNC KiInvalidTssFault
PUBLIC KiSegmentNotPresentFault
-.PROC KiSegmentNotPresentFault
- /* We have an error code */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
-
- /* Bugcheck */
- mov ecx, EXCEPTION_SEGMENT_NOT_PRESENT
- mov rdx, rbp
- call KiSystemFatalException
-
- jmp $
-.ENDP KiSegmentNotPresentFault
+FUNC KiSegmentNotPresentFault
+ /* We have an error code */
+ EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
+
+ /* Bugcheck */
+ Fatal EXCEPTION_SEGMENT_NOT_PRESENT
+ jmp $
+ENDFUNC KiSegmentNotPresentFault
PUBLIC KiStackFault
-.PROC KiStackFault
- /* We have an error code */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
-
- /* Bugcheck */
- mov ecx, EXCEPTION_STACK_FAULT
- mov rdx, rbp
- call KiSystemFatalException
-
- jmp $
-.ENDP KiStackFault
+FUNC KiStackFault
+ /* We have an error code */
+ EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
+
+ /* Bugcheck */
+ Fatal EXCEPTION_STACK_FAULT
+ jmp $
+ENDFUNC KiStackFault
PUBLIC KiGeneralProtectionFault
-.PROC KiGeneralProtectionFault
- /* We have an error code */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
-
- //TRAPINFO KiGeneralProtectionFault
- //mov rdx, [rbp + KTRAP_FRAME_Rip]
- //lea rcx, MsgGeneralProtFault[rip]
- //call qword ptr FrLdrDbgPrint[rip]
+FUNC KiGeneralProtectionFault
+ /* We have an error code */
+ EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
/* Call the C handler */
mov rcx, rbp
@@ -651,11 +357,7 @@
jge KiGpfExit
/* Dispatch the exception */
- mov edx, 3
- mov r9, 0
- mov r10, 0
- mov r11, 0
- call InternalDispatchException
+ DispatchException eax, 3, 0, 0, 0
KiGpfFatal:
@@ -670,25 +372,15 @@
KiGpfExit:
/* Return */
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiGeneralProtectionFault
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiGeneralProtectionFault
PUBLIC KiPageFault
-.PROC KiPageFault
- /* We have an error code */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
-
- TRAPINFO KiPageFault
-
-#if 0
- lea rcx, MsgPageFault[rip]
- mov rdx, [rbp + KTRAP_FRAME_ErrorCode]
- mov r8, [rbp + KTRAP_FRAME_Rip]
- mov r9, [rbp + KTRAP_FRAME_FaultAddress]
- call qword ptr FrLdrDbgPrint[rip]
-#endif
+FUNC KiPageFault
+ /* We have an error code */
+ EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
/* Save page fault address */
mov rdx, cr2
@@ -721,6 +413,7 @@
je SpecialCode
InPageException:
+
/* Dispatch in-page exception */
mov r11d, eax // Param3 = Status
mov eax, STATUS_IN_PAGE_ERROR // ExceptionCode
@@ -738,57 +431,50 @@
call InternalDispatchException
PageFaultReturn:
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiPageFault
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiPageFault
PUBLIC KiFloatingErrorFault
-.PROC KiFloatingErrorFault
- /* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
+FUNC KiFloatingErrorFault
+ /* No error code */
+ EnterTrap TF_SAVE_ALL
UNIMPLEMENTED KiFloatingErrorFault
-
- jmp $
-.ENDP KiFloatingErrorFault
+ int 3
+
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiFloatingErrorFault
PUBLIC KiAlignmentFault
-.PROC KiAlignmentFault
- /* We have an error code */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
-
- /* Enable interrupts */
- sti
-
- /* Bugcheck */
- mov ecx, EXCEPTION_ALIGNMENT_CHECK
- mov rdx, rbp
- call KiSystemFatalException
-
- jmp $
-.ENDP KiAlignmentFault
+FUNC KiAlignmentFault
+ /* We have an error code */
+ EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
+
+ /* Bugcheck */
+ Fatal EXCEPTION_ALIGNMENT_CHECK
+ jmp $
+ENDFUNC KiAlignmentFault
PUBLIC KiMcheckAbort
-.PROC KiMcheckAbort
- /* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
-
- /* Bugcheck */
- mov ecx, HEX(12)
- mov rdx, rbp
- call KiSystemFatalException
-
- jmp $
-.ENDP KiMcheckAbort
+FUNC KiMcheckAbort
+ /* No error code */
+ EnterTrap TF_SAVE_ALL
+
+ /* Bugcheck */
+ Fatal HEX(12)
+ jmp $
+ENDFUNC KiMcheckAbort
PUBLIC KiXmmException
-.PROC KiXmmException
- /* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
+FUNC KiXmmException
+ /* No error code */
+ EnterTrap TF_SAVE_ALL
/* Call the C handler */
mov rcx, rbp
@@ -799,99 +485,54 @@
jge KiXmmExit
/* Dispatch the exception */
- mov edx, 3
- mov r9, 0
- mov r10, 0
- mov r11, 0
- call InternalDispatchException
+ DispatchException eax, 3, 0, 0, 0
KiXmmExit:
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiXmmException
-
-
-PUBLIC KiApcInterrupt
-.PROC KiApcInterrupt
- /* We have an error code */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
-
- UNIMPLEMENTED KiApcInterrupt
-
- jmp $
-.ENDP KiApcInterrupt
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiXmmException
PUBLIC KiRaiseAssertion
-.PROC KiRaiseAssertion
- /* We have an error code */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
+FUNC KiRaiseAssertion
+ /* We have an error code */
+ EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
/* Decrement RIP to point to the INT2C instruction (2 bytes, not 1 like INT3) */
sub qword ptr [rbp + KTRAP_FRAME_Rip], 2
/* Dispatch the exception */
- mov eax, STATUS_ASSERTION_FAILURE
- mov edx, 0
- mov r9, 0
- mov r10, 0
- mov r11, 0
- call InternalDispatchException
-
- LEAVE_TRAP_FRAME
- iretq
-.ENDP KiRaiseAssertion
+ DispatchException STATUS_ASSERTION_FAILURE, 0, 0, 0, 0
+
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiRaiseAssertion
PUBLIC KiDebugServiceTrap
.PROC KiDebugServiceTrap
- /* Push pseudo error code */
- ENTER_TRAP_FRAME TRAPFLAG_ALL
-
- TRAPINFO KiDebugServiceTrap
+ /* No error code */
+ EnterTrap TF_SAVE_ALL
/* Increase Rip to skip the int3 */
inc qword ptr [rbp + KTRAP_FRAME_Rip]
- /* Dispatch the exception */
- mov eax, STATUS_BREAKPOINT
- mov edx, 3
- mov r9, [rbp+KTRAP_FRAME_Rax] // Service
- mov r10, [rbp+KTRAP_FRAME_Rcx] // Buffer
- mov r11, [rbp+KTRAP_FRAME_Rdx] // Length
- call InternalDispatchException
-
- LEAVE_TRAP_FRAME;
- iretq
+ /* Dispatch the exception (Params = service, buffer, legth) */
+ DispatchException STATUS_BREAKPOINT, 3, [rbp+KTRAP_FRAME_Rax], [rbp+KTRAP_FRAME_Rcx],
[rbp+KTRAP_FRAME_Rdx]
+
+ /* Return */
+ ExitTrap TF_SAVE_ALL
.ENDP KiDebugServiceTrap
-
-PUBLIC KiDpcInterrupt
-.PROC KiDpcInterrupt
- /* We have an error code */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
-
- UNIMPLEMENTED KiDpcInterrupt
-
- jmp $
-.ENDP KiDpcInterrupt
-
-
-PUBLIC KiIpiInterrupt
-.PROC KiIpiInterrupt
- /* We have an error code */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
-
- UNIMPLEMENTED KiIpiInterrupt
-
- jmp $
-.ENDP KiIpiInterrupt
+TRAP_ENTRY KiApcInterrupt, (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
+TRAP_ENTRY KiDpcInterrupt, (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
+TRAP_ENTRY KiIpiInterrupt, (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
PUBLIC KiUnexpectedInterrupt
-.PROC KiUnexpectedInterrupt
+FUNC KiUnexpectedInterrupt
/* The error code is the vector */
- ENTER_TRAP_FRAME (TRAPFLAG_HAS_ERRORCODE OR TRAPFLAG_ALL)
+ EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
#if 0
/* Set bugcheck parameters */
@@ -904,9 +545,9 @@
call KeBugCheckWithTf
jmp $
#endif
- LEAVE_TRAP_FRAME;
- iretq
-.ENDP KiUnexpectedInterrupt
+ /* Return */
+ ExitTrap TF_SAVE_ALL
+ENDFUNC KiUnexpectedInterrupt
#ifdef _MSC_VER
#undef lgdt