1/* $OpenBSD: setjmp.S,v 1.8 2022/05/24 17:21:17 guenther 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 "SYS.h" 37#include <machine/setjmp.h> 38 39 .hidden __jmpxor 40 41/* 42 * C library -- setjmp, longjmp 43 * 44 * longjmp(a,v) 45 * will generate a "return(v)" from the last call to 46 * setjmp(a) 47 * by restoring registers from the stack. 48 * The previous signal state is restored. 49 */ 50 51ENTRY(setjmp) 52 /* Block all signals and retrieve the old signal mask */ 53 mov r2, r0 54 mov r1, #0x00000000 55 mov r0, #0x00000001 /* SIG_BLOCK */ 56 SYSTRAP(sigprocmask) 57 58 /* Store signal mask */ 59 str r0, [r2, #(29 * 4)] 60 61 ldr r1, .Lsetjmp_magic 62 str r1, [r2], #4 63 64 ldr r12, .L_jmpxor_setjmp 651: add r12, pc, r12 /* r12 = &__jmpxor */ 66 ldr r3, [r12], #4 /* r3 = __jmpxor[1] */ 67 ldr r12, [r12] /* r12 = __jmpxor[0] */ 68 eor r12, r13, r12 /* r12 = sp ^ __jmpxor[0] */ 69 eor r3, lr, r3 /* r3 = lr ^ __jmpxor[1] */ 70 71#ifdef SOFTFLOAT 72 add r2, r2, #68 73#else 74 /* Store fpcsr */ 75 vmrs r1, fpscr 76 str r1, [r2], #4 77 /* Store fp registers */ 78 vstmia r2!, {d8-d15} 79#endif /* SOFTFLOAT */ 80 /* Store integer registers */ 81 stmia r2, {r3-r12} 82 83 mov r0, #0x00000000 84 mov r12, r0 /* overwrite __jmpxor copies */ 85 mov r3, r0 86 mov pc, lr 87 88.Lsetjmp_magic: 89 .word _JB_MAGIC_SETJMP 90.L_jmpxor_setjmp: 91 .word __jmpxor - 1b 92END_STRONG(setjmp) 93 94 95ENTRY(longjmp) 96 ldr r2, .Lsetjmp_magic 97 ldr r3, [r0] 98 teq r2, r3 99 bne .Lbotch 100 101 /* Fetch signal mask and call sigprocmask */ 102 mov r3, r0 /* r3 = jmpbuf */ 103 mov r2, r1 /* r2 = retvalue */ 104 ldr r1, [r0, #(29 * 4)] 105 mov r0, #0x00000003 /* SIG_SETMASK */ 106 SYSTRAP(sigprocmask) 107 108 add r3, r3, #4 109#ifdef SOFTFLOAT 110 add r3, r3, #68 111#else 112 /* Restore fpcsr */ 113 ldr r4, [r3], #4 114 vmsr fpscr, r4 115 /* Restore fp registers */ 116 vldmia r3!, {d8-d15} 117#endif /* SOFTFLOAT */ 118 /* Restore integer registers */ 119 ldmia r3, {r3-r12} 120 121 ldr r0, .L_jmpxor_longjmp 1221: add r0, pc, r0 /* r0 = &__jmpxor */ 123 ldr lr, [r0], #4 /* lr = __jmpxor[1] */ 124 eor lr, r3, lr /* lr ^= jmpbuf[LR] */ 125 ldr r0, [r0] /* r0 = __jmpxor[0] */ 126 eor r13, r0, r12 /* sp = __jmpxor[0] ^ jmpbuf[SP] */ 127 mov r12, r2 /* overwrite __jmpxor copies */ 128 mov r3, r2 129 130 /* Validate sp and lr */ 131 teq sp, #0 132 teqne lr, #0 133 beq .Lbotch 134 135 /* Set return value */ 136 mov r0, r12 137 teq r0, #0x00000000 138 moveq r0, #0x00000001 139 mov pc, lr 140 141.L_jmpxor_longjmp: 142 .word __jmpxor - 1b 143 144 /* validation failed, die die die. */ 145.Lbotch: 146 bl _HIDDEN(abort) 147 b . - 8 /* Cannot get here */ 148END_STRONG(longjmp) 149