[PSEH3]
[reactos.git] / reactos / lib / pseh / i386 / pseh3_i386.S
1 /*
2 * PROJECT: ReactOS system libraries
3 * LICENSE: GNU GPL - See COPYING in the top level directory
4 * PURPOSE: Support library for PSEH3
5 * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
6 */
7
8 #include "pseh3_asmdef.h"
9
10 .intel_syntax noprefix
11
12 .text
13
14 .extern __SEH3$_except_handler
15
16 /*
17 * void
18 * __attribute__((regparm(2)))
19 * __attribute__((returns_twice))
20 * _SEH3$_RegisterFrame[WithNonVolatiles](
21 * PSEH_DATA_TABLE DataTable<eax>,
22 * PSEH_REGISTRATION_FRAME RegistrationRecord<edx>);
23 */
24 .global __SEH3$_RegisterFrameWithNonVolatiles
25 __SEH3$_RegisterFrameWithNonVolatiles:
26
27 /* Save non-volatiles in the registration frame */
28 mov [edx + SEH3_REGISTRATION_FRAME_Ebx], ebx
29 mov [edx + SEH3_REGISTRATION_FRAME_Esi], esi
30 mov [edx + SEH3_REGISTRATION_FRAME_Edi], edi
31
32 .global __SEH3$_RegisterFrame
33 __SEH3$_RegisterFrame:
34
35 /* Save the address of the static data table */
36 mov [edx + SEH3_REGISTRATION_FRAME_ScopeTable], eax
37
38 /* Set the handler address */
39 mov dword ptr [edx + SEH3_REGISTRATION_FRAME_Handler], offset __SEH3$_except_handler
40
41 /* Set this as the end of the internal chain */
42 mov dword ptr [edx + SEH3_REGISTRATION_FRAME_EndOfChain], edx
43
44 /* Register the frame in the TEB */
45 mov eax, dword ptr fs:[0]
46 mov [edx + SEH3_REGISTRATION_FRAME_Next], eax
47 mov dword ptr fs:[0], edx
48
49 /* Save the stack registers */
50 mov [edx + SEH3_REGISTRATION_FRAME_Esp], esp
51 mov [edx + SEH3_REGISTRATION_FRAME_Ebp], ebp
52
53 /* Set eax to 0 to indicate 1st return */
54 xor eax, eax
55 ret
56
57
58 /*
59 * void
60 * __attribute__((regparm(2)))
61 * __attribute__((returns_twice))
62 * _SEH3$_RegisterTryLevel[WithNonVolatiles](
63 * PSEH_DATA_TABLE DataTable<eax>,
64 * PSEH_REGISTRATION_FRAME RegistrationRecord<edx>);
65 */
66 .global __SEH3$_RegisterTryLevelWithNonVolatiles
67 __SEH3$_RegisterTryLevelWithNonVolatiles:
68
69 /* Save non-volatiles in the registration frame */
70 mov [edx + SEH3_REGISTRATION_FRAME_Ebx], ebx
71 mov [edx + SEH3_REGISTRATION_FRAME_Esi], esi
72 mov [edx + SEH3_REGISTRATION_FRAME_Edi], edi
73
74 .global __SEH3$_RegisterTryLevel
75 __SEH3$_RegisterTryLevel:
76
77 /* Save the address of the static data table */
78 mov [edx + SEH3_REGISTRATION_FRAME_ScopeTable], eax
79
80 /* Set the handler address to NULL as identification */
81 and dword ptr [edx + SEH3_REGISTRATION_FRAME_Handler], 0
82
83 /* Get the current registered frame */
84 mov eax, dword ptr fs:[0]
85
86 /* Get the current end of the chain and set this as Next */
87 mov ecx, [eax + SEH3_REGISTRATION_FRAME_EndOfChain]
88 mov [edx + SEH3_REGISTRATION_FRAME_Next], ecx
89
90 /* Set this as the end of the internal chain */
91 mov dword ptr [eax + SEH3_REGISTRATION_FRAME_EndOfChain], edx
92
93 /* Save the stack registers */
94 mov [edx + SEH3_REGISTRATION_FRAME_Esp], esp
95 mov [edx + SEH3_REGISTRATION_FRAME_Ebp], ebp
96
97 /* Set eax to 0 to indicate 1st return */
98 xor eax, eax
99 ret
100