1*a9772df4Sskrll/* $NetBSD: compat_setjmp.S,v 1.5 2020/12/05 11:18:21 skrll Exp $ */ 2b638db2cSchristos 3b638db2cSchristos/* 4b638db2cSchristos * Copyright (c) 1997 Mark Brinicombe 5b638db2cSchristos * All rights reserved. 6b638db2cSchristos * 7b638db2cSchristos * Redistribution and use in source and binary forms, with or without 8b638db2cSchristos * modification, are permitted provided that the following conditions 9b638db2cSchristos * are met: 10b638db2cSchristos * 1. Redistributions of source code must retain the above copyright 11b638db2cSchristos * notice, this list of conditions and the following disclaimer. 12b638db2cSchristos * 2. Redistributions in binary form must reproduce the above copyright 13b638db2cSchristos * notice, this list of conditions and the following disclaimer in the 14b638db2cSchristos * documentation and/or other materials provided with the distribution. 15b638db2cSchristos * 3. All advertising materials mentioning features or use of this software 16b638db2cSchristos * must display the following acknowledgement: 17b638db2cSchristos * This product includes software developed by Mark Brinicombe 18b638db2cSchristos * 4. Neither the name of the University nor the names of its contributors 19b638db2cSchristos * may be used to endorse or promote products derived from this software 20b638db2cSchristos * without specific prior written permission. 21b638db2cSchristos * 22b638db2cSchristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23b638db2cSchristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24b638db2cSchristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25b638db2cSchristos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26b638db2cSchristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27b638db2cSchristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28b638db2cSchristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29b638db2cSchristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30b638db2cSchristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31b638db2cSchristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32b638db2cSchristos * SUCH DAMAGE. 33b638db2cSchristos */ 34b638db2cSchristos 35b638db2cSchristos#include <machine/asm.h> 36b638db2cSchristos#include <machine/setjmp.h> 37b638db2cSchristos 38b638db2cSchristos/* 39b638db2cSchristos * C library -- setjmp, longjmp 40b638db2cSchristos * 41b638db2cSchristos * longjmp(a,v) 42b638db2cSchristos * will generate a "return(v)" from the last call to 43b638db2cSchristos * setjmp(a) 44b638db2cSchristos * by restoring registers from the stack. 45b638db2cSchristos * The previous signal state is restored. 46b638db2cSchristos */ 47b638db2cSchristos 48b638db2cSchristosENTRY(setjmp) 49b638db2cSchristos /* Block all signals and retrieve the old signal mask */ 50b485ba73Smatt push {r0, lr} 51b485ba73Smatt movs r0, #0x00000000 52b638db2cSchristos 533c72d529Sjoerg bl PLT_SYM(_C_LABEL(sigblock)) 54b638db2cSchristos mov r1, r0 55b638db2cSchristos 56b638db2cSchristos /* Store signal mask */ 57426eefe1Smatt str r1, [r0, #(_JB_SIGMASK * 4)] 58b638db2cSchristos 59b638db2cSchristos ldr r1, .Lsetjmp_magic 60426eefe1Smatt str r1, [r0] 61b638db2cSchristos 62b638db2cSchristos /* Store integer registers */ 63b485ba73Smatt adds r0, r0, #(_JB_REG_R4 * 4) 64b485ba73Smatt#ifdef __thumb__ 65b485ba73Smatt#ifdef _ARM_ARCH_7 66b485ba73Smatt stmia r0!, {r4-r12} 67b485ba73Smatt str sp, [r0, #0] 68b485ba73Smatt str lr, [r0, #4] 69b485ba73Smatt#else 70b485ba73Smatt stmia r0!, {r4-r7} 71b485ba73Smatt mov r2, r8 72b485ba73Smatt mov r3, r9 73b485ba73Smatt stmia r0!, {r2-r3} 74b485ba73Smatt mov r1, r10 75b485ba73Smatt mov r2, r11 76b485ba73Smatt mov r3, r12 77b485ba73Smatt stmia r0!, {r1-r3} 78b485ba73Smatt mov r2, sp 79b485ba73Smatt mov r3, lr 80b485ba73Smatt stmia r0!, {r2-r3} 81b485ba73Smatt#endif 82b485ba73Smatt#else 83b485ba73Smatt stmia r0, {r4-lr} 84b485ba73Smatt#endif 85b485ba73Smatt movs r0, #0 86b485ba73Smatt pop {r3, pc} 87b485ba73SmattEND(setjmp) 88b638db2cSchristos 89b638db2cSchristosENTRY(longjmp) 90b638db2cSchristos ldr r2, .Lsetjmp_magic 91b638db2cSchristos ldr r3, [r0] 92b485ba73Smatt cmp r2, r3 93b638db2cSchristos bne botch 94b638db2cSchristos 95b638db2cSchristos /* Fetch signal mask */ 96426eefe1Smatt ldr r2, [r0, #(_JB_SIGMASK * 4)] 97b638db2cSchristos 98b638db2cSchristos /* Set signal mask */ 99b485ba73Smatt push {r0, r1} /* don't care about lr */ 100b638db2cSchristos 101b638db2cSchristos mov r0, r2 1023c72d529Sjoerg bl PLT_SYM(_C_LABEL(sigsetmask)) 103b638db2cSchristos 104b485ba73Smatt pop {r0, r1} 105b638db2cSchristos 106b638db2cSchristos /* Restore integer registers */ 107b485ba73Smatt adds r0, r0, #(_JB_REG_R4 * 4) 108b485ba73Smatt#if !defined(__thumb__) || defined(_ARM_ARCH_7) 109b485ba73Smatt ldmia r0!, {r4-r12} 110b485ba73Smatt#else 111b485ba73Smatt ldmia r0!, {r4-r7} 112b485ba73Smatt ldmia r0!, {r2-r3} 113b485ba73Smatt mov r8, r2 114b485ba73Smatt mov r9, r3 115b485ba73Smatt ldmia r0!, {r1-r3} 116b485ba73Smatt mov r10, r2 117b485ba73Smatt mov r11, r3 118b485ba73Smatt ldmia r0!, {r2} 119b485ba73Smatt mov r12, r2 120b485ba73Smatt#endif 121b638db2cSchristos 122b485ba73Smatt ldmia r0!, {r2-r3} /* r2 = sp, r3 = lr */ 123b485ba73Smatt 124b485ba73Smatt /* Validate sp */ 125b485ba73Smatt cmp r2, #0 126b638db2cSchristos beq botch 127b485ba73Smatt mov sp, r2 128b485ba73Smatt 129b485ba73Smatt /* Validate lr */ 130b485ba73Smatt cmp r3, #0 131b485ba73Smatt beq botch 132b485ba73Smatt mov lr, r3 133b638db2cSchristos 134b638db2cSchristos /* Set return value */ 135b638db2cSchristos mov r0, r1 136b485ba73Smatt cmp r0, #0 137b485ba73Smatt#ifdef __thumb__ 138b485ba73Smatt bne 1f 139b485ba73Smatt movs r0, #1 140b485ba73Smatt1: 141b485ba73Smatt#else 142b485ba73Smatt moveq r0, #1 143b485ba73Smatt#endif 144b638db2cSchristos RET 145b638db2cSchristos 146b638db2cSchristos /* validation failed, die die die. */ 147b638db2cSchristosbotch: 1483c72d529Sjoerg bl PLT_SYM(_C_LABEL(longjmperror)) 1493c72d529Sjoerg bl PLT_SYM(_C_LABEL(abort)) 150b485ba73Smatt2: b 2b /* Cannot get here */ 151b485ba73Smatt 152b485ba73Smatt .align 0 153b485ba73Smatt.Lsetjmp_magic: 154b485ba73Smatt .word _JB_MAGIC_SETJMP 155b485ba73SmattEND(longjmp) 156