The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame^] | 1 | /* $OpenBSD: setjmp.S,v 1.2 2004/02/01 05:40:52 drahn Exp $ */ |
| 2 | /* $NetBSD: setjmp.S,v 1.5 2003/04/05 23:08:51 bjh21 Exp $ */ |
| 3 | |
| 4 | /* |
| 5 | * Copyright (c) 1997 Mark Brinicombe |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. All advertising materials mentioning features or use of this software |
| 17 | * must display the following acknowledgement: |
| 18 | * This product includes software developed by Mark Brinicombe |
| 19 | * 4. Neither the name of the University nor the names of its contributors |
| 20 | * may be used to endorse or promote products derived from this software |
| 21 | * without specific prior written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 33 | * SUCH DAMAGE. |
| 34 | */ |
| 35 | |
| 36 | #include <machine/asm.h> |
| 37 | #include <machine/setjmp.h> |
| 38 | |
| 39 | /* |
| 40 | * C library -- setjmp, longjmp |
| 41 | * |
| 42 | * longjmp(a,v) |
| 43 | * will generate a "return(v)" from the last call to |
| 44 | * setjmp(a) |
| 45 | * by restoring registers from the stack. |
| 46 | * The previous signal state is restored. |
| 47 | */ |
| 48 | |
| 49 | ENTRY(setjmp) |
| 50 | /* Block all signals and retrieve the old signal mask */ |
| 51 | stmfd sp!, {r0, r14} |
| 52 | mov r0, #0x00000000 |
| 53 | |
| 54 | bl PIC_SYM(_C_LABEL(sigblock), PLT) |
| 55 | mov r1, r0 |
| 56 | |
| 57 | ldmfd sp!, {r0, r14} |
| 58 | |
| 59 | /* Store signal mask */ |
| 60 | str r1, [r0, #(25 * 4)] |
| 61 | |
| 62 | ldr r1, .Lsetjmp_magic |
| 63 | str r1, [r0], #4 |
| 64 | |
| 65 | #ifdef SOFTFLOAT |
| 66 | add r0, r0, #52 |
| 67 | #else |
| 68 | /* Store fp registers */ |
| 69 | sfm f4, 4, [r0], #48 |
| 70 | /* Store fpsr */ |
| 71 | rfs r1 |
| 72 | str r1, [r0], #0x0004 |
| 73 | #endif /*SOFTFLOAT*/ |
| 74 | /* Store integer registers */ |
| 75 | stmia r0, {r4-r14} |
| 76 | mov r0, #0x00000000 |
| 77 | bx lr |
| 78 | |
| 79 | .Lsetjmp_magic: |
| 80 | .word _JB_MAGIC_SETJMP |
| 81 | |
| 82 | |
| 83 | ENTRY(longjmp) |
| 84 | ldr r2, .Lsetjmp_magic |
| 85 | ldr r3, [r0] |
| 86 | teq r2, r3 |
| 87 | bne botch |
| 88 | |
| 89 | /* Fetch signal mask */ |
| 90 | ldr r2, [r0, #(25 * 4)] |
| 91 | |
| 92 | /* Set signal mask */ |
| 93 | stmfd sp!, {r0, r1, r14} |
| 94 | sub sp, sp, #4 /* align the stack */ |
| 95 | |
| 96 | mov r0, r2 |
| 97 | bl PIC_SYM(_C_LABEL(sigsetmask), PLT) |
| 98 | |
| 99 | add sp, sp, #4 /* unalign the stack */ |
| 100 | ldmfd sp!, {r0, r1, r14} |
| 101 | |
| 102 | add r0, r0, #4 |
| 103 | #ifdef SOFTFLOAT |
| 104 | add r0, r0, #52 |
| 105 | #else |
| 106 | /* Restore fp registers */ |
| 107 | lfm f4, 4, [r0], #48 |
| 108 | /* Restore FPSR */ |
| 109 | ldr r4, [r0], #0x0004 |
| 110 | wfs r4 |
| 111 | #endif /* SOFTFLOAT */ |
| 112 | /* Restore integer registers */ |
| 113 | ldmia r0, {r4-r14} |
| 114 | |
| 115 | /* Validate sp and r14 */ |
| 116 | teq sp, #0 |
| 117 | teqne r14, #0 |
| 118 | beq botch |
| 119 | |
| 120 | /* Set return value */ |
| 121 | |
| 122 | mov r0, r1 |
| 123 | teq r0, #0x00000000 |
| 124 | moveq r0, #0x00000001 |
| 125 | bx lr |
| 126 | #ifdef __ARM_26__ |
| 127 | mov r15, r14 |
| 128 | #else |
| 129 | mov r15, r14 |
| 130 | #endif |
| 131 | |
| 132 | /* validation failed, die die die. */ |
| 133 | botch: |
| 134 | bl PIC_SYM(_C_LABEL(longjmperror), PLT) |
| 135 | bl PIC_SYM(_C_LABEL(abort), PLT) |
| 136 | b . - 8 /* Cannot get here */ |