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. 16fbbd9655SWarner Losh * 3. 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#include <machine/asm.h> 342ceb2ce9SGarrett Wollman/* 352ceb2ce9SGarrett Wollman * C library -- _setjmp, _longjmp 362ceb2ce9SGarrett Wollman * 372ceb2ce9SGarrett Wollman * longjmp(a,v) 382ceb2ce9SGarrett Wollman * will generate a "return(v)" from the last call to 392ceb2ce9SGarrett Wollman * setjmp(a) 402ceb2ce9SGarrett Wollman * by restoring registers from the environment 'a'. 412ceb2ce9SGarrett Wollman * The previous signal state is restored. 422ceb2ce9SGarrett Wollman */ 432ceb2ce9SGarrett Wollman 442ceb2ce9SGarrett Wollman#include "SYS.h" 452ceb2ce9SGarrett Wollman 46bafd6b2fSJason EvansENTRY(setjmp) 471482008eSPeter Wemm pushq %rdi 481482008eSPeter Wemm movq %rdi,%rcx 497ef6516cSPeter Wemm movq $1,%rdi /* SIG_BLOCK */ 501482008eSPeter Wemm movq $0,%rsi /* (sigset_t*)set */ 513191d840SPeter Wemm leaq 72(%rcx),%rdx /* 9,10; (sigset_t*)oset */ 52990d5334SKonstantin Belousov /* stack is 16-byte aligned */ 53bd6060a1SKonstantin Belousov call __libc_sigprocmask 541482008eSPeter Wemm popq %rdi 551482008eSPeter Wemm movq %rdi,%rcx 56*acfd2615SDmitry Chagin movq 0(%rsp),%rdx /* return address */ 57*acfd2615SDmitry Chagin movq %rdx, 0(%rcx) /* 0; return address */ 583191d840SPeter Wemm movq %rbx, 8(%rcx) /* 1; rbx */ 593191d840SPeter Wemm movq %rsp,16(%rcx) /* 2; rsp */ 603191d840SPeter Wemm movq %rbp,24(%rcx) /* 3; rbp */ 613191d840SPeter Wemm movq %r12,32(%rcx) /* 4; r12 */ 623191d840SPeter Wemm movq %r13,40(%rcx) /* 5; r13 */ 633191d840SPeter Wemm movq %r14,48(%rcx) /* 6; r14 */ 643191d840SPeter Wemm movq %r15,56(%rcx) /* 7; r15 */ 653191d840SPeter Wemm fnstcw 64(%rcx) /* 8; fpu cw */ 6664c2e466SDavid Schultz stmxcsr 68(%rcx) /* and mxcsr */ 671482008eSPeter Wemm xorq %rax,%rax 682ceb2ce9SGarrett Wollman ret 695d053f46SPeter WemmEND(setjmp) 702ceb2ce9SGarrett Wollman 71d2ef321aSAndreas Tobler WEAK_REFERENCE(__longjmp, longjmp) 729976e592SJason EvansENTRY(__longjmp) 731482008eSPeter Wemm pushq %rdi 741482008eSPeter Wemm pushq %rsi 751482008eSPeter Wemm movq %rdi,%rdx 760b1bb81aSPeter Wemm movq $3,%rdi /* SIG_SETMASK */ 771482008eSPeter Wemm leaq 72(%rdx),%rsi /* (sigset_t*)set */ 787ef6516cSPeter Wemm movq $0,%rdx /* (sigset_t*)oset */ 79990d5334SKonstantin Belousov subq $0x8,%rsp /* make the stack 16-byte aligned */ 80bd6060a1SKonstantin Belousov call __libc_sigprocmask 81990d5334SKonstantin Belousov addq $0x8,%rsp 821482008eSPeter Wemm popq %rsi 831482008eSPeter Wemm popq %rdi /* jmpbuf */ 841482008eSPeter Wemm movq %rdi,%rdx 8564c2e466SDavid Schultz /* Restore the mxcsr, but leave exception flags intact. */ 8664c2e466SDavid Schultz stmxcsr -4(%rsp) 8764c2e466SDavid Schultz movl 68(%rdx),%eax 8864c2e466SDavid Schultz andl $0xffffffc0,%eax 8964c2e466SDavid Schultz movl -4(%rsp),%edi 9064c2e466SDavid Schultz andl $0x3f,%edi 9164c2e466SDavid Schultz xorl %eax,%edi 9264c2e466SDavid Schultz movl %edi,-4(%rsp) 9364c2e466SDavid Schultz ldmxcsr -4(%rsp) 941482008eSPeter Wemm movq %rsi,%rax /* retval */ 951482008eSPeter Wemm movq 0(%rdx),%rcx 961482008eSPeter Wemm movq 8(%rdx),%rbx 971482008eSPeter Wemm movq 16(%rdx),%rsp 981482008eSPeter Wemm movq 24(%rdx),%rbp 991482008eSPeter Wemm movq 32(%rdx),%r12 1001482008eSPeter Wemm movq 40(%rdx),%r13 1011482008eSPeter Wemm movq 48(%rdx),%r14 1021482008eSPeter Wemm movq 56(%rdx),%r15 1031482008eSPeter Wemm fldcw 64(%rdx) 1041482008eSPeter Wemm testq %rax,%rax 1052ceb2ce9SGarrett Wollman jnz 1f 1061482008eSPeter Wemm incq %rax 107*acfd2615SDmitry Chagin1: movq %rcx,0(%rsp) /* return address */ 1082ceb2ce9SGarrett Wollman ret 1095d053f46SPeter WemmEND(__longjmp) 11093ab7586SKonstantin Belousov 11193ab7586SKonstantin Belousov .section .note.GNU-stack,"",%progbits 112