1/* $OpenBSD: setjmp.S,v 1.15 2016/05/23 00:18:57 guenther Exp $ */ 2/*- 3 * Copyright (c) 2002 Steve Murphree, Jr. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Steve Murphree, Jr. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include "SYS.h" 33 34/* 35 * C library -- setjmp, longjmp 36 * 37 * longjmp(a,v) 38 * will generate a "return(v)" from the last call to 39 * setjmp(a) 40 * by restoring registers from the stack, as well as the signal mask. 41 * 42 * For m88k, we define our jmp_buf length to be the size of 21 (_JBLEN) longs. 43 * The buffer layout is as follows: 44 * 45 * jmp_buf[0] return address 46 * jmp_buf[1] signal set 47 * jmp_buf[2 to 19] r14 to r31 48 * jmp_buf[20] setjmp type 49 */ 50 51#define SETJMP_SIG 0x5824 52 53/* 54int setjmp(jmp_buf env); 55 */ 56ENTRY(setjmp) 57 st %r1, %r2,0 /* save registers to the environment buffer */ 58 st %r14,%r2,8 59 st %r15,%r2,12 60 st %r16,%r2,16 61 st %r17,%r2,20 62 st %r18,%r2,24 63 st %r19,%r2,28 64 st %r20,%r2,32 65 st %r21,%r2,36 66 st %r22,%r2,40 67 st %r23,%r2,44 68 st %r24,%r2,48 69 st %r25,%r2,52 70 st %r26,%r2,56 71 st %r27,%r2,60 72 st %r28,%r2,64 73 st %r29,%r2,68 74 st %r30,%r2,72 75 st %r31,%r2,76 76 or %r4,%r0,SETJMP_SIG /* r4 now contains setjmp type */ 77 st %r4,%r2,80 /* setjmp type to _setjmp */ 78 or %r14,%r2,0 /* store address of env in r14 */ 79#ifdef __PIC__ 80 bsr.n _C_LABEL(_libc_sigblock)#plt /* r2 = sigblock(0) */ 81#else 82 bsr.n _C_LABEL(_libc_sigblock) /* r2 = sigblock(0) */ 83#endif 84 or %r2,%r0,0 85 st %r2,%r14,4 /* save signal set in offset 4 of env */ 86 ld %r1,%r14,0 87 ld %r14,%r14,8 88 jmp.n %r1 /* return 0 */ 89 or %r2,%r0,0 90END(setjmp) 91 92/* 93void longjmp(jmp_buf env, int retval); 94 */ 95ENTRY(longjmp) 96 bcnd eq0,%r2,2f /* check for bad environment buffer address. */ 97 ld %r4,%r2,80 /* check setjmp type. */ 98 cmp %r4,%r4,SETJMP_SIG /* should be SETJMP_SIG */ 99 bb1 ne,%r4,2f /* if != SETJMP_SIG, abort. */ 100 101 ld %r14,%r2,8 /* restore registers from the environment buffer */ 102 ld %r15,%r2,12 103 ld %r16,%r2,16 104 ld %r17,%r2,20 105 ld %r18,%r2,24 106 ld %r19,%r2,28 107 ld %r20,%r2,32 108 ld %r21,%r2,36 109 ld %r22,%r2,40 110 ld %r23,%r2,44 111 ld %r24,%r2,48 112 ld %r25,%r2,52 113 ld %r26,%r2,56 114 ld %r27,%r2,60 115 ld %r28,%r2,64 116 ld %r29,%r2,68 117 ld %r30,%r2,72 118 ld %r31,%r2,76 119 120 subu %r31,%r31,16 /* get a temporary stack */ 121 st.d %r2,%r31,0 /* save r2 and r3 on stack (env + return val) */ 122#ifdef __PIC__ 123 bsr.n _C_LABEL(_libc_sigsetmask)#plt /* restore the signal set */ 124#else 125 bsr.n _C_LABEL(_libc_sigsetmask) /* restore the signal set */ 126#endif 127 ld %r2,%r2,4 128 ld.d %r2,%r31,0 /* restore r2 and r3 */ 129 addu %r31,%r31,16 130 ld %r1,%r2,0 /* restore r1 */ 131 bcnd.n ne0,%r3,1f 132 or %r2,%r3,%r0 133 or %r2,%r0,1 /* never return zero! */ 1341: jmp %r1 135 1362: subu %r31,%r31,16 /* get a temporary stack */ 137 st %r1,%r31,0 /* save r1 on stack (return address) */ 138#ifdef __PIC__ 139 bsr _libc_abort#plt /* NO RETURN */ 140#else 141 bsr _libc_abort /* NO RETURN */ 142#endif 143 ld %r1,%r31,0 /* restore r1 from stack */ 144 jmp.n %r1 /* this should not happen but we are prepared */ 145 addu %r31,%r31,16 /* restore the stack */ 146END(longjmp) 147