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 |
#include <cpudefs.h>
|
sl@0
|
18 |
|
sl@0
|
19 |
extern "C" {
|
sl@0
|
20 |
|
sl@0
|
21 |
EXPORT_C __NAKED__ int setjmp(jmp_buf __jmpb)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
asm ("mov eax, [esp+4]"); // eax = __jmpb
|
sl@0
|
24 |
asm ("mov [eax], ebx");
|
sl@0
|
25 |
asm ("mov [eax+4], esi");
|
sl@0
|
26 |
asm ("mov [eax+8], edi");
|
sl@0
|
27 |
|
sl@0
|
28 |
// Get caller's ESP by popping the parameter and the return address (8 bytes) from current ESP value
|
sl@0
|
29 |
asm ("mov edx, esp");
|
sl@0
|
30 |
asm ("add edx, 8");
|
sl@0
|
31 |
asm ("mov [eax+12], edx"); // 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 [eax+32], ebp"); // caller's EBP (stack frame)
|
sl@0
|
37 |
asm ("mov edx, [esp]"); // Save the retaddr because it's also the
|
sl@0
|
38 |
asm ("mov [eax+36], edx"); // place in the calling function to which longjmp() must return to
|
sl@0
|
39 |
asm ("mov eax, 0");
|
sl@0
|
40 |
asm ("ret");
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
EXPORT_C __NAKED__ void longjmp(jmp_buf __jmpb, int __retval)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
asm("mov eax, [esp+4]"); // eax = __jmpb
|
sl@0
|
46 |
|
sl@0
|
47 |
// If __retval is 0 (KErrNone?) change it to a non-zero value
|
sl@0
|
48 |
asm("mov edx, [esp+8]"); // edx = __retval
|
sl@0
|
49 |
asm("cmp edx, 0");
|
sl@0
|
50 |
asm("jne is_not_zero");
|
sl@0
|
51 |
asm("inc edx");
|
sl@0
|
52 |
asm("is_not_zero:");
|
sl@0
|
53 |
asm("mov [eax+40],edx"); // __jmpb[10]=__retval
|
sl@0
|
54 |
|
sl@0
|
55 |
asm("mov ebp, [eax+12]");
|
sl@0
|
56 |
asm("mov esp, ebp"); // restore setjmp caller's ESP
|
sl@0
|
57 |
asm("mov ebx, [eax]");
|
sl@0
|
58 |
asm("mov esi, [eax+4]");
|
sl@0
|
59 |
asm("mov edi, [eax+8]");
|
sl@0
|
60 |
asm("mov ds, [eax+16]");
|
sl@0
|
61 |
asm("mov es, [eax+20]");
|
sl@0
|
62 |
asm("mov fs, [eax+24]");
|
sl@0
|
63 |
asm("mov gs, [eax+28]");
|
sl@0
|
64 |
|
sl@0
|
65 |
asm("mov ebp, [eax+32]"); // restore setjmp caller's EBP
|
sl@0
|
66 |
|
sl@0
|
67 |
asm("mov eax, [eax+36]"); // push return address on stack
|
sl@0
|
68 |
asm("push eax");
|
sl@0
|
69 |
asm("mov eax,edx");
|
sl@0
|
70 |
asm("ret"); // magically ret's to instruction following call to setjmp() with eax==__retval
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
} // extern "C"
|