1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#if defined(__lint)
28#include <setjmp.h>
29#endif
30
31#include <sys/asm_linkage.h>
32
33/*
34 *	longjmp(env, val)
35 * will generate a "return(val)" from
36 * the last call to
37 *	setjmp(env)
38 * by restoring registers rip rsp rbp rbx r12 r13 r14 r15 from 'env'
39 * and doing a return.
40 *
41 * entry    reg   offset
42 * env[0] = %rbx  0	register variables
43 * env[1] = %r12  8
44 * env[2] = %r13  16
45 * env[3] = %r14  24
46 * env[4] = %r15  32
47 * env[5] = %rbp  40	stack frame
48 * env[6] = %rsp  48
49 * env[7] = %rip  56
50 */
51
52#if defined(__lint)
53/*ARGSUSED*/
54int
55setjmp(jmp_buf env)
56{
57	return (0);
58}
59
60/*ARGSUSED*/
61int
62sigsetjmp(sigjmp_buf env, int savemask)
63{
64	return (0);
65}
66#else	/* __lint */
67
68	ENTRY(setjmp)
69	ALTENTRY(sigsetjmp)
70	movq	%rbx, 0(%rdi)
71	movq	%r12, 8(%rdi)
72	movq	%r13, 16(%rdi)
73	movq	%r14, 24(%rdi)
74	movq	%r15, 32(%rdi)
75	movq	%rbp, 40(%rdi)
76	popq	%rdx		/* return address */
77	movq	%rsp, 48(%rdi)
78	movq	%rdx, 56(%rdi)
79	xorl	%eax, %eax	/* return 0 */
80	jmp	*%rdx
81	SET_SIZE(sigsetjmp)
82	SET_SIZE(setjmp)
83
84#endif	/* __lint */
85
86#if defined(__lint)
87/*ARGSUSED*/
88void
89longjmp(jmp_buf env, int val)
90{
91}
92
93/*ARGSUSED*/
94void
95siglongjmp(sigjmp_buf env, int val)
96{
97}
98#else	/* __lint */
99
100	ENTRY(longjmp)
101	ALTENTRY(siglongjmp)
102	movq	0(%rdi), %rbx
103	movq	8(%rdi), %r12
104	movq	16(%rdi), %r13
105	movq	24(%rdi), %r14
106	movq	32(%rdi), %r15
107	movq	40(%rdi), %rbp
108	movq	48(%rdi), %rsp
109	movl	%esi, %eax
110	test	%eax, %eax	/* if val != 0		*/
111	jnz	1f		/* 	return val	*/
112	incl	%eax		/* else return 1	*/
1131:
114	movq	56(%rdi), %rdx	/* return to caller of setjmp */
115	jmp	*%rdx
116	SET_SIZE(siglongjmp)
117	SET_SIZE(longjmp)
118
119#endif	/* __lint */
120