Home | History | Annotate | Line # | Download | only in gen
_setjmp.S revision 1.3
      1  1.3  skrll /*	$NetBSD: _setjmp.S,v 1.3 2022/12/04 17:04:06 skrll Exp $	*/
      2  1.1   matt 
      3  1.1   matt /*-
      4  1.1   matt  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5  1.1   matt  * All rights reserved.
      6  1.1   matt  *
      7  1.1   matt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1   matt  * by Matt Thomas of 3am Software Foundry.
      9  1.1   matt  *
     10  1.1   matt  * Redistribution and use in source and binary forms, with or without
     11  1.1   matt  * modification, are permitted provided that the following conditions
     12  1.1   matt  * are met:
     13  1.1   matt  * 1. Redistributions of source code must retain the above copyright
     14  1.1   matt  *    notice, this list of conditions and the following disclaimer.
     15  1.1   matt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1   matt  *    notice, this list of conditions and the following disclaimer in the
     17  1.1   matt  *    documentation and/or other materials provided with the distribution.
     18  1.1   matt  *
     19  1.1   matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1   matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1   matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1   matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1   matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1   matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1   matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1   matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1   matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1   matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1   matt  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1   matt  */
     31  1.1   matt 
     32  1.1   matt #include <machine/asm.h>
     33  1.1   matt #include "assym.h"
     34  1.1   matt 
     35  1.1   matt #if defined(LIBC_SCCS)
     36  1.3  skrll __RCSID("$NetBSD: _setjmp.S,v 1.3 2022/12/04 17:04:06 skrll Exp $")
     37  1.1   matt #endif
     38  1.1   matt 
     39  1.1   matt /*
     40  1.1   matt  * C library -- _setjmp, _longjmp
     41  1.1   matt  *
     42  1.1   matt  *	_longjmp(a,v)
     43  1.1   matt  * will generate a "return(v?v:1)" from the last call to
     44  1.1   matt  *	_setjmp(a)
     45  1.1   matt  * by restoring registers from the stack.
     46  1.1   matt  * The previous signal state is NOT restored.
     47  1.1   matt  */
     48  1.1   matt 
     49  1.1   matt ENTRY(_setjmp)
     50  1.1   matt 	REG_S	zero, JB_MAGIC(a0)	/* indicate no sigmask */
     51  1.1   matt 	REG_S	ra, JB_RA(a0)		/* save return address */
     52  1.2   matt 	REG_S	sp, JB_SP(a0)		/* save stack pointer */
     53  1.2   matt 	REG_S	gp, JB_GP(a0)		/* save global pointer */
     54  1.2   matt 	REG_S	tp, JB_TP(a0)		/* save thread pointer */
     55  1.1   matt 	REG_S	s0, JB_S0(a0)		/* save callee saved register */
     56  1.1   matt 	REG_S	s1, JB_S1(a0)		/* save callee saved register */
     57  1.1   matt 	REG_S	s2, JB_S2(a0)		/* save callee saved register */
     58  1.1   matt 	REG_S	s3, JB_S3(a0)		/* save callee saved register */
     59  1.1   matt 	REG_S	s4, JB_S4(a0)		/* save callee saved register */
     60  1.1   matt 	REG_S	s5, JB_S5(a0)		/* save callee saved register */
     61  1.1   matt 	REG_S	s6, JB_S6(a0)		/* save callee saved register */
     62  1.1   matt 	REG_S	s7, JB_S7(a0)		/* save callee saved register */
     63  1.1   matt 	REG_S	s8, JB_S8(a0)		/* save callee saved register */
     64  1.1   matt 	REG_S	s9, JB_S9(a0)		/* save callee saved register */
     65  1.1   matt 	REG_S	s10, JB_S10(a0)		/* save callee saved register */
     66  1.1   matt 	REG_S	s11, JB_S11(a0)		/* save callee saved register */
     67  1.1   matt #ifndef _SOFT_FLOAT
     68  1.1   matt 	frcsr	t2			/* get FSCR */
     69  1.1   matt 	REG_S	t2, JB_FCSR(a0)		/* save it */
     70  1.2   matt 	fsd	fs0, JB_FS0(a0)		/* save callee saved register */
     71  1.2   matt 	fsd	fs1, JB_FS1(a0)		/* save callee saved register */
     72  1.2   matt 	fsd	fs2, JB_FS2(a0)		/* save callee saved register */
     73  1.2   matt 	fsd	fs3, JB_FS3(a0)		/* save callee saved register */
     74  1.2   matt 	fsd	fs4, JB_FS4(a0)		/* save callee saved register */
     75  1.2   matt 	fsd	fs5, JB_FS5(a0)		/* save callee saved register */
     76  1.2   matt 	fsd	fs6, JB_FS6(a0)		/* save callee saved register */
     77  1.2   matt 	fsd	fs7, JB_FS7(a0)		/* save callee saved register */
     78  1.2   matt 	fsd	fs8, JB_FS8(a0)		/* save callee saved register */
     79  1.2   matt 	fsd	fs9, JB_FS9(a0)		/* save callee saved register */
     80  1.2   matt 	fsd	fs10, JB_FS10(a0)	/* save callee saved register */
     81  1.2   matt 	fsd	fs11, JB_FS11(a0)	/* save callee saved register */
     82  1.1   matt #endif
     83  1.2   matt 	li	a0, 0			/* indicate success */
     84  1.1   matt 	ret				/* return */
     85  1.1   matt END(_setjmp)
     86  1.1   matt 
     87  1.1   matt ENTRY(_longjmp)
     88  1.1   matt 	REG_L	ra, JB_RA(a0)		/* save return address */
     89  1.2   matt 	REG_L	sp, JB_SP(a0)		/* save stack pointer */
     90  1.2   matt 	REG_L	gp, JB_GP(a0)		/* save global pointer */
     91  1.2   matt 	#REG_L	tp, JB_TP(a0)		/* save thread pointer */
     92  1.1   matt 	REG_L	s0, JB_S0(a0)		/* save callee saved register */
     93  1.1   matt 	REG_L	s1, JB_S1(a0)		/* save callee saved register */
     94  1.1   matt 	REG_L	s2, JB_S2(a0)		/* save callee saved register */
     95  1.1   matt 	REG_L	s3, JB_S3(a0)		/* save callee saved register */
     96  1.1   matt 	REG_L	s4, JB_S4(a0)		/* save callee saved register */
     97  1.1   matt 	REG_L	s5, JB_S5(a0)		/* save callee saved register */
     98  1.1   matt 	REG_L	s6, JB_S6(a0)		/* save callee saved register */
     99  1.1   matt 	REG_L	s7, JB_S7(a0)		/* save callee saved register */
    100  1.1   matt 	REG_L	s8, JB_S8(a0)		/* save callee saved register */
    101  1.1   matt 	REG_L	s9, JB_S9(a0)		/* save callee saved register */
    102  1.1   matt 	REG_L	s10, JB_S10(a0)		/* save callee saved register */
    103  1.1   matt 	REG_L	s11, JB_S11(a0)		/* save callee saved register */
    104  1.1   matt #ifndef _SOFT_FLOAT
    105  1.1   matt 	REG_L	t2, JB_FCSR(a0)		/* get it */
    106  1.1   matt 	fscsr	t2			/* restore FSCR */
    107  1.2   matt 	fld	fs0, JB_FS0(a0)		/* restore callee saved register */
    108  1.2   matt 	fld	fs1, JB_FS1(a0)		/* restore callee saved register */
    109  1.2   matt 	fld	fs2, JB_FS2(a0)		/* restore callee saved register */
    110  1.2   matt 	fld	fs3, JB_FS3(a0)		/* restore callee saved register */
    111  1.2   matt 	fld	fs4, JB_FS4(a0)		/* restore callee saved register */
    112  1.2   matt 	fld	fs5, JB_FS5(a0)		/* restore callee saved register */
    113  1.2   matt 	fld	fs6, JB_FS6(a0)		/* restore callee saved register */
    114  1.2   matt 	fld	fs7, JB_FS7(a0)		/* restore callee saved register */
    115  1.2   matt 	fld	fs8, JB_FS8(a0)		/* restore callee saved register */
    116  1.2   matt 	fld	fs9, JB_FS9(a0)		/* restore callee saved register */
    117  1.2   matt 	fld	fs10, JB_FS10(a0)	/* restore callee saved register */
    118  1.2   matt 	fld	fs11, JB_FS11(a0)	/* restore callee saved register */
    119  1.1   matt #endif
    120  1.2   matt 	li	a0, 1			/* default return value */
    121  1.1   matt 	beqz	a1, 1f			/* test return value */
    122  1.3  skrll 	mv	a0, a1			/* use it if not 0 */
    123  1.1   matt 1:	ret
    124  1.1   matt END(_longjmp)
    125