os/ossrv/genericopenlibs/cstdlib/LSIGNAL/JMP_MARM.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_MARM.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,71 @@
     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 +extern "C" {
    1.22 +
    1.23 +EXPORT_C int setjmp(jmp_buf __jmpb)
    1.24 +	{
    1.25 +#ifdef __MARM_THUMB__
    1.26 +	//the function destroys the contents of {r0,r1,r2,r3} registers
    1.27 +	//r0 is used to hold the retrun value
    1.28 +	//r1,r2,r3 - they are used usually to hold functions arguments/temp data and are
    1.29 +	//not expected to preserve their values between functions calls.
    1.30 +	asm("stmia r0!, {r4-r7}");//bytes {0..15} are occupied by {r4,r5,r6,r7} registers
    1.31 +	asm("mov r2, r8");
    1.32 +	asm("mov r3, r9");
    1.33 +	asm("mov r4, r10");
    1.34 +	asm("mov r5, r11");
    1.35 +	asm("mov r6, sp");
    1.36 +	asm("mov r7, lr");
    1.37 +	asm("stmia r0!, {r2-r7}");//bytes {16..39} are occupied by {r8,r9,r10,r11,sp,lr} registers
    1.38 +	asm("sub r0, #40");//r0 points now to the beginning of __jmpb
    1.39 +	asm("ldmia r0!, {r4-r7}");//restore the contents of {r4,r5,r6,r7} registers
    1.40 +#else
    1.41 +	asm("stmia	r0, {r4-r11, sp, lr}	"); // Save the context
    1.42 +#endif
    1.43 +	return(0);
    1.44 +	}
    1.45 +
    1.46 +EXPORT_C void longjmp(jmp_buf __jmpb, int __retval)
    1.47 +	{
    1.48 +#ifdef __MARM_THUMB__
    1.49 +	asm("mov	r3, r0"); // save the jmp_buf pointer
    1.50 +	asm("add	r3, #16");		//add on 16 to get to high registers
    1.51 +	asm("ldmia	r3!, {r4-r7}");  
    1.52 +	asm("mov	r8,r4");
    1.53 +	asm("mov	r9,r5");
    1.54 +	asm("mov	r10,r6");
    1.55 +	asm("mov	r11,r7");
    1.56 +	asm("ldmia	r3!, {r4-r5}");	//get sp and lr
    1.57 +	asm("mov	sp, r4");
    1.58 +	asm("mov	lr, r5");
    1.59 +	asm("mov	r3, r0");		//get the jmp_buf ptr again
    1.60 +	asm("ldmia  r3!, {r4-r7}");	//and restore the lo regs
    1.61 +	asm("mov	r0, r1"); // return(__retval)
    1.62 +	asm("cmp    r0, #0");
    1.63 +	asm("bne    1f");
    1.64 +	asm("mov    r0, #1");
    1.65 +	asm("1:");
    1.66 +#else
    1.67 +	asm("ldmia	r0, {r4-r11, sp, lr}	"); // Restore the context
    1.68 +	asm("movs	r0, r1"); // return(__retval == 0 ? 1 : retval)
    1.69 +	asm("moveq  r0, #1");
    1.70 +#endif
    1.71 +	return;
    1.72 +	}
    1.73 +
    1.74 +} // extern "C"