xref: /csrg-svn/lib/libc/vax/gen/setjmp.s (revision 25784)
121431Sdist/*
221431Sdist * Copyright (c) 1983 Regents of the University of California.
321431Sdist * All rights reserved.  The Berkeley software License Agreement
421431Sdist * specifies the terms and conditions for redistribution.
521431Sdist */
613419Sroot
721431Sdist#ifndef lint
8*25784Smckusick	.asciz	"@(#)setjmp.s	5.4 (Berkeley) 01/09/86"
921431Sdist#endif not lint
1021431Sdist
1113419Sroot/*
1213419Sroot * C library -- setjmp, longjmp
1313419Sroot *
1413419Sroot *	longjmp(a,v)
1513419Sroot * will generate a "return(v)" from
1613419Sroot * the last call to
1713419Sroot *	setjmp(a)
1813419Sroot * by restoring registers from the stack,
1918292Smckusick * and a struct sigcontext, see <signal.h>
2013419Sroot */
2113419Sroot
2213419Sroot#include "DEFS.h"
2313419Sroot
2418715SmckusickENTRY(setjmp, R6)
2518715Smckusick	movl	4(ap),r6		# construct sigcontext
2618292Smckusick	subl2	$8,sp			# space for current struct sigstack
2718292Smckusick	pushl	sp			# get current values
2818292Smckusick	pushl	$0			# no new values
2918292Smckusick	calls	$3,_sigstack		# pop args plus signal stack value
3024300Smckusick	movl	(sp)+,(r6)+		# save onsigstack status of caller
3113419Sroot	pushl	$0
3213419Sroot	calls	$1,_sigblock		# get signal mask
3318715Smckusick	movl	r0,(r6)+		# save signal mask of caller
3418292Smckusick	movl	(ap),r0
3518715Smckusick	moval	4(ap)[r0],(r6)+		# save sp of caller
3618715Smckusick	movl	12(fp),(r6)+		# save frame pointer of caller
3718715Smckusick	movl	8(fp),(r6)+		# save argument pointer of caller
3818715Smckusick	movl	16(fp),(r6)+		# save pc of caller
3918715Smckusick	movpsl	(r6)			# save psl of caller
4018715Smckusick	movw	4(fp),(r6)
4113419Sroot	clrl	r0
4213419Sroot	ret
4313419Sroot
4417329SsamENTRY(longjmp, 0)
4513419Sroot	movl	8(ap),r0		# return(v)
4613419Sroot	movl	4(ap),r1		# fetch buffer
4718292Smckusick	tstl	12(r1)
4813419Sroot	beql	botch
4913419Srootloop:
5018292Smckusick	cmpl	12(r1),fp		# are we there yet?
5118292Smckusick	beql	done
5218292Smckusick	blssu	botch
5318292Smckusick	moval	20(fp),r2
5418292Smckusick	blbc	6(fp),1f		# was r0 saved?
5518292Smckusick	movl	r0,(r2)+
5613419Sroot1:
5718292Smckusick	bbc	$1,6(fp),2f		# was r1 saved?
5818292Smckusick	movl	r1,(r2)
5913419Sroot2:
6013419Sroot	movl	$loop,16(fp)
6113419Sroot	ret				# pop another frame
6213419Sroot
6313419Srootdone:
6418292Smckusick
6518292Smckusick#ifndef NOCOMPAT
6618292Smckusick/*
6718292Smckusick * This code checks to see if it can use the new sigreturn.
6818292Smckusick * If it finds that sigtramp is using the new system call,
6918292Smckusick * it will also use it. Otherwise it uses the old system call
7018292Smckusick * to preserve compatibility.
7118292Smckusick */
7218292Smckusick#include <vax/machparam.h>
7318292Smckusick#define U (0x80000000-UPAGES*NBPG)
7418292Smckusick#define PCB_SIGC 0x6c
7518292Smckusick#define CHMKINS 7
7618292Smckusick	cmpl	3f,U+PCB_SIGC+CHMKINS	# check to see how sigtramp returns
7718292Smckusick	beql	4f			# sigtramp uses the new system call
7818292Smckusick	pushl	r1			# must use the old signal return
7918292Smckusick	chmk	$139			# restore previous context
8018292Smckusick	jmp	*20(r1)			# done, return
8113419Sroot3:
8218292Smckusick	chmk	$103			# the new system call for sigreturn
8313419Sroot4:
8418292Smckusick#endif NOCOMPAT
8513419Sroot
8618292Smckusick	pushl	r1			# pointer to sigcontext
8718292Smckusick	calls	$1,_sigreturn		# restore previous context
8818292Smckusick					# we should never return
8913419Srootbotch:
90*25784Smckusick	calls	$0,_longjmperror
9113419Sroot	halt
92