	.file	"setjmp.s"
/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 *
 */

/*	Copyright (c) 1984 AT&T	*/
/*	All Rights Reserved	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any	*/
/*	actual or intended publication of such source code.	*/

	.ident	"@(#)$Header: setjmp.s 1.3 89/10/10 $"

/* C library -- setjmp, longjmp	*/

/*	longjmp(a,v)						*/
/* will generate a "return(v)" from 				*/
/* the last call to						*/
/* 	setjmp(a)						*/
/* by restoring ip, sp, bp, bx, si, and di from 'a'		*/
/* and doing a return						*/

/* entry    reg		offset		*/
/* env[0] = %ebx	 0		*/
/* env[1] = %esi	 4		*/
/* env[2] = %edi	 8		*/
/* env[3] = %ebp	 12		*/
/* env[4] = %esp	 16		*/
/* env[5] = %eip	 20		*/

#include "sys.s"

ENTRY(setjmp)
	movl	SPARG0,%eax	/* %eax = buffer address */
	movl	%ebx,(%eax)	/* save %ebx */
	movl	%esi,4(%eax)	/*      %esi */
	movl	%edi,8(%eax)	/*      %edi */
	movl	%ebp,12(%eax)	/*      %ebp */
	popl	%edx		/* %edx = return address */
	movl	%esp,16(%eax)	/* save callers %esp */
	movl	%edx,20(%eax)	/* save callers %eip */
	xorl	%eax,%eax	/* return zero */
	jmp	*%edx

ENTRY(longjmp)
	movl	SPARG0,%edx	/* %edx = buffer address  */
	movl	SPARG1,%eax	/* %eax = return value */
	cmpl	12(%edx),%ebp	/* see if called from same procedure */
	je	.sameproc	/* if so, don't restore register variables */
	movl	(%edx),%ebx	/* restore %ebx */
	movl	4(%edx),%esi	/* 	   %esi */
	movl	8(%edx),%edi	/* 	   %edi */
	movl	12(%edx),%ebp	/*	   %ebp */
.sameproc:
	movl	16(%edx),%esp	/*	   %esp */
	testl	%eax,%eax	/* if v != 0 */
	jz	.ret1		/*	return v */
	jmp	*20(%edx)	/* return to caller */
.ret1:
	incl	%eax		/* else return 1 */
	jmp	*20(%edx)	/* return to caller */
