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 */ 57990d5334SKonstantin Belousov /* stack is 16-byte aligned */ 58*bd6060a1SKonstantin Belousov call __libc_sigprocmask 591482008eSPeter Wemm popq %rdi 601482008eSPeter Wemm movq %rdi,%rcx 611482008eSPeter Wemm movq 0(%rsp),%rdx /* retval */ 623191d840SPeter Wemm movq %rdx, 0(%rcx) /* 0; retval */ 633191d840SPeter Wemm movq %rbx, 8(%rcx) /* 1; rbx */ 643191d840SPeter Wemm movq %rsp,16(%rcx) /* 2; rsp */ 653191d840SPeter Wemm movq %rbp,24(%rcx) /* 3; rbp */ 663191d840SPeter Wemm movq %r12,32(%rcx) /* 4; r12 */ 673191d840SPeter Wemm movq %r13,40(%rcx) /* 5; r13 */ 683191d840SPeter Wemm movq %r14,48(%rcx) /* 6; r14 */ 693191d840SPeter Wemm movq %r15,56(%rcx) /* 7; r15 */ 703191d840SPeter Wemm fnstcw 64(%rcx) /* 8; fpu cw */ 7164c2e466SDavid Schultz stmxcsr 68(%rcx) /* and mxcsr */ 721482008eSPeter Wemm xorq %rax,%rax 732ceb2ce9SGarrett Wollman ret 745d053f46SPeter WemmEND(setjmp) 752ceb2ce9SGarrett Wollman 76d2ef321aSAndreas Tobler WEAK_REFERENCE(__longjmp, 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 */ 84990d5334SKonstantin Belousov subq $0x8,%rsp /* make the stack 16-byte aligned */ 85*bd6060a1SKonstantin Belousov call __libc_sigprocmask 86990d5334SKonstantin Belousov addq $0x8,%rsp 871482008eSPeter Wemm popq %rsi 881482008eSPeter Wemm popq %rdi /* jmpbuf */ 891482008eSPeter Wemm movq %rdi,%rdx 9064c2e466SDavid Schultz /* Restore the mxcsr, but leave exception flags intact. */ 9164c2e466SDavid Schultz stmxcsr -4(%rsp) 9264c2e466SDavid Schultz movl 68(%rdx),%eax 9364c2e466SDavid Schultz andl $0xffffffc0,%eax 9464c2e466SDavid Schultz movl -4(%rsp),%edi 9564c2e466SDavid Schultz andl $0x3f,%edi 9664c2e466SDavid Schultz xorl %eax,%edi 9764c2e466SDavid Schultz movl %edi,-4(%rsp) 9864c2e466SDavid Schultz ldmxcsr -4(%rsp) 991482008eSPeter Wemm movq %rsi,%rax /* retval */ 1001482008eSPeter Wemm movq 0(%rdx),%rcx 1011482008eSPeter Wemm movq 8(%rdx),%rbx 1021482008eSPeter Wemm movq 16(%rdx),%rsp 1031482008eSPeter Wemm movq 24(%rdx),%rbp 1041482008eSPeter Wemm movq 32(%rdx),%r12 1051482008eSPeter Wemm movq 40(%rdx),%r13 1061482008eSPeter Wemm movq 48(%rdx),%r14 1071482008eSPeter Wemm movq 56(%rdx),%r15 1081482008eSPeter Wemm fldcw 64(%rdx) 1091482008eSPeter Wemm testq %rax,%rax 1102ceb2ce9SGarrett Wollman jnz 1f 1111482008eSPeter Wemm incq %rax 1121482008eSPeter Wemm1: movq %rcx,0(%rsp) 1132ceb2ce9SGarrett Wollman ret 1145d053f46SPeter WemmEND(__longjmp) 11593ab7586SKonstantin Belousov 11693ab7586SKonstantin Belousov .section .note.GNU-stack,"",%progbits 117