[AMD64]
[reactos.git] / reactos / lib / rtl / amd64 / except_asm.S
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Runtime Library (RTL)
4 * FILE: lib/rtl/amd64/except_asm.S
5 * PURPOSE: Exception support for AMD64
6 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <reactos/asm.h>
12 #include <ndk/amd64/asm.h>
13
14 /* FUNCTIONS *****************************************************************/
15
16 .code64
17
18 /*
19 * VOID NTAPI
20 * RtlCaptureContext(
21 * PCONTEXT ContextRecord); <rcx>
22 */
23 PUBLIC RtlCaptureContext
24 .PROC RtlCaptureContext
25
26 /* Push rflags */
27 pushfq
28 .ALLOCSTACK 8
29 .ENDPROLOG
30
31 /* Save the basic register context */
32 mov [rcx + CONTEXT_Rax], rax
33 mov [rcx + CONTEXT_Rcx], rcx
34 mov [rcx + CONTEXT_Rdx], rdx
35
36 /* Load rflags into rax */
37 mov rax, [rsp]
38
39 mov [rcx + CONTEXT_Rbx], rbx
40 mov [rcx + CONTEXT_Rsi], rsi
41 mov [rcx + CONTEXT_Rdi], rdi
42
43 /* Store rflags */
44 mov [rcx + CONTEXT_EFlags], rax
45
46 mov [rcx + CONTEXT_Rbp], rbp
47 mov [rcx + CONTEXT_R8], r8
48 mov [rcx + CONTEXT_R9], r9
49
50 /* Load former stack pointer in rax */
51 lea rax, [rsp + 16]
52
53 mov [rcx + CONTEXT_R10], r10
54 mov [rcx + CONTEXT_R11], r11
55 mov [rcx + CONTEXT_R12], r12
56
57 /* Store stack pointer */
58 mov [rcx + CONTEXT_Rsp], rax
59
60 mov [rcx + CONTEXT_R13], r13
61 mov [rcx + CONTEXT_R14], r14
62 mov [rcx + CONTEXT_R15], r15
63
64 /* Load return address in rax */
65 mov rax, [rsp + 8]
66
67 /* Safe segment selectors */
68 mov [rcx + CONTEXT_SegCs], cs
69 mov [rcx + CONTEXT_SegDs], ds
70 mov [rcx + CONTEXT_SegEs], es
71 mov [rcx + CONTEXT_SegFs], fs
72 mov [rcx + CONTEXT_SegGs], gs
73 mov [rcx + CONTEXT_SegSs], ss
74
75 /* Store return address */
76 mov [rcx + CONTEXT_Rip], rax
77
78 /* Safe xmm registers */
79 movdqa [rcx + CONTEXT_Xmm0], xmm0
80 movdqa [rcx + CONTEXT_Xmm1], xmm1
81 movdqa [rcx + CONTEXT_Xmm2], xmm2
82 movdqa [rcx + CONTEXT_Xmm3], xmm3
83 movdqa [rcx + CONTEXT_Xmm4], xmm4
84 movdqa [rcx + CONTEXT_Xmm5], xmm5
85 movdqa [rcx + CONTEXT_Xmm6], xmm6
86 movdqa [rcx + CONTEXT_Xmm7], xmm7
87 movdqa [rcx + CONTEXT_Xmm8], xmm8
88 movdqa [rcx + CONTEXT_Xmm9], xmm9
89 movdqa [rcx + CONTEXT_Xmm10], xmm10
90 movdqa [rcx + CONTEXT_Xmm11], xmm11
91 movdqa [rcx + CONTEXT_Xmm12], xmm12
92 movdqa [rcx + CONTEXT_Xmm13], xmm13
93 movdqa [rcx + CONTEXT_Xmm14], xmm14
94 movdqa [rcx + CONTEXT_Xmm15], xmm15
95
96 /* Cleanup stack and return */
97 add rsp, 8
98 ret
99 .ENDP RtlCaptureContext
100
101 END
102
103