xref: /csrg-svn/lib/libc/vax/gen/setjmp.s (revision 18715)
1/*	setjmp.s	4.8	85/04/24	*/
2
3/*
4 * C library -- setjmp, longjmp
5 *
6 *	longjmp(a,v)
7 * will generate a "return(v)" from
8 * the last call to
9 *	setjmp(a)
10 * by restoring registers from the stack,
11 * and a struct sigcontext, see <signal.h>
12 */
13
14#include "DEFS.h"
15
16ENTRY(setjmp, R6)
17	movl	4(ap),r6		# construct sigcontext
18	subl2	$8,sp			# space for current struct sigstack
19	pushl	sp			# get current values
20	pushl	$0			# no new values
21	calls	$3,_sigstack		# pop args plus signal stack value
22	movl	*(sp)+,(r6)+		# save onsigstack status of caller
23	pushl	$0
24	calls	$1,_sigblock		# get signal mask
25	movl	r0,(r6)+		# save signal mask of caller
26	movl	(ap),r0
27	moval	4(ap)[r0],(r6)+		# save sp of caller
28	movl	12(fp),(r6)+		# save frame pointer of caller
29	movl	8(fp),(r6)+		# save argument pointer of caller
30	movl	16(fp),(r6)+		# save pc of caller
31	movpsl	(r6)			# save psl of caller
32	movw	4(fp),(r6)
33	clrl	r0
34	ret
35
36ENTRY(longjmp, 0)
37	movl	8(ap),r0		# return(v)
38	movl	4(ap),r1		# fetch buffer
39	tstl	12(r1)
40	beql	botch
41loop:
42	cmpl	12(r1),fp		# are we there yet?
43	beql	done
44	blssu	botch
45	moval	20(fp),r2
46	blbc	6(fp),1f		# was r0 saved?
47	movl	r0,(r2)+
481:
49	bbc	$1,6(fp),2f		# was r1 saved?
50	movl	r1,(r2)
512:
52	movl	$loop,16(fp)
53	ret				# pop another frame
54
55done:
56
57#ifndef NOCOMPAT
58/*
59 * This code checks to see if it can use the new sigreturn.
60 * If it finds that sigtramp is using the new system call,
61 * it will also use it. Otherwise it uses the old system call
62 * to preserve compatibility.
63 */
64#include <vax/machparam.h>
65#define U (0x80000000-UPAGES*NBPG)
66#define PCB_SIGC 0x6c
67#define CHMKINS 7
68	cmpl	3f,U+PCB_SIGC+CHMKINS	# check to see how sigtramp returns
69	beql	4f			# sigtramp uses the new system call
70	pushl	r1			# must use the old signal return
71	chmk	$139			# restore previous context
72	jmp	*20(r1)			# done, return
733:
74	chmk	$103			# the new system call for sigreturn
754:
76#endif NOCOMPAT
77
78	pushl	r1			# pointer to sigcontext
79	calls	$1,_sigreturn		# restore previous context
80					# we should never return
81botch:
82	pushl	$msgend-msg
83	pushl	$msg
84	pushl	$2
85	calls	$3,_write
86	halt
87
88	.data
89msg:	.ascii	"longjmp botch\n"
90msgend:
91