xref: /netbsd-src/lib/libc/arch/sparc64/gen/_setjmp.S (revision b549c6746970e078134af04fa34af510d91655fd)
1*b549c674Smartin/*	$NetBSD: _setjmp.S,v 1.7 2011/04/30 19:43:17 martin Exp $	*/
2cf009bccSeeh
3cf009bccSeeh/*
4cf009bccSeeh * Copyright (c) 1992, 1993
5cf009bccSeeh *	The Regents of the University of California.  All rights reserved.
6cf009bccSeeh *
7cf009bccSeeh * This software was developed by the Computer Systems Engineering group
8cf009bccSeeh * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9cf009bccSeeh * contributed to Berkeley.
10cf009bccSeeh *
11cf009bccSeeh * Redistribution and use in source and binary forms, with or without
12cf009bccSeeh * modification, are permitted provided that the following conditions
13cf009bccSeeh * are met:
14cf009bccSeeh * 1. Redistributions of source code must retain the above copyright
15cf009bccSeeh *    notice, this list of conditions and the following disclaimer.
16cf009bccSeeh * 2. Redistributions in binary form must reproduce the above copyright
17cf009bccSeeh *    notice, this list of conditions and the following disclaimer in the
18cf009bccSeeh *    documentation and/or other materials provided with the distribution.
19eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
20cf009bccSeeh *    may be used to endorse or promote products derived from this software
21cf009bccSeeh *    without specific prior written permission.
22cf009bccSeeh *
23cf009bccSeeh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24cf009bccSeeh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25cf009bccSeeh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26cf009bccSeeh * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27cf009bccSeeh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28cf009bccSeeh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29cf009bccSeeh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30cf009bccSeeh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31cf009bccSeeh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32cf009bccSeeh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33cf009bccSeeh * SUCH DAMAGE.
34cf009bccSeeh *
35cf009bccSeeh * from: Header: _setjmp.s,v 1.1 91/07/06 16:45:53 torek Exp
36cf009bccSeeh */
37cf009bccSeeh
38cf009bccSeeh#include <machine/asm.h>
39cf009bccSeeh#if defined(LIBC_SCCS) && !defined(lint)
40cf009bccSeeh#if 0
41cf009bccSeeh	.asciz "@(#)_setjmp.s	8.1 (Berkeley) 6/4/93"
42cf009bccSeeh#else
43*b549c674Smartin	RCSID("$NetBSD: _setjmp.S,v 1.7 2011/04/30 19:43:17 martin Exp $")
44cf009bccSeeh#endif
45cf009bccSeeh#endif /* LIBC_SCCS and not lint */
46cf009bccSeeh
47*b549c674Smartin	.register %g2,#ignore
48*b549c674Smartin	.register %g3,#ignore
49*b549c674Smartin
50cf009bccSeeh/*
51cf009bccSeeh * C library -- _setjmp, _longjmp
52cf009bccSeeh *
53cf009bccSeeh *	_longjmp(a,v)
54cf009bccSeeh * will generate a "return(v?v:1)" from
55cf009bccSeeh * the last call to
56cf009bccSeeh *	_setjmp(a)
57cf009bccSeeh * The previous signal state is NOT restored.
58cf009bccSeeh */
59cf009bccSeeh
60cf009bccSeehENTRY(_setjmp)
61528e949bSmartin	stx	%sp, [%o0+0]	/* store caller's stack pointer */
62528e949bSmartin	stx	%o7, [%o0+8]	/* and return pc */
63*b549c674Smartin	stx	%g0, [%o0+0x18]	/* mark as non-sigmask jmpbuf */
64*b549c674Smartin
65*b549c674Smartin	/* store globals, offsets compatible with siglongjmp */
66*b549c674Smartin	stx	%g1, [%o0+0x28]
67*b549c674Smartin	stx	%g2, [%o0+0x30]		/* adjust asserts in longjmp.c */
68*b549c674Smartin	stx	%g3, [%o0+0x48]		/* if you change any of these */
69*b549c674Smartin	stx	%g6, [%o0+0x50]		/* offsets! */
70*b549c674Smartin	stx	%g7, [%o0+0x58]
71*b549c674Smartin
72cf009bccSeeh	retl
73cf009bccSeeh	 clr	%o0		! return 0
74cf009bccSeeh
75cf009bccSeehENTRY(_longjmp)
76528e949bSmartin	save	%sp, -CC64FSZ, %sp
77528e949bSmartin	flushw
78528e949bSmartin	/*
79528e949bSmartin	 * We restore the saved stack pointer to %fp, then issue
80528e949bSmartin	 * a `restore' instruction which will reload the register
81528e949bSmartin	 * window from the stack.
82528e949bSmartin	 */
83*b549c674Smartin	ldx	[%i0+0x28],%g1
84*b549c674Smartin	ldx	[%i0+0x30],%g2
85*b549c674Smartin	ldx	[%i0+0x48],%g3
86*b549c674Smartin	ldx	[%i0+0x50],%g6
87*b549c674Smartin	ldx	[%i0+0x58],%g7
88528e949bSmartin	ldx	[%i0+8], %i7
89528e949bSmartin	ldx	[%i0+0], %fp
90528e949bSmartin	mov	1, %i0
91528e949bSmartin	movrnz	%i1, %i1, %i0	! compute v ? v : 1
92528e949bSmartin	ret
93528e949bSmartin	 restore
94