xref: /original-bsd/lib/libc/hp300/gen/setjmp.s (revision c3e32dec)
1/*-
2 * Copyright (c) 1990, 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 * the Systems Programming Group of the University of Utah Computer
7 * Science Department.
8 *
9 * %sccs.include.redist.c%
10 */
11
12#if defined(LIBC_SCCS) && !defined(lint)
13	.asciz "@(#)setjmp.s	8.1 (Berkeley) 06/04/93"
14#endif /* LIBC_SCCS and not lint */
15
16/*
17 * C library -- setjmp, longjmp
18 *
19 *	longjmp(a,v)
20 * will generate a "return(v)" from
21 * the last call to
22 *	setjmp(a)
23 * by restoring registers from the stack,
24 * and a struct sigcontext, see <signal.h>
25 */
26
27#include "DEFS.h"
28
29ENTRY(setjmp)
30	subl	#12,sp		/* space for sigaltstack args/rvals */
31	clrl	sp@		/* don't change it... */
32	movl	sp,sp@(4)	/* ...but return the current val */
33	jsr	_sigaltstack	/* note: onstack returned in sp@(8) */
34	clrl	sp@		/* don't change mask, just return */
35	jsr	_sigblock	/*   old value */
36	movl	sp@(8),d1	/* old onstack value */
37	andl	#1,d1		/* extract onstack flag */
38	addl	#12,sp
39	movl	sp@(4),a0	/* save area pointer */
40	movl	d1,a0@+		/* save old onstack value */
41	movl	d0,a0@+		/* save old signal mask */
42	lea	sp@(4),a1	/* adjust saved SP since we won't rts */
43	movl	a1,a0@+		/* save old SP */
44	movl	a6,a0@+		/* save old FP */
45	clrl	a0@+		/* no AP */
46	movl	sp@,a0@+	/* save old PC */
47	clrl	a0@+		/* clean PS */
48	moveml	#0x3CFC,a0@	/* save remaining non-scratch regs */
49	clrl	d0		/* return 0 */
50	rts
51
52ENTRY(longjmp)
53	movl	sp@(4),a0	/* save area pointer */
54	tstl	a0@(8)		/* ensure non-zero SP */
55	jeq	botch		/* oops! */
56	movl	sp@(8),d0	/* grab return value */
57	jne	ok		/* non-zero ok */
58	moveq	#1,d0		/* else make non-zero */
59ok:
60	moveml	a0@(28),#0x3CFC	/* restore non-scratch regs */
61	movl	a0,sp@-		/* let sigreturn */
62	jsr	_sigreturn	/*   finish for us */
63
64botch:
65	jsr	_longjmperror
66	stop	#0
67