setjmp.S revision 507cfe2e10a6c4ad61b9638820ba10bfe881a18c
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
394906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
404906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#include <machine/asm.h>
414906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#include <machine/setjmp.h>
424906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
434906e5653c57d49f94940f28556009a88c42a583Elliott Hughes/*
444906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * C library -- _setjmp, _longjmp
454906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *
464906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *	longjmp(a,v)
474906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * will generate a "return(v)" from the last call to
484906e5653c57d49f94940f28556009a88c42a583Elliott Hughes *	setjmp(a)
494906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * by restoring registers from the stack.
504906e5653c57d49f94940f28556009a88c42a583Elliott Hughes * The previous signal state is restored.
514906e5653c57d49f94940f28556009a88c42a583Elliott Hughes */
524906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
534906e5653c57d49f94940f28556009a88c42a583Elliott HughesENTRY(setjmp)
544906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	pushq	%rdi
554906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	xorq	%rdi,%rdi
564906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#ifdef __PIC__
574906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	call	PIC_PLT(_C_LABEL(sigblock))
584906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#else
594906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	call	_C_LABEL(sigblock)
604906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#endif
614906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	popq	%rdi
624906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	%rax,(_JB_SIGMASK * 8)(%rdi)
634906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
644906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	(%rsp),%r11
654906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	%rbx,(_JB_RBX * 8)(%rdi)
664906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	%rbp,(_JB_RBP * 8)(%rdi)
674906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	%r12,(_JB_R12 * 8)(%rdi)
684906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	%r13,(_JB_R13 * 8)(%rdi)
694906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	%r14,(_JB_R14 * 8)(%rdi)
704906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	%r15,(_JB_R15 * 8)(%rdi)
714906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	%rsp,(_JB_RSP * 8)(%rdi)
724906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	%r11,(_JB_PC  * 8)(%rdi)
734906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
744906e5653c57d49f94940f28556009a88c42a583Elliott Hughes2:	xorl	%eax,%eax
754906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	ret
76507cfe2e10a6c4ad61b9638820ba10bfe881a18cChristopher FerrisEND(setjmp)
774906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
784906e5653c57d49f94940f28556009a88c42a583Elliott HughesENTRY(longjmp)
794906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	%rdi,%r12
804906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movl	%esi,%r8d
814906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
824906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	(_JB_SIGMASK * 8)(%rdi),%rdi
834906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	pushq	%r8
844906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#ifdef __PIC__
854906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	call	PIC_PLT(_C_LABEL(sigsetmask))
864906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#else
874906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	call	_C_LABEL(sigsetmask)
884906e5653c57d49f94940f28556009a88c42a583Elliott Hughes#endif
894906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	popq	%r8
904906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	(_JB_RBX * 8)(%r12),%rbx
914906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	(_JB_RBP * 8)(%r12),%rbp
924906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	(_JB_R13 * 8)(%r12),%r13
934906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	(_JB_R14 * 8)(%r12),%r14
944906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	(_JB_R15 * 8)(%r12),%r15
954906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	(_JB_RSP * 8)(%r12),%rsp
964906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	(_JB_PC  * 8)(%r12),%r11
974906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movq	(_JB_R12 * 8)(%r12),%r12
984906e5653c57d49f94940f28556009a88c42a583Elliott Hughes
994906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	movl	%r8d,%eax
1004906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	testl	%eax,%eax
1014906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	jnz	1f
1024906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	incl	%eax
1034906e5653c57d49f94940f28556009a88c42a583Elliott Hughes1:	movq	%r11,0(%rsp)
1044906e5653c57d49f94940f28556009a88c42a583Elliott Hughes	ret
105507cfe2e10a6c4ad61b9638820ba10bfe881a18cChristopher FerrisEND(longjmp)
106