sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: sl@0: #ifdef __CW32__ sl@0: #define _asm asm sl@0: #endif sl@0: sl@0: extern "C" { sl@0: sl@0: EXPORT_C int setjmp(jmp_buf __jmpb) sl@0: { sl@0: // preamble does "push ebp; mov ebp,esp;" sl@0: _asm mov eax, __jmpb sl@0: _asm mov [eax], ebx sl@0: _asm mov [eax+4], esi sl@0: _asm mov [eax+8], edi sl@0: _asm mov [eax+12], ebp // caller's ESP sl@0: _asm mov [eax+16], ds sl@0: _asm mov [eax+20], es sl@0: _asm mov [eax+24], fs sl@0: _asm mov [eax+28], gs sl@0: _asm mov edx, [ebp] sl@0: _asm mov [eax+32], edx // caller's EBP sl@0: _asm mov edx, [ebp+4] sl@0: _asm mov [eax+36], edx // return address EIP sl@0: return(0); sl@0: } sl@0: sl@0: EXPORT_C void longjmp(jmp_buf __jmpb, int __retval) sl@0: { sl@0: __jmpb[10]= (__retval == 0) ? 1 : __retval; // so we can return it after changing ESP/EBP sl@0: _asm mov eax, __jmpb sl@0: _asm mov ebp, [eax+12] sl@0: _asm mov esp, ebp // restore setjmp ESP (and leave EBP==ESP) sl@0: _asm mov ebx, [eax] sl@0: _asm mov esi, [eax+4] sl@0: _asm mov edi, [eax+8] sl@0: _asm mov ds, [eax+16] sl@0: _asm mov es, [eax+20] sl@0: _asm mov fs, [eax+24] sl@0: _asm mov gs, [eax+28] sl@0: _asm mov edx, [eax+32] sl@0: _asm mov [ebp], edx // put setjmp caller's EBP back into stack sl@0: _asm mov edx, [eax+36] sl@0: _asm mov [ebp+4], edx // put setjmp caller's EIP back into stack sl@0: _asm mov eax, [eax+40] sl@0: _asm pop ebp sl@0: _asm ret sl@0: } sl@0: sl@0: } // extern "C"