_setjmp.S revision 99018
185518Sjake/*
285518Sjake * Copyright (c) 1992, 1993
385518Sjake *	The Regents of the University of California.  All rights reserved.
485518Sjake *
585518Sjake * This software was developed by the Computer Systems Engineering group
685518Sjake * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
785518Sjake * contributed to Berkeley.
885518Sjake *
985518Sjake * Redistribution and use in source and binary forms, with or without
1085518Sjake * modification, are permitted provided that the following conditions
1185518Sjake * are met:
1285518Sjake * 1. Redistributions of source code must retain the above copyright
1385518Sjake *    notice, this list of conditions and the following disclaimer.
1485518Sjake * 2. Redistributions in binary form must reproduce the above copyright
1585518Sjake *    notice, this list of conditions and the following disclaimer in the
1685518Sjake *    documentation and/or other materials provided with the distribution.
1785518Sjake * 3. All advertising materials mentioning features or use of this software
1885518Sjake *    must display the following acknowledgement:
1985518Sjake *	This product includes software developed by the University of
2085518Sjake *	California, Berkeley and its contributors.
2185518Sjake * 4. Neither the name of the University nor the names of its contributors
2285518Sjake *    may be used to endorse or promote products derived from this software
2385518Sjake *    without specific prior written permission.
2485518Sjake *
2585518Sjake * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2685518Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2785518Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2885518Sjake * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2985518Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3085518Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3185518Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3285518Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3385518Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3485518Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3585518Sjake * SUCH DAMAGE.
3685518Sjake *
3785518Sjake *	from: Header: _setjmp.s,v 1.1 91/07/06 16:45:53 torek Exp
3885518Sjake */
3985518Sjake
4085518Sjake#if defined(LIBC_SCCS) && !defined(lint)
4199018Sobrien	.asciz "@(#)_setjmp.s	8.1 (Berkeley) 6/4/93"
4285518Sjake#if 0
4385518Sjake	RCSID("$NetBSD: _setjmp.S,v 1.4 1998/10/08 02:27:59 eeh Exp $")
4485518Sjake#endif
4585518Sjake#endif /* LIBC_SCCS and not lint */
4685518Sjake#include <machine/asm.h>
4799018Sobrien__FBSDID("$FreeBSD: head/lib/libc/sparc64/gen/_setjmp.S 99018 2002-06-29 03:23:51Z obrien $");
4885518Sjake
4986534Sjake#include "assym.s"
5086534Sjake
5188609Sjake	.register %g2,#ignore
5288609Sjake	.register %g3,#ignore
5388609Sjake
5485518Sjake/*
5585518Sjake * C library -- _setjmp, _longjmp
5685518Sjake *
5785518Sjake *	_longjmp(a,v)
5885518Sjake * will generate a "return(v?v:1)" from
5985518Sjake * the last call to
6085518Sjake *	_setjmp(a)
6185518Sjake * by unwinding the call stack.
6285518Sjake * The previous signal state is NOT restored.
6385518Sjake */
6485518Sjake
6585518SjakeENTRY(_setjmp)
6688609Sjake	stx	%sp, [%o0 + _JB_SP]
6788609Sjake	stx	%o7, [%o0 + _JB_PC]
6888609Sjake	stx	%fp, [%o0 + _JB_FP]
6985518Sjake	retl
7086534Sjake	 clr	%o0
7186534SjakeEND(_setjmp)
7285518Sjake
7385518SjakeENTRY(_longjmp)
7486534Sjake	mov	1, %g1
7586534Sjake	movrnz	%o1, %o1, %g1			! compute v ? v : 1
7686534Sjake	mov	%o0, %g2
7788609Sjake	ldx	[%g2 + _JB_FP], %g3		! fetch callers frame
7886534Sjake1:	cmp	%fp, %g3			! compare against desired frame
7986534Sjake	bl,a	1b				! if below,
8086534Sjake	 restore				!    pop frame and loop
8186534Sjake	be,a	2f				! if there,
8288609Sjake	 ldx	[%g2 + _JB_SP], %o0		!    fetch return %sp
8385518Sjake
8485518Sjake.Lbotch:
8586534Sjake	call	CNAME(longjmperror)
8685518Sjake	 nop
8788609Sjake	call	CNAME(abort)
8888609Sjake	 nop
8985518Sjake	illtrap
9085518Sjake
9186534Sjake2:	cmp	%o0, %sp			! %sp must not decrease
9285518Sjake	bge,a	3f
9386534Sjake	 mov	%o0, %sp			! it is OK, put it in place
9485518Sjake	b,a	.Lbotch
9585518Sjake	 nop
9688609Sjake3:	ldx	[%g2 + _JB_PC], %o7		! fetch return address
9786534Sjake	retl
9886534Sjake	 mov	%g1, %o0			! return v ? v : 1;
9986534SjakeEND(_longjmp)
100