Release 960616
[wine.git] / if1632 / except.S
blob2b522ca8b03e9887fa846854ebeeff67b3e2a20e
1 /*
2  * Win32 exception assembly functions
3  *
4  * Copyright (c) 1996 Onno Hovers, (onno@stack.urc.tue.nl)
5  *
6  */
7 #if defined(__svr4__) || defined(_SCO_DS)
8 #define __ELF__ 1
9 #endif
11 #ifndef __ELF__
13      .globl _EXC_CallUnhandledExceptionFilter
14  _EXC_CallUnhandledExceptionFilter:
16 #else  /* __ELF__ */
18      .globl EXC_CallUnhandledExceptionFilter
19  EXC_CallUnhandledExceptionFilter:
21 #endif  /* __ELF__ */
22      leal   4(%esp),%eax
23      pushl  %eax
24 #ifndef __ELF__
25      call   *_pTopExcHandler
26 #else  /* __ELF__ */
27      call   *pTopExcHandler
28 #endif  /* __ELF__ */
29      movl   %ebp,%esp
30      ret
34 /*******************************************************************
35  *
36  *        RaiseException           (KERNEL32. 418 )
37  *        RtlUnwind                (KERNEL32. 443 )
38  *
39  * we need to save our context before a call to
40  *
41  * -RaiseException
42  * -RtlUnwind
43  *
44  * after these functions we need to restore that context structure as
45  * the actual context so changes made to the context structure in an
46  * exception-handler will be reflected in the context after these
47  * functions return. Fortunately both functions have 4 DWORD params.
48  * we pass the function to be called as a fifth parameter to ContextCall
49  *
50  */
51 #define CONTEXT_SegSs        -4
52 #define CONTEXT_Esp          -8
53 #define CONTEXT_EFlags       -12
54 #define CONTEXT_SegCs        -16
55 #define CONTEXT_Eip          -20
56 #define CONTEXT_Ebp          -24
57 #define CONTEXT_Eax          -28
58 #define CONTEXT_Ecx          -32
59 #define CONTEXT_Edx          -36
60 #define CONTEXT_Ebx          -40
61 #define CONTEXT_Esi          -44
62 #define CONTEXT_Edi          -48
63 #define CONTEXT_SegDs        -52
64 #define CONTEXT_SegEs        -56
65 #define CONTEXT_SegFs        -60
66 #define CONTEXT_SegGs        -64
67 #define FLOAT_Cr0NpxState    -68
68 #define FLOAT_RegisterArea   -148
69 #define FLOAT_DataSelector   -152
70 #define FLOAT_DataOffset     -156
71 #define FLOAT_ErrorSelector  -160
72 #define FLOAT_ErrorOffset    -164
73 #define FLOAT_TagWord        -168
74 #define FLOAT_StatusWord     -172
75 #define FLOAT_ControlWord    -176
76 #define CONTEXT_FloatSave    -176
77 #define CONTEXT_Dr7          -180
78 #define CONTEXT_Dr6          -184
79 #define CONTEXT_Dr3          -188
80 #define CONTEXT_Dr2          -192
81 #define CONTEXT_Dr1          -196
82 #define CONTEXT_Dr0          -200
83 #define CONTEXT_ContextFlags -204
84 #define CONTEXT              -204
85 #define CONTEXTSIZE           204
86 #define CONTEXTFLAGS          0x10007
88 #define ORIG_ESP              16         /** cdecl !!! **/
89 #define PARM_ARG4             28
90 #define PARM_ARG3             24
91 #define PARM_ARG2             20
92 #define PARM_ARG1             16
93 #define PARM_RETURN           12
94 #define PARM_CALLFUNC         8
95 #define PARM_EBP              4
96 #define PARM_EFLAGS           0
98 #ifndef __ELF__
99         .globl _RaiseException
101  _RaiseException:
102        push   $_EXC_RaiseException
103        jmp    ContextCall
105        .globl _RtlUnwind
107  _RtlUnwind:
108        push   $_EXC_RtlUnwind
110 #else  /* __ELF__ */
111        .globl RaiseException
113  RaiseException:
114        push   $EXC_RaiseException
115        jmp    ContextCall
117        .globl RtlUnwind
119  RtlUnwind:
120        push   $EXC_RtlUnwind
121 #endif  /* __ELF__ */
123  ContextCall:
124        pushl  %ebp
125        pushfl
126        movl   %esp, %ebp
127        subl   $CONTEXTSIZE,      %esp
128        movl   %eax, CONTEXT_Eax(%ebp)
129        leal   ORIG_ESP(%ebp), %eax
130        movl   %eax, CONTEXT_Esp(%ebp)
131        movl   PARM_EFLAGS(%ebp), %eax
132        movl   %eax, CONTEXT_EFlags(%ebp)
133        movl   PARM_EBP(%ebp), %eax
134        movl   %eax, CONTEXT_Ebp(%ebp)
135        movl   PARM_RETURN(%ebp), %eax
136        movl   %eax, CONTEXT_Eip(%ebp)
137        movl   %edi, CONTEXT_Edi(%ebp)
138        movl   %esi, CONTEXT_Esi(%ebp)
139        movl   %ebx, CONTEXT_Ebx(%ebp)
140        movl   %edx, CONTEXT_Edx(%ebp)
141        movl   %ecx, CONTEXT_Ecx(%ebp)
142        xorl   %eax, %eax
143        movw   %ss, %ax
144        movl   %eax, CONTEXT_SegSs(%ebp)
145        movw   %cs, %ax
146        movl   %eax, CONTEXT_SegCs(%ebp)
147        movw   %gs, %ax
148        movl   %eax, CONTEXT_SegGs(%ebp)
149        movw   %fs, %ax
150        movl   %eax, CONTEXT_SegFs(%ebp)
151        movw   %es, %ax
152        movl   %eax, CONTEXT_SegEs(%ebp)
153        movw   %ds, %ax
154        movl   %eax, CONTEXT_SegDs(%ebp)
155        fsave  CONTEXT_FloatSave(%ebp)
156        movl   $CONTEXTFLAGS, %eax
157        movl   %eax, CONTEXT_ContextFlags(%ebp)
158        pushl  %ebp
159        leal   CONTEXT(%ebp), %eax
160        pushl  %eax
161        pushl  PARM_ARG4(%ebp)
162        pushl  PARM_ARG3(%ebp)
163        pushl  PARM_ARG2(%ebp)
164        pushl  PARM_ARG1(%ebp)
165        call   *PARM_CALLFUNC(%ebp)
166        addl   $20,%esp
167        popl   %ebp
168        lds    CONTEXT_Esp(%ebp),%edi
169        movl   CONTEXT_Eip(%ebp),%eax
170        movl   %eax,-4(%edi)
171        movl   CONTEXT_EFlags(%ebp),%eax
172        movl   %eax,-8(%edi)
173        movl   CONTEXT_Edi(%ebp),%eax
174        movl   %eax,-12(%edi)
175        movl   CONTEXT_SegDs(%ebp),%eax
176        movw   %ax,%ds
177        movl   CONTEXT_SegEs(%ebp),%eax
178        movw   %ax,%es
179        movl   CONTEXT_SegFs(%ebp),%eax
180        movw   %ax,%fs
181        movl   CONTEXT_SegGs(%ebp),%eax
182        movw   %ax,%gs
183        frstor CONTEXT_FloatSave(%ebp)
184        movl   CONTEXT_Ecx(%ebp),%ecx
185        movl   CONTEXT_Edx(%ebp),%edx
186        movl   CONTEXT_Ebx(%ebp),%ebx
187        movl   CONTEXT_Esi(%ebp),%esi
188        movl   CONTEXT_Eax(%ebp),%eax
189        movl   CONTEXT_Ebp(%ebp),%ebp
190        lea    -12(%edi),%esp
191        popl   %edi
192        popfl
193        ret