1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSIGNAL/JMP_X86GCC.CIA Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,73 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <setjmp.h>
1.20 +#include <cpudefs.h>
1.21 +
1.22 +extern "C" {
1.23 +
1.24 +EXPORT_C __NAKED__ int setjmp(jmp_buf __jmpb)
1.25 + {
1.26 + asm ("mov eax, [esp+4]"); // eax = __jmpb
1.27 + asm ("mov [eax], ebx");
1.28 + asm ("mov [eax+4], esi");
1.29 + asm ("mov [eax+8], edi");
1.30 +
1.31 + // Get caller's ESP by popping the parameter and the return address (8 bytes) from current ESP value
1.32 + asm ("mov edx, esp");
1.33 + asm ("add edx, 8");
1.34 + asm ("mov [eax+12], edx"); // caller's ESP
1.35 + asm ("mov [eax+16], ds");
1.36 + asm ("mov [eax+20], es");
1.37 + asm ("mov [eax+24], fs");
1.38 + asm ("mov [eax+28], gs");
1.39 + asm ("mov [eax+32], ebp"); // caller's EBP (stack frame)
1.40 + asm ("mov edx, [esp]"); // Save the retaddr because it's also the
1.41 + asm ("mov [eax+36], edx"); // place in the calling function to which longjmp() must return to
1.42 + asm ("mov eax, 0");
1.43 + asm ("ret");
1.44 + }
1.45 +
1.46 +EXPORT_C __NAKED__ void longjmp(jmp_buf __jmpb, int __retval)
1.47 + {
1.48 + asm("mov eax, [esp+4]"); // eax = __jmpb
1.49 +
1.50 + // If __retval is 0 (KErrNone?) change it to a non-zero value
1.51 + asm("mov edx, [esp+8]"); // edx = __retval
1.52 + asm("cmp edx, 0");
1.53 + asm("jne is_not_zero");
1.54 + asm("inc edx");
1.55 + asm("is_not_zero:");
1.56 + asm("mov [eax+40],edx"); // __jmpb[10]=__retval
1.57 +
1.58 + asm("mov ebp, [eax+12]");
1.59 + asm("mov esp, ebp"); // restore setjmp caller's ESP
1.60 + asm("mov ebx, [eax]");
1.61 + asm("mov esi, [eax+4]");
1.62 + asm("mov edi, [eax+8]");
1.63 + asm("mov ds, [eax+16]");
1.64 + asm("mov es, [eax+20]");
1.65 + asm("mov fs, [eax+24]");
1.66 + asm("mov gs, [eax+28]");
1.67 +
1.68 + asm("mov ebp, [eax+32]"); // restore setjmp caller's EBP
1.69 +
1.70 + asm("mov eax, [eax+36]"); // push return address on stack
1.71 + asm("push eax");
1.72 + asm("mov eax,edx");
1.73 + asm("ret"); // magically ret's to instruction following call to setjmp() with eax==__retval
1.74 + }
1.75 +
1.76 +} // extern "C"