xref: /onnv-gate/usr/src/lib/libc/amd64/gen/setjmp.s (revision 11426:e23113f1f2f0)
10Sstevel@tonic-gate/*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
56812Sraf * Common Development and Distribution License (the "License").
66812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
216812Sraf
220Sstevel@tonic-gate/*
23*11426SRoger.Faulkner@Sun.COM * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
277298SMark.J.Nelson@Sun.COM	.file	"setjmp.s"
280Sstevel@tonic-gate
290Sstevel@tonic-gate/*
300Sstevel@tonic-gate *	longjmp(env, val)
310Sstevel@tonic-gate * will generate a "return(val)" from
320Sstevel@tonic-gate * the last call to
330Sstevel@tonic-gate *	setjmp(env)
340Sstevel@tonic-gate * by restoring registers rip rsp rbp rbx r12 r13 r14 r15 from 'env'
350Sstevel@tonic-gate * and doing a return.
360Sstevel@tonic-gate */
370Sstevel@tonic-gate
380Sstevel@tonic-gate/*
390Sstevel@tonic-gate * entry    reg   offset
400Sstevel@tonic-gate * env[0] = %rbx  0	register variables
410Sstevel@tonic-gate * env[1] = %r12  8
420Sstevel@tonic-gate * env[2] = %r13  16
430Sstevel@tonic-gate * env[3] = %r14  24
440Sstevel@tonic-gate * env[4] = %r15  32
450Sstevel@tonic-gate * env[5] = %rbp  40	stack frame
460Sstevel@tonic-gate * env[6] = %rsp  48
470Sstevel@tonic-gate * env[7] = %rip  56
480Sstevel@tonic-gate */
490Sstevel@tonic-gate
500Sstevel@tonic-gate#include <sys/asm_linkage.h>
51*11426SRoger.Faulkner@Sun.COM#include <../assym.h>
520Sstevel@tonic-gate
530Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(setjmp,function)
540Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(longjmp,function)
550Sstevel@tonic-gate
560Sstevel@tonic-gate	ENTRY(setjmp)
570Sstevel@tonic-gate	movq	%rbx, 0(%rdi)
580Sstevel@tonic-gate	movq	%r12, 8(%rdi)
590Sstevel@tonic-gate	movq	%r13, 16(%rdi)
600Sstevel@tonic-gate	movq	%r14, 24(%rdi)
610Sstevel@tonic-gate	movq	%r15, 32(%rdi)
620Sstevel@tonic-gate	movq	%rbp, 40(%rdi)
630Sstevel@tonic-gate	popq	%rdx		/* return address */
640Sstevel@tonic-gate	movq	%rsp, 48(%rdi)
650Sstevel@tonic-gate	movq	%rdx, 56(%rdi)
66*11426SRoger.Faulkner@Sun.COM
67*11426SRoger.Faulkner@Sun.COM	movq	%fs:UL_SIGLINK, %rax
68*11426SRoger.Faulkner@Sun.COM	xorq	%rcx, %rcx
69*11426SRoger.Faulkner@Sun.COM	testq	%rax, %rax	/* are we in a signal handler? */
70*11426SRoger.Faulkner@Sun.COM	jnz	1f
71*11426SRoger.Faulkner@Sun.COM	incq	%rcx		/* no, tell longjmp to clear ul_siglink */
72*11426SRoger.Faulkner@Sun.COM1:	orq	%rcx, 48(%rdi)	/* low-order 1-bit flag in the saved %rsp */
73*11426SRoger.Faulkner@Sun.COM
740Sstevel@tonic-gate	xorl	%eax, %eax	/* return 0 */
750Sstevel@tonic-gate	jmp	*%rdx
760Sstevel@tonic-gate	SET_SIZE(setjmp)
770Sstevel@tonic-gate
780Sstevel@tonic-gate	ENTRY(longjmp)
790Sstevel@tonic-gate	movq	0(%rdi), %rbx
800Sstevel@tonic-gate	movq	8(%rdi), %r12
810Sstevel@tonic-gate	movq	16(%rdi), %r13
820Sstevel@tonic-gate	movq	24(%rdi), %r14
830Sstevel@tonic-gate	movq	32(%rdi), %r15
840Sstevel@tonic-gate	movq	40(%rdi), %rbp
85*11426SRoger.Faulkner@Sun.COM
86*11426SRoger.Faulkner@Sun.COM	movq	48(%rdi), %rax	/* test low-order bit in the saved %rsp */
87*11426SRoger.Faulkner@Sun.COM	testq	$1, %rax
88*11426SRoger.Faulkner@Sun.COM	jz	1f
89*11426SRoger.Faulkner@Sun.COM	xorq	%rcx, %rcx	/* if set, clear ul_siglink */
90*11426SRoger.Faulkner@Sun.COM	movq	%rcx, %fs:UL_SIGLINK
91*11426SRoger.Faulkner@Sun.COM	subq	$1, %rax	/* clear the flag bit */
92*11426SRoger.Faulkner@Sun.COM1:	movq	%rax, %rsp
93*11426SRoger.Faulkner@Sun.COM
940Sstevel@tonic-gate	movl	%esi, %eax
950Sstevel@tonic-gate	test	%eax, %eax	/* if val != 0		*/
960Sstevel@tonic-gate	jnz	1f		/* 	return val	*/
970Sstevel@tonic-gate	incl	%eax		/* else return 1	*/
980Sstevel@tonic-gate1:
990Sstevel@tonic-gate	movq	56(%rdi), %rdx	/* return to caller of setjmp */
1000Sstevel@tonic-gate	jmp	*%rdx
1010Sstevel@tonic-gate	SET_SIZE(longjmp)
102