source: trunk/src/kernel32/exceptutil.asm@ 5655

Last change on this file since 5655 was 5564, checked in by sandervl, 24 years ago

removed wrong segment definition

File size: 8.7 KB
Line 
1; $Id: exceptutil.asm,v 1.16 2001-04-22 09:00:19 sandervl Exp $
2
3;/*
4; * Project Odin Software License can be found in LICENSE.TXT
5; * Win32 Exception handling + misc functions for OS/2
6; *
7; * Copyright 1998 Sander van Leeuwen
8; *
9; */
10.386p
11 NAME except
12
13DATA32 segment dword use32 public 'DATA'
14DATA32 ends
15CONST32_RO segment dword use32 public 'CONST'
16CONST32_RO ends
17BSS32 segment dword use32 public 'BSS'
18BSS32 ends
19DGROUP group BSS32, DATA32
20 assume cs:FLAT, ds:FLAT, ss:FLAT, es:FLAT
21
22DATA32 segment dword use32 public 'DATA'
23
24CONST32_RO segment
25 align 04h
26@CBE8 db "KERNEL32: Calling handle"
27db "r at %p code=%lx flags=%"
28db "lx",0ah,0h
29@CBE9 db "KERNEL32: Handler return"
30db "ed %lx",0ah,0h
31CONST32_RO ends
32DATA32 ends
33
34CODE32 SEGMENT DWORD PUBLIC USE32 'CODE'
35 public _RaiseException@16
36 extrn OS2RAISEEXCEPTION : near
37
38_RaiseException@16 proc near
39 push dword ptr [esp+4] ;DWORD dwExceptionCode
40 push dword ptr [esp+12] ;DWORD dwExceptionFlags
41 push dword ptr [esp+20] ;DWORD cArguments
42 push dword ptr [esp+28] ;DWORD *lpArguments
43 push dword ptr [esp+16] ;return address
44 push esp
45 add dword ptr [esp], 20
46 push ebp
47 pushfd
48 push eax
49 push ebx
50 push ecx
51 push edx
52 push edi
53 push esi
54 xor eax, eax
55 mov eax, cs
56 push eax
57 mov eax, ds
58 push eax
59 mov eax, es
60 push eax
61 mov eax, fs
62 push eax
63 mov eax, gs
64 push eax
65 mov eax, ss
66 push eax
67 call OS2RAISEEXCEPTION
68
69 ret 16 ;__stdcall
70_RaiseException@16 endp
71
72 public _RtlUnwind@16
73 extrn OS2RTLUNWIND : near
74
75_RtlUnwind@16 proc near
76 push dword ptr [esp+4] ;PWINEXCEPTION_FRAME pEndFrame
77 push dword ptr [esp+12] ;LPVOID unusedEip
78 push dword ptr [esp+20] ;PWINEXCEPTION_RECORD pRecord
79 push dword ptr [esp+28] ;DWORD returnEax
80 push dword ptr [esp+16] ;return address
81 push esp
82 add dword ptr [esp], 20
83 push ebp
84 pushfd
85 push eax
86 push ebx
87 push ecx
88 push edx
89 push edi
90 push esi
91 xor eax, eax
92 mov eax, cs
93 push eax
94 mov eax, ds
95 push eax
96 mov eax, es
97 push eax
98 mov eax, fs
99 push eax
100 mov eax, gs
101 push eax
102 mov eax, ss
103 push eax
104 call OS2RTLUNWIND
105
106 ret 16 ;__stdcall
107_RtlUnwind@16 endp
108
109
110 PUBLIC QueryExceptionChain
111
112QueryExceptionChain proc near
113 mov eax, fs:[0]
114 ret
115QueryExceptionChain endp
116
117 PUBLIC GetExceptionRecord
118GetExceptionRecord proc near
119 push ebp
120 mov ebp, esp
121 push fs
122 push ebx
123
124 mov eax, [ebp+8]
125 mov fs, eax
126 mov ebx, [ebp+12]
127 mov eax, fs:[ebx]
128
129 pop ebx
130 pop fs
131 pop ebp
132 ret
133GetExceptionRecord endp
134
135 PUBLIC ChangeTIBStack
136ChangeTIBStack proc near
137; xor eax, eax
138 push ebx
139 mov eax, fs:[4]
140 mov ebx, fs:[8]
141 add ebx, 8
142 mov fs:[4], ebx
143 mov fs:[8], eax
144 pop ebx
145 ret
146ChangeTIBStack endp
147
148 PUBLIC _SetExceptionChain
149
150_SetExceptionChain proc near
151 mov eax, dword ptr [esp+4]
152 mov fs:[0], eax
153 ret
154_SetExceptionChain endp
155
156 PUBLIC getEAX
157 PUBLIC getEBX
158getEAX proc near
159 ret
160getEAX endp
161
162getEBX proc near
163 mov eax, ebx
164 ret
165getEBX endp
166
167 PUBLIC GetFS
168GetFS proc near
169 mov eax, fs
170 ret
171GetFS endp
172
173 PUBLIC SetFS
174SetFS proc near
175 mov eax, [esp+4]
176 mov fs, eax
177 ret
178SetFS endp
179
180 PUBLIC getCS
181getCS proc near
182 mov eax, cs
183 ret
184getCS endp
185
186 PUBLIC getDS
187getDS proc near
188 mov eax, ds
189 ret
190getDS endp
191
192 PUBLIC SetReturnFS
193SetReturnFS proc near
194 push fs
195 mov eax, [esp+8]
196 mov fs, eax
197 pop eax
198 ret
199SetReturnFS endp
200
201 PUBLIC getSS
202getSS proc near
203 mov ax, ss
204 ret
205getSS endp
206
207 PUBLIC getES
208getES proc near
209 mov eax, es
210 ret
211getES endp
212
213 PUBLIC getGS
214getGS proc near
215 mov eax, gs
216 ret
217getGS endp
218
219 PUBLIC getESP
220getESP proc near
221 mov eax, esp
222 ret
223getESP endp
224
225 PUBLIC RestoreOS2FS
226RestoreOS2FS proc near
227 push 150bh
228 mov ax, fs
229 pop fs
230 ret
231RestoreOS2FS endp
232
233 PUBLIC _Mul32x32to64
234_Mul32x32to64 proc near
235 push ebp
236 mov ebp, esp
237 push eax
238 push edx
239 push edi
240
241 mov edi, [ebp+8] ;64 bits result
242 mov eax, [ebp+12] ;op1
243 mov edx, [ebp+16] ;op2
244 mul edx
245 mov [edi], eax
246 mov [edi+4], edx
247
248 pop edi
249 pop edx
250 pop eax
251 pop ebp
252 ret
253_Mul32x32to64 endp
254
255 PUBLIC _AsmCallThreadHandler
256_AsmCallThreadHandler proc near
257 push ebp
258 mov ebp, esp
259
260 push dword ptr [ebp+12]
261 mov eax, dword ptr [ebp+8]
262 call eax
263
264 mov esp, ebp
265 pop ebp
266 ret
267_AsmCallThreadHandler endp
268
269; 281 static DWORD EXC_CallHandler( WINEXCEPTION_RECORD *record, WINEXCEPTION_FRAME *frame,
270 EXTRN WriteLog:PROC
271 EXTRN _GetThreadTEB@0:PROC
272IFDEF DEBUG
273 EXTRN DbgEnabled:DWORD
274ENDIF
275
276EXC_push_frame__FP19_WINEXCEPTION_FRAME proc
277 push ebp
278 mov ebp,esp
279 sub esp,04h
280 mov [ebp+08h],eax; frame
281
282; 132 TEB *teb = GetThreadTEB();
283 call _GetThreadTEB@0
284 mov [ebp-04h],eax; teb
285
286; 133 frame->Prev = (PWINEXCEPTION_FRAME)teb->except;
287 mov ecx,[ebp-04h]; teb
288 mov ecx,[ecx]
289 mov eax,[ebp+08h]; frame
290 mov [eax],ecx
291
292; 134 teb->except = frame;
293 mov eax,[ebp-04h]; teb
294 mov ecx,[ebp+08h]; frame
295 mov [eax],ecx
296
297; 135 return frame->Prev;
298 mov eax,[ebp+08h]; frame
299 mov eax,[eax]
300 leave
301 ret
302EXC_push_frame__FP19_WINEXCEPTION_FRAME endp
303
304; 138 static inline WINEXCEPTION_FRAME * EXC_pop_frame( WINEXCEPTION_FRAME *frame )
305 align 04h
306
307EXC_pop_frame__FP19_WINEXCEPTION_FRAME proc
308 push ebp
309 mov ebp,esp
310 sub esp,04h
311 mov [ebp+08h],eax; frame
312
313; 141 TEB *teb = GetThreadTEB();
314 call _GetThreadTEB@0
315 mov [ebp-04h],eax; teb
316
317; 142 teb->except = frame->Prev;
318 mov ecx,[ebp+08h]; frame
319 mov ecx,[ecx]
320 mov eax,[ebp-04h]; teb
321 mov [eax],ecx
322
323; 143 return frame->Prev;
324 mov eax,[ebp+08h]; frame
325 mov eax,[eax]
326 leave
327 ret
328EXC_pop_frame__FP19_WINEXCEPTION_FRAME endp
329
330 align 04h
331 PUBLIC EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5
332
333EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 proc
334 push ebp
335 mov ebp,esp
336 sub esp,010h
337 sub esp,04h
338 mov [ebp+08h],eax; record
339 mov [ebp+0ch],edx; frame
340 mov [ebp+010h],ecx; context
341
342; 296 newframe.frame.Handler = nested_handler;
343 mov eax,[ebp+01ch]; nested_handler
344 mov [ebp-08h],eax; newframe
345
346; 297 newframe.prevFrame = frame;
347 mov eax,[ebp+0ch]; frame
348 mov [ebp-04h],eax; newframe
349
350; 298 EXC_push_frame( &newframe.frame );
351 lea eax,[ebp-0ch]; newframe
352 call EXC_push_frame__FP19_WINEXCEPTION_FRAME
353
354; 299 dprintf(("KERNEL32: Calling handler at %p code=%lx flags=%lx\n",
355IFDEF DEBUG
356 cmp word ptr DbgEnabled+020h,01h
357 jne @BLBL20
358 mov eax,[ebp+08h]; record
359 push dword ptr [eax+04h]
360 mov eax,[ebp+08h]; record
361 push dword ptr [eax]
362 push dword ptr [ebp+018h]; handler
363 push offset FLAT:@CBE8
364 call WriteLog
365 add esp,010h
366ENDIF
367
368; 300 handler, record->ExceptionCode, record->ExceptionFlags));
369@BLBL20:
370
371; 301 ret = handler( record, frame, context, dispatcher );
372 push dword ptr [ebp+014h]; dispatcher
373 push dword ptr [ebp+010h]; context
374 push dword ptr [ebp+0ch]; frame
375 push dword ptr [ebp+08h]; record
376 call dword ptr [ebp+018h]; handler
377 mov [ebp-010h],eax; ret
378
379IFDEF DEBUG
380; 302 dprintf(("KERNEL32: Handler returned %lx\n", ret));
381 cmp word ptr DbgEnabled+020h,01h
382 jne @BLBL21
383 push dword ptr [ebp-010h]; ret
384 push offset FLAT:@CBE9
385 call WriteLog
386 add esp,08h
387@BLBL21:
388ENDIF
389
390; 303 EXC_pop_frame( &newframe.frame );
391 lea eax,[ebp-0ch]; newframe
392 call EXC_pop_frame__FP19_WINEXCEPTION_FRAME
393
394; 304 return ret;
395 mov eax,[ebp-010h]; ret
396 add esp,04h
397 leave
398 ret
399EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 endp
400
401CODE32 ENDS
402
403 END
Note: See TracBrowser for help on using the repository browser.