xref: /original-bsd/lib/libc/vax/gen/setjmp.s (revision 883fb6be)
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#ifdef LIBC_SCCS
8	.asciz	"@(#)setjmp.s	5.6 (Berkeley) 05/10/87"
9#endif LIBC_SCCS
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	pushl	r1			# pointer to sigcontext
65	calls	$1,_sigreturn		# restore previous context
66					# we should never return
67botch:
68	calls	$0,_longjmperror
69	halt
70