xref: /original-bsd/lib/libc/vax/gen/setjmp.s (revision c3e32dec)
1/*
2 * Copyright (c) 1983, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
9	.asciz "@(#)setjmp.s	8.1 (Berkeley) 06/04/93"
10#endif /* LIBC_SCCS and not lint */
11
12/*
13 * C library -- setjmp, longjmp
14 *
15 *	longjmp(a,v)
16 * will generate a "return(v)" from
17 * the last call to
18 *	setjmp(a)
19 * by restoring registers from the stack,
20 * and a struct sigcontext, see <signal.h>
21 */
22
23#include "DEFS.h"
24
25ENTRY(setjmp, R6)
26	movl	4(ap),r6		# construct sigcontext
27	subl2	$8,sp			# space for current struct sigstack
28	pushl	sp			# get current values
29	pushl	$0			# no new values
30	calls	$3,_sigstack		# pop args plus signal stack value
31	movl	(sp)+,(r6)+		# save onsigstack status of caller
32	pushl	$0
33	calls	$1,_sigblock		# get signal mask
34	movl	r0,(r6)+		# save signal mask of caller
35	movl	(ap),r0
36	moval	4(ap)[r0],(r6)+		# save sp of caller
37	movl	12(fp),(r6)+		# save frame pointer of caller
38	movl	8(fp),(r6)+		# save argument pointer of caller
39	movl	16(fp),(r6)+		# save pc of caller
40	movpsl	(r6)			# save psl of caller
41	movw	4(fp),(r6)
42	clrl	r0
43	ret
44
45ENTRY(longjmp, 0)
46	movl	8(ap),r0		# return(v)
47	movl	4(ap),r1		# fetch buffer
48	tstl	12(r1)
49	beql	botch
50loop:
51	cmpl	12(r1),fp		# are we there yet?
52	beql	done
53	blssu	botch
54	moval	20(fp),r2
55	blbc	6(fp),1f		# was r0 saved?
56	movl	r0,(r2)+
571:
58	bbc	$1,6(fp),2f		# was r1 saved?
59	movl	r1,(r2)
602:
61	movl	$loop,16(fp)
62	ret				# pop another frame
63
64done:
65	pushl	r1			# pointer to sigcontext
66	calls	$1,_sigreturn		# restore previous context
67					# we should never return
68botch:
69	calls	$0,_longjmperror
70	halt
71