|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <setjmp.h> |
|
17 |
|
18 extern "C" { |
|
19 |
|
20 EXPORT_C int setjmp(jmp_buf __jmpb) |
|
21 { |
|
22 #ifdef __MARM_THUMB__ |
|
23 //the function destroys the contents of {r0,r1,r2,r3} registers |
|
24 //r0 is used to hold the retrun value |
|
25 //r1,r2,r3 - they are used usually to hold functions arguments/temp data and are |
|
26 //not expected to preserve their values between functions calls. |
|
27 asm("stmia r0!, {r4-r7}");//bytes {0..15} are occupied by {r4,r5,r6,r7} registers |
|
28 asm("mov r2, r8"); |
|
29 asm("mov r3, r9"); |
|
30 asm("mov r4, r10"); |
|
31 asm("mov r5, r11"); |
|
32 asm("mov r6, sp"); |
|
33 asm("mov r7, lr"); |
|
34 asm("stmia r0!, {r2-r7}");//bytes {16..39} are occupied by {r8,r9,r10,r11,sp,lr} registers |
|
35 asm("sub r0, #40");//r0 points now to the beginning of __jmpb |
|
36 asm("ldmia r0!, {r4-r7}");//restore the contents of {r4,r5,r6,r7} registers |
|
37 #else |
|
38 asm("stmia r0, {r4-r11, sp, lr} "); // Save the context |
|
39 #endif |
|
40 return(0); |
|
41 } |
|
42 |
|
43 EXPORT_C void longjmp(jmp_buf __jmpb, int __retval) |
|
44 { |
|
45 #ifdef __MARM_THUMB__ |
|
46 asm("mov r3, r0"); // save the jmp_buf pointer |
|
47 asm("add r3, #16"); //add on 16 to get to high registers |
|
48 asm("ldmia r3!, {r4-r7}"); |
|
49 asm("mov r8,r4"); |
|
50 asm("mov r9,r5"); |
|
51 asm("mov r10,r6"); |
|
52 asm("mov r11,r7"); |
|
53 asm("ldmia r3!, {r4-r5}"); //get sp and lr |
|
54 asm("mov sp, r4"); |
|
55 asm("mov lr, r5"); |
|
56 asm("mov r3, r0"); //get the jmp_buf ptr again |
|
57 asm("ldmia r3!, {r4-r7}"); //and restore the lo regs |
|
58 asm("mov r0, r1"); // return(__retval) |
|
59 asm("cmp r0, #0"); |
|
60 asm("bne 1f"); |
|
61 asm("mov r0, #1"); |
|
62 asm("1:"); |
|
63 #else |
|
64 asm("ldmia r0, {r4-r11, sp, lr} "); // Restore the context |
|
65 asm("movs r0, r1"); // return(__retval == 0 ? 1 : retval) |
|
66 asm("moveq r0, #1"); |
|
67 #endif |
|
68 return; |
|
69 } |
|
70 |
|
71 } // extern "C" |