/*-1* Copyright (c) 1990 The Regents of the University of California.2* All rights reserved.3*4* This code is derived from software contributed to Berkeley by5* William Jolitz.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15* 3. Neither the name of the University nor the names of its contributors16* may be used to endorse or promote products derived from this software17* without specific prior written permission.18*19* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*/3132#include <machine/asm.h>33/*34* C library -- _setjmp, _longjmp35*36* longjmp(a,v)37* will generate a "return(v)" from the last call to38* setjmp(a)39* by restoring registers from the environment 'a'.40* The previous signal state is restored.41*/4243#include "SYS.h"4445ENTRY(setjmp)46pushq %rdi47movq %rdi,%rcx48movq $1,%rdi /* SIG_BLOCK */49movq $0,%rsi /* (sigset_t*)set */50leaq 72(%rcx),%rdx /* 9,10; (sigset_t*)oset */51/* stack is 16-byte aligned */52call __libc_sigprocmask53popq %rdi54movq %rdi,%rcx55movq 0(%rsp),%rdx /* return address */56movq %rdx, 0(%rcx) /* 0; return address */57movq %rbx, 8(%rcx) /* 1; rbx */58movq %rsp,16(%rcx) /* 2; rsp */59movq %rbp,24(%rcx) /* 3; rbp */60movq %r12,32(%rcx) /* 4; r12 */61movq %r13,40(%rcx) /* 5; r13 */62movq %r14,48(%rcx) /* 6; r14 */63movq %r15,56(%rcx) /* 7; r15 */64fnstcw 64(%rcx) /* 8; fpu cw */65stmxcsr 68(%rcx) /* and mxcsr */66xorq %rax,%rax67ret68END(setjmp)6970WEAK_REFERENCE(__longjmp, longjmp)71ENTRY(__longjmp)72pushq %rdi73pushq %rsi74movq %rdi,%rdx75movq $3,%rdi /* SIG_SETMASK */76leaq 72(%rdx),%rsi /* (sigset_t*)set */77movq $0,%rdx /* (sigset_t*)oset */78subq $0x8,%rsp /* make the stack 16-byte aligned */79call __libc_sigprocmask80addq $0x8,%rsp81popq %rsi82popq %rdi /* jmpbuf */83movq %rdi,%rdx84/* Restore the mxcsr, but leave exception flags intact. */85stmxcsr -4(%rsp)86movl 68(%rdx),%eax87andl $0xffffffc0,%eax88movl -4(%rsp),%edi89andl $0x3f,%edi90xorl %eax,%edi91movl %edi,-4(%rsp)92ldmxcsr -4(%rsp)93movq %rsi,%rax /* retval */94movq 0(%rdx),%rcx95movq 8(%rdx),%rbx96movq 16(%rdx),%rsp97movq 24(%rdx),%rbp98movq 32(%rdx),%r1299movq 40(%rdx),%r13100movq 48(%rdx),%r14101movq 56(%rdx),%r15102fldcw 64(%rdx)103testq %rax,%rax104jnz 1f105incq %rax1061: movq %rcx,0(%rsp) /* return address */107ret108END(__longjmp)109110.section .note.GNU-stack,"",%progbits111112113