1/* $NetBSD: _setjmp.S,v 1.20.34.5 2010/02/03 23:46:47 matt Exp $ */ 2 3/*- 4 * Copyright (c) 1991, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Ralph Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35#include <machine/asm.h> 36__FBSDID("$FreeBSD$"); 37#include <machine/regnum.h> 38 39#include "SYS.h" 40 41#if defined(LIBC_SCCS) && !defined(lint) 42#if 0 43 RCSID("from: @(#)_setjmp.s 8.1 (Berkeley) 6/4/93") 44#else 45 RCSID("$NetBSD: _setjmp.S,v 1.20.34.5 2010/02/03 23:46:47 matt Exp $") 46#endif 47#endif /* LIBC_SCCS and not lint */ 48 49/* 50 * C library -- _setjmp, _longjmp 51 * 52 * _longjmp(a,v) 53 * will generate a "return(v)" from 54 * the last call to 55 * _setjmp(a) 56 * by restoring registers from the stack, 57 * The previous signal state is NOT restored. 58 */ 59 60 .set noreorder 61 62LEAF(_setjmp) 63 REG_PROLOGUE 64 REG_LI v0, _JB_MAGIC__SETJMP # sigcontext magic number 65 REG_S v0, (_JB_MAGIC * SZREG)(a0) 66 REG_S ra, (_JB_REG_RA * SZREG)(a0) 67 /* 68 * From "MIPSpro N32 ABI Handbook", Table 2-1: 69 * Registers s0..s7 are callee-saved. 70 * The sp register is callee-saved. 71 * The fp (or s8) register is callee-saved. 72 * The gp register is callee-saved (for n32/n64). 73 */ 74 REG_S s0, (_JB_REG_S0 * SZREG)(a0) 75 REG_S s1, (_JB_REG_S1 * SZREG)(a0) 76 REG_S s2, (_JB_REG_S2 * SZREG)(a0) 77 REG_S s3, (_JB_REG_S3 * SZREG)(a0) 78 REG_S s4, (_JB_REG_S4 * SZREG)(a0) 79 REG_S s5, (_JB_REG_S5 * SZREG)(a0) 80 REG_S s6, (_JB_REG_S6 * SZREG)(a0) 81 REG_S s7, (_JB_REG_S7 * SZREG)(a0) 82 REG_S sp, (_JB_REG_SP * SZREG)(a0) 83 REG_S s8, (_JB_REG_S8 * SZREG)(a0) 84#if defined(__mips_n32) || defined(__mips_n64) 85 REG_S gp, (_JB_REG_GP * SZREG)(a0) # newabi gp is callee-saved 86#endif 87 /* 88 * From "MIPSpro N32 ABI Handbook", Table 2-1: 89 * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved. 90 * In N64, FP registers F24 .. F31 are callee-saved. 91 * In O32, FP registers F20 .. F23 are callee-saved. 92 */ 93#ifndef SOFTFLOAT 94 cfc1 v0, $31 # too bad can't check if FP used 95#if defined(__mips_n64) || defined(__mips_n32) 96 FP_S $f30, (_JB_FPREG_F30 * SZREG)(a0) 97 FP_S $f28, (_JB_FPREG_F28 * SZREG)(a0) 98 FP_S $f26, (_JB_FPREG_F26 * SZREG)(a0) 99 FP_S $f24, (_JB_FPREG_F24 * SZREG)(a0) 100#endif 101#if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64) 102 FP_S $f22, (_JB_FPREG_F22 * SZREG)(a0) 103 FP_S $f20, (_JB_FPREG_F20 * SZREG)(a0) 104#endif 105#if defined(__mips_o32) || defined(__mips_o64) 106 FP_S $f21, (_JB_FPREG_F21 * SZREG)(a0) 107 FP_S $f23, (_JB_FPREG_F23 * SZREG)(a0) 108#endif 109#if defined(__mips_n64) 110 FP_S $f25, (_JB_FPREG_F25 * SZREG)(a0) 111 FP_S $f27, (_JB_FPREG_F27 * SZREG)(a0) 112 FP_S $f29, (_JB_FPREG_F29 * SZREG)(a0) 113 FP_S $f31, (_JB_FPREG_F31 * SZREG)(a0) 114#endif 115 INT_S v0, (_JB_FPREG_FCSR * SZREG)(a0) 116#endif /* ! SOFTFLOAT */ 117 REG_EPILOGUE 118 119 j ra 120 move v0, zero 121END(_setjmp) 122 123LEAF(_longjmp) 124 PIC_PROLOGUE(_longjmp) 125 PTR_SUBU sp, sp, CALLFRAME_SIZ 126 SAVE_GP(CALLFRAME_GP) 127 128 REG_PROLOGUE 129 REG_L v0, (_JB_MAGIC * SZREG)(a0) # get magic number 130 REG_L ra, (_JB_REG_RA * SZREG)(a0) 131 REG_LI t0, _JB_MAGIC__SETJMP 132 bne v0, t0, botch # jump if error 133 PTR_ADDU sp, sp, CALLFRAME_SIZ # does not matter, sanity 134 /* 135 * From "MIPSpro N32 ABI Handbook", Table 2-1: 136 * Registers s0..s7 are callee-saved. 137 * The sp register is callee-saved. 138 * The fp (or s8) register is callee-saved. 139 * The gp register is callee-saved (for n32/n64). 140 */ 141 REG_L s0, (_JB_REG_S0 * SZREG)(a0) 142 REG_L s1, (_JB_REG_S1 * SZREG)(a0) 143 REG_L s2, (_JB_REG_S2 * SZREG)(a0) 144 REG_L s3, (_JB_REG_S3 * SZREG)(a0) 145 REG_L s4, (_JB_REG_S4 * SZREG)(a0) 146 REG_L s5, (_JB_REG_S5 * SZREG)(a0) 147 REG_L s6, (_JB_REG_S6 * SZREG)(a0) 148 REG_L s7, (_JB_REG_S7 * SZREG)(a0) 149 REG_L sp, (_JB_REG_SP * SZREG)(a0) 150 REG_L s8, (_JB_REG_S8 * SZREG)(a0) 151#if defined(__mips_n32) || defined(__mips_n64) 152 REG_L gp, (_JB_REG_GP * SZREG)(a0) 153#endif 154#ifndef SOFTFLOAT 155 # get fpu status 156 INT_L v0, (_JB_FPREG_FCSR * SZREG)(a0) 157 ctc1 v0, $31 158 /* 159 * From "MIPSpro N32 ABI Handbook", Table 2-1: 160 * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved. 161 * In N64, FP registers F24 .. F31 are callee-saved. 162 * In O32, FP registers F20 .. F23 are callee-saved. 163 */ 164#if defined(__mips_n64) || defined(__mips_n32) 165 FP_L $f30, (_JB_FPREG_F30 * SZREG)(a0) 166 FP_L $f28, (_JB_FPREG_F28 * SZREG)(a0) 167 FP_L $f26, (_JB_FPREG_F26 * SZREG)(a0) 168 FP_L $f24, (_JB_FPREG_F24 * SZREG)(a0) 169#endif 170#if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64) 171 FP_L $f22, (_JB_FPREG_F22 * SZREG)(a0) 172 FP_L $f20, (_JB_FPREG_F20 * SZREG)(a0) 173#endif 174#if defined(__mips_o32) || defined(__mips_o64) 175 FP_L $f21, (_JB_FPREG_F21 * SZREG)(a0) 176 FP_L $f23, (_JB_FPREG_F23 * SZREG)(a0) 177#endif 178#if defined(__mips_n64) 179 FP_L $f25, (_JB_FPREG_F25 * SZREG)(a0) 180 FP_L $f27, (_JB_FPREG_F27 * SZREG)(a0) 181 FP_L $f29, (_JB_FPREG_F29 * SZREG)(a0) 182 FP_L $f31, (_JB_FPREG_F31 * SZREG)(a0) 183#endif 184#endif /* ! SOFTFLOAT */ 185 186 REG_EPILOGUE 187 move v0, a1 # get return value in 1st arg 188 j ra 189 nop 190 191botch: 192 /* 193 * We know we aren't returning so we don't care about restoring 194 * our caller's GP. 195 */ 196 PTR_LA t9, _C_LABEL(longjmperror) 197 jalr t9 198 nop 199 200 PIC_TAILCALL(abort) 201END(_longjmp) 202