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