xref: /netbsd-src/lib/libc/arch/sparc/gen/_setjmp.S (revision 847b24765317389e722cebf86b0ad07ad2218f57)
1*847b2476Snakayama/*	$NetBSD: _setjmp.S,v 1.10 2014/07/12 19:11:57 nakayama Exp $	*/
21394f01bSchristos
30ffda58aSpk/*-
40ffda58aSpk * Copyright (c) 1999 The NetBSD Foundation, Inc.
50ffda58aSpk * All rights reserved.
60b9f5089Scgd *
70ffda58aSpk * This code is derived from software contributed to The NetBSD Foundation
80ffda58aSpk * by Paul Kranenburg.
90b9f5089Scgd *
100b9f5089Scgd * Redistribution and use in source and binary forms, with or without
110b9f5089Scgd * modification, are permitted provided that the following conditions
120b9f5089Scgd * are met:
130b9f5089Scgd * 1. Redistributions of source code must retain the above copyright
140b9f5089Scgd *    notice, this list of conditions and the following disclaimer.
150b9f5089Scgd * 2. Redistributions in binary form must reproduce the above copyright
160b9f5089Scgd *    notice, this list of conditions and the following disclaimer in the
170b9f5089Scgd *    documentation and/or other materials provided with the distribution.
180b9f5089Scgd *
190ffda58aSpk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
200ffda58aSpk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
210ffda58aSpk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
220ffda58aSpk * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
230ffda58aSpk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
240ffda58aSpk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
250ffda58aSpk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
260ffda58aSpk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
270ffda58aSpk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
280ffda58aSpk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
290ffda58aSpk * POSSIBILITY OF SUCH DAMAGE.
300b9f5089Scgd */
310b9f5089Scgd
321394f01bSchristos#include <machine/asm.h>
330ffda58aSpk#include <machine/trap.h>
340ffda58aSpk
350b9f5089Scgd#if defined(LIBC_SCCS) && !defined(lint)
36*847b2476SnakayamaRCSID("$NetBSD: _setjmp.S,v 1.10 2014/07/12 19:11:57 nakayama Exp $")
370b9f5089Scgd#endif /* LIBC_SCCS and not lint */
380b9f5089Scgd
390b9f5089Scgd/*
400b9f5089Scgd * C library -- _setjmp, _longjmp
410b9f5089Scgd *
420b9f5089Scgd *	_longjmp(a,v)
430b9f5089Scgd * will generate a "return(v?v:1)" from
440b9f5089Scgd * the last call to
450b9f5089Scgd *	_setjmp(a)
460b9f5089Scgd * The previous signal state is NOT restored.
470b9f5089Scgd */
480b9f5089Scgd
490b9f5089ScgdENTRY(_setjmp)
50251de2deSmartin	/* store important globals, sigsetjmp compatible */
51251de2deSmartin	st	%g3, [%o0 + 16]
52251de2deSmartin	st	%g2, [%o0 + 24]
53251de2deSmartin	st	%g4, [%o0 + 48]
54251de2deSmartin	st	%g7, [%o0 + 52]
55251de2deSmartin
567e18fd4eSpk	st	%sp, [%o0+0]	/* store caller's stack pointer */
570ffda58aSpk	st	%o7, [%o0+4]	/* and the return pc */
580b9f5089Scgd	retl
590b9f5089Scgd	 clr	%o0		! return 0
600b9f5089Scgd
610b9f5089ScgdENTRY(_longjmp)
62*847b2476Snakayama#ifdef __sparc_v9__
63*847b2476Snakayama	save	%sp, -CCFSZ, %sp
64*847b2476Snakayama	flushw
65*847b2476Snakayama	/*
66*847b2476Snakayama	 * We restore the saved stack pointer to %fp, then issue
67*847b2476Snakayama	 * a `restore' instruction which will reload the register
68*847b2476Snakayama	 * window from the stack.
69*847b2476Snakayama	 */
70*847b2476Snakayama	ld	[%i0 + 16], %g3
71*847b2476Snakayama	ld	[%i0 + 24], %g2
72*847b2476Snakayama	ld	[%i0 + 48], %g4
73*847b2476Snakayama	ld	[%i0 + 52], %g7
74*847b2476Snakayama	ld	[%i0 + 4], %i7	/* restore return pc */
75*847b2476Snakayama	ld	[%i0 + 0], %fp	/* and stack pointer */
76*847b2476Snakayama	mov	1, %i0
77*847b2476Snakayama	movrnz	%i1, %i1, %i0	! compute v ? v : 1
78*847b2476Snakayama	ret
79*847b2476Snakayama	 restore
80*847b2476Snakayama#else
81*847b2476Snakayama	save	%sp, -64, %sp	! set up a local stack frame
82*847b2476Snakayama	tst	%i1		! compute v ? v : 1
830b9f5089Scgd	be,a	0f
84*847b2476Snakayama	 mov	1, %i1
850b9f5089Scgd0:
860ffda58aSpk	t	ST_FLUSHWIN	! flush register windows out to the stack
870b9f5089Scgd
88251de2deSmartin	/* restore globals */
89*847b2476Snakayama	ld	[%i0 + 16], %g3
90*847b2476Snakayama	ld	[%i0 + 24], %g2
91*847b2476Snakayama	ld	[%i0 + 48], %g4
92*847b2476Snakayama	ld	[%i0 + 52], %g7
93251de2deSmartin
940ffda58aSpk	/*
950ffda58aSpk	 * We restore the saved stack pointer to %fp, then issue
960ffda58aSpk	 * a `restore' instruction which will reload the register
970ffda58aSpk	 * window from the stack.
980ffda58aSpk	 */
99*847b2476Snakayama	ld	[%i0+4], %i7	/* restore return pc */
100*847b2476Snakayama	ld	[%i0+0], %fp	/* and stack pointer */
1010b9f5089Scgd
102*847b2476Snakayama	ret			! success, return %i1
103*847b2476Snakayama	 restore	%i1, 0, %o0
104*847b2476Snakayama#endif
105