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