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

Last change on this file since 7029 was 6375, checked in by sandervl, 24 years ago

initterm update

File size: 9.1 KB
Line 
1; $Id: exceptutil.asm,v 1.18 2001-07-20 15:33:29 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
162public getEDX
163getEDX proc near
164 mov EAX, EDX
165 ret
166endp
167
168getEBX proc near
169 mov eax, ebx
170 ret
171getEBX endp
172
173 PUBLIC GetFS
174GetFS proc near
175 mov eax, fs
176 ret
177GetFS endp
178
179 PUBLIC SetFS
180SetFS proc near
181 mov eax, [esp+4]
182 mov fs, eax
183 ret
184SetFS endp
185
186 PUBLIC getCS
187getCS proc near
188 mov eax, cs
189 ret
190getCS endp
191
192 PUBLIC getDS
193getDS proc near
194 mov eax, ds
195 ret
196getDS endp
197
198 PUBLIC SetReturnFS
199SetReturnFS proc near
200 push fs
201 mov eax, [esp+8]
202 mov fs, eax
203 pop eax
204 ret
205SetReturnFS endp
206
207 PUBLIC getSS
208getSS proc near
209 mov ax, ss
210 ret
211getSS endp
212
213 PUBLIC getES
214getES proc near
215 mov eax, es
216 ret
217getES endp
218
219 PUBLIC getGS
220getGS proc near
221 mov eax, gs
222 ret
223getGS endp
224
225 PUBLIC getESP
226getESP proc near
227 mov eax, esp
228 ret
229getESP endp
230
231 PUBLIC RestoreOS2FS
232RestoreOS2FS proc near
233 push 150bh
234 mov ax, fs
235 pop fs
236 ret
237RestoreOS2FS endp
238
239 PUBLIC _Mul32x32to64
240_Mul32x32to64 proc near
241 push ebp
242 mov ebp, esp
243 push eax
244 push edx
245 push edi
246
247 mov edi, [ebp+8] ;64 bits result
248 mov eax, [ebp+12] ;op1
249 mov edx, [ebp+16] ;op2
250 mul edx
251 mov [edi], eax
252 mov [edi+4], edx
253
254 pop edi
255 pop edx
256 pop eax
257 pop ebp
258 ret
259_Mul32x32to64 endp
260
261 PUBLIC _AsmCallThreadHandler
262_AsmCallThreadHandler proc near
263 push ebp
264 mov ebp, esp
265
266 push dword ptr [ebp+12]
267 mov eax, dword ptr [ebp+8]
268 call eax
269
270 mov esp, ebp
271 pop ebp
272 ret
273_AsmCallThreadHandler endp
274
275 PUBLIC _CallEntryPoint
276_CallEntryPoint proc near
277 push ebp
278 mov ebp, esp
279
280 mov eax, esp
281 sub eax, 16
282 and eax, 0FFFFFFF0h
283 add eax, 4
284 mov esp, eax
285
286 push dword ptr [ebp+12]
287 mov eax, dword ptr [ebp+8]
288 call eax
289
290 mov esp, ebp
291 pop ebp
292 ret
293_CallEntryPoint endp
294
295
296; 281 static DWORD EXC_CallHandler( WINEXCEPTION_RECORD *record, WINEXCEPTION_FRAME *frame,
297 EXTRN WriteLog:PROC
298 EXTRN _GetThreadTEB@0:PROC
299IFDEF DEBUG
300 EXTRN DbgEnabledKERNEL32:DWORD
301ENDIF
302
303EXC_push_frame__FP19_WINEXCEPTION_FRAME proc
304 push ebp
305 mov ebp,esp
306 sub esp,04h
307 mov [ebp+08h],eax; frame
308
309; 132 TEB *teb = GetThreadTEB();
310 call _GetThreadTEB@0
311 mov [ebp-04h],eax; teb
312
313; 133 frame->Prev = (PWINEXCEPTION_FRAME)teb->except;
314 mov ecx,[ebp-04h]; teb
315 mov ecx,[ecx]
316 mov eax,[ebp+08h]; frame
317 mov [eax],ecx
318
319; 134 teb->except = frame;
320 mov eax,[ebp-04h]; teb
321 mov ecx,[ebp+08h]; frame
322 mov [eax],ecx
323
324; 135 return frame->Prev;
325 mov eax,[ebp+08h]; frame
326 mov eax,[eax]
327 leave
328 ret
329EXC_push_frame__FP19_WINEXCEPTION_FRAME endp
330
331; 138 static inline WINEXCEPTION_FRAME * EXC_pop_frame( WINEXCEPTION_FRAME *frame )
332 align 04h
333
334EXC_pop_frame__FP19_WINEXCEPTION_FRAME proc
335 push ebp
336 mov ebp,esp
337 sub esp,04h
338 mov [ebp+08h],eax; frame
339
340; 141 TEB *teb = GetThreadTEB();
341 call _GetThreadTEB@0
342 mov [ebp-04h],eax; teb
343
344; 142 teb->except = frame->Prev;
345 mov ecx,[ebp+08h]; frame
346 mov ecx,[ecx]
347 mov eax,[ebp-04h]; teb
348 mov [eax],ecx
349
350; 143 return frame->Prev;
351 mov eax,[ebp+08h]; frame
352 mov eax,[eax]
353 leave
354 ret
355EXC_pop_frame__FP19_WINEXCEPTION_FRAME endp
356
357 align 04h
358 PUBLIC EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5
359
360EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 proc
361 push ebp
362 mov ebp,esp
363 sub esp,010h
364 sub esp,04h
365 mov [ebp+08h],eax; record
366 mov [ebp+0ch],edx; frame
367 mov [ebp+010h],ecx; context
368
369; 296 newframe.frame.Handler = nested_handler;
370 mov eax,[ebp+01ch]; nested_handler
371 mov [ebp-08h],eax; newframe
372
373; 297 newframe.prevFrame = frame;
374 mov eax,[ebp+0ch]; frame
375 mov [ebp-04h],eax; newframe
376
377; 298 EXC_push_frame( &newframe.frame );
378 lea eax,[ebp-0ch]; newframe
379 call EXC_push_frame__FP19_WINEXCEPTION_FRAME
380
381; 299 dprintf(("KERNEL32: Calling handler at %p code=%lx flags=%lx\n",
382IFDEF DEBUG
383 cmp word ptr DbgEnabledKERNEL32+020h,01h
384 jne @BLBL20
385 mov eax,[ebp+08h]; record
386 push dword ptr [eax+04h]
387 mov eax,[ebp+08h]; record
388 push dword ptr [eax]
389 push dword ptr [ebp+018h]; handler
390 push offset FLAT:@CBE8
391 call WriteLog
392 add esp,010h
393ENDIF
394
395; 300 handler, record->ExceptionCode, record->ExceptionFlags));
396@BLBL20:
397
398; 301 ret = handler( record, frame, context, dispatcher );
399 push dword ptr [ebp+014h]; dispatcher
400 push dword ptr [ebp+010h]; context
401 push dword ptr [ebp+0ch]; frame
402 push dword ptr [ebp+08h]; record
403 call dword ptr [ebp+018h]; handler
404 mov [ebp-010h],eax; ret
405
406IFDEF DEBUG
407; 302 dprintf(("KERNEL32: Handler returned %lx\n", ret));
408 cmp word ptr DbgEnabledKERNEL32+020h,01h
409 jne @BLBL21
410 push dword ptr [ebp-010h]; ret
411 push offset FLAT:@CBE9
412 call WriteLog
413 add esp,08h
414@BLBL21:
415ENDIF
416
417; 303 EXC_pop_frame( &newframe.frame );
418 lea eax,[ebp-0ch]; newframe
419 call EXC_pop_frame__FP19_WINEXCEPTION_FRAME
420
421; 304 return ret;
422 mov eax,[ebp-010h]; ret
423 add esp,04h
424 leave
425 ret
426EXC_CallHandler__FP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPP19_WINEXCEPTION_FRAMEPFP20_WINEXCEPTION_RECORDP19_WINEXCEPTION_FRAMEP10WINCONTEXTPv_UlT5 endp
427
428CODE32 ENDS
429
430 END
Note: See TracBrowser for help on using the repository browser.