compat_setjmp.S revision 1.3
11.3Smatt/* $NetBSD: compat_setjmp.S,v 1.3 2013/08/19 22:11:50 matt Exp $ */ 21.1Schristos 31.1Schristos/* 41.1Schristos * Copyright (c) 1997 Mark Brinicombe 51.1Schristos * All rights reserved. 61.1Schristos * 71.1Schristos * Redistribution and use in source and binary forms, with or without 81.1Schristos * modification, are permitted provided that the following conditions 91.1Schristos * are met: 101.1Schristos * 1. Redistributions of source code must retain the above copyright 111.1Schristos * notice, this list of conditions and the following disclaimer. 121.1Schristos * 2. Redistributions in binary form must reproduce the above copyright 131.1Schristos * notice, this list of conditions and the following disclaimer in the 141.1Schristos * documentation and/or other materials provided with the distribution. 151.1Schristos * 3. All advertising materials mentioning features or use of this software 161.1Schristos * must display the following acknowledgement: 171.1Schristos * This product includes software developed by Mark Brinicombe 181.1Schristos * 4. Neither the name of the University nor the names of its contributors 191.1Schristos * may be used to endorse or promote products derived from this software 201.1Schristos * without specific prior written permission. 211.1Schristos * 221.1Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 231.1Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241.1Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251.1Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 261.1Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271.1Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281.1Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291.1Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301.1Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311.1Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321.1Schristos * SUCH DAMAGE. 331.1Schristos */ 341.1Schristos 351.1Schristos#include <machine/asm.h> 361.1Schristos#include <machine/setjmp.h> 371.1Schristos 381.1Schristos/* 391.1Schristos * C library -- setjmp, longjmp 401.1Schristos * 411.1Schristos * longjmp(a,v) 421.1Schristos * will generate a "return(v)" from the last call to 431.1Schristos * setjmp(a) 441.1Schristos * by restoring registers from the stack. 451.1Schristos * The previous signal state is restored. 461.1Schristos */ 471.1Schristos 481.1SchristosENTRY(setjmp) 491.1Schristos /* Block all signals and retrieve the old signal mask */ 501.3Smatt push {r0, lr} 511.3Smatt movs r0, #0x00000000 521.1Schristos 531.1Schristos bl PIC_SYM(_C_LABEL(sigblock), PLT) 541.1Schristos mov r1, r0 551.1Schristos 561.1Schristos /* Store signal mask */ 571.2Smatt str r1, [r0, #(_JB_SIGMASK * 4)] 581.1Schristos 591.1Schristos ldr r1, .Lsetjmp_magic 601.2Smatt str r1, [r0] 611.1Schristos 621.1Schristos /* Store integer registers */ 631.3Smatt adds r0, r0, #(_JB_REG_R4 * 4) 641.3Smatt#ifdef __thumb__ 651.3Smatt#ifdef _ARM_ARCH_7 661.3Smatt stmia r0!, {r4-r12} 671.3Smatt str sp, [r0, #0] 681.3Smatt str lr, [r0, #4] 691.3Smatt#else 701.3Smatt stmia r0!, {r4-r7} 711.3Smatt mov r2, r8 721.3Smatt mov r3, r9 731.3Smatt stmia r0!, {r2-r3} 741.3Smatt mov r1, r10 751.3Smatt mov r2, r11 761.3Smatt mov r3, r12 771.3Smatt stmia r0!, {r1-r3} 781.3Smatt mov r2, sp 791.3Smatt mov r3, lr 801.3Smatt stmia r0!, {r2-r3} 811.3Smatt#endif 821.3Smatt#else 831.3Smatt stmia r0, {r4-lr} 841.3Smatt#endif 851.3Smatt movs r0, #0 861.3Smatt pop {r3, pc} 871.3SmattEND(setjmp) 881.1Schristos 891.1SchristosENTRY(longjmp) 901.1Schristos ldr r2, .Lsetjmp_magic 911.1Schristos ldr r3, [r0] 921.3Smatt cmp r2, r3 931.1Schristos bne botch 941.1Schristos 951.1Schristos /* Fetch signal mask */ 961.2Smatt ldr r2, [r0, #(_JB_SIGMASK * 4)] 971.1Schristos 981.1Schristos /* Set signal mask */ 991.3Smatt push {r0, r1} /* don't care about lr */ 1001.1Schristos 1011.1Schristos mov r0, r2 1021.1Schristos bl PIC_SYM(_C_LABEL(sigsetmask), PLT) 1031.1Schristos 1041.3Smatt pop {r0, r1} 1051.1Schristos 1061.1Schristos /* Restore integer registers */ 1071.3Smatt adds r0, r0, #(_JB_REG_R4 * 4) 1081.3Smatt#if !defined(__thumb__) || defined(_ARM_ARCH_7) 1091.3Smatt ldmia r0!, {r4-r12} 1101.3Smatt#else 1111.3Smatt ldmia r0!, {r4-r7} 1121.3Smatt ldmia r0!, {r2-r3} 1131.3Smatt mov r8, r2 1141.3Smatt mov r9, r3 1151.3Smatt ldmia r0!, {r1-r3} 1161.3Smatt mov r10, r2 1171.3Smatt mov r11, r3 1181.3Smatt ldmia r0!, {r2} 1191.3Smatt mov r12, r2 1201.3Smatt#endif 1211.3Smatt 1221.3Smatt ldmia r0!, {r2-r3} /* r2 = sp, r3 = lr */ 1231.1Schristos 1241.3Smatt /* Validate sp */ 1251.3Smatt cmp r2, #0 1261.1Schristos beq botch 1271.3Smatt mov sp, r2 1281.3Smatt 1291.3Smatt /* Validate lr */ 1301.3Smatt cmp r3, #0 1311.3Smatt beq botch 1321.3Smatt mov lr, r3 1331.1Schristos 1341.1Schristos /* Set return value */ 1351.1Schristos mov r0, r1 1361.3Smatt cmp r0, #0 1371.3Smatt#ifdef __thumb__ 1381.3Smatt bne 1f 1391.3Smatt movs r0, #1 1401.3Smatt1: 1411.3Smatt#else 1421.3Smatt moveq r0, #1 1431.3Smatt#endif 1441.1Schristos RET 1451.1Schristos 1461.1Schristos /* validation failed, die die die. */ 1471.1Schristosbotch: 1481.1Schristos bl PIC_SYM(_C_LABEL(longjmperror), PLT) 1491.1Schristos bl PIC_SYM(_C_LABEL(abort), PLT) 1501.3Smatt2: b 2b /* Cannot get here */ 1511.3Smatt 1521.3Smatt .align 0 1531.3Smatt.Lsetjmp_magic: 1541.3Smatt .word _JB_MAGIC_SETJMP 1551.3SmattEND(longjmp) 156