#include "SYS.h"

	.globl	_Ssetjmp
_Ssetjmp:
	.word	0
	movl		4(ap),r0	/* pointer to jmp_buf */
	movl		12(fp),(r0)	/* save caller's fp */
	movl		16(fp),4(r0)	/*  and pc */
	clrl		r0		/* return zero */
	ret

/* longjmp temporary data area.  can get away with this because
   longjmp blocks ASTs around the area where it uses these variables. */
	.data
	.lcomm	ljt_rv,4
	.lcomm	ljt_jb,4
	.text
	.globl	_Slongjmp
_Slongjmp:
	.word	0
	calls		$0,_blockast
	movl		8(ap),ljt_rv	/* return value */
	movl		4(ap),ljt_jb	/* pointer to jmp_buf */
loop:
	cmpl		fp,*ljt_jb	/* just popped last frame? */
	jeql		lastframe	/* yes, finish up */
	jgtr		botch		/* no, missed it - botch */
	movab		loop,16(fp)	/* no, pop another */
	ret
lastframe:
	calls		$0,1f		/* create new call frame */
1:	.word	0
	movl		ljt_jb,r0	/* pointer to jmp_buf */
	movl		4(r0),16(fp)	/* stuff pc into frame */
	movl		ljt_rv,-(sp)	/* save return value */
	calls		$0,_clearast	/* unblock ASTs */
	movl		(sp)+,r0	/* put return value in r0 */
	ret				/* return to setjmp's caller */
botch:
	pushl		$13
	pushab		1f
	.data
1:	.ascii	"longjmp botch"
	.text
	pushl		$1
	calls		$3,_write
	halt
