1/* $OpenBSD: _setjmp.S,v 1.3 2016/05/12 15:46:03 deraadt Exp $ */ 2/* $NetBSD: _setjmp.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 .hidden __jmpxor 44 45/* 46 * C library -- _setjmp, _longjmp 47 * 48 * _longjmp(a,v) 49 * will generate a "return(v)" from the last call to 50 * _setjmp(a) 51 * by restoring registers from the stack. 52 * The previous signal state is NOT restored. 53 */ 54 55ENTRY(_setjmp) 56 movq (%rsp),%r11 57 leaq __jmpxor(%rip),%rcx 58 movq %rbx,(_JB_RBX * 8)(%rdi) 59 movq %rbp,%rax 60 xorq (0*8)(%rcx),%rax 61 movq %rax,(_JB_RBP * 8)(%rdi) 62 movq %r12,(_JB_R12 * 8)(%rdi) 63 movq %r13,(_JB_R13 * 8)(%rdi) 64 movq %r14,(_JB_R14 * 8)(%rdi) 65 movq %r15,(_JB_R15 * 8)(%rdi) 66 movq %rsp,%rax 67 xorq (1*8)(%rcx),%rax 68 movq %rax,(_JB_RSP * 8)(%rdi) 69 movq %r11,%rax 70 xorq (2*8)(%rcx),%rax 71 movq %rax,(_JB_PC * 8)(%rdi) 72 xorq %rcx,%rcx 73 74 xorq %rax,%rax 75 ret 76END(_setjmp) 77 78ENTRY(_longjmp) 79 leaq __jmpxor(%rip),%rcx 80 movq (_JB_RBX * 8)(%rdi),%rbx 81 movq (_JB_RBP * 8)(%rdi),%r11 82 xorq (0*8)(%rcx),%r11 83 movq %r11,%rbp 84 movq (_JB_R12 * 8)(%rdi),%r12 85 movq (_JB_R13 * 8)(%rdi),%r13 86 movq (_JB_R14 * 8)(%rdi),%r14 87 movq (_JB_R15 * 8)(%rdi),%r15 88 movq (_JB_RSP * 8)(%rdi),%r11 89 xorq (1*8)(%rcx),%r11 90 movq %r11,%rsp 91 movq (_JB_PC * 8)(%rdi),%r11 92 xorq (2*8)(%rcx),%r11 93 xorq %rcx,%rcx 94 95 movl %esi,%eax 96 testl %eax,%eax 97 jnz 1f 98 incl %eax 991: movq %r11,0(%rsp) 100 ret 101END(_longjmp) 102