os/ossrv/genericopenlibs/cstdlib/LSIGNAL/JMP_WINS.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSIGNAL/JMP_WINS.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,65 @@
     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 +
    1.21 +#ifdef __CW32__
    1.22 +#define _asm asm
    1.23 +#endif
    1.24 +
    1.25 +extern "C" {
    1.26 +
    1.27 +EXPORT_C int setjmp(jmp_buf __jmpb)
    1.28 +	{
    1.29 +	// preamble does "push ebp; mov ebp,esp;"
    1.30 +	_asm mov eax, __jmpb
    1.31 +	_asm mov [eax],    ebx
    1.32 +	_asm mov [eax+4],  esi
    1.33 +	_asm mov [eax+8],  edi
    1.34 +	_asm mov [eax+12], ebp		// 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 edx, [ebp]
    1.40 +	_asm mov [eax+32], edx		// caller's EBP
    1.41 +	_asm mov edx, [ebp+4]
    1.42 +	_asm mov [eax+36], edx		// return address EIP
    1.43 +	return(0);
    1.44 +	}
    1.45 +
    1.46 +EXPORT_C void longjmp(jmp_buf __jmpb, int __retval)
    1.47 +	{
    1.48 +	__jmpb[10]= (__retval == 0) ? 1 : __retval;		// so we can return it after changing ESP/EBP
    1.49 +	_asm mov eax, __jmpb
    1.50 +	_asm mov ebp, [eax+12]
    1.51 +	_asm mov esp, ebp		// restore setjmp ESP (and leave EBP==ESP)
    1.52 +	_asm mov ebx, [eax]
    1.53 +	_asm mov esi, [eax+4]
    1.54 +	_asm mov edi, [eax+8]
    1.55 +	_asm mov ds, [eax+16]
    1.56 +	_asm mov es, [eax+20]
    1.57 +	_asm mov fs, [eax+24]
    1.58 +	_asm mov gs, [eax+28]
    1.59 +	_asm mov edx, [eax+32]
    1.60 +	_asm mov [ebp], edx		// put setjmp caller's EBP back into stack
    1.61 +	_asm mov edx, [eax+36]
    1.62 +	_asm mov [ebp+4], edx		// put setjmp caller's EIP back into stack
    1.63 +	_asm mov eax, [eax+40]
    1.64 +	_asm pop ebp
    1.65 +	_asm ret 
    1.66 +	}
    1.67 +
    1.68 +} // extern "C"
    1.69 \ No newline at end of file