|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <setjmp.h> |
|
17 |
|
18 #ifdef __CW32__ |
|
19 #define _asm asm |
|
20 #endif |
|
21 |
|
22 extern "C" { |
|
23 |
|
24 EXPORT_C int setjmp(jmp_buf __jmpb) |
|
25 { |
|
26 // preamble does "push ebp; mov ebp,esp;" |
|
27 _asm mov eax, __jmpb |
|
28 _asm mov [eax], ebx |
|
29 _asm mov [eax+4], esi |
|
30 _asm mov [eax+8], edi |
|
31 _asm mov [eax+12], ebp // caller's ESP |
|
32 _asm mov [eax+16], ds |
|
33 _asm mov [eax+20], es |
|
34 _asm mov [eax+24], fs |
|
35 _asm mov [eax+28], gs |
|
36 _asm mov edx, [ebp] |
|
37 _asm mov [eax+32], edx // caller's EBP |
|
38 _asm mov edx, [ebp+4] |
|
39 _asm mov [eax+36], edx // return address EIP |
|
40 return(0); |
|
41 } |
|
42 |
|
43 EXPORT_C void longjmp(jmp_buf __jmpb, int __retval) |
|
44 { |
|
45 __jmpb[10]= (__retval == 0) ? 1 : __retval; // so we can return it after changing ESP/EBP |
|
46 _asm mov eax, __jmpb |
|
47 _asm mov ebp, [eax+12] |
|
48 _asm mov esp, ebp // restore setjmp ESP (and leave EBP==ESP) |
|
49 _asm mov ebx, [eax] |
|
50 _asm mov esi, [eax+4] |
|
51 _asm mov edi, [eax+8] |
|
52 _asm mov ds, [eax+16] |
|
53 _asm mov es, [eax+20] |
|
54 _asm mov fs, [eax+24] |
|
55 _asm mov gs, [eax+28] |
|
56 _asm mov edx, [eax+32] |
|
57 _asm mov [ebp], edx // put setjmp caller's EBP back into stack |
|
58 _asm mov edx, [eax+36] |
|
59 _asm mov [ebp+4], edx // put setjmp caller's EIP back into stack |
|
60 _asm mov eax, [eax+40] |
|
61 _asm pop ebp |
|
62 _asm ret |
|
63 } |
|
64 |
|
65 } // extern "C" |