xref: /titanic_44/usr/src/lib/libc/amd64/gen/setjmp.s (revision 159d09a20817016f09b3ea28d1bdada4a336bb91)
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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27	.file	"setjmp.s"
28
29/*
30 *	longjmp(env, val)
31 * will generate a "return(val)" from
32 * the last call to
33 *	setjmp(env)
34 * by restoring registers rip rsp rbp rbx r12 r13 r14 r15 from 'env'
35 * and doing a return.
36 */
37
38/*
39 * entry    reg   offset
40 * env[0] = %rbx  0	register variables
41 * env[1] = %r12  8
42 * env[2] = %r13  16
43 * env[3] = %r14  24
44 * env[4] = %r15  32
45 * env[5] = %rbp  40	stack frame
46 * env[6] = %rsp  48
47 * env[7] = %rip  56
48 */
49
50#include <sys/asm_linkage.h>
51
52	ANSI_PRAGMA_WEAK(setjmp,function)
53	ANSI_PRAGMA_WEAK(longjmp,function)
54
55	ENTRY(setjmp)
56	movq	%rbx, 0(%rdi)
57	movq	%r12, 8(%rdi)
58	movq	%r13, 16(%rdi)
59	movq	%r14, 24(%rdi)
60	movq	%r15, 32(%rdi)
61	movq	%rbp, 40(%rdi)
62	popq	%rdx		/* return address */
63	movq	%rsp, 48(%rdi)
64	movq	%rdx, 56(%rdi)
65	xorl	%eax, %eax	/* return 0 */
66	jmp	*%rdx
67	SET_SIZE(setjmp)
68
69	ENTRY(longjmp)
70	movq	0(%rdi), %rbx
71	movq	8(%rdi), %r12
72	movq	16(%rdi), %r13
73	movq	24(%rdi), %r14
74	movq	32(%rdi), %r15
75	movq	40(%rdi), %rbp
76	movq	48(%rdi), %rsp
77	movl	%esi, %eax
78	test	%eax, %eax	/* if val != 0		*/
79	jnz	1f		/* 	return val	*/
80	incl	%eax		/* else return 1	*/
811:
82	movq	56(%rdi), %rdx	/* return to caller of setjmp */
83	jmp	*%rdx
84	SET_SIZE(longjmp)
85