1/* $OpenBSD: _setjmp.S,v 1.7 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 "DEFS.h" 37#include <machine/setjmp.h> 38 39 .section .openbsd.randomdata,"aw",%progbits 40 .balign 4 41 .globl __jmpxor 42__jmpxor: 43 .zero 4*2 /* (sp, lr) */ 44 END(__jmpxor) 45 .type __jmpxor,%object 46 47 48/* 49 * C library -- _setjmp, _longjmp 50 * 51 * _longjmp(a,v) 52 * will generate a "return(v)" from the last call to 53 * _setjmp(a) 54 * by restoring registers from the stack. 55 * The previous signal state is NOT restored. 56 * 57 * Note: r0 is the return value 58 * r1-r3 are scratch registers in functions 59 */ 60 61ENTRY(_setjmp) 62 ldr r1, .L_setjmp_magic 63 str r1, [r0], #4 64 ldr r2, .L_jmpxor_setjmp 651: add r2, pc, r2 /* r2 = &__jmpxor */ 66 ldr r3, [r2], #4 /* r3 = __jmpxor[1] */ 67 ldr r2, [r2] /* r2 = __jmpxor[0] */ 68 eor r2, r13, r2 /* r2 = sp ^ __jmpxor[0] */ 69 eor r3, lr, r3 /* r3 = lr ^ __jmpxor[1] */ 70 71#ifdef SOFTFLOAT 72 add r0, r0, #68 73#else 74 /* Store fpcsr */ 75 vmrs r1, fpscr 76 str r1, [r0], #4 77 /* Store fp registers */ 78 vstmia r0!, {d8-d15} 79#endif /* SOFTFLOAT */ 80 /* Store integer registers */ 81 stmia r0, {r2-r11} 82 83 mov r0, #0x00000000 84 mov r2, r0 /* overwrite __jmpxor copies */ 85 mov r3, r0 86 mov pc, lr 87 88.L_jmpxor_setjmp: 89 .word __jmpxor - 1b 90END_STRONG(_setjmp) 91 92 .section .rodata.cst4, "aM", %progbits, 4 93 .balign 4 94.L_setjmp_magic: 95 .word _JB_MAGIC__SETJMP 96 97ENTRY(_longjmp) 98 ldr r2, .L_setjmp_magic 99 ldr r3, [r0], #4 100 teq r2, r3 101 bne .Lbotch 102 103#ifdef SOFTFLOAT 104 add r0, r0, #68 105#else 106 /* Restore fpcsr */ 107 ldr r4, [r0], #4 108 vmsr fpscr, r4 109 /* Restore fp registers */ 110 vldmia r0!, {d8-d15} 111#endif /* SOFTFLOAT */ 112 /* Restore integer registers */ 113 ldmia r0, {r2-r11} 114 115 ldr r0, .L_jmpxor_longjmp 1161: add r0, pc, r0 /* r0 = &__jmpxor */ 117 ldr lr, [r0], #4 /* lr = __jmpxor[1] */ 118 eor lr, r3, lr /* lr ^= jmpbuf[LR] */ 119 ldr r0, [r0] /* r0 = __jmpxor[0] */ 120 eor r13, r0, r2 /* sp = __jmpxor[0] ^ jmpbuf[SP] */ 121 mov r2, r1 /* overwrite __jmpxor copies */ 122 mov r3, r1 123 124 /* Validate sp and lr */ 125 teq sp, #0 126 teqne lr, #0 127 beq .Lbotch 128 129 /* Set return value */ 130 mov r0, r1 131 teq r0, #0x00000000 132 moveq r0, #0x00000001 133 mov pc, lr 134 135.L_jmpxor_longjmp: 136 .word __jmpxor - 1b 137 138 /* validation failed, die die die. */ 139.Lbotch: 140 bl _HIDDEN(abort) 141 b . - 8 /* Cannot get here */ 142END_STRONG(_longjmp) 143