Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 1 | /* $OpenBSD: sigsetjmp.S,v 1.3 2012/08/22 17:19:34 pascal Exp $ */ |
| 2 | /* $NetBSD: __setjmp14.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ |
| 3 | |
| 4 | /* |
| 5 | * Copyright (c) 2001 Wasabi Systems, Inc. |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Written by Frank van der Linden for Wasabi Systems, Inc. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * 1. Redistributions of source code must retain the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer. |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in the |
| 17 | * documentation and/or other materials provided with the distribution. |
| 18 | * 3. All advertising materials mentioning features or use of this software |
| 19 | * must display the following acknowledgement: |
| 20 | * This product includes software developed for the NetBSD Project by |
| 21 | * Wasabi Systems, Inc. |
| 22 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse |
| 23 | * or promote products derived from this software without specific prior |
| 24 | * written permission. |
| 25 | * |
| 26 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND |
| 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 28 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 29 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
| 30 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 31 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 32 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 35 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | * POSSIBILITY OF SUCH DAMAGE. |
| 37 | */ |
| 38 | |
| 39 | |
| 40 | #include <machine/asm.h> |
| 41 | #include <machine/setjmp.h> |
| 42 | |
| 43 | /* |
| 44 | * C library -- _setjmp, _longjmp |
| 45 | * |
| 46 | * longjmp(a,v) |
| 47 | * will generate a "return(v)" from the last call to |
| 48 | * setjmp(a) |
| 49 | * by restoring registers from the stack. |
| 50 | * The previous signal state is restored. |
| 51 | */ |
| 52 | |
| 53 | ENTRY(sigsetjmp) |
| 54 | movl %esi,(_JB_SIGFLAG * 8)(%rdi) |
| 55 | testl %esi,%esi |
| 56 | jz 2f |
| 57 | |
| 58 | pushq %rdi |
| 59 | xorq %rdi,%rdi |
| 60 | #ifdef __PIC__ |
Elliott Hughes | 09289d9 | 2014-02-20 11:51:11 -0800 | [diff] [blame] | 61 | call PIC_PLT(sigblock) |
Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 62 | #else |
Elliott Hughes | 09289d9 | 2014-02-20 11:51:11 -0800 | [diff] [blame] | 63 | call sigblock |
Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 64 | #endif |
| 65 | popq %rdi |
| 66 | movq %rax,(_JB_SIGMASK * 8)(%rdi) |
| 67 | |
| 68 | 2: movq (%rsp),%r11 |
| 69 | movq %rbx,(_JB_RBX * 8)(%rdi) |
| 70 | movq %rbp,(_JB_RBP * 8)(%rdi) |
| 71 | movq %r12,(_JB_R12 * 8)(%rdi) |
| 72 | movq %r13,(_JB_R13 * 8)(%rdi) |
| 73 | movq %r14,(_JB_R14 * 8)(%rdi) |
| 74 | movq %r15,(_JB_R15 * 8)(%rdi) |
| 75 | movq %rsp,(_JB_RSP * 8)(%rdi) |
| 76 | movq %r11,(_JB_PC * 8)(%rdi) |
| 77 | |
| 78 | 2: xorl %eax,%eax |
| 79 | ret |
Christopher Ferris | 507cfe2 | 2013-11-19 13:45:27 -0800 | [diff] [blame] | 80 | END(sigsetjmp) |
Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 81 | |
| 82 | ENTRY(siglongjmp) |
| 83 | movq %rdi,%r12 |
| 84 | pushq %rsi |
| 85 | cmpl $0, (_JB_SIGFLAG * 8)(%rdi) |
| 86 | jz 2f |
| 87 | |
| 88 | movq (_JB_SIGMASK * 8)(%rdi),%rdi |
| 89 | #ifdef __PIC__ |
Elliott Hughes | 09289d9 | 2014-02-20 11:51:11 -0800 | [diff] [blame] | 90 | call PIC_PLT(sigsetmask) |
Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 91 | #else |
Elliott Hughes | 09289d9 | 2014-02-20 11:51:11 -0800 | [diff] [blame] | 92 | call sigsetmask |
Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 93 | #endif |
| 94 | 2: popq %rax |
| 95 | movq (_JB_RBX * 8)(%r12),%rbx |
| 96 | movq (_JB_RBP * 8)(%r12),%rbp |
| 97 | movq (_JB_R13 * 8)(%r12),%r13 |
| 98 | movq (_JB_R14 * 8)(%r12),%r14 |
| 99 | movq (_JB_R15 * 8)(%r12),%r15 |
| 100 | movq (_JB_RSP * 8)(%r12),%rsp |
| 101 | movq (_JB_PC * 8)(%r12),%r11 |
| 102 | movq (_JB_R12 * 8)(%r12),%r12 |
| 103 | |
| 104 | testl %eax,%eax |
| 105 | jnz 1f |
| 106 | incl %eax |
| 107 | 1: movq %r11,0(%rsp) |
| 108 | ret |
Christopher Ferris | 507cfe2 | 2013-11-19 13:45:27 -0800 | [diff] [blame] | 109 | END(siglongjmp) |