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: extern "C" { sl@0: sl@0: EXPORT_C int setjmp(jmp_buf __jmpb) sl@0: { sl@0: #ifdef __MARM_THUMB__ sl@0: //the function destroys the contents of {r0,r1,r2,r3} registers sl@0: //r0 is used to hold the retrun value sl@0: //r1,r2,r3 - they are used usually to hold functions arguments/temp data and are sl@0: //not expected to preserve their values between functions calls. sl@0: asm("stmia r0!, {r4-r7}");//bytes {0..15} are occupied by {r4,r5,r6,r7} registers sl@0: asm("mov r2, r8"); sl@0: asm("mov r3, r9"); sl@0: asm("mov r4, r10"); sl@0: asm("mov r5, r11"); sl@0: asm("mov r6, sp"); sl@0: asm("mov r7, lr"); sl@0: asm("stmia r0!, {r2-r7}");//bytes {16..39} are occupied by {r8,r9,r10,r11,sp,lr} registers sl@0: asm("sub r0, #40");//r0 points now to the beginning of __jmpb sl@0: asm("ldmia r0!, {r4-r7}");//restore the contents of {r4,r5,r6,r7} registers sl@0: #else sl@0: asm("stmia r0, {r4-r11, sp, lr} "); // Save the context sl@0: #endif sl@0: return(0); sl@0: } sl@0: sl@0: EXPORT_C void longjmp(jmp_buf __jmpb, int __retval) sl@0: { sl@0: #ifdef __MARM_THUMB__ sl@0: asm("mov r3, r0"); // save the jmp_buf pointer sl@0: asm("add r3, #16"); //add on 16 to get to high registers sl@0: asm("ldmia r3!, {r4-r7}"); sl@0: asm("mov r8,r4"); sl@0: asm("mov r9,r5"); sl@0: asm("mov r10,r6"); sl@0: asm("mov r11,r7"); sl@0: asm("ldmia r3!, {r4-r5}"); //get sp and lr sl@0: asm("mov sp, r4"); sl@0: asm("mov lr, r5"); sl@0: asm("mov r3, r0"); //get the jmp_buf ptr again sl@0: asm("ldmia r3!, {r4-r7}"); //and restore the lo regs sl@0: asm("mov r0, r1"); // return(__retval) sl@0: asm("cmp r0, #0"); sl@0: asm("bne 1f"); sl@0: asm("mov r0, #1"); sl@0: asm("1:"); sl@0: #else sl@0: asm("ldmia r0, {r4-r11, sp, lr} "); // Restore the context sl@0: asm("movs r0, r1"); // return(__retval == 0 ? 1 : retval) sl@0: asm("moveq r0, #1"); sl@0: #endif sl@0: return; sl@0: } sl@0: sl@0: } // extern "C"