xref: /minix3/lib/libc/arch/sparc64/gen/setjmp.S (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc/*	$NetBSD: setjmp.S,v 1.10 2013/09/12 15:36:16 joerg Exp $	*/
22fe8fb19SBen Gras
32fe8fb19SBen Gras/*
42fe8fb19SBen Gras * Copyright (c) 1992, 1993
52fe8fb19SBen Gras *	The Regents of the University of California.  All rights reserved.
62fe8fb19SBen Gras *
72fe8fb19SBen Gras * This software was developed by the Computer Systems Engineering group
82fe8fb19SBen Gras * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
92fe8fb19SBen Gras * contributed to Berkeley.
102fe8fb19SBen Gras *
112fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without
122fe8fb19SBen Gras * modification, are permitted provided that the following conditions
132fe8fb19SBen Gras * are met:
142fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright
152fe8fb19SBen Gras *    notice, this list of conditions and the following disclaimer.
162fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
172fe8fb19SBen Gras *    notice, this list of conditions and the following disclaimer in the
182fe8fb19SBen Gras *    documentation and/or other materials provided with the distribution.
192fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors
202fe8fb19SBen Gras *    may be used to endorse or promote products derived from this software
212fe8fb19SBen Gras *    without specific prior written permission.
222fe8fb19SBen Gras *
232fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
242fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
252fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
262fe8fb19SBen Gras * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
272fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
282fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
292fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
302fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
312fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
322fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
332fe8fb19SBen Gras * SUCH DAMAGE.
342fe8fb19SBen Gras *
352fe8fb19SBen Gras * from: Header: setjmp.s,v 1.2 92/06/25 03:18:43 torek Exp
362fe8fb19SBen Gras */
372fe8fb19SBen Gras
382fe8fb19SBen Gras#define _LOCORE
392fe8fb19SBen Gras#include <machine/asm.h>
402fe8fb19SBen Gras#include <machine/frame.h>
412fe8fb19SBen Gras#if defined(LIBC_SCCS) && !defined(lint)
422fe8fb19SBen Gras#if 0
432fe8fb19SBen Gras	.asciz "@(#)setjmp.s	8.1 (Berkeley) 6/4/93"
442fe8fb19SBen Gras#else
45*84d9c625SLionel Sambuc	RCSID("$NetBSD: setjmp.S,v 1.10 2013/09/12 15:36:16 joerg Exp $")
462fe8fb19SBen Gras#endif
472fe8fb19SBen Gras#endif /* LIBC_SCCS and not lint */
482fe8fb19SBen Gras
492fe8fb19SBen Gras/*
502fe8fb19SBen Gras * C library -- setjmp
512fe8fb19SBen Gras *
522fe8fb19SBen Gras *	__longjmp14(a,v)
532fe8fb19SBen Gras * will generate a "return(v)" from
542fe8fb19SBen Gras * the last call to
552fe8fb19SBen Gras *	setjmp(a)
562fe8fb19SBen Gras * by restoring registers from the stack,
572fe8fb19SBen Gras * and a struct sigcontext, see <signal.h>
582fe8fb19SBen Gras */
592fe8fb19SBen Gras
602fe8fb19SBen Gras#include "SYS.h"
612fe8fb19SBen Gras
622fe8fb19SBen Gras	.register %g2,#ignore
632fe8fb19SBen Gras	.register %g3,#ignore
642fe8fb19SBen Gras	.register %g6,#ignore
652fe8fb19SBen Gras
662fe8fb19SBen GrasENTRY(__setjmp14)
672fe8fb19SBen Gras	save	%sp, -CC64FSZ, %sp
682fe8fb19SBen Gras
692fe8fb19SBen Gras	/* save globals into locals */
702fe8fb19SBen Gras	mov	%g1, %l1
712fe8fb19SBen Gras	mov	%g2, %l2
722fe8fb19SBen Gras	mov	%g3, %l3
732fe8fb19SBen Gras	mov	%g4, %l4
742fe8fb19SBen Gras	mov	%g5, %l5
752fe8fb19SBen Gras	mov	%g6, %l6
762fe8fb19SBen Gras	mov	%g7, %l7
772fe8fb19SBen Gras
78*84d9c625SLionel Sambuc#ifdef __PIC__
792fe8fb19SBen Gras	PIC_PROLOGUE(%i1, %o4)
802fe8fb19SBen Gras#endif
812fe8fb19SBen Gras
822fe8fb19SBen Gras	/* now get sigmask and onstack flag */
832fe8fb19SBen Gras	add	%i0, 0x38, %o2		/* build sigcontext in [%o2]->sc.sc_mask */
842fe8fb19SBen Gras	mov	1, %o0			/* SIG_BLOCK */
852fe8fb19SBen Gras					/* sigprocmask(SIG_BLOCK, (sigset_t *)NULL, (sigset_t *)a) */
86*84d9c625SLionel Sambuc#if __PIC__ - 0 >= 2
872fe8fb19SBen Gras	set	_C_LABEL(__sigprocmask14), %o4
882fe8fb19SBen Gras	ldx	[%i1 + %o4], %g2
89*84d9c625SLionel Sambuc	call	%g2
90*84d9c625SLionel Sambuc#elif __PIC__ - 0 >= 1
912fe8fb19SBen Gras	ldx	[%i1 + _C_LABEL(__sigprocmask14)], %g2
922fe8fb19SBen Gras	call	%g2
932fe8fb19SBen Gras#else
942fe8fb19SBen Gras	call	_C_LABEL(__sigprocmask14)
952fe8fb19SBen Gras#endif
962fe8fb19SBen Gras	 clr	%o1
972fe8fb19SBen Gras
982fe8fb19SBen Gras	clr	%o0			/* sigstack(NULL, &foo) */
99*84d9c625SLionel Sambuc#if __PIC__ - 0 >= 2
1002fe8fb19SBen Gras	set	_C_LABEL(__sigaltstack14), %o4
1012fe8fb19SBen Gras	ldx	[%i1 + %o4], %g2
102*84d9c625SLionel Sambuc	call	%g2
103*84d9c625SLionel Sambuc#elif __PIC__ - 0 >= 1
1042fe8fb19SBen Gras	ldx	[%i1 + _C_LABEL(__sigaltstack14)], %g2
1052fe8fb19SBen Gras	call	%g2
1062fe8fb19SBen Gras#else
1072fe8fb19SBen Gras	call	_C_LABEL(__sigaltstack14)
1082fe8fb19SBen Gras#endif
1092fe8fb19SBen Gras	 add	%i0, 8, %o1		/* (foo being part of the sigcontext we're overwriting) */
1102fe8fb19SBen Gras
1112fe8fb19SBen Gras	lduw	[%i0 + 8 + 0x10], %o0	/* foo.ss_flags */
1122fe8fb19SBen Gras	and	%o0, 1, %o1		/* onstack = foo.ss_flags & SS_ONSTACK; */
1132fe8fb19SBen Gras	st	%o1, [%i0 + 0x00]	/* sc.sc_onstack = current onstack; */
1142fe8fb19SBen Gras
1152fe8fb19SBen Gras	/* store essential state */
1162fe8fb19SBen Gras	stx	%fp, [%i0 + 0x08]	/* sc.sc_sp = sp */
1172fe8fb19SBen Gras	add	%i7, 8, %o0
1182fe8fb19SBen Gras	stx	%o0, [%i0 + 0x10]	/* sc.sc_pc = return_pc */
1192fe8fb19SBen Gras	stx	%g0, [%i0 + 0x20]	/* sc.sc_tstate = (clean ccr) */
1202fe8fb19SBen Gras	stx	%l1, [%i0 + 0x28]	/* sc.sc_g1 */
1212fe8fb19SBen Gras	stx	%l2, [%i0 + 0x30]	/* sc.sc_o0, set in longjmp, use as %g2 */
122e415d488SLionel Sambuc	/* 0x38: 4x32bit */		/* sc.sc_mask was already saved above */
1232fe8fb19SBen Gras
1242fe8fb19SBen Gras	/* save additional registers needed to fill a complete mcontext */
125e415d488SLionel Sambuc	stx	%l3, [%i0 + 0x48]	/* adjust asserts in longjmp.c */
126e415d488SLionel Sambuc	stx	%l6, [%i0 + 0x50]	/* if you change any of these */
127e415d488SLionel Sambuc	stx	%l7, [%i0 + 0x58]	/* offsets! */
1282fe8fb19SBen Gras
1292fe8fb19SBen Gras	ret				/* return 0 */
1302fe8fb19SBen Gras	 restore %g0, 0, %o0
131