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 * 3. All advertising materials mentioning features or use of this software 172ceb2ce9SGarrett Wollman * must display the following acknowledgement: 182ceb2ce9SGarrett Wollman * This product includes software developed by the University of 192ceb2ce9SGarrett Wollman * California, Berkeley and its contributors. 202ceb2ce9SGarrett Wollman * 4. Neither the name of the University nor the names of its contributors 212ceb2ce9SGarrett Wollman * may be used to endorse or promote products derived from this software 222ceb2ce9SGarrett Wollman * without specific prior written permission. 232ceb2ce9SGarrett Wollman * 242ceb2ce9SGarrett Wollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 252ceb2ce9SGarrett Wollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 262ceb2ce9SGarrett Wollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 272ceb2ce9SGarrett Wollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 282ceb2ce9SGarrett Wollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 292ceb2ce9SGarrett Wollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 302ceb2ce9SGarrett Wollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 312ceb2ce9SGarrett Wollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 322ceb2ce9SGarrett Wollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 332ceb2ce9SGarrett Wollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 342ceb2ce9SGarrett Wollman * SUCH DAMAGE. 352ceb2ce9SGarrett Wollman */ 362ceb2ce9SGarrett Wollman 370f4f0285SDavid E. O'Brien#if defined(LIBC_SCCS) && !defined(lint) 380f4f0285SDavid E. O'Brien .asciz "@(#)setjmp.s 5.1 (Berkeley) 4/23/90" 390f4f0285SDavid E. O'Brien#endif /* LIBC_SCCS and not lint */ 400f4f0285SDavid E. O'Brien#include <machine/asm.h> 410f4f0285SDavid E. O'Brien__FBSDID("$FreeBSD$"); 422ceb2ce9SGarrett Wollman 432ceb2ce9SGarrett Wollman/* 442ceb2ce9SGarrett Wollman * C library -- _setjmp, _longjmp 452ceb2ce9SGarrett Wollman * 462ceb2ce9SGarrett Wollman * longjmp(a,v) 472ceb2ce9SGarrett Wollman * will generate a "return(v)" from the last call to 482ceb2ce9SGarrett Wollman * setjmp(a) 492ceb2ce9SGarrett Wollman * by restoring registers from the environment 'a'. 502ceb2ce9SGarrett Wollman * The previous signal state is restored. 512ceb2ce9SGarrett Wollman */ 522ceb2ce9SGarrett Wollman 532ceb2ce9SGarrett Wollman#include "SYS.h" 542ceb2ce9SGarrett Wollman 55bafd6b2fSJason EvansENTRY(setjmp) 561482008eSPeter Wemm pushq %rdi 571482008eSPeter Wemm movq %rdi,%rcx 587ef6516cSPeter Wemm movq $1,%rdi /* SIG_BLOCK */ 591482008eSPeter Wemm movq $0,%rsi /* (sigset_t*)set */ 607ef6516cSPeter Wemm leaq 72(%rcx),%rdx /* (sigset_t*)oset */ 61d201fe46SDaniel Eischen call PIC_PLT(CNAME(_sigprocmask)) 621482008eSPeter Wemm popq %rdi 631482008eSPeter Wemm movq %rdi,%rcx 641482008eSPeter Wemm movq 0(%rsp),%rdx /* retval */ 651482008eSPeter Wemm movq %rdx, 0(%rcx) /* retval */ 661482008eSPeter Wemm movq %rbx, 8(%rcx) 671482008eSPeter Wemm movq %rsp,16(%rcx) 681482008eSPeter Wemm movq %rbp,24(%rcx) 691482008eSPeter Wemm movq %r12,32(%rcx) 701482008eSPeter Wemm movq %r13,40(%rcx) 711482008eSPeter Wemm movq %r14,48(%rcx) 721482008eSPeter Wemm movq %r15,56(%rcx) 731482008eSPeter Wemm fnstcw 64(%rcx) 741482008eSPeter Wemm xorq %rax,%rax 752ceb2ce9SGarrett Wollman ret 762ceb2ce9SGarrett Wollman 77d201fe46SDaniel Eischen .weak CNAME(longjmp) 78d201fe46SDaniel Eischen .set CNAME(longjmp),CNAME(__longjmp) 799976e592SJason EvansENTRY(__longjmp) 801482008eSPeter Wemm pushq %rdi 811482008eSPeter Wemm pushq %rsi 821482008eSPeter Wemm movq %rdi,%rdx 837ef6516cSPeter Wemm movq $1,%rdi /* SIG_SETMASK */ 841482008eSPeter Wemm leaq 72(%rdx),%rsi /* (sigset_t*)set */ 857ef6516cSPeter Wemm movq $0,%rdx /* (sigset_t*)oset */ 86d201fe46SDaniel Eischen call PIC_PLT(CNAME(_sigprocmask)) 871482008eSPeter Wemm popq %rsi 881482008eSPeter Wemm popq %rdi /* jmpbuf */ 891482008eSPeter Wemm movq %rdi,%rdx 901482008eSPeter Wemm movq %rsi,%rax /* retval */ 911482008eSPeter Wemm movq 0(%rdx),%rcx 921482008eSPeter Wemm movq 8(%rdx),%rbx 931482008eSPeter Wemm movq 16(%rdx),%rsp 941482008eSPeter Wemm movq 24(%rdx),%rbp 951482008eSPeter Wemm movq 32(%rdx),%r12 961482008eSPeter Wemm movq 40(%rdx),%r13 971482008eSPeter Wemm movq 48(%rdx),%r14 981482008eSPeter Wemm movq 56(%rdx),%r15 992ceb2ce9SGarrett Wollman fninit 1001482008eSPeter Wemm fldcw 64(%rdx) 1011482008eSPeter Wemm testq %rax,%rax 1022ceb2ce9SGarrett Wollman jnz 1f 1031482008eSPeter Wemm incq %rax 1041482008eSPeter Wemm1: movq %rcx,0(%rsp) 1052ceb2ce9SGarrett Wollman ret 106