xref: /freebsd/lib/libc/amd64/gen/setjmp.S (revision 5d053f461caeb73f6de165aa1e07b2003101605c)
12ceb2ce9SGarrett Wollman/*-
22ceb2ce9SGarrett Wollman * Copyright (c) 1990 The Regents of the University of California.
32ceb2ce9SGarrett Wollman * All rights reserved.
42ceb2ce9SGarrett Wollman *
52ceb2ce9SGarrett Wollman * This code is derived from software contributed to Berkeley by
62ceb2ce9SGarrett Wollman * William Jolitz.
72ceb2ce9SGarrett Wollman *
82ceb2ce9SGarrett Wollman * Redistribution and use in source and binary forms, with or without
92ceb2ce9SGarrett Wollman * modification, are permitted provided that the following conditions
102ceb2ce9SGarrett Wollman * are met:
112ceb2ce9SGarrett Wollman * 1. Redistributions of source code must retain the above copyright
122ceb2ce9SGarrett Wollman *    notice, this list of conditions and the following disclaimer.
132ceb2ce9SGarrett Wollman * 2. Redistributions in binary form must reproduce the above copyright
142ceb2ce9SGarrett Wollman *    notice, this list of conditions and the following disclaimer in the
152ceb2ce9SGarrett Wollman *    documentation and/or other materials provided with the distribution.
162ceb2ce9SGarrett Wollman * 4. Neither the name of the University nor the names of its contributors
172ceb2ce9SGarrett Wollman *    may be used to endorse or promote products derived from this software
182ceb2ce9SGarrett Wollman *    without specific prior written permission.
192ceb2ce9SGarrett Wollman *
202ceb2ce9SGarrett Wollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
212ceb2ce9SGarrett Wollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
222ceb2ce9SGarrett Wollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
232ceb2ce9SGarrett Wollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
242ceb2ce9SGarrett Wollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
252ceb2ce9SGarrett Wollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
262ceb2ce9SGarrett Wollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
272ceb2ce9SGarrett Wollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
282ceb2ce9SGarrett Wollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
292ceb2ce9SGarrett Wollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
302ceb2ce9SGarrett Wollman * SUCH DAMAGE.
312ceb2ce9SGarrett Wollman */
322ceb2ce9SGarrett Wollman
330f4f0285SDavid E. O'Brien#if defined(LIBC_SCCS) && !defined(lint)
340f4f0285SDavid E. O'Brien	.asciz "@(#)setjmp.s	5.1 (Berkeley) 4/23/90"
350f4f0285SDavid E. O'Brien#endif /* LIBC_SCCS and not lint */
360f4f0285SDavid E. O'Brien#include <machine/asm.h>
370f4f0285SDavid E. O'Brien__FBSDID("$FreeBSD$");
382ceb2ce9SGarrett Wollman
392ceb2ce9SGarrett Wollman/*
402ceb2ce9SGarrett Wollman * C library -- _setjmp, _longjmp
412ceb2ce9SGarrett Wollman *
422ceb2ce9SGarrett Wollman *	longjmp(a,v)
432ceb2ce9SGarrett Wollman * will generate a "return(v)" from the last call to
442ceb2ce9SGarrett Wollman *	setjmp(a)
452ceb2ce9SGarrett Wollman * by restoring registers from the environment 'a'.
462ceb2ce9SGarrett Wollman * The previous signal state is restored.
472ceb2ce9SGarrett Wollman */
482ceb2ce9SGarrett Wollman
492ceb2ce9SGarrett Wollman#include "SYS.h"
502ceb2ce9SGarrett Wollman
51bafd6b2fSJason EvansENTRY(setjmp)
521482008eSPeter Wemm	pushq	%rdi
531482008eSPeter Wemm	movq	%rdi,%rcx
547ef6516cSPeter Wemm	movq	$1,%rdi			/* SIG_BLOCK       */
551482008eSPeter Wemm	movq	$0,%rsi			/* (sigset_t*)set  */
563191d840SPeter Wemm	leaq	72(%rcx),%rdx		/* 9,10; (sigset_t*)oset */
57d201fe46SDaniel Eischen	call	PIC_PLT(CNAME(_sigprocmask))
581482008eSPeter Wemm	popq	%rdi
591482008eSPeter Wemm	movq	%rdi,%rcx
601482008eSPeter Wemm	movq	0(%rsp),%rdx		/* retval */
613191d840SPeter Wemm	movq	%rdx, 0(%rcx)		/* 0; retval */
623191d840SPeter Wemm	movq	%rbx, 8(%rcx)		/* 1; rbx */
633191d840SPeter Wemm	movq	%rsp,16(%rcx)		/* 2; rsp */
643191d840SPeter Wemm	movq	%rbp,24(%rcx)		/* 3; rbp */
653191d840SPeter Wemm	movq	%r12,32(%rcx)		/* 4; r12 */
663191d840SPeter Wemm	movq	%r13,40(%rcx)		/* 5; r13 */
673191d840SPeter Wemm	movq	%r14,48(%rcx)		/* 6; r14 */
683191d840SPeter Wemm	movq	%r15,56(%rcx)		/* 7; r15 */
693191d840SPeter Wemm	fnstcw	64(%rcx)		/* 8; fpu cw */
7064c2e466SDavid Schultz	stmxcsr	68(%rcx)		/*    and mxcsr */
711482008eSPeter Wemm	xorq	%rax,%rax
722ceb2ce9SGarrett Wollman	ret
735d053f46SPeter WemmEND(setjmp)
742ceb2ce9SGarrett Wollman
75d201fe46SDaniel Eischen	.weak CNAME(longjmp)
76d201fe46SDaniel Eischen	.set CNAME(longjmp),CNAME(__longjmp)
779976e592SJason EvansENTRY(__longjmp)
781482008eSPeter Wemm	pushq	%rdi
791482008eSPeter Wemm	pushq	%rsi
801482008eSPeter Wemm	movq	%rdi,%rdx
810b1bb81aSPeter Wemm	movq	$3,%rdi			/* SIG_SETMASK     */
821482008eSPeter Wemm	leaq	72(%rdx),%rsi		/* (sigset_t*)set  */
837ef6516cSPeter Wemm	movq	$0,%rdx			/* (sigset_t*)oset */
84d201fe46SDaniel Eischen	call	PIC_PLT(CNAME(_sigprocmask))
851482008eSPeter Wemm	popq	%rsi
861482008eSPeter Wemm	popq	%rdi			/* jmpbuf */
871482008eSPeter Wemm	movq	%rdi,%rdx
8864c2e466SDavid Schultz	/* Restore the mxcsr, but leave exception flags intact. */
8964c2e466SDavid Schultz	stmxcsr	-4(%rsp)
9064c2e466SDavid Schultz	movl	68(%rdx),%eax
9164c2e466SDavid Schultz	andl	$0xffffffc0,%eax
9264c2e466SDavid Schultz	movl	-4(%rsp),%edi
9364c2e466SDavid Schultz	andl	$0x3f,%edi
9464c2e466SDavid Schultz	xorl	%eax,%edi
9564c2e466SDavid Schultz	movl	%edi,-4(%rsp)
9664c2e466SDavid Schultz	ldmxcsr -4(%rsp)
971482008eSPeter Wemm	movq	%rsi,%rax		/* retval */
981482008eSPeter Wemm	movq	0(%rdx),%rcx
991482008eSPeter Wemm	movq	8(%rdx),%rbx
1001482008eSPeter Wemm	movq	16(%rdx),%rsp
1011482008eSPeter Wemm	movq	24(%rdx),%rbp
1021482008eSPeter Wemm	movq	32(%rdx),%r12
1031482008eSPeter Wemm	movq	40(%rdx),%r13
1041482008eSPeter Wemm	movq	48(%rdx),%r14
1051482008eSPeter Wemm	movq	56(%rdx),%r15
1061482008eSPeter Wemm	fldcw	64(%rdx)
1071482008eSPeter Wemm	testq	%rax,%rax
1082ceb2ce9SGarrett Wollman	jnz	1f
1091482008eSPeter Wemm	incq	%rax
1101482008eSPeter Wemm1:	movq	%rcx,0(%rsp)
1112ceb2ce9SGarrett Wollman	ret
1125d053f46SPeter WemmEND(__longjmp)
113