1*2fe8fb19SBen Gras/* $NetBSD: compat_setjmp.S,v 1.2 2009/12/14 03:04:33 matt Exp $ */ 2*2fe8fb19SBen Gras 3*2fe8fb19SBen Gras/*- 4*2fe8fb19SBen Gras * Copyright (c) 1991, 1993 5*2fe8fb19SBen Gras * The Regents of the University of California. All rights reserved. 6*2fe8fb19SBen Gras * 7*2fe8fb19SBen Gras * This code is derived from software contributed to Berkeley by 8*2fe8fb19SBen Gras * Ralph Campbell. 9*2fe8fb19SBen Gras * 10*2fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 11*2fe8fb19SBen Gras * modification, are permitted provided that the following conditions 12*2fe8fb19SBen Gras * are met: 13*2fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 14*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 15*2fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 16*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 17*2fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 18*2fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors 19*2fe8fb19SBen Gras * may be used to endorse or promote products derived from this software 20*2fe8fb19SBen Gras * without specific prior written permission. 21*2fe8fb19SBen Gras * 22*2fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*2fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*2fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*2fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*2fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*2fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*2fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*2fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*2fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*2fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*2fe8fb19SBen Gras * SUCH DAMAGE. 33*2fe8fb19SBen Gras */ 34*2fe8fb19SBen Gras 35*2fe8fb19SBen Gras#include <sys/syscall.h> 36*2fe8fb19SBen Gras#include <mips/asm.h> 37*2fe8fb19SBen Gras 38*2fe8fb19SBen Gras#include "assym.h" 39*2fe8fb19SBen Gras 40*2fe8fb19SBen Gras#if defined(LIBC_SCCS) && !defined(lint) 41*2fe8fb19SBen Gras#if 0 42*2fe8fb19SBen Gras RCSID("from: @(#)setjmp.s 8.1 (Berkeley) 6/4/93") 43*2fe8fb19SBen Gras#else 44*2fe8fb19SBen Gras RCSID("$NetBSD: compat_setjmp.S,v 1.2 2009/12/14 03:04:33 matt Exp $") 45*2fe8fb19SBen Gras#endif 46*2fe8fb19SBen Gras#endif /* LIBC_SCCS and not lint */ 47*2fe8fb19SBen Gras 48*2fe8fb19SBen Gras/* 49*2fe8fb19SBen Gras * C library -- setjmp, longjmp 50*2fe8fb19SBen Gras * 51*2fe8fb19SBen Gras * longjmp(a,v) 52*2fe8fb19SBen Gras * will generate a "return(v)" from 53*2fe8fb19SBen Gras * the last call to 54*2fe8fb19SBen Gras * setjmp(a) 55*2fe8fb19SBen Gras * by restoring registers from the stack, 56*2fe8fb19SBen Gras * and a struct sigcontext, see <signal.h> 57*2fe8fb19SBen Gras */ 58*2fe8fb19SBen Gras 59*2fe8fb19SBen Gras#define SETJMP_FRAME_SIZE (CALLFRAME_SIZ + STACK_T_SIZE) 60*2fe8fb19SBen Gras 61*2fe8fb19SBen GrasNON_LEAF(setjmp, SETJMP_FRAME_SIZE, ra) 62*2fe8fb19SBen Gras .mask 0x80010000, (CALLFRAME_RA - CALLFRAME_SIZ) 63*2fe8fb19SBen Gras SETUP_GP 64*2fe8fb19SBen Gras PTR_SUBU sp, sp, SETJMP_FRAME_SIZE # allocate stack frame 65*2fe8fb19SBen Gras SAVE_GP(CALLFRAME_GP) 66*2fe8fb19SBen Gras SETUP_GP64(CALLFRAME_GP, setjmp) 67*2fe8fb19SBen Gras 68*2fe8fb19SBen Gras REG_S ra, CALLFRAME_RA(sp) # save RA 69*2fe8fb19SBen Gras REG_S s0, CALLFRAME_S0(sp) # save S0 70*2fe8fb19SBen Gras move s0, a0 # save sigcontext 71*2fe8fb19SBen Gras 72*2fe8fb19SBen Gras /* Get the signal mask. */ 73*2fe8fb19SBen Gras move a0, zero # get current sigmask 74*2fe8fb19SBen Gras jal _C_LABEL(sigblock) 75*2fe8fb19SBen Gras nop 76*2fe8fb19SBen Gras INT_S v0, _OFFSETOF_SC_MASK13(s0) # save sc_mask13 77*2fe8fb19SBen Gras 78*2fe8fb19SBen Gras /* Get the signal stack. */ 79*2fe8fb19SBen Gras move a0, zero 80*2fe8fb19SBen Gras PTR_ADDU a1, sp, CALLFRAME_SIZ # pointer to stack_t 81*2fe8fb19SBen Gras jal _C_LABEL(__sigaltstack14) 82*2fe8fb19SBen Gras 83*2fe8fb19SBen Gras move a0, s0 # restore jmpbuf 84*2fe8fb19SBen Gras INT_L v1, CALLFRAME_SIZ+_OFFSETOF_STACK_T_FLAGS(sp) 85*2fe8fb19SBen Gras # get old ss_onstack 86*2fe8fb19SBen Gras and v1, v1, SS_ONSTACK # extract onstack flag 87*2fe8fb19SBen Gras INT_S v1, _OFFSETOF_SC_ONSTACK(a0) # save it in sc_onstack 88*2fe8fb19SBen Gras 89*2fe8fb19SBen Gras REG_L s0, CALLFRAME_S0(sp) # restore S0 90*2fe8fb19SBen Gras REG_L ra, CALLFRAME_RA(sp) # restore RA 91*2fe8fb19SBen Gras blt v0, zero, botch # check for sigaltstack() error 92*2fe8fb19SBen Gras nop 93*2fe8fb19SBen Gras /* 94*2fe8fb19SBen Gras * We know we won't need this routine's GP anymore. 95*2fe8fb19SBen Gras */ 96*2fe8fb19SBen Gras RESTORE_GP64 97*2fe8fb19SBen Gras PTR_ADDU sp, sp, SETJMP_FRAME_SIZE # pop stack frame 98*2fe8fb19SBen Gras 99*2fe8fb19SBen Gras REG_PROLOGUE 100*2fe8fb19SBen Gras REG_S ra, _OFFSETOF_SC_PC(a0) # sc_pc = return address 101*2fe8fb19SBen Gras REG_LI v0, 0xACEDBADE # sigcontext magic number 102*2fe8fb19SBen Gras REG_S v0, _OFFSETOF_SC_REGS(a0) # saved in sc_regs[0] 103*2fe8fb19SBen Gras REG_S s0, _OFFSETOF_SC_REGS_S0(a0) 104*2fe8fb19SBen Gras REG_S s1, _OFFSETOF_SC_REGS_S1(a0) 105*2fe8fb19SBen Gras REG_S s2, _OFFSETOF_SC_REGS_S2(a0) 106*2fe8fb19SBen Gras REG_S s3, _OFFSETOF_SC_REGS_S3(a0) 107*2fe8fb19SBen Gras REG_S s4, _OFFSETOF_SC_REGS_S4(a0) 108*2fe8fb19SBen Gras REG_S s5, _OFFSETOF_SC_REGS_S5(a0) 109*2fe8fb19SBen Gras REG_S s6, _OFFSETOF_SC_REGS_S6(a0) 110*2fe8fb19SBen Gras REG_S s7, _OFFSETOF_SC_REGS_S7(a0) 111*2fe8fb19SBen Gras REG_S gp, _OFFSETOF_SC_REGS_GP(a0) 112*2fe8fb19SBen Gras REG_S sp, _OFFSETOF_SC_REGS_SP(a0) 113*2fe8fb19SBen Gras REG_S s8, _OFFSETOF_SC_REGS_S8(a0) 114*2fe8fb19SBen Gras li v0, 1 # be nice if we could tell 115*2fe8fb19SBen Gras INT_S v0, _OFFSETOF_SC_FPUSED(a0) # sc_fpused = 1 116*2fe8fb19SBen Gras cfc1 v0, $31 117*2fe8fb19SBen Gras INT_S v0, _OFFSETOF_SC_FPREGS_FCSR(a0) 118*2fe8fb19SBen Gras#if defined(__mips_o32) || defined(__mips_o64) || defined(__mips_n32) 119*2fe8fb19SBen Gras FP_S $f20, _OFFSETOF_SC_FPREGS_F20(a0) 120*2fe8fb19SBen Gras FP_S $f22, _OFFSETOF_SC_FPREGS_F22(a0) 121*2fe8fb19SBen Gras#endif 122*2fe8fb19SBen Gras#if defined(__mips_o32) || defined(__mips_o64) 123*2fe8fb19SBen Gras FP_S $f21, _OFFSETOF_SC_FPREGS_F21(a0) 124*2fe8fb19SBen Gras FP_S $f23, _OFFSETOF_SC_FPREGS_F23(a0) 125*2fe8fb19SBen Gras#endif 126*2fe8fb19SBen Gras#if defined(__mips_n32) || defined(__mips_n64) 127*2fe8fb19SBen Gras FP_S $f24, _OFFSETOF_SC_FPREGS_F24(a0) 128*2fe8fb19SBen Gras FP_S $f26, _OFFSETOF_SC_FPREGS_F26(a0) 129*2fe8fb19SBen Gras FP_S $f28, _OFFSETOF_SC_FPREGS_F28(a0) 130*2fe8fb19SBen Gras FP_S $f30, _OFFSETOF_SC_FPREGS_F30(a0) 131*2fe8fb19SBen Gras#endif 132*2fe8fb19SBen Gras#if defined(__mips_n64) 133*2fe8fb19SBen Gras FP_S $f25, _OFFSETOF_SC_FPREGS_F25(a0) 134*2fe8fb19SBen Gras FP_S $f27, _OFFSETOF_SC_FPREGS_F27(a0) 135*2fe8fb19SBen Gras FP_S $f29, _OFFSETOF_SC_FPREGS_F29(a0) 136*2fe8fb19SBen Gras FP_S $f31, _OFFSETOF_SC_FPREGS_F31(a0) 137*2fe8fb19SBen Gras#endif 138*2fe8fb19SBen Gras REG_EPILOGUE 139*2fe8fb19SBen Gras j ra 140*2fe8fb19SBen Gras move v0, zero 141*2fe8fb19SBen Gras 142*2fe8fb19SBen Grasbotch: 143*2fe8fb19SBen Gras jal _C_LABEL(abort) 144*2fe8fb19SBen GrasEND(setjmp) 145*2fe8fb19SBen Gras 146*2fe8fb19SBen GrasLEAF(longjmp) 147*2fe8fb19SBen Gras SETUP_GP 148*2fe8fb19SBen Gras PTR_SUBU sp, sp, CALLFRAME_SIZ 149*2fe8fb19SBen Gras SAVE_GP(CALLFRAME_S0) 150*2fe8fb19SBen Gras SETUP_GP64(s0, longjmp) 151*2fe8fb19SBen Gras 152*2fe8fb19SBen Gras REG_PROLOGUE 153*2fe8fb19SBen Gras /* save return value in sc_regs[_R_V0] */ 154*2fe8fb19SBen Gras REG_S a1, _OFFSETOF_SC_REGS_V0(a0) 155*2fe8fb19SBen Gras REG_EPILOGUE 156*2fe8fb19SBen Gras 157*2fe8fb19SBen Gras li v0, SYS_compat_13_sigreturn13 158*2fe8fb19SBen Gras syscall 159*2fe8fb19SBen Gras 160*2fe8fb19SBen Gras jal _C_LABEL(longjmperror) 161*2fe8fb19SBen Gras jal _C_LABEL(abort) 162*2fe8fb19SBen GrasEND(longjmp) 163