Home | History | Annotate | Line # | Download | only in gen
setjmp.S revision 1.8
      1 /*	$NetBSD: setjmp.S,v 1.8 1998/09/27 22:59:40 jonathan 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. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the University of
     21  *	California, Berkeley and its contributors.
     22  * 4. Neither the name of the University nor the names of its contributors
     23  *    may be used to endorse or promote products derived from this software
     24  *    without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  * SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/syscall.h>
     40 #include <mips/regnum.h>
     41 #include <mips/asm.h>
     42 
     43 #if defined(LIBC_SCCS) && !defined(lint)
     44 	ASMSTR("from: @(#)setjmp.s	8.1 (Berkeley) 6/4/93")
     45 	ASMSTR("$NetBSD: setjmp.S,v 1.8 1998/09/27 22:59:40 jonathan Exp $")
     46 #endif /* LIBC_SCCS and not lint */
     47 
     48 #ifdef ABICALLS
     49 	.abicalls
     50 #endif
     51 
     52 /*
     53  * C library -- setjmp, longjmp
     54  *
     55  *	longjmp(a,v)
     56  * will generate a "return(v)" from
     57  * the last call to
     58  *	setjmp(a)
     59  * by restoring registers from the stack,
     60  * and a struct sigcontext, see <signal.h>
     61  */
     62 
     63 #define SETJMP_FRAME_SIZE	(STAND_FRAME_SIZE + 12)
     64 
     65 NON_LEAF(setjmp, SETJMP_FRAME_SIZE, ra)
     66 	.mask	0x80000000, (STAND_RA_OFFSET - STAND_FRAME_SIZE)
     67 #ifdef ABICALLS
     68 	.set	noreorder
     69 	.cpload	t9
     70 	.set	reorder
     71 #endif
     72 	subu	sp, sp, SETJMP_FRAME_SIZE	# allocate stack frame
     73 #ifdef ABICALLS
     74 	.cprestore 16
     75 #endif
     76 	sw	ra, STAND_RA_OFFSET(sp)		# save state
     77 	sw	a0, SETJMP_FRAME_SIZE(sp)
     78 	move	a0, zero			# get current signal mask
     79 	jal	_C_LABEL(sigblock)
     80 	lw	v1, SETJMP_FRAME_SIZE(sp)	# v1 = jmpbuf
     81 	sw	v0, (1 * 4)(v1)			# save sc_mask = sigblock(0)
     82 	move	a0, zero
     83 	addu	a1, sp, STAND_FRAME_SIZE	# pointer to struct sigaltstack
     84 	jal	_C_LABEL(__sigaltstack14)
     85 	lw	a0, SETJMP_FRAME_SIZE(sp)	# restore jmpbuf
     86 	lw	v1, STAND_FRAME_SIZE+8(sp)	# get old ss_onstack
     87 	and	v1, v1, 1			# extract onstack flag
     88 	sw	v1, 0(a0)			# save it in sc_onstack
     89 	lw	ra, STAND_RA_OFFSET(sp)
     90 	addu	sp, sp, SETJMP_FRAME_SIZE
     91 	blt	v0, zero, botch			# check for sigstack() error
     92 	sw	ra, (2 * 4)(a0)			# sc_pc = return address
     93 	li	v0, 0xACEDBADE			# sigcontext magic number
     94 	sw	v0, ((ZERO + 3) * 4)(a0)	#   saved in sc_regs[0]
     95 	sw	s0, ((S0 + 3) * 4)(a0)
     96 	sw	s1, ((S1 + 3) * 4)(a0)
     97 	sw	s2, ((S2 + 3) * 4)(a0)
     98 	sw	s3, ((S3 + 3) * 4)(a0)
     99 	sw	s4, ((S4 + 3) * 4)(a0)
    100 	sw	s5, ((S5 + 3) * 4)(a0)
    101 	sw	s6, ((S6 + 3) * 4)(a0)
    102 	sw	s7, ((S7 + 3) * 4)(a0)
    103 	sw	gp, ((GP + 3) * 4)(a0)
    104 	sw	sp, ((SP + 3) * 4)(a0)
    105 	sw	s8, ((S8 + 3) * 4)(a0)
    106 	li	v0, 1				# be nice if we could tell
    107 	sw	v0, (37 * 4)(a0)		# sc_fpused = 1
    108 	cfc1	v0, $31
    109 	swc1	$f20, ((20 + 38) * 4)(a0)
    110 	swc1	$f21, ((21 + 38) * 4)(a0)
    111 	swc1	$f22, ((22 + 38) * 4)(a0)
    112 	swc1	$f23, ((23 + 38) * 4)(a0)
    113 	swc1	$f24, ((24 + 38) * 4)(a0)
    114 	swc1	$f25, ((25 + 38) * 4)(a0)
    115 	swc1	$f26, ((26 + 38) * 4)(a0)
    116 	swc1	$f27, ((27 + 38) * 4)(a0)
    117 	swc1	$f28, ((28 + 38) * 4)(a0)
    118 	swc1	$f29, ((29 + 38) * 4)(a0)
    119 	swc1	$f30, ((30 + 38) * 4)(a0)
    120 	swc1	$f31, ((31 + 38) * 4)(a0)
    121 	sw	v0, ((32 + 38) * 4)(a0)
    122 	move	v0, zero
    123 	j	ra
    124 END(setjmp)
    125 
    126 LEAF(longjmp)
    127 #ifdef ABICALLS
    128 	.set	noreorder
    129 	.cpload	t9
    130 	.set	reorder
    131 	subu	sp, sp, 32
    132 	.cprestore 16
    133 #endif
    134 	sw	a1, ((V0 + 3) * 4)(a0)	# save return value in sc_regs[V0]
    135 	li	v0, SYS_compat_13_sigreturn13
    136 	syscall
    137 botch:
    138 	jal	_C_LABEL(longjmperror)
    139 	jal	_C_LABEL(abort)
    140 END(longjmp)
    141