1/* $OpenBSD: _setjmp.S,v 1.8 2022/05/25 17:32:36 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_setjmp_magic: 89 .word _JB_MAGIC__SETJMP 90 91.L_jmpxor_setjmp: 92 .word __jmpxor - 1b 93END_STRONG(_setjmp) 94 95ENTRY(_longjmp) 96 ldr r2, .L_setjmp_magic 97 ldr r3, [r0], #4 98 teq r2, r3 99 bne .Lbotch 100 101#ifdef SOFTFLOAT 102 add r0, r0, #68 103#else 104 /* Restore fpcsr */ 105 ldr r4, [r0], #4 106 vmsr fpscr, r4 107 /* Restore fp registers */ 108 vldmia r0!, {d8-d15} 109#endif /* SOFTFLOAT */ 110 /* Restore integer registers */ 111 ldmia r0, {r2-r11} 112 113 ldr r0, .L_jmpxor_longjmp 1141: add r0, pc, r0 /* r0 = &__jmpxor */ 115 ldr lr, [r0], #4 /* lr = __jmpxor[1] */ 116 eor lr, r3, lr /* lr ^= jmpbuf[LR] */ 117 ldr r0, [r0] /* r0 = __jmpxor[0] */ 118 eor r13, r0, r2 /* sp = __jmpxor[0] ^ jmpbuf[SP] */ 119 mov r2, r1 /* overwrite __jmpxor copies */ 120 mov r3, r1 121 122 /* Validate sp and lr */ 123 teq sp, #0 124 teqne lr, #0 125 beq .Lbotch 126 127 /* Set return value */ 128 mov r0, r1 129 teq r0, #0x00000000 130 moveq r0, #0x00000001 131 mov pc, lr 132 133.L_jmpxor_longjmp: 134 .word __jmpxor - 1b 135 136 /* validation failed, die die die. */ 137.Lbotch: 138 bl _HIDDEN(abort) 139 b . - 8 /* Cannot get here */ 140END_STRONG(_longjmp) 141