xref: /original-bsd/lib/libc/tahoe/gen/setjmp.s (revision c3e32dec)
1/*
2 * Copyright (c) 1988, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Computer Consoles Inc.
7 *
8 * %sccs.include.redist.c%
9 */
10
11#if defined(LIBC_SCCS) && !defined(lint)
12	.asciz "@(#)setjmp.s	8.1 (Berkeley) 06/04/93"
13#endif /* LIBC_SCCS and not lint */
14
15/*
16 * C library -- setjmp, longjmp
17 *
18 *	longjmp(a,v)
19 * will generate a "return(v)" from
20 * the last call to
21 *	setjmp(a)
22 * by restoring registers from the stack,
23 * previous signal mask, and doing a return.
24 */
25
26#include "DEFS.h"
27
28ENTRY(setjmp, R6)
29	movl	4(fp),r6		# construct sigcontext
30	movab	-8(sp),sp		# space for current struct sigstack
31	pushal	(sp)			# get current values
32	pushl	$0			# no new values
33	callf	$16,_sigstack		# pop args plus signal stack value
34	movl	(sp)+,(r6)		# save onsigstack status of caller
35	pushl	$0
36	callf	$8,_sigblock		# get signal mask
37	movl	r0,4(r6)		# save signal mask of caller
38	addl3	$8,fp,8(r6)		# save stack pointer of caller
39	movl	(fp),12(r6)		# save frame pointer of caller
40	movl	-8(fp),20(r6)		# save pc of caller
41	movpsl	24(r6)			# save psl of caller
42	clrl	r0
43	ret
44
45ENTRY(longjmp, 0)
46	movl	8(fp),r0		# return(v)
47	movl	4(fp),r1		# fetch buffer
48	tstl	12(r1)
49	beql	botch
50loop:
51	cmpl	12(r1),(fp)
52	beql	done
53	blssu	botch
54	movl	$loop,-8(fp)
55	ret				# pop another frame
56
57done:
58	cmpb	*-8(fp),reiins		# returning to an "rei"?
59	bneq	1f
60	movab	3f,-8(fp)		# do return w/ psl-pc pop
61	brw	2f
621:
63	movab	4f,-8(fp)		# do standard return
642:
65	ret				# unwind stack before signals enabled
663:
67	addl2	$8,sp			# compensate for PSL-PC push
684:
69	pushl	r1			# pointer to sigcontext
70	callf	$4,_sigreturn		# restore previous context
71					# we should never return
72
73botch:
74	callf	$4,_longjmperror
75	halt
76
77	.data
78reiins:	rei
79