xref: /csrg-svn/lib/libc/tahoe/gen/setjmp.s (revision 34438)
1*34438Sbostic/*
2*34438Sbostic * Copyright (c) 1988 Regents of the University of California.
3*34438Sbostic * All rights reserved.
4*34438Sbostic *
5*34438Sbostic * This code is derived from software contributed to Berkeley by
6*34438Sbostic * Computer Consoles Inc.
7*34438Sbostic *
8*34438Sbostic * Redistribution and use in source and binary forms are permitted
9*34438Sbostic * provided that this notice is preserved and that due credit is given
10*34438Sbostic * to the University of California at Berkeley. The name of the University
11*34438Sbostic * may not be used to endorse or promote products derived from this
12*34438Sbostic * software without specific prior written permission. This software
13*34438Sbostic * is provided ``as is'' without express or implied warranty.
14*34438Sbostic */
1529698Ssam
16*34438Sbostic#if defined(LIBC_SCCS) && !defined(lint)
17*34438Sbostic_sccsid:.asciz	"@(#)setjmp.s	1.3 (Berkeley) 05/23/88"
18*34438Sbostic#endif /* LIBC_SCCS and not lint */
19*34438Sbostic
2029698Ssam/*
2129698Ssam * C library -- setjmp, longjmp
2229698Ssam *
2329698Ssam *	longjmp(a,v)
2429698Ssam * will generate a "return(v)" from
2529698Ssam * the last call to
2629698Ssam *	setjmp(a)
2729698Ssam * by restoring registers from the stack,
2829698Ssam * previous signal mask, and doing a return.
2929698Ssam */
3029698Ssam
3129698Ssam#include "DEFS.h"
3229698Ssam
3329797SsamENTRY(setjmp, R6)
3429797Ssam	movl	4(fp),r6		# construct sigcontext
3529797Ssam	movab	-8(sp),sp		# space for current struct sigstack
3629797Ssam	pushal	(sp)			# get current values
3729797Ssam	pushl	$0			# no new values
3829797Ssam	callf	$16,_sigstack		# pop args plus signal stack value
3929797Ssam	movl	(sp)+,(r6)		# save onsigstack status of caller
4029698Ssam	pushl	$0
4129698Ssam	callf	$8,_sigblock		# get signal mask
4229797Ssam	movl	r0,4(r6)		# save signal mask of caller
4329797Ssam	addl3	$8,fp,8(r6)		# save stack pointer of caller
4429797Ssam	movl	(fp),12(r6)		# save frame pointer of caller
4529797Ssam	movl	-8(fp),20(r6)		# save pc of caller
4629797Ssam	movpsl	24(r6)			# save psl of caller
4729698Ssam	clrl	r0
4829698Ssam	ret
4929698Ssam
5029698SsamENTRY(longjmp, 0)
5129698Ssam	movl	8(fp),r0		# return(v)
5229698Ssam	movl	4(fp),r1		# fetch buffer
5329797Ssam	tstl	12(r1)
5429698Ssam	beql	botch
5529698Ssamloop:
5629797Ssam	cmpl	12(r1),(fp)
5729698Ssam	beql	done
5829698Ssam	blssu	botch
5929698Ssam	movl	$loop,-8(fp)
6029698Ssam	ret				# pop another frame
6129698Ssam
6229698Ssamdone:
6329698Ssam	cmpb	*-8(fp),reiins		# returning to an "rei"?
6429698Ssam	bneq	1f
6529698Ssam	movab	3f,-8(fp)		# do return w/ psl-pc pop
6629698Ssam	brw	2f
6729698Ssam1:
6829698Ssam	movab	4f,-8(fp)		# do standard return
6929698Ssam2:
7029698Ssam	ret				# unwind stack before signals enabled
7129698Ssam3:
7229698Ssam	addl2	$8,sp			# compensate for PSL-PC push
7329698Ssam4:
7429797Ssam	pushl	r1			# pointer to sigcontext
7529797Ssam	callf	$4,_sigreturn		# restore previous context
7629797Ssam					# we should never return
7729698Ssam
7829698Ssambotch:
7929698Ssam	callf	$4,_longjmperror
8029698Ssam	halt
8129698Ssam
8229698Ssam	.data
8329698Ssamreiins:	rei
84