xref: /titanic_51/usr/src/lib/libc/i386/gen/setjmp.s (revision e52fb54bb8f22da555df8e240ebd249941b0ed95)
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 2010 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27	.file	"setjmp.s"
28
29/	longjmp(env, val)
30/ will generate a "return(val)" from
31/ the last call to
32/	setjmp(env)
33/ by restoring registers ip, sp, bp, bx, si, and di from 'env'
34/ and doing a return.
35
36/ entry    reg	offset from (%si)
37/ env[0] = %ebx	 0	/ register variables
38/ env[1] = %esi	 4
39/ env[2] = %edi	 8
40/ env[3] = %ebp	 12	/ stack frame
41/ env[4] = %esp	 16
42/ env[5] = %eip	 20
43/ env[6] = jmp flags 24
44
45#include <sys/asm_linkage.h>
46#include <../assym.h>
47
48	ANSI_PRAGMA_WEAK(setjmp,function)
49	ANSI_PRAGMA_WEAK(longjmp,function)
50
51	ENTRY(setjmp)
52	movl	4(%esp),%eax	/ jmpbuf address
53	movl	%ebx,0(%eax)	/ save ebx
54	movl	%esi,4(%eax)	/ save esi
55	movl	%edi,8(%eax)	/ save edi
56	movl	%ebp,12(%eax)	/ save caller's ebp
57
58	movl	%gs:UL_SIGLINK, %ecx
59	xorl	%edx, %edx
60	test	%ecx, %ecx	/ are we in a signal handler?
61	jnz	1f
62	inc	%edx		/ no, tell longjmp to clear ul_siglink
631:	movl	%edx, 24(%eax)	/ set flag word
64
65	popl	%edx		/ return address
66	movl	%esp,16(%eax)	/ save caller's esp
67	movl	%edx,20(%eax)	/ save caller's return address
68	xorl	%eax, %eax	/ return 0
69	pushl	%edx
70	ret
71	SET_SIZE(setjmp)
72
73	ENTRY(longjmp)
74	movl	4(%esp),%edx	/ first parameter after return addr
75	movl	8(%esp),%eax	/ second parameter
76	movl	0(%edx),%ebx	/ restore ebx
77	movl	4(%edx),%esi	/ restore esi
78	movl	8(%edx),%edi	/ restore edi
79	movl	12(%edx),%ebp	/ restore caller's ebp
80	movl	16(%edx),%esp	/ restore caller's esp
81
82	movl	24(%edx), %ecx
83	test	%ecx, %ecx	/ test flag word
84	jz	1f
85	xorl	%ecx, %ecx	/ if set, clear ul_siglink
86	movl	%ecx, %gs:UL_SIGLINK
871:
88	test	%eax,%eax	/ if val != 0
89	jnz	1f		/ 	return val
90	incl	%eax		/ else return 1
911:
92	jmp	*20(%edx)	/ return to caller
93	SET_SIZE(longjmp)
94