setjmp.S revision 851e68a2402fa414544e66650e09dfdaac813e51
14906e5653c57d49f94940f28556009a88c42a583Elliott Hughes/* $OpenBSD: setjmp.S,v 1.3 2012/08/22 17:19:34 pascal Exp $ */ 24906e5653c57d49f94940f28556009a88c42a583Elliott Hughes/* $NetBSD: __setjmp14.S,v 1.1 2001/06/19 00:25:02 fvdl Exp $ */ 34906e5653c57d49f94940f28556009a88c42a583Elliott Hughes 44906e5653c57d49f94940f28556009a88c42a583Elliott Hughes/* 54906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * Copyright (c) 2001 Wasabi Systems, Inc. 64906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * All rights reserved. 74906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * 84906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * Written by Frank van der Linden for Wasabi Systems, Inc. 94906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * 104906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * Redistribution and use in source and binary forms, with or without 114906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * modification, are permitted provided that the following conditions 124906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * are met: 134906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * 1. Redistributions of source code must retain the above copyright 144906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * notice, this list of conditions and the following disclaimer. 154906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * 2. Redistributions in binary form must reproduce the above copyright 164906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * notice, this list of conditions and the following disclaimer in the 174906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * documentation and/or other materials provided with the distribution. 184906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * 3. All advertising materials mentioning features or use of this software 194906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * must display the following acknowledgement: 204906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * This product includes software developed for the NetBSD Project by 214906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * Wasabi Systems, Inc. 224906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * 4. The name of Wasabi Systems, Inc. may not be used to endorse 234906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * or promote products derived from this software without specific prior 244906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * written permission. 254906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * 264906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 274906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 284906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 294906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 304906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 314906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 324906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 334906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 344906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 354906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 364906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * POSSIBILITY OF SUCH DAMAGE. 374906e5653c57d49f94940f28556009a88c42a583Elliott Hughes */ 384906e5653c57d49f94940f28556009a88c42a583Elliott Hughes 39851e68a2402fa414544e66650e09dfdaac813e51Elliott Hughes#include <private/bionic_asm.h> 404906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#include <machine/setjmp.h> 414906e5653c57d49f94940f28556009a88c42a583Elliott Hughes 424906e5653c57d49f94940f28556009a88c42a583Elliott Hughes/* 434906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * C library -- _setjmp, _longjmp 444906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * 454906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * longjmp(a,v) 464906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * will generate a "return(v)" from the last call to 474906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * setjmp(a) 484906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * by restoring registers from the stack. 494906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * The previous signal state is restored. 504906e5653c57d49f94940f28556009a88c42a583Elliott Hughes */ 514906e5653c57d49f94940f28556009a88c42a583Elliott Hughes 524906e5653c57d49f94940f28556009a88c42a583Elliott HughesENTRY(setjmp) 534906e5653c57d49f94940f28556009a88c42a583Elliott Hughes pushq %rdi 544906e5653c57d49f94940f28556009a88c42a583Elliott Hughes xorq %rdi,%rdi 554906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#ifdef __PIC__ 5609289d92f920f307fc50dd64e9970c36c30b58e4Elliott Hughes call PIC_PLT(sigblock) 574906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#else 5809289d92f920f307fc50dd64e9970c36c30b58e4Elliott Hughes call sigblock 594906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#endif 604906e5653c57d49f94940f28556009a88c42a583Elliott Hughes popq %rdi 614906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq %rax,(_JB_SIGMASK * 8)(%rdi) 624906e5653c57d49f94940f28556009a88c42a583Elliott Hughes 634906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq (%rsp),%r11 644906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq %rbx,(_JB_RBX * 8)(%rdi) 654906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq %rbp,(_JB_RBP * 8)(%rdi) 664906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq %r12,(_JB_R12 * 8)(%rdi) 674906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq %r13,(_JB_R13 * 8)(%rdi) 684906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq %r14,(_JB_R14 * 8)(%rdi) 694906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq %r15,(_JB_R15 * 8)(%rdi) 704906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq %rsp,(_JB_RSP * 8)(%rdi) 714906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq %r11,(_JB_PC * 8)(%rdi) 724906e5653c57d49f94940f28556009a88c42a583Elliott Hughes 734906e5653c57d49f94940f28556009a88c42a583Elliott Hughes2: xorl %eax,%eax 744906e5653c57d49f94940f28556009a88c42a583Elliott Hughes ret 75507cfe2e10a6c4ad61b9638820ba10bfe881a18cChristopher FerrisEND(setjmp) 764906e5653c57d49f94940f28556009a88c42a583Elliott Hughes 774906e5653c57d49f94940f28556009a88c42a583Elliott HughesENTRY(longjmp) 784906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq %rdi,%r12 794906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movl %esi,%r8d 804906e5653c57d49f94940f28556009a88c42a583Elliott Hughes 814906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq (_JB_SIGMASK * 8)(%rdi),%rdi 824906e5653c57d49f94940f28556009a88c42a583Elliott Hughes pushq %r8 834906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#ifdef __PIC__ 8409289d92f920f307fc50dd64e9970c36c30b58e4Elliott Hughes call PIC_PLT(sigsetmask) 854906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#else 8609289d92f920f307fc50dd64e9970c36c30b58e4Elliott Hughes call sigsetmask 874906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#endif 884906e5653c57d49f94940f28556009a88c42a583Elliott Hughes popq %r8 894906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq (_JB_RBX * 8)(%r12),%rbx 904906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq (_JB_RBP * 8)(%r12),%rbp 914906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq (_JB_R13 * 8)(%r12),%r13 924906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq (_JB_R14 * 8)(%r12),%r14 934906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq (_JB_R15 * 8)(%r12),%r15 944906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq (_JB_RSP * 8)(%r12),%rsp 954906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq (_JB_PC * 8)(%r12),%r11 964906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movq (_JB_R12 * 8)(%r12),%r12 974906e5653c57d49f94940f28556009a88c42a583Elliott Hughes 984906e5653c57d49f94940f28556009a88c42a583Elliott Hughes movl %r8d,%eax 994906e5653c57d49f94940f28556009a88c42a583Elliott Hughes testl %eax,%eax 1004906e5653c57d49f94940f28556009a88c42a583Elliott Hughes jnz 1f 1014906e5653c57d49f94940f28556009a88c42a583Elliott Hughes incl %eax 1024906e5653c57d49f94940f28556009a88c42a583Elliott Hughes1: movq %r11,0(%rsp) 1034906e5653c57d49f94940f28556009a88c42a583Elliott Hughes ret 104507cfe2e10a6c4ad61b9638820ba10bfe881a18cChristopher FerrisEND(longjmp) 105