1b2b3ffcdSSimon Schubert/*- 2b2b3ffcdSSimon Schubert * Copyright (c) 1990 The Regents of the University of California. 3b2b3ffcdSSimon Schubert * All rights reserved. 4b2b3ffcdSSimon Schubert * 5b2b3ffcdSSimon Schubert * This code is derived from software contributed to Berkeley by 6b2b3ffcdSSimon Schubert * William Jolitz. 7b2b3ffcdSSimon Schubert * 8b2b3ffcdSSimon Schubert * Redistribution and use in source and binary forms, with or without 9b2b3ffcdSSimon Schubert * modification, are permitted provided that the following conditions 10b2b3ffcdSSimon Schubert * are met: 11b2b3ffcdSSimon Schubert * 1. Redistributions of source code must retain the above copyright 12b2b3ffcdSSimon Schubert * notice, this list of conditions and the following disclaimer. 13b2b3ffcdSSimon Schubert * 2. Redistributions in binary form must reproduce the above copyright 14b2b3ffcdSSimon Schubert * notice, this list of conditions and the following disclaimer in the 15b2b3ffcdSSimon Schubert * documentation and/or other materials provided with the distribution. 16*c66c7e2fSzrj * 3. Neither the name of the University nor the names of its contributors 17b2b3ffcdSSimon Schubert * may be used to endorse or promote products derived from this software 18b2b3ffcdSSimon Schubert * without specific prior written permission. 19b2b3ffcdSSimon Schubert * 20b2b3ffcdSSimon Schubert * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21b2b3ffcdSSimon Schubert * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22b2b3ffcdSSimon Schubert * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23b2b3ffcdSSimon Schubert * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24b2b3ffcdSSimon Schubert * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25b2b3ffcdSSimon Schubert * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26b2b3ffcdSSimon Schubert * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27b2b3ffcdSSimon Schubert * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28b2b3ffcdSSimon Schubert * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29b2b3ffcdSSimon Schubert * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30b2b3ffcdSSimon Schubert * SUCH DAMAGE. 31b2b3ffcdSSimon Schubert * 32b2b3ffcdSSimon Schubert * @(#)setjmp.s 5.1 (Berkeley) 4/23/90 33b2b3ffcdSSimon Schubert * $Id: sigsetjmp.S,v 1.1 1993/12/05 13:01:05 ats Exp $ 34b2b3ffcdSSimon Schubert * $FreeBSD: src/lib/libc/amd64/gen/sigsetjmp.S,v 1.30 2008/11/02 01:10:54 peter Exp $ 35b2b3ffcdSSimon Schubert */ 36b2b3ffcdSSimon Schubert 37b2b3ffcdSSimon Schubert#include <machine/asm.h> 38b2b3ffcdSSimon Schubert#include "SYS.h" 39b2b3ffcdSSimon Schubert 40b2b3ffcdSSimon Schubert/*- 41b2b3ffcdSSimon Schubert * TODO: 42b2b3ffcdSSimon Schubert * Rename sigsetjmp to __sigsetjmp and siglongjmp to __siglongjmp, 43b2b3ffcdSSimon Schubert * remove the other *jmp functions and define everything in terms 44b2b3ffcdSSimon Schubert * of the renamed functions. This requires compiler support for 45b2b3ffcdSSimon Schubert * the renamed functions (introduced in gcc-2.5.3; previous versions 46b2b3ffcdSSimon Schubert * only supported *jmp with 0 or 1 leading underscores). 47b2b3ffcdSSimon Schubert * 48b2b3ffcdSSimon Schubert * Restore _all_ the registers and the signal mask atomically. Can 49b2b3ffcdSSimon Schubert * use sigreturn() if sigreturn() works. 50b2b3ffcdSSimon Schubert */ 51b2b3ffcdSSimon Schubert 52b2b3ffcdSSimon SchubertENTRY(sigsetjmp) 53b2b3ffcdSSimon Schubert movl %esi,88(%rdi) /* 11; savemask */ 54b2b3ffcdSSimon Schubert testl %esi,%esi 55b2b3ffcdSSimon Schubert jz 2f 56b2b3ffcdSSimon Schubert pushq %rdi 57b2b3ffcdSSimon Schubert movq %rdi,%rcx 58b2b3ffcdSSimon Schubert movq $1,%rdi /* SIG_BLOCK */ 59b2b3ffcdSSimon Schubert movq $0,%rsi /* (sigset_t*)set */ 60b2b3ffcdSSimon Schubert leaq 72(%rcx),%rdx /* 9,10 (sigset_t*)oset */ 61a77a7390SJohn Marino /* stack is 16-byte aligned */ 62b2b3ffcdSSimon Schubert call PIC_PLT(CNAME(_sigprocmask)) 63b2b3ffcdSSimon Schubert popq %rdi 64b2b3ffcdSSimon Schubert2: movq %rdi,%rcx 65b2b3ffcdSSimon Schubert movq 0(%rsp),%rdx /* retval */ 66b2b3ffcdSSimon Schubert movq %rdx, 0(%rcx) /* 0; retval */ 67b2b3ffcdSSimon Schubert movq %rbx, 8(%rcx) /* 1; rbx */ 68b2b3ffcdSSimon Schubert movq %rsp,16(%rcx) /* 2; rsp */ 69b2b3ffcdSSimon Schubert movq %rbp,24(%rcx) /* 3; rbp */ 70b2b3ffcdSSimon Schubert movq %r12,32(%rcx) /* 4; r12 */ 71b2b3ffcdSSimon Schubert movq %r13,40(%rcx) /* 5; r13 */ 72b2b3ffcdSSimon Schubert movq %r14,48(%rcx) /* 6; r14 */ 73b2b3ffcdSSimon Schubert movq %r15,56(%rcx) /* 7; r15 */ 74b2b3ffcdSSimon Schubert fnstcw 64(%rcx) /* 8; fpu cw */ 75b2b3ffcdSSimon Schubert xorq %rax,%rax 76b2b3ffcdSSimon Schubert ret 77b2b3ffcdSSimon SchubertEND(sigsetjmp) 78b2b3ffcdSSimon Schubert 79b2b3ffcdSSimon Schubert .weak CNAME(siglongjmp) 80b2b3ffcdSSimon Schubert .set CNAME(siglongjmp),CNAME(__siglongjmp) 81b2b3ffcdSSimon SchubertENTRY(__siglongjmp) 82b2b3ffcdSSimon Schubert cmpl $0,88(%rdi) 83b2b3ffcdSSimon Schubert jz 2f 84b2b3ffcdSSimon Schubert movq %rdi,%rdx 85b2b3ffcdSSimon Schubert pushq %rdi 86b2b3ffcdSSimon Schubert pushq %rsi 87b2b3ffcdSSimon Schubert movq $3,%rdi /* SIG_SETMASK */ 88b2b3ffcdSSimon Schubert leaq 72(%rdx),%rsi /* (sigset_t*)set */ 89b2b3ffcdSSimon Schubert movq $0,%rdx /* (sigset_t*)oset */ 90a77a7390SJohn Marino subq $0x8,%rsp /* make the stack 16-byte aligned */ 91b2b3ffcdSSimon Schubert call PIC_PLT(CNAME(_sigprocmask)) 92a77a7390SJohn Marino addq $0x8,%rsp 93b2b3ffcdSSimon Schubert popq %rsi 94b2b3ffcdSSimon Schubert popq %rdi /* jmpbuf */ 95b2b3ffcdSSimon Schubert2: movq %rdi,%rdx 96b2b3ffcdSSimon Schubert movq %rsi,%rax /* retval */ 97b2b3ffcdSSimon Schubert movq 0(%rdx),%rcx 98b2b3ffcdSSimon Schubert movq 8(%rdx),%rbx 99b2b3ffcdSSimon Schubert movq 16(%rdx),%rsp 100b2b3ffcdSSimon Schubert movq 24(%rdx),%rbp 101b2b3ffcdSSimon Schubert movq 32(%rdx),%r12 102b2b3ffcdSSimon Schubert movq 40(%rdx),%r13 103b2b3ffcdSSimon Schubert movq 48(%rdx),%r14 104b2b3ffcdSSimon Schubert movq 56(%rdx),%r15 105b2b3ffcdSSimon Schubert fldcw 64(%rdx) 106b2b3ffcdSSimon Schubert testq %rax,%rax 107b2b3ffcdSSimon Schubert jnz 1f 108b2b3ffcdSSimon Schubert incq %rax 109b2b3ffcdSSimon Schubert1: movq %rcx,0(%rsp) 110b2b3ffcdSSimon Schubert ret 111b2b3ffcdSSimon SchubertEND(__siglongjmp) 112a77a7390SJohn Marino 113a77a7390SJohn Marino .section .note.GNU-stack,"",%progbits 114