xref: /original-bsd/lib/libc/sparc/gen/_setjmp.s (revision c3e32dec)
1/*
2 * Copyright (c) 1992, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This software was developed by the Computer Systems Engineering group
6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 * contributed to Berkeley.
8 *
9 * %sccs.include.redist.c%
10 *
11 * from: $Header: _setjmp.s,v 1.1 91/07/06 16:45:53 torek Exp $
12 */
13
14#if defined(LIBC_SCCS) && !defined(lint)
15	.asciz "@(#)_setjmp.s	8.1 (Berkeley) 06/04/93"
16#endif /* LIBC_SCCS and not lint */
17
18/*
19 * C library -- _setjmp, _longjmp
20 *
21 *	_longjmp(a,v)
22 * will generate a "return(v?v:1)" from
23 * the last call to
24 *	_setjmp(a)
25 * by unwinding the call stack.
26 * The previous signal state is NOT restored.
27 */
28
29#include "DEFS.h"
30
31ENTRY(_setjmp)
32	std	%sp, [%o0+0]	/* caller's stack pointer and return pc */
33	st	%fp, [%o0+8]	/* store caller's frame pointer */
34	retl
35	 clr	%o0		! return 0
36
37ENTRY(_longjmp)
38	addcc	%o1, %g0, %g6	! compute v ? v : 1 in a global register
39	be,a	0f
40	 mov	1, %g6
410:
42	mov	%o0, %g1	! save a in another global register
43	ld	[%g1+8], %g7	/* get caller's frame */
441:
45	cmp	%fp, %g7	! compare against desired frame
46	bl,a	1b		! if below,
47	 restore		!    pop frame and loop
48	be,a	2f		! if there,
49	 ldd	[%g1+0], %o2	!    fetch return %sp and pc, and get out
50
51Lbotch:
52	call	_longjmperror	! otherwise, went too far; bomb out
53	nop
54	unimp	0
55
562:
57	cmp	%o2, %sp	! %sp must not decrease
58	bge,a	3f
59	 mov	%o2, %sp	! it is OK, put it in place
60	b,a	Lbotch
613:
62	jmp	%o3 + 8		! success, return %g6
63	 mov	%g6, %o0
64