1/* $OpenBSD: setjmp.S,v 1.9 2016/05/09 16:33:48 guenther Exp $ */ 2/* $NetBSD: setjmp.S,v 1.2 1996/10/17 03:08:06 cgd Exp $ */ 3 4/* 5 * Copyright (c) 1994, 1995 Carnegie-Mellon University. 6 * All rights reserved. 7 * 8 * Author: Chris G. Demetriou 9 * 10 * Permission to use, copy, modify and distribute this software and 11 * its documentation is hereby granted, provided that both the copyright 12 * notice and this permission notice appear in all copies of the 13 * software, derivative works or modified versions, and any portions 14 * thereof, and that both notices appear in supporting documentation. 15 * 16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19 * 20 * Carnegie Mellon requests users of this software to return to 21 * 22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23 * School of Computer Science 24 * Carnegie Mellon University 25 * Pittsburgh PA 15213-3890 26 * 27 * any improvements or extensions that they make and grant Carnegie the 28 * rights to redistribute these changes. 29 */ 30 31#include "SYS.h" 32 33/* 34 * C library -- setjmp, longjmp 35 * 36 * longjmp(a,v) 37 * will generate a "return(v)" from 38 * the last call to 39 * setjmp(a) 40 * by restoring registers from the stack, 41 * and the previous signal state. 42 */ 43 44 .set noreorder 45 46LEAF(setjmp, 1) 47 LDGP(pv) 48 stq ra, (2 * 8)(a0) /* sc_pc = return address */ 49 stq s0, (( 9 + 4) * 8)(a0) /* saved bits of sc_regs */ 50 stq s1, ((10 + 4) * 8)(a0) 51 stq s2, ((11 + 4) * 8)(a0) 52 stq s3, ((12 + 4) * 8)(a0) 53 stq s4, ((13 + 4) * 8)(a0) 54 stq s5, ((14 + 4) * 8)(a0) 55 stq s6, ((15 + 4) * 8)(a0) 56 stq ra, ((26 + 4) * 8)(a0) 57 stq sp, ((30 + 4) * 8)(a0) 58 59 /* 60 * get signal mask 61 */ 62 mov a0, s0 /* squirrel away ptr to sc */ 63 ldiq a0, 1 /* how == SIG_BLOCK */ 64 mov zero, a1 /* set == empty */ 65 CALLSYS_NOERROR(sigprocmask) 66 bne a3, botch /* impossible */ 67 stq v0, (1 * 8)(s0) /* save oset in sc_mask */ 68 69 /* 70 * Restore old s0 and a0, and continue saving registers 71 */ 72 mov s0, a0 73 ldq s0, (( 9 + 4) * 8)(a0) 74 75 ldiq t0, 0xacedbadf /* *not* sigcontext magic */ 76 stq t0, ((31 + 4) * 8)(a0) /* magic in sc_regs[31] */ 77 /* Too bad we can't check if we actually used FP */ 78 ldiq t0, 1 79 stq t0, (36 * 8)(a0) /* say we've used FP. */ 80 stt fs0, ((2 + 37) * 8)(a0) /* saved bits of sc_fpregs */ 81 stt fs1, ((3 + 37) * 8)(a0) 82 stt fs2, ((4 + 37) * 8)(a0) 83 stt fs3, ((5 + 37) * 8)(a0) 84 stt fs4, ((6 + 37) * 8)(a0) 85 stt fs5, ((7 + 37) * 8)(a0) 86 stt fs6, ((8 + 37) * 8)(a0) 87 stt fs7, ((9 + 37) * 8)(a0) 88 mf_fpcr ft0 /* get FP control reg */ 89 stt ft0, (69 * 8)(a0) /* and store it in sc_fpcr */ 90 stq zero, (70 * 8)(a0) /* FP software control XXX */ 91 stq zero, (71 * 8)(a0) /* sc_reserved[0] */ 92 stq zero, (72 * 8)(a0) /* sc_reserved[1] */ 93 stq zero, (73 * 8)(a0) /* sc_xxx[0] */ 94 stq zero, (74 * 8)(a0) /* sc_xxx[1] */ 95 stq zero, (75 * 8)(a0) /* sc_xxx[2] */ 96 stq zero, (76 * 8)(a0) /* sc_xxx[3] */ 97 stq zero, (77 * 8)(a0) /* sc_xxx[4] */ 98 stq zero, (78 * 8)(a0) /* sc_xxx[5] */ 99 stq zero, (79 * 8)(a0) /* sc_xxx[6] */ 100 stq zero, (80 * 8)(a0) /* sc_xxx[7] */ 101 102 mov zero, v0 /* return zero */ 103 RET 104END_STRONG(setjmp) 105 106LEAF(longjmp, 2) 107 LDGP(pv) 108 ldq t0, ((31 + 4) * 8)(a0) /* magic in sc_regs[31] */ 109 ldiq t1, 0xacedbadf 110 cmpeq t0, t1, t0 111 beq t0, botch /* If the magic was bad, punt */ 112 113 /* 114 * set signal mask 115 */ 116 mov a0, s0 /* squirrel away ptr to sc */ 117 mov a1, s1 /* and the return value */ 118 ldiq a0, 3 /* how == SIG_SETMASK */ 119 ldq a1, (1 * 8)(s0) /* get set from sc_mask */ 120 CALLSYS_NOERROR(sigprocmask) 121 bne a3, botch /* impossible */ 122 123 /* 124 * Restore a0 and a1, and continue restoring registers 125 */ 126 mov s0, a0 127 mov s1, a1 128 129 ldq ra, (2 * 8)(a0) /* sc_pc = return address */ 130 ldq s0, (( 9 + 4) * 8)(a0) /* saved bits of sc_regs */ 131 ldq s1, ((10 + 4) * 8)(a0) 132 ldq s2, ((11 + 4) * 8)(a0) 133 ldq s3, ((12 + 4) * 8)(a0) 134 ldq s4, ((13 + 4) * 8)(a0) 135 ldq s5, ((14 + 4) * 8)(a0) 136 ldq s6, ((15 + 4) * 8)(a0) 137 /* ldq ra, ((26 + 4) * 8)(a0) set above */ 138 ldq sp, ((30 + 4) * 8)(a0) 139 ldt fs0, ((2 + 37) * 8)(a0) /* saved bits of sc_fpregs */ 140 ldt fs1, ((3 + 37) * 8)(a0) 141 ldt fs2, ((4 + 37) * 8)(a0) 142 ldt fs3, ((5 + 37) * 8)(a0) 143 ldt fs4, ((6 + 37) * 8)(a0) 144 ldt fs5, ((7 + 37) * 8)(a0) 145 ldt fs6, ((8 + 37) * 8)(a0) 146 ldt fs7, ((9 + 37) * 8)(a0) 147 ldt ft0, (69 * 8)(a0) /* get sc_fpcr */ 148 mt_fpcr ft0 /* and restore it. */ 149 150 bne a1, 1f 151 addq a1, 1, a1 1521: 153 mov a1, v0 /* return second arg */ 154 RET 155 156botch: 157 CALL(_HIDDEN(abort)) 158 RET /* "can't" get here... */ 159END_STRONG(longjmp) 160