xref: /csrg-svn/lib/libc/sparc/gen/_setjmp.s (revision 61168)
154385Storek/*
2*61168Sbostic * Copyright (c) 1992, 1993
3*61168Sbostic *	The Regents of the University of California.  All rights reserved.
454385Storek *
554385Storek * This software was developed by the Computer Systems Engineering group
654385Storek * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
754385Storek * contributed to Berkeley.
854385Storek *
954385Storek * %sccs.include.redist.c%
1054385Storek *
1154385Storek * from: $Header: _setjmp.s,v 1.1 91/07/06 16:45:53 torek Exp $
1254385Storek */
1354385Storek
1454385Storek#if defined(LIBC_SCCS) && !defined(lint)
15*61168Sbostic	.asciz "@(#)_setjmp.s	8.1 (Berkeley) 06/04/93"
1654385Storek#endif /* LIBC_SCCS and not lint */
1754385Storek
1854385Storek/*
1954385Storek * C library -- _setjmp, _longjmp
2054385Storek *
2154385Storek *	_longjmp(a,v)
2254385Storek * will generate a "return(v?v:1)" from
2354385Storek * the last call to
2454385Storek *	_setjmp(a)
2554385Storek * by unwinding the call stack.
2654385Storek * The previous signal state is NOT restored.
2754385Storek */
2854385Storek
2954385Storek#include "DEFS.h"
3054385Storek
3154385StorekENTRY(_setjmp)
3254385Storek	std	%sp, [%o0+0]	/* caller's stack pointer and return pc */
3354385Storek	st	%fp, [%o0+8]	/* store caller's frame pointer */
3454385Storek	retl
3554385Storek	 clr	%o0		! return 0
3654385Storek
3754385StorekENTRY(_longjmp)
3854385Storek	addcc	%o1, %g0, %g6	! compute v ? v : 1 in a global register
3954385Storek	be,a	0f
4054385Storek	 mov	1, %g6
4154385Storek0:
4254385Storek	mov	%o0, %g1	! save a in another global register
4354385Storek	ld	[%g1+8], %g7	/* get caller's frame */
4454385Storek1:
4554385Storek	cmp	%fp, %g7	! compare against desired frame
4654385Storek	bl,a	1b		! if below,
4754385Storek	 restore		!    pop frame and loop
4854385Storek	be,a	2f		! if there,
4954385Storek	 ldd	[%g1+0], %o2	!    fetch return %sp and pc, and get out
5054385Storek
5154385StorekLbotch:
5254385Storek	call	_longjmperror	! otherwise, went too far; bomb out
5354385Storek	nop
5454385Storek	unimp	0
5554385Storek
5654385Storek2:
5754385Storek	cmp	%o2, %sp	! %sp must not decrease
5854385Storek	bge,a	3f
5954385Storek	 mov	%o2, %sp	! it is OK, put it in place
6054385Storek	b,a	Lbotch
6154385Storek3:
6254385Storek	jmp	%o3 + 8		! success, return %g6
6354385Storek	 mov	%g6, %o0
64