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