Home | History | Annotate | Line # | Download | only in gen
_setjmp.S revision 1.1
      1 /*	$NetBSD: _setjmp.S,v 1.1 2014/09/19 17:36:25 matt Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Matt Thomas of 3am Software Foundry.
      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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <machine/asm.h>
     33 #include "assym.h"
     34 
     35 #if defined(LIBC_SCCS)
     36 __RCSID("$NetBSD: _setjmp.S,v 1.1 2014/09/19 17:36:25 matt Exp $")
     37 #endif
     38 
     39 /*
     40  * C library -- _setjmp, _longjmp
     41  *
     42  *	_longjmp(a,v)
     43  * will generate a "return(v?v:1)" from the last call to
     44  *	_setjmp(a)
     45  * by restoring registers from the stack.
     46  * The previous signal state is NOT restored.
     47  */
     48 
     49 ENTRY(_setjmp)
     50 	REG_S	zero, JB_MAGIC(a0)	/* indicate no sigmask */
     51 	REG_S	ra, JB_RA(a0)		/* save return address */
     52 	REG_S	s0, JB_S0(a0)		/* save callee saved register */
     53 	REG_S	s1, JB_S1(a0)		/* save callee saved register */
     54 	REG_S	s2, JB_S2(a0)		/* save callee saved register */
     55 	REG_S	s3, JB_S3(a0)		/* save callee saved register */
     56 	REG_S	s4, JB_S4(a0)		/* save callee saved register */
     57 	REG_S	s5, JB_S5(a0)		/* save callee saved register */
     58 	REG_S	s6, JB_S6(a0)		/* save callee saved register */
     59 	REG_S	s7, JB_S7(a0)		/* save callee saved register */
     60 	REG_S	s8, JB_S8(a0)		/* save callee saved register */
     61 	REG_S	s9, JB_S9(a0)		/* save callee saved register */
     62 	REG_S	s10, JB_S10(a0)		/* save callee saved register */
     63 	REG_S	s11, JB_S11(a0)		/* save callee saved register */
     64 	REG_S	sp, JB_SP(a0)		/* save stack pointer */
     65 	REG_S	tp, JB_TP(a0)		/* save thread pointer */
     66 	REG_S	gp, JB_GP(a0)		/* save global pointer */
     67 #ifndef _SOFT_FLOAT
     68 	frcsr	t2			/* get FSCR */
     69 	REG_S	t2, JB_FCSR(a0)		/* save it */
     70 	fsd	fs0, JB_F0(a0)		/* save callee saved register */
     71 	fsd	fs1, JB_F1(a0)		/* save callee saved register */
     72 	fsd	fs2, JB_F2(a0)		/* save callee saved register */
     73 	fsd	fs3, JB_F3(a0)		/* save callee saved register */
     74 	fsd	fs4, JB_F4(a0)		/* save callee saved register */
     75 	fsd	fs5, JB_F5(a0)		/* save callee saved register */
     76 	fsd	fs6, JB_F6(a0)		/* save callee saved register */
     77 	fsd	fs7, JB_F7(a0)		/* save callee saved register */
     78 	fsd	fs8, JB_F8(a0)		/* save callee saved register */
     79 	fsd	fs9, JB_F9(a0)		/* save callee saved register */
     80 	fsd	fs10, JB_F10(a0)	/* save callee saved register */
     81 	fsd	fs11, JB_F11(a0)	/* save callee saved register */
     82 	fsd	fs12, JB_F12(a0)	/* save callee saved register */
     83 	fsd	fs13, JB_F13(a0)	/* save callee saved register */
     84 	fsd	fs14, JB_F14(a0)	/* save callee saved register */
     85 	fsd	fs15, JB_F15(a0)	/* save callee saved register */
     86 #endif
     87 	li	x1, 0			/* indicate success */
     88 	ret				/* return */
     89 END(_setjmp)
     90 
     91 ENTRY(_longjmp)
     92 	REG_L	ra, JB_RA(a0)		/* save return address */
     93 	REG_L	s0, JB_S0(a0)		/* save callee saved register */
     94 	REG_L	s1, JB_S1(a0)		/* save callee saved register */
     95 	REG_L	s2, JB_S2(a0)		/* save callee saved register */
     96 	REG_L	s3, JB_S3(a0)		/* save callee saved register */
     97 	REG_L	s4, JB_S4(a0)		/* save callee saved register */
     98 	REG_L	s5, JB_S5(a0)		/* save callee saved register */
     99 	REG_L	s6, JB_S6(a0)		/* save callee saved register */
    100 	REG_L	s7, JB_S7(a0)		/* save callee saved register */
    101 	REG_L	s8, JB_S8(a0)		/* save callee saved register */
    102 	REG_L	s9, JB_S9(a0)		/* save callee saved register */
    103 	REG_L	s10, JB_S10(a0)		/* save callee saved register */
    104 	REG_L	s11, JB_S11(a0)		/* save callee saved register */
    105 	REG_L	sp, JB_SP(a0)		/* save stack pointer */
    106 	#REG_L	tp, JB_TP(a0)		/* save thread pointer */
    107 	REG_L	gp, JB_GP(a0)		/* save global pointer */
    108 #ifndef _SOFT_FLOAT
    109 	REG_L	t2, JB_FCSR(a0)		/* get it */
    110 	fscsr	t2			/* restore FSCR */
    111 	fld	fs0, JB_F0(a0)		/* restore callee saved register */
    112 	fld	fs1, JB_F1(a0)		/* restore callee saved register */
    113 	fld	fs2, JB_F2(a0)		/* restore callee saved register */
    114 	fld	fs3, JB_F3(a0)		/* restore callee saved register */
    115 	fld	fs4, JB_F4(a0)		/* restore callee saved register */
    116 	fld	fs5, JB_F5(a0)		/* restore callee saved register */
    117 	fld	fs6, JB_F6(a0)		/* restore callee saved register */
    118 	fld	fs7, JB_F7(a0)		/* restore callee saved register */
    119 	fld	fs8, JB_F8(a0)		/* restore callee saved register */
    120 	fld	fs9, JB_F9(a0)		/* restore callee saved register */
    121 	fld	fs10, JB_F10(a0)	/* restore callee saved register */
    122 	fld	fs11, JB_F11(a0)	/* restore callee saved register */
    123 	fld	fs12, JB_F12(a0)	/* restore callee saved register */
    124 	fld	fs13, JB_F13(a0)	/* restore callee saved register */
    125 	fld	fs14, JB_F14(a0)	/* restore callee saved register */
    126 	fld	fs15, JB_F15(a0)	/* restore callee saved register */
    127 #endif
    128 	li	v0, 1			/* default return value */
    129 	beqz	a1, 1f			/* test return value */
    130 	move	v0, a1			/* use it if not 0 */
    131 1:	ret
    132 END(_longjmp)
    133