trap.S is now fully MASM/ML compatible

svn path=/branches/ros-amd64-bringup/; revision=45336
This commit is contained in:
Timo Kreuzer 2010-01-30 03:12:26 +00:00
parent bfd0e180c3
commit 752c8aead9

View file

@ -11,7 +11,7 @@
#include <ndk/amd64/asm.h> #include <ndk/amd64/asm.h>
EXTERN _KiDispatchException:PROC EXTERN _KiDispatchException:PROC
EXTERN _FrLdrDbgPrint:PROC EXTERN _FrLdrDbgPrint:DWORD
EXTERN _KeBugCheckWithTf:PROC EXTERN _KeBugCheckWithTf:PROC
EXTERN _MmAccessFault:PROC EXTERN _MmAccessFault:PROC
@ -45,16 +45,16 @@ _MsgTrapInfo:
.ascii "Trap: %s at %p\n\0" .ascii "Trap: %s at %p\n\0"
MACRO(TRAPINFO, func) MACRO(TRAPINFO, func)
LOCAL label1, label2
#if 0 #if 0
jmp 2f jmp label2
.equ expr, 12 label1: .asciz "\func"
1: .asciz "\func" label2:
2:
sub rsp, 32 sub rsp, 32
lea rcx, RIP(_MsgTrapInfo) lea rcx, RIP(_MsgTrapInfo)
lea rdx, 1b[rip] lea rdx, 1b[rip]
mov r8, [rbp + KTRAP_FRAME_Rip] mov r8, [rbp + KTRAP_FRAME_Rip]
call _FrLdrDbgPrint[rip] call qword ptr RIP(_FrLdrDbgPrint)
add rsp, 32 add rsp, 32
#endif #endif
ENDM ENDM
@ -86,6 +86,7 @@ ENDM
* ENTER_TRAP_FRAME - Allocate SIZE_KTRAP_FRAME and save registers to it * ENTER_TRAP_FRAME - Allocate SIZE_KTRAP_FRAME and save registers to it
*/ */
MACRO(ENTER_TRAP_FRAME, Flags) MACRO(ENTER_TRAP_FRAME, Flags)
LOCAL dont_swap
SIZE_INITIAL_FRAME = 7 * 8 SIZE_INITIAL_FRAME = 7 * 8
SIZE_TRAP_FRAME_ALLOC = SIZE_KTRAP_FRAME - SIZE_INITIAL_FRAME SIZE_TRAP_FRAME_ALLOC = SIZE_KTRAP_FRAME - SIZE_INITIAL_FRAME
TRAPFLAGS = VAL(Flags) TRAPFLAGS = VAL(Flags)
@ -145,9 +146,9 @@ endif
mov ax, [rbp + KTRAP_FRAME_SegCs] mov ax, [rbp + KTRAP_FRAME_SegCs]
and al, 1 and al, 1
mov [rbp + KTRAP_FRAME_PreviousMode], al mov [rbp + KTRAP_FRAME_PreviousMode], al
jz 1f jz dont_swap
swapgs swapgs
1: dont_swap:
/* Save previous irql */ /* Save previous irql */
mov rax, cr8 mov rax, cr8
@ -189,7 +190,7 @@ ENDM
* LEAVE_TRAP_FRAME - Restore registers and free stack space * LEAVE_TRAP_FRAME - Restore registers and free stack space
*/ */
MACRO(LEAVE_TRAP_FRAME) MACRO(LEAVE_TRAP_FRAME)
LOCAL dont_swap_back
if (TRAPFLAGS AND TRAPFLAG_SEGMENTS) if (TRAPFLAGS AND TRAPFLAG_SEGMENTS)
/* Restore segment selectors */ /* Restore segment selectors */
mov ax, [rbp + KTRAP_FRAME_SegDs] mov ax, [rbp + KTRAP_FRAME_SegDs]
@ -201,9 +202,9 @@ if (TRAPFLAGS AND TRAPFLAG_SEGMENTS)
endif endif
test byte ptr [rbp + KTRAP_FRAME_PreviousMode], 1 test byte ptr [rbp + KTRAP_FRAME_PreviousMode], 1
jz 1f jz dont_swap_back
swapgs swapgs
1: dont_swap_back:
if (TRAPFLAGS AND TRAPFLAG_NONVOLATILES) if (TRAPFLAGS AND TRAPFLAG_NONVOLATILES)
/* Restore non-volatile registers */ /* Restore non-volatile registers */
@ -330,7 +331,7 @@ _InternalDispatchException:
PUBLIC _KiDivideErrorFault PUBLIC _KiDivideErrorFault
.PROC _KiDivideErrorFault .PROC _KiDivideErrorFault
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -343,7 +344,7 @@ PUBLIC _KiDivideErrorFault
PUBLIC _KiDebugTrapOrFault PUBLIC _KiDebugTrapOrFault
.PROC _KiDebugTrapOrFault .PROC _KiDebugTrapOrFault
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -377,7 +378,7 @@ KiDebugTrapOrFaultKMode:
PUBLIC _KiNmiInterrupt PUBLIC _KiNmiInterrupt
.PROC _KiNmiInterrupt .PROC _KiNmiInterrupt
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -390,7 +391,7 @@ PUBLIC _KiNmiInterrupt
PUBLIC _KiBreakpointTrap PUBLIC _KiBreakpointTrap
.PROC _KiBreakpointTrap .PROC _KiBreakpointTrap
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -402,7 +403,7 @@ PUBLIC _KiBreakpointTrap
// lea rcx, RIP(_MsgBreakpointTrap) // lea rcx, RIP(_MsgBreakpointTrap)
// mov rdx, rsp // mov rdx, rsp
// call RIP(_FrLdrDbgPrint) // call qword ptr RIP(_FrLdrDbgPrint)
/* Dispatch the exception */ /* Dispatch the exception */
mov eax, STATUS_BREAKPOINT mov eax, STATUS_BREAKPOINT
@ -419,7 +420,7 @@ PUBLIC _KiBreakpointTrap
PUBLIC _KiOverflowTrap PUBLIC _KiOverflowTrap
.PROC _KiOverflowTrap .PROC _KiOverflowTrap
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -431,7 +432,7 @@ PUBLIC _KiOverflowTrap
PUBLIC _KiBoundFault PUBLIC _KiBoundFault
.PROC _KiBoundFault .PROC _KiBoundFault
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -450,7 +451,7 @@ PUBLIC _KiBoundFault
PUBLIC _KiInvalidOpcodeFault PUBLIC _KiInvalidOpcodeFault
.PROC _KiInvalidOpcodeFault .PROC _KiInvalidOpcodeFault
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -464,7 +465,7 @@ PUBLIC _KiInvalidOpcodeFault
mov rdx, [rbp + KTRAP_FRAME_Rip] mov rdx, [rbp + KTRAP_FRAME_Rip]
lea rcx, RIP(_MsgInvalidOpcodeFault) lea rcx, RIP(_MsgInvalidOpcodeFault)
call RIP(_FrLdrDbgPrint) call qword ptr RIP(_FrLdrDbgPrint)
jmp $ jmp $
/* Return */ /* Return */
@ -474,7 +475,7 @@ PUBLIC _KiInvalidOpcodeFault
PUBLIC _KiNpxNotAvailableFault PUBLIC _KiNpxNotAvailableFault
.PROC _KiNpxNotAvailableFault .PROC _KiNpxNotAvailableFault
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -487,7 +488,7 @@ PUBLIC _KiNpxNotAvailableFault
PUBLIC _KiDoubleFaultAbort PUBLIC _KiDoubleFaultAbort
.PROC _KiDoubleFaultAbort .PROC _KiDoubleFaultAbort
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -498,7 +499,7 @@ PUBLIC _KiDoubleFaultAbort
lea rcx, RIP(_MsgDoubleFault) lea rcx, RIP(_MsgDoubleFault)
mov rdx, [rbp + KTRAP_FRAME_FaultAddress] mov rdx, [rbp + KTRAP_FRAME_FaultAddress]
mov r8, rbp mov r8, rbp
call RIP(_FrLdrDbgPrint) call qword ptr RIP(_FrLdrDbgPrint)
/* Bugcheck code UNEXPECTED_KERNEL_MODE_TRAP */ /* Bugcheck code UNEXPECTED_KERNEL_MODE_TRAP */
mov rcx, HEX(0000007F) mov rcx, HEX(0000007F)
@ -516,7 +517,7 @@ PUBLIC _KiDoubleFaultAbort
PUBLIC _KiNpxSegmentOverrunAbort PUBLIC _KiNpxSegmentOverrunAbort
.PROC _KiNpxSegmentOverrunAbort .PROC _KiNpxSegmentOverrunAbort
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -529,7 +530,7 @@ PUBLIC _KiNpxSegmentOverrunAbort
PUBLIC _KiInvalidTssFault PUBLIC _KiInvalidTssFault
.PROC _KiInvalidTssFault .PROC _KiInvalidTssFault
.pushframe 1 .pushframe code
/* We have an error code */ /* We have an error code */
.endprolog .endprolog
@ -540,7 +541,7 @@ PUBLIC _KiInvalidTssFault
PUBLIC _KiSegmentNotPresentFault PUBLIC _KiSegmentNotPresentFault
.PROC _KiSegmentNotPresentFault .PROC _KiSegmentNotPresentFault
.pushframe 1 .pushframe
/* We have an error code */ /* We have an error code */
.endprolog .endprolog
@ -551,7 +552,7 @@ PUBLIC _KiSegmentNotPresentFault
PUBLIC _KiStackFault PUBLIC _KiStackFault
.PROC _KiStackFault .PROC _KiStackFault
.pushframe 1 .pushframe code
/* We have an error code */ /* We have an error code */
.endprolog .endprolog
@ -562,7 +563,7 @@ PUBLIC _KiStackFault
PUBLIC _KiGeneralProtectionFault PUBLIC _KiGeneralProtectionFault
.PROC _KiGeneralProtectionFault .PROC _KiGeneralProtectionFault
.pushframe 1 .pushframe code
/* We have an error code */ /* We have an error code */
.endprolog .endprolog
@ -573,7 +574,7 @@ PUBLIC _KiGeneralProtectionFault
mov rdx, [rbp + KTRAP_FRAME_Rip] mov rdx, [rbp + KTRAP_FRAME_Rip]
lea rcx, RIP(_MsgGeneralProtFault) lea rcx, RIP(_MsgGeneralProtFault)
call RIP(_FrLdrDbgPrint) call qword ptr RIP(_FrLdrDbgPrint)
/* Check if this was from user-mode */ /* Check if this was from user-mode */
cmp byte ptr [rbp + KTRAP_FRAME_PreviousMode], KernelMode cmp byte ptr [rbp + KTRAP_FRAME_PreviousMode], KernelMode
@ -675,7 +676,7 @@ KiGpfExit:
PUBLIC _KiPageFault PUBLIC _KiPageFault
.PROC _KiPageFault .PROC _KiPageFault
.pushframe 1 .pushframe code
/* We have an error code */ /* We have an error code */
.endprolog .endprolog
@ -688,7 +689,7 @@ PUBLIC _KiPageFault
mov rdx, [rbp + KTRAP_FRAME_ErrorCode] mov rdx, [rbp + KTRAP_FRAME_ErrorCode]
mov r8, [rbp + KTRAP_FRAME_Rip] mov r8, [rbp + KTRAP_FRAME_Rip]
mov r9, [rbp + KTRAP_FRAME_FaultAddress] mov r9, [rbp + KTRAP_FRAME_FaultAddress]
call RIP(_FrLdrDbgPrint) call qword ptr RIP(_FrLdrDbgPrint)
#endif #endif
/* Save page fault address */ /* Save page fault address */
@ -745,7 +746,7 @@ PageFaultReturn:
PUBLIC _KiFloatingErrorFault PUBLIC _KiFloatingErrorFault
.PROC _KiFloatingErrorFault .PROC _KiFloatingErrorFault
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -758,7 +759,7 @@ PUBLIC _KiFloatingErrorFault
PUBLIC _KiAlignmentFault PUBLIC _KiAlignmentFault
.PROC _KiAlignmentFault .PROC _KiAlignmentFault
.pushframe 1 .pushframe code
/* We have an error code */ /* We have an error code */
.endprolog .endprolog
@ -769,7 +770,7 @@ PUBLIC _KiAlignmentFault
PUBLIC _KiMcheckAbort PUBLIC _KiMcheckAbort
.PROC _KiMcheckAbort .PROC _KiMcheckAbort
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -782,7 +783,7 @@ PUBLIC _KiMcheckAbort
PUBLIC _KiXmmException PUBLIC _KiXmmException
.PROC _KiXmmException .PROC _KiXmmException
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -795,7 +796,7 @@ PUBLIC _KiXmmException
PUBLIC _KiApcInterrupt PUBLIC _KiApcInterrupt
.PROC _KiApcInterrupt .PROC _KiApcInterrupt
.pushframe 1 .pushframe code
.endprolog .endprolog
UNIMPLEMENTED KiApcInterrupt UNIMPLEMENTED KiApcInterrupt
@ -805,7 +806,7 @@ PUBLIC _KiApcInterrupt
PUBLIC _KiRaiseAssertion PUBLIC _KiRaiseAssertion
.PROC _KiRaiseAssertion .PROC _KiRaiseAssertion
.pushframe 1 .pushframe code
.endprolog .endprolog
UNIMPLEMENTED KiRaiseAssertion UNIMPLEMENTED KiRaiseAssertion
@ -815,7 +816,7 @@ PUBLIC _KiRaiseAssertion
PUBLIC _KiDebugServiceTrap PUBLIC _KiDebugServiceTrap
.PROC _KiDebugServiceTrap .PROC _KiDebugServiceTrap
.pushframe 0 .pushframe
/* Push pseudo error code */ /* Push pseudo error code */
push 0 push 0
.allocstack 8 .allocstack 8
@ -842,7 +843,7 @@ PUBLIC _KiDebugServiceTrap
PUBLIC _KiDpcInterrupt PUBLIC _KiDpcInterrupt
.PROC _KiDpcInterrupt .PROC _KiDpcInterrupt
.pushframe 1 .pushframe code
.endprolog .endprolog
UNIMPLEMENTED KiDpcInterrupt UNIMPLEMENTED KiDpcInterrupt
@ -852,7 +853,7 @@ PUBLIC _KiDpcInterrupt
PUBLIC _KiIpiInterrupt PUBLIC _KiIpiInterrupt
.PROC _KiIpiInterrupt .PROC _KiIpiInterrupt
.pushframe 1 .pushframe code
.endprolog .endprolog
UNIMPLEMENTED KiIpiInterrupt UNIMPLEMENTED KiIpiInterrupt
@ -862,7 +863,7 @@ PUBLIC _KiIpiInterrupt
PUBLIC _KiUnexpectedInterrupt PUBLIC _KiUnexpectedInterrupt
.PROC _KiUnexpectedInterrupt .PROC _KiUnexpectedInterrupt
.pushframe 0 .pushframe
.endprolog .endprolog
/* The error code is the vector */ /* The error code is the vector */