1*e415d488SLionel Sambuc/* $NetBSD: _setjmp.S,v 1.24 2012/07/08 00:59:34 matt Exp $ */ 22fe8fb19SBen Gras 32fe8fb19SBen Gras/*- 42fe8fb19SBen Gras * Copyright (c) 1991, 1993 52fe8fb19SBen Gras * The Regents of the University of California. All rights reserved. 62fe8fb19SBen Gras * 72fe8fb19SBen Gras * This code is derived from software contributed to Berkeley by 82fe8fb19SBen Gras * Ralph Campbell. 92fe8fb19SBen Gras * 102fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without 112fe8fb19SBen Gras * modification, are permitted provided that the following conditions 122fe8fb19SBen Gras * are met: 132fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright 142fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer. 152fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright 162fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the 172fe8fb19SBen Gras * documentation and/or other materials provided with the distribution. 182fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors 192fe8fb19SBen Gras * may be used to endorse or promote products derived from this software 202fe8fb19SBen Gras * without specific prior written permission. 212fe8fb19SBen Gras * 222fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 232fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 242fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 252fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 262fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 272fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 282fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 292fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 302fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 312fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 322fe8fb19SBen Gras * SUCH DAMAGE. 332fe8fb19SBen Gras */ 342fe8fb19SBen Gras 352fe8fb19SBen Gras#include <machine/cdefs.h> 362fe8fb19SBen Gras#include <mips/regnum.h> 372fe8fb19SBen Gras#include <mips/asm.h> 382fe8fb19SBen Gras#include <machine/setjmp.h> 392fe8fb19SBen Gras#include <machine/signal.h> /* XXX */ 402fe8fb19SBen Gras 412fe8fb19SBen Gras#include "assym.h" 422fe8fb19SBen Gras 432fe8fb19SBen Gras#include "SYS.h" 442fe8fb19SBen Gras 452fe8fb19SBen Gras#if defined(LIBC_SCCS) && !defined(lint) 462fe8fb19SBen Gras#if 0 472fe8fb19SBen Gras RCSID("from: @(#)_setjmp.s 8.1 (Berkeley) 6/4/93") 482fe8fb19SBen Gras#else 49*e415d488SLionel Sambuc RCSID("$NetBSD: _setjmp.S,v 1.24 2012/07/08 00:59:34 matt Exp $") 502fe8fb19SBen Gras#endif 512fe8fb19SBen Gras#endif /* LIBC_SCCS and not lint */ 522fe8fb19SBen Gras 532fe8fb19SBen Gras/* 542fe8fb19SBen Gras * C library -- _setjmp, _longjmp 552fe8fb19SBen Gras * 562fe8fb19SBen Gras * _longjmp(a,v) 572fe8fb19SBen Gras * will generate a "return(v)" from 582fe8fb19SBen Gras * the last call to 592fe8fb19SBen Gras * _setjmp(a) 602fe8fb19SBen Gras * by restoring registers from the stack, 612fe8fb19SBen Gras * The previous signal state is NOT restored. 622fe8fb19SBen Gras */ 632fe8fb19SBen Gras 642fe8fb19SBen Gras .set noreorder 652fe8fb19SBen Gras 662fe8fb19SBen GrasLEAF(_setjmp) 672fe8fb19SBen Gras REG_PROLOGUE 682fe8fb19SBen Gras REG_LI v0, 0xACEDBADE # sigcontext magic number 692fe8fb19SBen Gras REG_S ra, _OFFSETOF_SC_PC(a0) # sc_pc = return address 702fe8fb19SBen Gras REG_S v0, _OFFSETOF_SC_REGS(a0) # saved in sc_regs[0] 712fe8fb19SBen Gras REG_S s0, _OFFSETOF_SC_REGS_S0(a0) 722fe8fb19SBen Gras REG_S s1, _OFFSETOF_SC_REGS_S1(a0) 732fe8fb19SBen Gras REG_S s2, _OFFSETOF_SC_REGS_S2(a0) 742fe8fb19SBen Gras REG_S s3, _OFFSETOF_SC_REGS_S3(a0) 752fe8fb19SBen Gras REG_S s4, _OFFSETOF_SC_REGS_S4(a0) 762fe8fb19SBen Gras REG_S s5, _OFFSETOF_SC_REGS_S5(a0) 772fe8fb19SBen Gras REG_S s6, _OFFSETOF_SC_REGS_S6(a0) 782fe8fb19SBen Gras REG_S s7, _OFFSETOF_SC_REGS_S7(a0) 792fe8fb19SBen Gras REG_S sp, _OFFSETOF_SC_REGS_SP(a0) 802fe8fb19SBen Gras REG_S s8, _OFFSETOF_SC_REGS_S8(a0) 812fe8fb19SBen Gras#if defined(__mips_n32) || defined(__mips_n64) 822fe8fb19SBen Gras REG_S gp, _OFFSETOF_SC_REGS_GP(a0) # newabi gp is callee-saved 832fe8fb19SBen Gras#endif 842fe8fb19SBen Gras /* 852fe8fb19SBen Gras * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved. 862fe8fb19SBen Gras * In N64, FP registers F23 .. F31 are callee-saved. 872fe8fb19SBen Gras * In O32, FP registers F20 .. F23 are callee-saved. 882fe8fb19SBen Gras */ 892fe8fb19SBen Gras#ifndef SOFTFLOAT_FOR_GCC 902fe8fb19SBen Gras cfc1 v0, $31 # too bad cant check if FP used 912fe8fb19SBen Gras#if defined(__mips_n64) || defined(__mips_n32) 922fe8fb19SBen Gras FP_S $f30, _OFFSETOF_SC_FPREGS_F30(a0) 932fe8fb19SBen Gras FP_S $f28, _OFFSETOF_SC_FPREGS_F28(a0) 942fe8fb19SBen Gras FP_S $f26, _OFFSETOF_SC_FPREGS_F26(a0) 952fe8fb19SBen Gras FP_S $f24, _OFFSETOF_SC_FPREGS_F24(a0) 962fe8fb19SBen Gras#endif 972fe8fb19SBen Gras#if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64) 982fe8fb19SBen Gras FP_S $f22, _OFFSETOF_SC_FPREGS_F22(a0) 992fe8fb19SBen Gras FP_S $f20, _OFFSETOF_SC_FPREGS_F20(a0) 1002fe8fb19SBen Gras#endif 1012fe8fb19SBen Gras#if defined(__mips_o32) || defined(__mips_o64) 1022fe8fb19SBen Gras FP_S $f21, _OFFSETOF_SC_FPREGS_F21(a0) 1032fe8fb19SBen Gras FP_S $f23, _OFFSETOF_SC_FPREGS_F23(a0) 1042fe8fb19SBen Gras#endif 1052fe8fb19SBen Gras#if defined(__mips_n64) 1062fe8fb19SBen Gras FP_S $f25, _OFFSETOF_SC_FPREGS_F25(a0) 1072fe8fb19SBen Gras FP_S $f27, _OFFSETOF_SC_FPREGS_F27(a0) 1082fe8fb19SBen Gras FP_S $f29, _OFFSETOF_SC_FPREGS_F29(a0) 1092fe8fb19SBen Gras FP_S $f31, _OFFSETOF_SC_FPREGS_F31(a0) 1102fe8fb19SBen Gras#endif 111*e415d488SLionel Sambuc INT_S v0, _OFFSETOF_SC_FPREGS_FCSR(a0) 1122fe8fb19SBen Gras#endif /* SOFTFLOAT_FOR_GCC */ 1132fe8fb19SBen Gras REG_EPILOGUE 1142fe8fb19SBen Gras 1152fe8fb19SBen Gras j ra 1162fe8fb19SBen Gras move v0, zero 1172fe8fb19SBen GrasEND(_setjmp) 1182fe8fb19SBen Gras 1192fe8fb19SBen GrasLEAF(_longjmp) 1202fe8fb19SBen Gras PIC_PROLOGUE(_longjmp) 1212fe8fb19SBen Gras PTR_SUBU sp, sp, CALLFRAME_SIZ 1222fe8fb19SBen Gras SAVE_GP(CALLFRAME_GP) 1232fe8fb19SBen Gras 1242fe8fb19SBen Gras REG_PROLOGUE 1252fe8fb19SBen Gras REG_L v0, _OFFSETOF_SC_REGS(a0) # get magic number 1262fe8fb19SBen Gras REG_L ra, _OFFSETOF_SC_PC(a0) 1272fe8fb19SBen Gras REG_LI t0, 0xACEDBADE 1282fe8fb19SBen Gras bne v0, t0, botch # jump if error 1292fe8fb19SBen Gras PTR_ADDU sp, sp, CALLFRAME_SIZ # does not matter, sanity 1302fe8fb19SBen Gras REG_S a1, _OFFSETOF_SC_REGS_V0(a0) # save return value 1312fe8fb19SBen Gras REG_L s0, _OFFSETOF_SC_REGS_S0(a0) 1322fe8fb19SBen Gras REG_L s1, _OFFSETOF_SC_REGS_S1(a0) 1332fe8fb19SBen Gras REG_L s2, _OFFSETOF_SC_REGS_S2(a0) 1342fe8fb19SBen Gras REG_L s3, _OFFSETOF_SC_REGS_S3(a0) 1352fe8fb19SBen Gras REG_L s4, _OFFSETOF_SC_REGS_S4(a0) 1362fe8fb19SBen Gras REG_L s5, _OFFSETOF_SC_REGS_S5(a0) 1372fe8fb19SBen Gras REG_L s6, _OFFSETOF_SC_REGS_S6(a0) 1382fe8fb19SBen Gras REG_L s7, _OFFSETOF_SC_REGS_S7(a0) 1392fe8fb19SBen Gras#if defined(__mips_n32) || defined(__mips_n64) 1402fe8fb19SBen Gras REG_L gp, _OFFSETOF_SC_REGS_GP(a0) 1412fe8fb19SBen Gras#endif 142*e415d488SLionel Sambuc#ifndef SOFTFLOAT_FOR_GCC 1432fe8fb19SBen Gras # get fpu status 144*e415d488SLionel Sambuc INT_L v0, _OFFSETOF_SC_FPREGS_FCSR(a0) 145*e415d488SLionel Sambuc#endif 1462fe8fb19SBen Gras REG_L sp, _OFFSETOF_SC_REGS_SP(a0) 1472fe8fb19SBen Gras REG_L s8, _OFFSETOF_SC_REGS_S8(a0) 1482fe8fb19SBen Gras#ifndef SOFTFLOAT_FOR_GCC 1492fe8fb19SBen Gras ctc1 v0, $31 1502fe8fb19SBen Gras /* 1512fe8fb19SBen Gras * In N32, FP registers F20, F22, F24, F26, F28, F30 are callee-saved. 1522fe8fb19SBen Gras * In N64, FP registers F23 .. F31 are callee-saved. 1532fe8fb19SBen Gras * In O32, FP registers F20 .. F23 are callee-saved. 1542fe8fb19SBen Gras */ 1552fe8fb19SBen Gras#if defined(__mips_n64) || defined(__mips_n32) 1562fe8fb19SBen Gras FP_L $f30, _OFFSETOF_SC_FPREGS_F30(a0) 1572fe8fb19SBen Gras FP_L $f28, _OFFSETOF_SC_FPREGS_F28(a0) 1582fe8fb19SBen Gras FP_L $f26, _OFFSETOF_SC_FPREGS_F26(a0) 1592fe8fb19SBen Gras FP_L $f24, _OFFSETOF_SC_FPREGS_F24(a0) 1602fe8fb19SBen Gras#endif 1612fe8fb19SBen Gras#if defined(__mips_n32) || defined(__mips_o32) || defined(__mips_o64) 1622fe8fb19SBen Gras FP_L $f22, _OFFSETOF_SC_FPREGS_F22(a0) 1632fe8fb19SBen Gras FP_L $f20, _OFFSETOF_SC_FPREGS_F20(a0) 1642fe8fb19SBen Gras#endif 1652fe8fb19SBen Gras#if defined(__mips_o32) || defined(__mips_o64) 1662fe8fb19SBen Gras FP_L $f21, _OFFSETOF_SC_FPREGS_F21(a0) 1672fe8fb19SBen Gras FP_L $f23, _OFFSETOF_SC_FPREGS_F23(a0) 1682fe8fb19SBen Gras#endif 1692fe8fb19SBen Gras#if defined(__mips_n64) 1702fe8fb19SBen Gras FP_L $f25, _OFFSETOF_SC_FPREGS_F25(a0) 1712fe8fb19SBen Gras FP_L $f27, _OFFSETOF_SC_FPREGS_F27(a0) 1722fe8fb19SBen Gras FP_L $f29, _OFFSETOF_SC_FPREGS_F29(a0) 1732fe8fb19SBen Gras FP_L $f31, _OFFSETOF_SC_FPREGS_F31(a0) 1742fe8fb19SBen Gras#endif 1752fe8fb19SBen Gras#endif /* SOFTFLOAT_FOR_GCC */ 1762fe8fb19SBen Gras 1772fe8fb19SBen Gras REG_EPILOGUE 1782fe8fb19SBen Gras j ra 179*e415d488SLionel Sambuc move v0, a1 # get return value in 1st arg 1802fe8fb19SBen Gras 1812fe8fb19SBen Grasbotch: 1822fe8fb19SBen Gras /* 1832fe8fb19SBen Gras * We know we aren't returning so we don't care about restoring 1842fe8fb19SBen Gras * our caller's GP. 1852fe8fb19SBen Gras */ 1862fe8fb19SBen Gras jal _C_LABEL(longjmperror) 187*e415d488SLionel Sambuc nop 1882fe8fb19SBen Gras 1892fe8fb19SBen Gras PIC_TAILCALL(abort) 190*e415d488SLionel Sambuc nop 1912fe8fb19SBen GrasEND(_longjmp) 192