xref: /netbsd-src/lib/libc/compat/arch/m68k/gen/compat_setjmp.S (revision c479ba2f5a7a23d986183eb5e99cb81f4fa026d3)
1*c479ba2fSmatt/*	$NetBSD: compat_setjmp.S,v 1.3 2014/03/04 06:27:00 matt Exp $	*/
2eebf1202Schristos
3eebf1202Schristos/*-
4eebf1202Schristos * Copyright (c) 1990 The Regents of the University of California.
5eebf1202Schristos * All rights reserved.
6eebf1202Schristos *
7eebf1202Schristos * This code is derived from software contributed to Berkeley by
8eebf1202Schristos * the Systems Programming Group of the University of Utah Computer
9eebf1202Schristos * Science Department.
10eebf1202Schristos *
11eebf1202Schristos * Redistribution and use in source and binary forms, with or without
12eebf1202Schristos * modification, are permitted provided that the following conditions
13eebf1202Schristos * are met:
14eebf1202Schristos * 1. Redistributions of source code must retain the above copyright
15eebf1202Schristos *    notice, this list of conditions and the following disclaimer.
16eebf1202Schristos * 2. Redistributions in binary form must reproduce the above copyright
17eebf1202Schristos *    notice, this list of conditions and the following disclaimer in the
18eebf1202Schristos *    documentation and/or other materials provided with the distribution.
19eebf1202Schristos * 3. Neither the name of the University nor the names of its contributors
20eebf1202Schristos *    may be used to endorse or promote products derived from this software
21eebf1202Schristos *    without specific prior written permission.
22eebf1202Schristos *
23eebf1202Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24eebf1202Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25eebf1202Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26eebf1202Schristos * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27eebf1202Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28eebf1202Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29eebf1202Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30eebf1202Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31eebf1202Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32eebf1202Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33eebf1202Schristos * SUCH DAMAGE.
34eebf1202Schristos */
35eebf1202Schristos
36eebf1202Schristos#include <machine/asm.h>
37eebf1202Schristos
38eebf1202Schristos#if defined(LIBC_SCCS) && !defined(lint)
39eebf1202Schristos#if 0
40eebf1202Schristos	RCSID("from: @(#)setjmp.s	5.1 (Berkeley) 5/12/90")
41eebf1202Schristos#else
42*c479ba2fSmatt	RCSID("$NetBSD: compat_setjmp.S,v 1.3 2014/03/04 06:27:00 matt Exp $")
43eebf1202Schristos#endif
44eebf1202Schristos#endif /* LIBC_SCCS and not lint */
45eebf1202Schristos
46eebf1202Schristos/*
47eebf1202Schristos * C library -- setjmp, longjmp
48eebf1202Schristos *
49eebf1202Schristos *	longjmp(a,v)
50eebf1202Schristos * will generate a "return(v)" from
51eebf1202Schristos * the last call to
52eebf1202Schristos *	setjmp(a)
53eebf1202Schristos * by restoring registers from the stack,
54eebf1202Schristos * and a struct sigcontext, see <signal.h>
55eebf1202Schristos */
56eebf1202Schristos
57eebf1202SchristosENTRY(setjmp)
5888723221Smatt	lea	-12(%sp),%sp	/* space for sigstack args/rvals */
5988723221Smatt	clrl	(%sp)		/* don't change it... */
6088723221Smatt	movl	%sp,4(%sp)	/* ...but return the current val */
61eebf1202Schristos	jbsr	PIC_PLT(_C_LABEL(__sigaltstack14))
62eebf1202Schristos				/* note: flags returned in sp@(8) */
6388723221Smatt	clrl	(%sp)		/* don't change mask, just return */
64eebf1202Schristos	jbsr	PIC_PLT(_C_LABEL(sigblock)) /*  old value */
6588723221Smatt	movl	8(%sp),%d1	/* old flags value */
66eebf1202Schristos	andl	#1,%d1		/* extract onstack flag */
6788723221Smatt	lea	12(%sp),%sp
6888723221Smatt	movl	4(%sp),%a0	/* save area pointer */
6988723221Smatt	movl	%d1,(%a0)+	/* save old onstack value */
7088723221Smatt	movl	%d0,(%a0)+	/* save old signal mask */
7188723221Smatt	lea	4(%sp),%a1	/* adjust saved SP since we won't rts */
7288723221Smatt	movl	%a1,(%a0)+	/* save old SP */
7388723221Smatt	movl	%a6,(%a0)+	/* save old FP */
7488723221Smatt	clrl	(%a0)+		/* no AP */
7588723221Smatt	movl	(%sp),(%a0)+	/* save old PC */
7688723221Smatt	clrl	(%a0)+		/* clean PS */
7788723221Smatt	moveml	#0x3CFC,(%a0)	/* save remaining non-scratch regs */
78eebf1202Schristos	clrl	%d0		/* return 0 */
79eebf1202Schristos	rts
8088723221SmattEND(setjmp)
81eebf1202Schristos
82eebf1202SchristosENTRY(longjmp)
8388723221Smatt	movl	4(%sp),%a0	/* save area pointer */
8488723221Smatt	tstl	8(%a0)		/* ensure non-zero SP */
85eebf1202Schristos	jeq	botch		/* oops! */
8688723221Smatt	movl	8(%sp),%d0	/* grab return value */
87eebf1202Schristos	jne	ok		/* non-zero ok */
88eebf1202Schristos	moveq	#1,%d0		/* else make non-zero */
89eebf1202Schristosok:
9088723221Smatt	moveml	28(%a0),#0x3CFC /* restore non-scratch regs */
9188723221Smatt	movl	%a0,-(%sp)	/* let sigreturn */
92*c479ba2fSmatt	trap	#1		/* finish via compat_13_sigreturn13() */
93eebf1202Schristos
94eebf1202Schristosbotch:
95eebf1202Schristos	jbsr	PIC_PLT(_C_LABEL(longjmperror))
96eebf1202Schristos	stop	#0
9788723221SmattEND(longjmp)
98