2 * FILE: ntoskrnl/ke/amd64/trap.S
3 * COPYRIGHT: See COPYING in the top level directory
4 * PURPOSE: System Traps, Entrypoints and Exitpoints
5 * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
8 /* INCLUDES ******************************************************************/
11 #include <ksamd64.inc>
12 #include <trapamd64.inc>
14 EXTERN KiDispatchException:PROC
15 EXTERN FrLdrDbgPrint:DWORD
16 EXTERN KeBugCheckWithTf:PROC
17 EXTERN MmAccessFault:PROC
18 EXTERN KiSystemFatalException:PROC
19 EXTERN KiNpxNotAvailableFaultHandler:PROC
20 EXTERN KiGeneralProtectionFaultHandler:PROC
21 EXTERN KiXmmExceptionHandler:PROC
22 EXTERN KiDeliverApc:PROC
23 EXTERN KiDpcInterruptHandler:PROC
25 /* GLOBALS *******************************************************************/
29 PUBLIC MsgUnimplemented
31 .asciz "WARNING: %s at %s:%d is UNIMPLEMENTED!\n"
34 /* Helper Macros *************************************************************/
36 MACRO(DispatchException, Status, Number, P1, P2, P3)
42 call InternalDispatchException
45 MACRO(Fatal, BugcheckCode)
49 call KiSystemFatalException
53 /* FUNCTIONS *****************************************************************/
59 MACRO(UnexpectedVectorStub, Vector)
60 /* This nop is to make the relative jmp address 4 bytes aligned and to
61 make the whole code 8 bytes long */
63 /* This is a push instruction with 8bit operand. Since the instruction
64 sign extends the value to 32 bits, we need to offset it */
65 PUBLIC KxUnexpectedInterrupt&Vector
66 KxUnexpectedInterrupt&Vector:
68 jmp KiUnexpectedInterrupt
71 PUBLIC KiUnexpectedRange
75 UnexpectedVectorStub %Vector
78 PUBLIC KiUnexpectedRangeEnd
81 PUBLIC KiInterruptDispatchTemplate
82 KiInterruptDispatchTemplate:
83 /* This instruction pushes the return address on the stack, which is the
84 address of the interrupt object's DispatchCode member, then jumps
85 to the address stored in the interrupt object's DispatchAddress member */
86 call qword ptr KiInterruptDispatchTemplate[rip - KINTERRUPT_DispatchCode + KINTERRUPT_DispatchAddress]
89 // rbp = TrapFrame, eax = ExceptionCode, edx = NumParams, r9,r10,r11 = params
90 .PROC InternalDispatchException
92 /* Allocate stack space for EXCEPTION_RECORD and KEXCEPTION_FRAME */
93 sub rsp, EXCEPTION_RECORD_LENGTH + KEXCEPTION_FRAME_LENGTH
94 .allocstack (EXCEPTION_RECORD_LENGTH + KEXCEPTION_FRAME_LENGTH)
97 /* Set up EXCEPTION_RECORD */
98 lea rcx, [rsp + KEXCEPTION_FRAME_LENGTH]
99 mov [rcx + EXCEPTION_RECORD_ExceptionCode], eax
101 mov [rcx + EXCEPTION_RECORD_ExceptionFlags], eax
102 mov [rcx + EXCEPTION_RECORD_ExceptionRecord], rax
103 mov rax, [rbp + KTRAP_FRAME_Rip]
104 mov [rcx + EXCEPTION_RECORD_ExceptionAddress], rax
105 mov [rcx + EXCEPTION_RECORD_NumberParameters], edx
106 mov [rcx + EXCEPTION_RECORD_ExceptionInformation + HEX(00)], r9
107 mov [rcx + EXCEPTION_RECORD_ExceptionInformation + HEX(08)], r10
108 mov [rcx + EXCEPTION_RECORD_ExceptionInformation + HEX(10)], r11
110 /* Set up KEXCEPTION_FRAME */
111 mov rax, [rbp + KTRAP_FRAME_Rbp]
112 mov [rsp + KEXCEPTION_FRAME_Rbp], rax
113 mov [rsp + KEXCEPTION_FRAME_Rbx], rbx
114 mov [rsp + KEXCEPTION_FRAME_Rdi], rdi
115 mov [rsp + KEXCEPTION_FRAME_Rsi], rsi
116 mov [rsp + KEXCEPTION_FRAME_R12], r12
117 mov [rsp + KEXCEPTION_FRAME_R13], r13
118 mov [rsp + KEXCEPTION_FRAME_R14], r14
119 mov [rsp + KEXCEPTION_FRAME_R15], r15
120 movdqa [rsp + KEXCEPTION_FRAME_Xmm6], xmm6
121 movdqa [rsp + KEXCEPTION_FRAME_Xmm7], xmm7
122 movdqa [rsp + KEXCEPTION_FRAME_Xmm8], xmm8
123 movdqa [rsp + KEXCEPTION_FRAME_Xmm9], xmm9
124 movdqa [rsp + KEXCEPTION_FRAME_Xmm10], xmm10
125 movdqa [rsp + KEXCEPTION_FRAME_Xmm11], xmm11
126 movdqa [rsp + KEXCEPTION_FRAME_Xmm12], xmm12
127 movdqa [rsp + KEXCEPTION_FRAME_Xmm13], xmm13
128 movdqa [rsp + KEXCEPTION_FRAME_Xmm14], xmm14
129 movdqa [rsp + KEXCEPTION_FRAME_Xmm15], xmm15
130 mov qword ptr [rsp + KEXCEPTION_FRAME_Return], 0
132 /* Call KiDispatchException */
133 // rcx already points to ExceptionRecord
134 mov rdx, rsp // ExceptionFrame
135 mov r8, rbp // TrapFrame
136 mov r9b, [r8 + KTRAP_FRAME_PreviousMode] // PreviousMode
137 mov byte ptr [rsp + KEXCEPTION_FRAME_P5], 1 // FirstChance
138 call KiDispatchException
140 /* Restore registers */
141 mov r12, [rsp + KEXCEPTION_FRAME_R12]
142 mov r13, [rsp + KEXCEPTION_FRAME_R13]
143 mov r14, [rsp + KEXCEPTION_FRAME_R14]
144 mov r15, [rsp + KEXCEPTION_FRAME_R15]
145 movdqa xmm6, [rsp + KEXCEPTION_FRAME_Xmm6]
146 movdqa xmm7, [rsp + KEXCEPTION_FRAME_Xmm7]
147 movdqa xmm8, [rsp + KEXCEPTION_FRAME_Xmm8]
148 movdqa xmm9, [rsp + KEXCEPTION_FRAME_Xmm9]
149 movdqa xmm10, [rsp + KEXCEPTION_FRAME_Xmm10]
150 movdqa xmm11, [rsp + KEXCEPTION_FRAME_Xmm11]
151 movdqa xmm12, [rsp + KEXCEPTION_FRAME_Xmm12]
152 movdqa xmm13, [rsp + KEXCEPTION_FRAME_Xmm13]
153 movdqa xmm14, [rsp + KEXCEPTION_FRAME_Xmm14]
154 movdqa xmm15, [rsp + KEXCEPTION_FRAME_Xmm15]
156 add rsp, EXCEPTION_RECORD_LENGTH + KEXCEPTION_FRAME_LENGTH
161 /* CPU EXCEPTION HANDLERS ****************************************************/
163 PUBLIC KiDivideErrorFault
164 FUNC KiDivideErrorFault
165 /* Push pseudo error code */
166 EnterTrap TF_SAVE_ALL
168 /* Enable interrupts */
171 /* Dispatch the exception */
172 DispatchException STATUS_INTEGER_DIVIDE_BY_ZERO, 0, 0, 0, 0
179 PUBLIC KiDebugTrapOrFault
180 FUNC KiDebugTrapOrFault
181 /* Push pseudo error code */
182 EnterTrap TF_SAVE_ALL
184 /* Check if the frame was from kernelmode */
185 test word ptr [rbp + KTRAP_FRAME_SegCs], 3
186 jz KiDebugTrapOrFaultKMode
188 /* Enable interrupts for user-mode */
191 KiDebugTrapOrFaultKMode:
192 /* Dispatch the exception */
193 DispatchException STATUS_SINGLE_STEP, 0, 0, 0, 0
200 PUBLIC KiNmiInterrupt
202 /* Push pseudo error code */
203 EnterTrap TF_SAVE_ALL
205 UNIMPLEMENTED KiNmiInterrupt
213 PUBLIC KiBreakpointTrap
214 FUNC KiBreakpointTrap
215 /* Push pseudo error code */
216 EnterTrap TF_SAVE_ALL
218 /* Check if the frame was from kernelmode */
219 test word ptr [rbp + KTRAP_FRAME_SegCs], 3
220 jz KiBreakpointTrapKMode
222 /* Enable interrupts for user-mode */
225 KiBreakpointTrapKMode:
226 /* Dispatch the exception */
227 DispatchException STATUS_BREAKPOINT, 3, BREAKPOINT_BREAK, 0, 0
234 PUBLIC KiOverflowTrap
236 /* Push pseudo error code */
237 EnterTrap TF_SAVE_ALL
239 /* Enable interrupts */
242 /* Dispatch the exception */
243 DispatchException STATUS_INTEGER_OVERFLOW, 3, 0, 0, 0
253 EnterTrap TF_SAVE_ALL
255 /* Check if the frame was from kernelmode */
256 test word ptr [rbp + KTRAP_FRAME_SegCs], 3
257 jnz KiBoundFaultUserMode
260 Fatal EXCEPTION_BOUND_CHECK
262 KiBoundFaultUserMode:
263 /* Enable interrupts for user-mode */
266 /* Dispatch the exception */
267 DispatchException STATUS_ARRAY_BOUNDS_EXCEEDED, 0, 0, 0, 0
274 PUBLIC KiInvalidOpcodeFault
275 FUNC KiInvalidOpcodeFault
277 EnterTrap TF_SAVE_ALL
279 /* Enable interrupts */
282 /* Check if the frame was from kernelmode */
283 test word ptr [rbp + KTRAP_FRAME_SegCs], 3
284 jz KiInvalidOpcodeKernel
286 // FIXME: handle STATUS_INVALID_LOCK_SEQUENCE
288 KiInvalidOpcodeKernel:
289 /* Kernel mode fault */
291 /* Dispatch the exception */
292 DispatchException STATUS_ILLEGAL_INSTRUCTION, 3, 0, 0, 0
299 PUBLIC KiNpxNotAvailableFault
300 FUNC KiNpxNotAvailableFault
302 EnterTrap TF_SAVE_ALL
304 /* Call the C handler */
306 call KiNpxNotAvailableFaultHandler
308 /* Check the return status code */
310 jz KiNpxNotAvailableFaultExit
312 /* Dispatch the exception */
313 DispatchException eax, 3, 0, 0, 0
315 KiNpxNotAvailableFaultExit:
321 PUBLIC KiDoubleFaultAbort
322 FUNC KiDoubleFaultAbort
324 EnterTrap TF_SAVE_ALL
327 Fatal 8 // EXCEPTION_DOUBLE_FAULT
332 PUBLIC KiNpxSegmentOverrunAbort
333 FUNC KiNpxSegmentOverrunAbort
335 EnterTrap TF_SAVE_ALL
338 Fatal EXCEPTION_NPX_OVERRUN
343 PUBLIC KiInvalidTssFault
344 FUNC KiInvalidTssFault
345 /* We have an error code */
346 EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
349 Fatal EXCEPTION_INVALID_TSS
354 PUBLIC KiSegmentNotPresentFault
355 FUNC KiSegmentNotPresentFault
356 /* We have an error code */
357 EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
360 Fatal EXCEPTION_SEGMENT_NOT_PRESENT
367 /* We have an error code */
368 EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
371 Fatal EXCEPTION_STACK_FAULT
376 PUBLIC KiGeneralProtectionFault
377 FUNC KiGeneralProtectionFault
378 /* We have an error code */
379 EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
381 /* Call the C handler */
383 call KiGeneralProtectionFaultHandler
385 /* Check for success */
389 /* Dispatch the exception */
390 DispatchException eax, 3, 0, 0, 0
395 mov ecx, UNEXPECTED_KERNEL_MODE_TRAP
396 mov rdx, HEX(000D) // EXCEPTION_GP_FAULT
398 mov r9, [rbp + KTRAP_FRAME_ErrorCode] // error code
400 mov [rsp + KTRAP_FRAME_P5+8], rbp // trap frame
401 call KeBugCheckWithTf
412 /* We have an error code */
413 EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
415 /* Save page fault address */
417 mov [rbp + KTRAP_FRAME_FaultAddress], rdx
419 /* Enable interrupts for the page fault handler */
422 /* Call page fault handler */
423 mov ecx, [rbp + KTRAP_FRAME_ErrorCode] // StoreInstruction
426 mov r8b, [rbp + KTRAP_FRAME_SegCs] // Mode
428 mov r9, rbp // TrapInformation
431 /* Check for success */
435 /* Disable interrupts again for the debugger */
438 /* Set parameter 1 to error code */
439 mov r9d, [rbp + KTRAP_FRAME_ErrorCode]
441 /* Set parameter2 to faulting address */
442 mov r10, cr2 // Param2 = faulting address
444 cmp eax, STATUS_ACCESS_VIOLATION
446 cmp eax, STATUS_GUARD_PAGE_VIOLATION
448 cmp eax, STATUS_STACK_OVERFLOW
453 /* Dispatch in-page exception */
454 mov r11d, eax // Param3 = Status
455 mov eax, STATUS_IN_PAGE_ERROR // ExceptionCode
456 mov edx, 3 // ParamCount
457 call InternalDispatchException
461 /* Use more proper status code */
462 mov eax, KI_EXCEPTION_ACCESS_VIOLATION
465 /* Setup a normal page fault exception */
466 mov edx, 2 // ParamCount
467 call InternalDispatchException
471 ExitTrap (TF_SAVE_ALL or TF_CHECKUSERAPC)
475 PUBLIC KiFloatingErrorFault
476 FUNC KiFloatingErrorFault
478 EnterTrap TF_SAVE_ALL
480 UNIMPLEMENTED KiFloatingErrorFault
488 PUBLIC KiAlignmentFault
489 FUNC KiAlignmentFault
490 /* We have an error code */
491 EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
494 Fatal EXCEPTION_ALIGNMENT_CHECK
502 EnterTrap TF_SAVE_ALL
510 PUBLIC KiXmmException
513 EnterTrap TF_SAVE_ALL
515 /* Call the C handler */
517 call KiXmmExceptionHandler
519 /* Check for success */
523 /* Dispatch the exception */
524 DispatchException eax, 3, 0, 0, 0
532 /* SOFTWARE INTERRUPT SERVICES ***********************************************/
534 PUBLIC KiRaiseAssertion
535 FUNC KiRaiseAssertion
536 /* We have an error code */
537 EnterTrap (TF_SAVE_ALL)
539 /* Decrement RIP to point to the INT2C instruction (2 bytes, not 1 like INT3) */
540 sub qword ptr [rbp + KTRAP_FRAME_Rip], 2
542 /* Dispatch the exception */
543 DispatchException STATUS_ASSERTION_FAILURE, 0, 0, 0, 0
550 PUBLIC KiDebugServiceTrap
551 .PROC KiDebugServiceTrap
553 EnterTrap TF_SAVE_ALL
555 /* Increase Rip to skip the int3 */
556 inc qword ptr [rbp + KTRAP_FRAME_Rip]
558 /* Dispatch the exception (Params = service, buffer, legth) */
559 DispatchException STATUS_BREAKPOINT, 3, [rbp+KTRAP_FRAME_Rax], [rbp+KTRAP_FRAME_Rcx], [rbp+KTRAP_FRAME_Rdx]
566 PUBLIC KiApcInterrupt
569 EnterTrap (TF_VOLATILES or TF_IRQL)
571 /* Raise to APC_LEVEL */
575 /* End the interrupt */
576 mov dword ptr [APIC_EOI], 0
578 /* Enable interrupts */
581 /* Call the worker routine */
582 mov cl, [rbp + KTRAP_FRAME_SegCs] // ProcessorMode
584 mov rdx, 0 // ExceptionFrame
585 mov r8, rdx // TrapFrame
588 /* Disable interrupts */
591 /* Lower IRQL back to PASSIVE */
592 mov rax, PASSIVE_LEVEL
596 ExitTrap (TF_VOLATILES or TF_IRQL)
599 EXTERN KiRetireDpcList:PROC
600 PUBLIC KiRetireDpcListInDpcStack
601 .PROC KiRetireDpcListInDpcStack
608 /* Switch stack and call the function */
613 /* Restore stack, cleanup and return */
619 PUBLIC KiDpcInterrupt
622 EnterTrap (TF_VOLATILES or TF_IRQL)
624 /* Call the worker routine */
625 call KiDpcInterruptHandler
627 /* Return, but don't send an EOI! */
628 ExitTrap (TF_VOLATILES or TF_IRQL)
632 PUBLIC KiIpiInterrupt
635 EnterTrap (TF_VOLATILES or TF_IRQL)
637 /* Raise to IPI_LEVEL */
641 /* End the interrupt */
642 mov dword ptr [APIC_EOI], 0
647 ExitTrap (TF_VOLATILES or TF_IRQL)
651 PUBLIC KiUnexpectedInterrupt
652 FUNC KiUnexpectedInterrupt
653 /* The error code is the vector */
654 EnterTrap (TF_HAS_ERROR_CODE OR TF_SAVE_ALL)
657 /* Set bugcheck parameters */
658 mov ecx, TRAP_CAUSE_UNKNOWN
659 mov rdx, [rbp + KTRAP_FRAME_ErrorCode] // the vector
660 mov r8, 0 // The unknown floating-point exception
661 mov r9, 0 // The enabled and asserted status bits
663 mov [rbp + KTRAP_FRAME_P5 + 8], rbp // trap frame
664 call KeBugCheckWithTf
671 PUBLIC KiInterruptDispatch
672 FUNC KiInterruptDispatch
673 /* The error code is a pointer to the interrupt object's code */
674 EnterTrap (TF_HAS_ERROR_CODE or TF_SAVE_ALL or TF_IRQL)
676 /* Increase interrupt count */
677 inc dword ptr gs:[PcInterruptCount];
679 /* Load the address of the interrupt object into rcx */
680 mov rcx, [rbp + KTRAP_FRAME_ErrorCode]
682 /* Substract offset of the DispatchCode member plus 6 for the call instruction */
683 sub rcx, KINTERRUPT_DispatchCode + 6
685 /* Raise IRQL to SynchronizeIrql */
686 movzx rax, byte ptr [rcx + KINTERRUPT_SynchronizeIrql]
690 /* Acquire interrupt lock */
691 mov r8, [rcx + KINTERRUPT_ActualLock]
693 //KxAcquireSpinLock(Interrupt->ActualLock);
697 mov rdx, [rcx + KINTERRUPT_ServiceContext]
698 call qword ptr [rcx + KINTERRUPT_ServiceRoutine]
701 /* Release interrupt lock */
702 //KxReleaseSpinLock(Interrupt->ActualLock);
705 /* Go back to old irql */
706 movzx rax, byte ptr [rbp + KTRAP_FRAME_PreviousIrql]
710 ExitTrap (TF_SAVE_ALL or TF_SEND_EOI)
714 #define MAX_SYSCALL_PARAM_SIZE (16 * 8)
715 #define HOME_SIZE 6*8
716 #define SYSCALL_ALLOCATION (MAX_SYSCALL_PARAM_SIZE + HOME_SIZE)
718 EXTERN KiSystemCallHandler:PROC
720 /*! \name KiSystemCallEntry64
722 * \brief This is the entrypoint for syscalls from 64bit user mode
724 * \param rax - The system call number
725 * \param rcx - User mode return address, set by the syscall instruction
726 * \param rdx,r8,r9 - Parameters 2-4 to the service function
727 * \param r10 - Parameter 1 to the service function
728 * \param r11 - RFLAGS saved by the syscall instruction
730 PUBLIC KiSystemCallEntry64
731 .PROC KiSystemCallEntry64
733 /* Old stack pointer is in rcx, lie and say we saved it in rbp */
737 /* Swap gs to kernel, so we can access the PCR */
740 /* Save the user mode rsp in the PCR */
741 mov gs:[PcUserRsp], rsp
743 /* Get the kernel stack from the PCR */
744 mov rsp, gs:[PcRspBase]
746 /* Allocate a TRAP_FRAME and space for parameters */
747 sub rsp, (KTRAP_FRAME_LENGTH + MAX_SYSCALL_PARAM_SIZE + HOME_SIZE)
749 /* Save rbp and load it with the old stack pointer */
750 mov [rsp + HOME_SIZE + MAX_SYSCALL_PARAM_SIZE + HOME_SIZE + KTRAP_FRAME_Rbp], rbp
751 mov rbp, gs:[PcUserRsp]
754 /* Save important volatiles in the trap frame */
755 mov [rsp + HOME_SIZE + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rax], rax
756 mov [rsp + HOME_SIZE + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rcx], rcx
757 mov [rsp + HOME_SIZE + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R10], r10
758 mov [rsp + HOME_SIZE + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R11], r11
760 /* Set sane segments */
761 mov ax, (KGDT64_R3_DATA or RPL_MASK)
765 /* Call the C-handler (will enable interrupts) */
766 lea rcx, [rsp + SYSCALL_ALLOCATION]
767 call KiSystemCallHandler
769 /* Deallocate the handlers home stack frame */
772 /* The return value is the address of the Nt-function */
781 mov rbp, [rsp + SYSCALL_ALLOCATION + KTRAP_FRAME_Rbp]
784 /* Disable interrupts for return */
787 /* Restore old trap frame */
788 mov rcx, gs:[PcCurrentThread]
789 mov rdx, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_TrapFrame]
790 mov [rcx + KTHREAD_TrapFrame], rdx
792 /* Prepare user mode return address (rcx) and eflags (r11) for sysret */
793 mov rcx, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rcx]
794 mov r11, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_R11]
796 /* Load user mode stack (It was copied to the trap frame) */
797 mov rsp, [rsp + MAX_SYSCALL_PARAM_SIZE + KTRAP_FRAME_Rsp]
799 /* Swap gs back to user */
802 /* return to user mode */
803 .byte HEX(48) // REX prefix to return to long mode
808 PUBLIC KiSystemCallEntry32
814 PUBLIC KiZwSystemService
815 FUNC KiZwSystemService
818 sub rsp, KTRAP_FRAME_LENGTH
819 .allocstack KTRAP_FRAME_LENGTH
820 mov [rsp + KTRAP_FRAME_Rsi], rsi
821 .savereg rsi, KTRAP_FRAME_Rsi
822 mov [rsp + KTRAP_FRAME_Rdi], rdi
823 .savereg rdi, KTRAP_FRAME_Rdi
828 /* Get current thread */
829 mov r11, gs:[PcCurrentThread]
831 /* Save the old trap frame in TrapFrame.Rdx */
832 mov rdi, [r11 + KTHREAD_TrapFrame]
833 mov [rbp + KTRAP_FRAME_Rdx], rdi
835 /* Set the new trap frame and previous mode */
836 mov [r11 + ThTrapFrame], rbp
837 mov byte ptr [r11 + KTHREAD_PreviousMode], 0
839 /* allocate space for parameters */
841 and rsp, HEX(0fffffffffffffff0)
844 mov [rbp + KTRAP_FRAME_Rcx], rcx
846 /* copy parameters to the new location */
847 lea rsi, [rbp + KTRAP_FRAME_LENGTH + 16]
854 mov rcx, [rbp + KTRAP_FRAME_Rcx]
856 /* Call the service function */
859 /* Restore the old trap frame */
860 mov r11, gs:[PcCurrentThread]
861 mov rsi, [rsp + KTRAP_FRAME_Rdx]
862 mov [r11 + KTHREAD_TrapFrame], rsi
864 /* Restore rdi and rsi */
865 mov rsi, [rbp + KTRAP_FRAME_Rsi]
866 mov rdi, [rbp + KTRAP_FRAME_Rdi]
868 /* Cleanup the stack and return */
869 lea rsp, [rbp + KTRAP_FRAME_LENGTH]
882 * KiServiceExit(IN PKTRAP_FRAME TrapFrame, IN NTSTATUS Status));
886 mov [rcx + KTRAP_FRAME_Rax], rdx
891 //ExitTrap TF_SAVE_ALL
896 * KiServiceExit2(IN PKTRAP_FRAME TrapFrame);
898 PUBLIC KiServiceExit2
909 PUBLIC KiInitializeSegments
910 KiInitializeSegments:
911 mov ax, KGDT64_R3_DATA or RPL_MASK
922 //void __lgdt(void *Source);
928 //void __sgdt(void *Destination);
934 // void __lldt(unsigned short Value)
940 //void __sldt(void *Destination);
946 //void __ltr(unsigned short Source);
952 //void __str(unsigned short *Destination);