11849Swollman/*-
21849Swollman * Copyright (c) 1990 The Regents of the University of California.
31849Swollman * All rights reserved.
41849Swollman *
51849Swollman * This code is derived from software contributed to Berkeley by
61849Swollman * William Jolitz.
71849Swollman *
81849Swollman * Redistribution and use in source and binary forms, with or without
91849Swollman * modification, are permitted provided that the following conditions
101849Swollman * are met:
111849Swollman * 1. Redistributions of source code must retain the above copyright
121849Swollman *    notice, this list of conditions and the following disclaimer.
131849Swollman * 2. Redistributions in binary form must reproduce the above copyright
141849Swollman *    notice, this list of conditions and the following disclaimer in the
151849Swollman *    documentation and/or other materials provided with the distribution.
161849Swollman * 4. Neither the name of the University nor the names of its contributors
171849Swollman *    may be used to endorse or promote products derived from this software
181849Swollman *    without specific prior written permission.
191849Swollman *
201849Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211849Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221849Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231849Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241849Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251849Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261849Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271849Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281849Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291849Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301849Swollman * SUCH DAMAGE.
3192999Sobrien *
3292999Sobrien *	@(#)setjmp.s	5.1 (Berkeley) 4/23/90"
331849Swollman */
341849Swollman
3592999Sobrien#if defined(LIBC_SCCS) && !defined(lint)
365790Sdg	.text
3792999Sobrien	.asciz "$Id: sigsetjmp.S,v 1.1 1993/12/05 13:01:05 ats Exp $"
3892999Sobrien#endif /* LIBC_SCCS and not lint */
3992999Sobrien#include <machine/asm.h>
4092999Sobrien__FBSDID("$FreeBSD$");
411849Swollman
421849Swollman#include "SYS.h"
431849Swollman
443851Sbde/*-
453851Sbde * TODO:
463851Sbde *	Rename sigsetjmp to __sigsetjmp and siglongjmp to __siglongjmp,
473851Sbde *	remove the other *jmp functions and define everything in terms
483851Sbde *	of the renamed functions.  This requires compiler support for
493851Sbde *	the renamed functions (introduced in gcc-2.5.3; previous versions
503851Sbde *	only supported *jmp with 0 or 1 leading underscores).
513851Sbde *
523851Sbde *	Restore _all_ the registers and the signal mask atomically.  Can
533851Sbde *	use sigreturn() if sigreturn() works.
543851Sbde */
553851Sbde
5656345SjasoneENTRY(sigsetjmp)
57115745Speter	movl	%esi,88(%rdi)		/* 11; savemask */
58114309Speter	testl	%esi,%esi
5915731Sjdp	jz	2f
60114829Speter	pushq	%rdi
61115738Speter	movq	%rdi,%rcx
62114829Speter	movq	$1,%rdi			/* SIG_BLOCK       */
63114309Speter	movq	$0,%rsi			/* (sigset_t*)set  */
64115745Speter	leaq	72(%rcx),%rdx		/* 9,10 (sigset_t*)oset */
65227023Skib	/* stack is 16-byte aligned */
6671579Sdeischen	call	PIC_PLT(CNAME(_sigprocmask))
67114309Speter	popq	%rdi
68114829Speter2:	movq	%rdi,%rcx
69114829Speter	movq	0(%rsp),%rdx		/* retval */
70115745Speter	movq	%rdx, 0(%rcx)		/* 0; retval */
71115745Speter	movq	%rbx, 8(%rcx)		/* 1; rbx */
72115745Speter	movq	%rsp,16(%rcx)		/* 2; rsp */
73115745Speter	movq	%rbp,24(%rcx)		/* 3; rbp */
74115745Speter	movq	%r12,32(%rcx)		/* 4; r12 */
75115745Speter	movq	%r13,40(%rcx)		/* 5; r13 */
76115745Speter	movq	%r14,48(%rcx)		/* 6; r14 */
77115745Speter	movq	%r15,56(%rcx)		/* 7; r15 */
78115745Speter	fnstcw	64(%rcx)		/* 8; fpu cw */
79114309Speter	xorq	%rax,%rax
801849Swollman	ret
81184547SpeterEND(sigsetjmp)
821849Swollman
83114309Speter	.weak CNAME(siglongjmp)
84114309Speter	.set CNAME(siglongjmp),CNAME(__siglongjmp)
85114309SpeterENTRY(__siglongjmp)
86114309Speter	cmpl	$0,88(%rdi)
8715731Sjdp	jz	2f
88114309Speter	movq	%rdi,%rdx
89114309Speter	pushq	%rdi
90114309Speter	pushq	%rsi
91114829Speter	movq	$3,%rdi			/* SIG_SETMASK     */
92114309Speter	leaq	72(%rdx),%rsi		/* (sigset_t*)set  */
93114829Speter	movq	$0,%rdx			/* (sigset_t*)oset */
94227023Skib	subq	$0x8,%rsp		/* make the stack 16-byte aligned */
9571579Sdeischen	call	PIC_PLT(CNAME(_sigprocmask))
96227023Skib	addq	$0x8,%rsp
97114309Speter	popq	%rsi
98114309Speter	popq	%rdi			/* jmpbuf */
99114309Speter2:	movq	%rdi,%rdx
100114309Speter	movq	%rsi,%rax		/* retval */
101114309Speter	movq	0(%rdx),%rcx
102114309Speter	movq	8(%rdx),%rbx
103114309Speter	movq	16(%rdx),%rsp
104114309Speter	movq	24(%rdx),%rbp
105114309Speter	movq	32(%rdx),%r12
106114309Speter	movq	40(%rdx),%r13
107114309Speter	movq	48(%rdx),%r14
108114309Speter	movq	56(%rdx),%r15
1093851Sbde	fninit
110114309Speter	fldcw	64(%rdx)
111114309Speter	testq	%rax,%rax
11215731Sjdp	jnz	1f
113114309Speter	incq	%rax
114114309Speter1:	movq	%rcx,0(%rsp)
1151849Swollman	ret
116184547SpeterEND(__siglongjmp)
117217106Skib
118217106Skib	.section .note.GNU-stack,"",%progbits
119