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.
311849Swollman */
321849Swollman
3392999Sobrien#if defined(LIBC_SCCS) && !defined(lint)
3492999Sobrien	.asciz "@(#)_setjmp.s	5.1 (Berkeley) 4/23/90"
3592999Sobrien#endif /* LIBC_SCCS and not lint */
3692999Sobrien#include <machine/asm.h>
3792999Sobrien__FBSDID("$FreeBSD$");
381849Swollman
391849Swollman/*
401849Swollman * C library -- _setjmp, _longjmp
411849Swollman *
421849Swollman *	_longjmp(a,v)
431849Swollman * will generate a "return(v)" from the last call to
441849Swollman *	_setjmp(a)
451849Swollman * by restoring registers from the environment 'a'.
461849Swollman * The previous signal state is NOT restored.
471849Swollman */
481849Swollman
4956345SjasoneENTRY(_setjmp)
50114309Speter	movq	%rdi,%rax
51114309Speter	movq	0(%rsp),%rdx		/* retval */
52115745Speter	movq	%rdx, 0(%rax)		/* 0; retval */
53115745Speter	movq	%rbx, 8(%rax)		/* 1; rbx */
54115745Speter	movq	%rsp,16(%rax)		/* 2; rsp */
55115745Speter	movq	%rbp,24(%rax)		/* 3; rbp */
56115745Speter	movq	%r12,32(%rax)		/* 4; r12 */
57115745Speter	movq	%r13,40(%rax)		/* 5; r13 */
58115745Speter	movq	%r14,48(%rax)		/* 6; r14 */
59115745Speter	movq	%r15,56(%rax)		/* 7; r15 */
60115745Speter	fnstcw	64(%rax)		/* 8; fpu cw */
61180080Sdas	stmxcsr	68(%rax)		/*    and mxcsr */
62114309Speter	xorq	%rax,%rax
631849Swollman	ret
64184547SpeterEND(_setjmp)
651849Swollman
6671579Sdeischen	.weak	CNAME(_longjmp)
6771579Sdeischen	.set	CNAME(_longjmp),CNAME(___longjmp)
6856345SjasoneENTRY(___longjmp)
69114309Speter	movq	%rdi,%rdx
70180080Sdas	/* Restore the mxcsr, but leave exception flags intact. */
71180080Sdas	stmxcsr	-4(%rsp)
72180080Sdas	movl	68(%rdx),%eax
73180080Sdas	andl	$0xffffffc0,%eax
74180080Sdas	movl	-4(%rsp),%edi
75180080Sdas	andl	$0x3f,%edi
76180080Sdas	xorl	%eax,%edi
77180080Sdas	movl	%edi,-4(%rsp)
78180080Sdas	ldmxcsr -4(%rsp)
79114309Speter	movq	%rsi,%rax		/* retval */
80114309Speter	movq	0(%rdx),%rcx
81114309Speter	movq	8(%rdx),%rbx
82114309Speter	movq	16(%rdx),%rsp
83114309Speter	movq	24(%rdx),%rbp
84114309Speter	movq	32(%rdx),%r12
85114309Speter	movq	40(%rdx),%r13
86114309Speter	movq	48(%rdx),%r14
87114309Speter	movq	56(%rdx),%r15
88114309Speter	fldcw	64(%rdx)
89114309Speter	testq	%rax,%rax
901849Swollman	jnz	1f
91114309Speter	incq	%rax
92114309Speter1:	movq	%rcx,0(%rsp)
931849Swollman	ret
94184547SpeterEND(___longjmp)
95217106Skib
96217106Skib	.section .note.GNU-stack,"",%progbits
97