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