1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ralph Campbell. 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 the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 */ 36 37#include <sys/syscall.h> 38#include <machine/reg.h> 39#include <machine/machAsmDefs.h> 40 41#if defined(LIBC_SCCS) && !defined(lint) 42 ASMSTR("from: @(#)setjmp.s 8.1 (Berkeley) 6/4/93") 43 ASMSTR("$Id: setjmp.S,v 1.3 1994/12/15 17:24:51 mycroft Exp $") 44#endif /* LIBC_SCCS and not lint */ 45 46/* 47 * C library -- setjmp, longjmp 48 * 49 * longjmp(a,v) 50 * will generate a "return(v)" from 51 * the last call to 52 * setjmp(a) 53 * by restoring registers from the stack, 54 * and a struct sigcontext, see <signal.h> 55 */ 56 57#define SETJMP_FRAME_SIZE (STAND_FRAME_SIZE + 12) 58 59NON_LEAF(setjmp, SETJMP_FRAME_SIZE, ra) 60 subu sp, sp, SETJMP_FRAME_SIZE # allocate stack frame 61 .mask 0x80000000, (STAND_RA_OFFSET - STAND_FRAME_SIZE) 62 sw ra, STAND_RA_OFFSET(sp) # save state 63 sw a0, SETJMP_FRAME_SIZE(sp) 64 move a0, zero # get current signal mask 65 jal _C_LABEL(sigblock) 66 lw v1, SETJMP_FRAME_SIZE(sp) # v1 = jmpbuf 67 sw v0, (1 * 4)(v1) # save sc_mask = sigblock(0) 68 move a0, zero 69 addu a1, sp, STAND_FRAME_SIZE # pointer to struct sigaltstack 70 jal _C_LABEL(sigaltstack) 71 lw a0, SETJMP_FRAME_SIZE(sp) # restore jmpbuf 72 lw v1, STAND_FRAME_SIZE+8(sp) # get old ss_onstack 73 and v1, v1, 1 # extract onstack flag 74 sw v1, 0(a0) # save it in sc_onstack 75 lw ra, STAND_RA_OFFSET(sp) 76 addu sp, sp, SETJMP_FRAME_SIZE 77 blt v0, zero, botch # check for sigstack() error 78 sw ra, (2 * 4)(a0) # sc_pc = return address 79 li v0, 0xACEDBADE # sigcontext magic number 80 sw v0, ((ZERO + 3) * 4)(a0) # saved in sc_regs[0] 81 sw s0, ((S0 + 3) * 4)(a0) 82 sw s1, ((S1 + 3) * 4)(a0) 83 sw s2, ((S2 + 3) * 4)(a0) 84 sw s3, ((S3 + 3) * 4)(a0) 85 sw s4, ((S4 + 3) * 4)(a0) 86 sw s5, ((S5 + 3) * 4)(a0) 87 sw s6, ((S6 + 3) * 4)(a0) 88 sw s7, ((S7 + 3) * 4)(a0) 89 sw gp, ((GP + 3) * 4)(a0) 90 sw sp, ((SP + 3) * 4)(a0) 91 sw s8, ((S8 + 3) * 4)(a0) 92 li v0, 1 # be nice if we could tell 93 sw v0, (37 * 4)(a0) # sc_fpused = 1 94 cfc1 v0, $31 95 swc1 $f20, ((20 + 38) * 4)(a0) 96 swc1 $f21, ((21 + 38) * 4)(a0) 97 swc1 $f22, ((22 + 38) * 4)(a0) 98 swc1 $f23, ((23 + 38) * 4)(a0) 99 swc1 $f24, ((24 + 38) * 4)(a0) 100 swc1 $f25, ((25 + 38) * 4)(a0) 101 swc1 $f26, ((26 + 38) * 4)(a0) 102 swc1 $f27, ((27 + 38) * 4)(a0) 103 swc1 $f28, ((28 + 38) * 4)(a0) 104 swc1 $f29, ((29 + 38) * 4)(a0) 105 swc1 $f30, ((30 + 38) * 4)(a0) 106 swc1 $f31, ((31 + 38) * 4)(a0) 107 sw v0, ((32 + 38) * 4)(a0) 108 move v0, zero 109 j ra 110END(setjmp) 111 112LEAF(longjmp) 113 sw a1, ((V0 + 3) * 4)(a0) # save return value in sc_regs[V0] 114 li v0, SYS_sigreturn 115 syscall 116botch: 117 jal _C_LABEL(longjmperror) 118 jal _C_LABEL(abort) 119END(longjmp) 120