Home | History | Annotate | Line # | Download | only in gen
setjmp.S revision 1.5
      1 /*	$NetBSD: setjmp.S,v 1.5 1996/09/16 18:11:01 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 <machine/regnum.h>
     41 #include <machine/machAsmDefs.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.5 1996/09/16 18:11:01 jonathan Exp $")
     46 #endif /* LIBC_SCCS and not lint */
     47 
     48 /*
     49  * C library -- setjmp, longjmp
     50  *
     51  *	longjmp(a,v)
     52  * will generate a "return(v)" from
     53  * the last call to
     54  *	setjmp(a)
     55  * by restoring registers from the stack,
     56  * and a struct sigcontext, see <signal.h>
     57  */
     58 
     59 #define SETJMP_FRAME_SIZE	(STAND_FRAME_SIZE + 12)
     60 
     61 NON_LEAF(setjmp, SETJMP_FRAME_SIZE, ra)
     62 	subu	sp, sp, SETJMP_FRAME_SIZE	# allocate stack frame
     63 	.mask	0x80000000, (STAND_RA_OFFSET - STAND_FRAME_SIZE)
     64 	sw	ra, STAND_RA_OFFSET(sp)		# save state
     65 	sw	a0, SETJMP_FRAME_SIZE(sp)
     66 	move	a0, zero			# get current signal mask
     67 	jal	_C_LABEL(sigblock)
     68 	lw	v1, SETJMP_FRAME_SIZE(sp)	# v1 = jmpbuf
     69 	sw	v0, (1 * 4)(v1)			# save sc_mask = sigblock(0)
     70 	move	a0, zero
     71 	addu	a1, sp, STAND_FRAME_SIZE	# pointer to struct sigaltstack
     72 	jal	_C_LABEL(sigaltstack)
     73 	lw	a0, SETJMP_FRAME_SIZE(sp)	# restore jmpbuf
     74 	lw	v1, STAND_FRAME_SIZE+8(sp)	# get old ss_onstack
     75 	and	v1, v1, 1			# extract onstack flag
     76 	sw	v1, 0(a0)			# save it in sc_onstack
     77 	lw	ra, STAND_RA_OFFSET(sp)
     78 	addu	sp, sp, SETJMP_FRAME_SIZE
     79 	blt	v0, zero, botch			# check for sigstack() error
     80 	sw	ra, (2 * 4)(a0)			# sc_pc = return address
     81 	li	v0, 0xACEDBADE			# sigcontext magic number
     82 	sw	v0, ((ZERO + 3) * 4)(a0)	#   saved in sc_regs[0]
     83 	sw	s0, ((S0 + 3) * 4)(a0)
     84 	sw	s1, ((S1 + 3) * 4)(a0)
     85 	sw	s2, ((S2 + 3) * 4)(a0)
     86 	sw	s3, ((S3 + 3) * 4)(a0)
     87 	sw	s4, ((S4 + 3) * 4)(a0)
     88 	sw	s5, ((S5 + 3) * 4)(a0)
     89 	sw	s6, ((S6 + 3) * 4)(a0)
     90 	sw	s7, ((S7 + 3) * 4)(a0)
     91 	sw	gp, ((GP + 3) * 4)(a0)
     92 	sw	sp, ((SP + 3) * 4)(a0)
     93 	sw	s8, ((S8 + 3) * 4)(a0)
     94 	li	v0, 1				# be nice if we could tell
     95 	sw	v0, (37 * 4)(a0)		# sc_fpused = 1
     96 	cfc1	v0, $31
     97 	swc1	$f20, ((20 + 38) * 4)(a0)
     98 	swc1	$f21, ((21 + 38) * 4)(a0)
     99 	swc1	$f22, ((22 + 38) * 4)(a0)
    100 	swc1	$f23, ((23 + 38) * 4)(a0)
    101 	swc1	$f24, ((24 + 38) * 4)(a0)
    102 	swc1	$f25, ((25 + 38) * 4)(a0)
    103 	swc1	$f26, ((26 + 38) * 4)(a0)
    104 	swc1	$f27, ((27 + 38) * 4)(a0)
    105 	swc1	$f28, ((28 + 38) * 4)(a0)
    106 	swc1	$f29, ((29 + 38) * 4)(a0)
    107 	swc1	$f30, ((30 + 38) * 4)(a0)
    108 	swc1	$f31, ((31 + 38) * 4)(a0)
    109 	sw	v0, ((32 + 38) * 4)(a0)
    110 	move	v0, zero
    111 	j	ra
    112 END(setjmp)
    113 
    114 LEAF(longjmp)
    115 	sw	a1, ((V0 + 3) * 4)(a0)	# save return value in sc_regs[V0]
    116 	li	v0, SYS_sigreturn
    117 	syscall
    118 botch:
    119 	jal	_C_LABEL(longjmperror)
    120 	jal	_C_LABEL(abort)
    121 END(longjmp)
    122