setjmp.S revision 1.1
11.1Spaulus/*-
21.1Spaulus * Copyright (c) 1990 The Regents of the University of California.
31.1Spaulus * All rights reserved.
41.1Spaulus *
51.1Spaulus * This code is derived from software contributed to Berkeley by
61.1Spaulus * the Systems Programming Group of the University of Utah Computer
71.1Spaulus * Science Department.
81.1Spaulus *
91.1Spaulus * Redistribution and use in source and binary forms, with or without
101.1Spaulus * modification, are permitted provided that the following conditions
111.1Spaulus * are met:
121.1Spaulus * 1. Redistributions of source code must retain the above copyright
131.1Spaulus *    notice, this list of conditions and the following disclaimer.
141.1Spaulus * 2. Redistributions in binary form must reproduce the above copyright
151.1Spaulus *    notice, this list of conditions and the following disclaimer in the
161.1Spaulus *    documentation and/or other materials provided with the distribution.
171.1Spaulus * 3. All advertising materials mentioning features or use of this software
181.1Spaulus *    must display the following acknowledgement:
191.1Spaulus *	This product includes software developed by the University of
201.1Spaulus *	California, Berkeley and its contributors.
211.1Spaulus * 4. Neither the name of the University nor the names of its contributors
221.1Spaulus *    may be used to endorse or promote products derived from this software
231.1Spaulus *    without specific prior written permission.
241.1Spaulus *
251.1Spaulus * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
261.1Spaulus * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
271.1Spaulus * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
281.1Spaulus * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291.1Spaulus * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
301.1Spaulus * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
311.1Spaulus * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
321.1Spaulus * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
331.1Spaulus * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
341.1Spaulus * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
351.1Spaulus * SUCH DAMAGE.
361.1Spaulus */
371.1Spaulus
381.1Spaulus#if defined(LIBC_SCCS) && !defined(lint)
391.1Spaulus	.text
401.1Spaulus	/*.asciz "from: @(#)setjmp.s	5.1 (Berkeley) 5/12/90"*/
411.1Spaulus	.asciz "$Id: setjmp.S,v 1.1 1993/11/25 23:37:19 paulus Exp $"
421.1Spaulus#endif /* LIBC_SCCS and not lint */
431.1Spaulus
441.1Spaulus/*
451.1Spaulus * C library -- setjmp, longjmp
461.1Spaulus *
471.1Spaulus *	longjmp(a,v)
481.1Spaulus * will generate a "return(v)" from
491.1Spaulus * the last call to
501.1Spaulus *	setjmp(a)
511.1Spaulus * by restoring registers from the stack,
521.1Spaulus * and a struct sigcontext, see <signal.h>
531.1Spaulus */
541.1Spaulus
551.1Spaulus#include "DEFS.h"
561.1Spaulus
571.1SpaulusENTRY(setjmp)
581.1Spaulus	subql	#8,sp		/* space for sigstack args/rvals */
591.1Spaulus	clrl	sp@		/* don't change it... */
601.1Spaulus	movl	sp,sp@(4)	/* ...but return the current val */
611.1Spaulus	jbsr	_sigstack	/* note: onstack returned in sp@(4) */
621.1Spaulus	clrl	sp@		/* don't change mask, just return */
631.1Spaulus	jbsr	_sigblock	/*   old value */
641.1Spaulus	movl	sp@(4),d1	/* old onstack value */
651.1Spaulus	addql	#8,sp
661.1Spaulus	movl	sp@(4),a0	/* save area pointer */
671.1Spaulus	movl	d1,a0@+		/* save old onstack value */
681.1Spaulus	movl	d0,a0@+		/* save old signal mask */
691.1Spaulus	lea	sp@(4),a1	/* adjust saved SP since we won't rts */
701.1Spaulus	movl	a1,a0@+		/* save old SP */
711.1Spaulus	movl	a6,a0@+		/* save old FP */
721.1Spaulus	clrl	a0@+		/* no AP */
731.1Spaulus	movl	sp@,a0@+	/* save old PC */
741.1Spaulus	clrl	a0@+		/* clean PS */
751.1Spaulus	moveml	#0x3CFC,a0@	/* save remaining non-scratch regs */
761.1Spaulus	clrl	d0		/* return 0 */
771.1Spaulus	rts
781.1Spaulus
791.1SpaulusENTRY(longjmp)
801.1Spaulus	movl	sp@(4),a0	/* save area pointer */
811.1Spaulus	tstl	a0@(8)		/* ensure non-zero SP */
821.1Spaulus	jeq	botch		/* oops! */
831.1Spaulus	movl	sp@(8),d0	/* grab return value */
841.1Spaulus	jne	ok		/* non-zero ok */
851.1Spaulus	moveq	#1,d0		/* else make non-zero */
861.1Spaulusok:
871.1Spaulus	moveml	a0@(28),#0x3CFC	/* restore non-scratch regs */
881.1Spaulus	movl	a0,sp@-		/* let sigreturn */
891.1Spaulus	jbsr	_sigreturn	/*   finish for us */
901.1Spaulus
911.1Spaulusbotch:
921.1Spaulus	jbsr	_longjmperror
931.1Spaulus	stop	#0
94