xref: /csrg-svn/lib/libc/vax/gen/setjmp.s (revision 18292)
1*18292Smckusick/*	setjmp.s	4.7	85/03/11	*/
213419Sroot
313419Sroot/*
413419Sroot * C library -- setjmp, longjmp
513419Sroot *
613419Sroot *	longjmp(a,v)
713419Sroot * will generate a "return(v)" from
813419Sroot * the last call to
913419Sroot *	setjmp(a)
1013419Sroot * by restoring registers from the stack,
11*18292Smckusick * and a struct sigcontext, see <signal.h>
1213419Sroot */
1313419Sroot
1413419Sroot#include "DEFS.h"
1513419Sroot
1617329SsamENTRY(setjmp, 0)
17*18292Smckusick	movl	4(ap),r1		# construct sigcontext
18*18292Smckusick	subl2	$8,sp			# space for current struct sigstack
19*18292Smckusick	pushl	sp			# get current values
20*18292Smckusick	pushl	$0			# no new values
21*18292Smckusick	calls	$3,_sigstack		# pop args plus signal stack value
22*18292Smckusick	movl	*(sp)+,(r1)+		# save onsigstack status of caller
2313419Sroot	pushl	$0
2413419Sroot	calls	$1,_sigblock		# get signal mask
25*18292Smckusick	movl	r0,(r1)+		# save signal mask of caller
26*18292Smckusick	movl	(ap),r0
27*18292Smckusick	moval	4(ap)[r0],(r1)+		# save sp of caller
28*18292Smckusick	movl	12(fp),(r1)+		# save frame pointer of caller
29*18292Smckusick	movl	8(fp),(r1)+		# save argument pointer of caller
30*18292Smckusick	movl	16(fp),(r1)+		# save pc of caller
31*18292Smckusick	movpsl	(r1)			# save psl of caller
32*18292Smckusick	movw	4(fp),(r1)
3313419Sroot	clrl	r0
3413419Sroot	ret
3513419Sroot
3617329SsamENTRY(longjmp, 0)
3713419Sroot	movl	8(ap),r0		# return(v)
3813419Sroot	movl	4(ap),r1		# fetch buffer
39*18292Smckusick	tstl	12(r1)
4013419Sroot	beql	botch
4113419Srootloop:
42*18292Smckusick	cmpl	12(r1),fp		# are we there yet?
43*18292Smckusick	beql	done
44*18292Smckusick	blssu	botch
45*18292Smckusick	moval	20(fp),r2
46*18292Smckusick	blbc	6(fp),1f		# was r0 saved?
47*18292Smckusick	movl	r0,(r2)+
4813419Sroot1:
49*18292Smckusick	bbc	$1,6(fp),2f		# was r1 saved?
50*18292Smckusick	movl	r1,(r2)
5113419Sroot2:
5213419Sroot	movl	$loop,16(fp)
5313419Sroot	ret				# pop another frame
5413419Sroot
5513419Srootdone:
56*18292Smckusick
57*18292Smckusick#ifndef NOCOMPAT
58*18292Smckusick/*
59*18292Smckusick * This code checks to see if it can use the new sigreturn.
60*18292Smckusick * If it finds that sigtramp is using the new system call,
61*18292Smckusick * it will also use it. Otherwise it uses the old system call
62*18292Smckusick * to preserve compatibility.
63*18292Smckusick */
64*18292Smckusick#include <vax/machparam.h>
65*18292Smckusick#define U (0x80000000-UPAGES*NBPG)
66*18292Smckusick#define PCB_SIGC 0x6c
67*18292Smckusick#define CHMKINS 7
68*18292Smckusick	cmpl	3f,U+PCB_SIGC+CHMKINS	# check to see how sigtramp returns
69*18292Smckusick	beql	4f			# sigtramp uses the new system call
70*18292Smckusick	pushl	r1			# must use the old signal return
71*18292Smckusick	chmk	$139			# restore previous context
72*18292Smckusick	jmp	*20(r1)			# done, return
7313419Sroot3:
74*18292Smckusick	chmk	$103			# the new system call for sigreturn
7513419Sroot4:
76*18292Smckusick#endif NOCOMPAT
7713419Sroot
78*18292Smckusick	pushl	r1			# pointer to sigcontext
79*18292Smckusick	calls	$1,_sigreturn		# restore previous context
80*18292Smckusick					# we should never return
8113419Srootbotch:
8213500Ssam	pushl	$msgend-msg
8313419Sroot	pushl	$msg
8413419Sroot	pushl	$2
8513419Sroot	calls	$3,_write
8613419Sroot	halt
8713419Sroot
8813625Ssam	.data
8913500Ssammsg:	.ascii	"longjmp botch\n"
9013500Ssammsgend:
91