xref: /titanic_50/usr/src/lib/libc/i386/gen/setjmp.s (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
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	.ident	"%Z%%M%	%I%	%E% SMI"
28
29	.file	"%M%"
30
31/	longjmp(env, val)
32/ will generate a "return(val)" from
33/ the last call to
34/	setjmp(env)
35/ by restoring registers ip, sp, bp, bx, si, and di from 'env'
36/ and doing a return.
37
38/ entry    reg	offset from (%si)
39/ env[0] = %ebx	 0	/ register variables
40/ env[1] = %esi	 4
41/ env[2] = %edi	 8
42/ env[3] = %ebp	 12	/ stack frame
43/ env[4] = %esp	 16
44/ env[5] = %eip	 20
45
46#include <sys/asm_linkage.h>
47
48	ANSI_PRAGMA_WEAK(setjmp,function)
49	ANSI_PRAGMA_WEAK(longjmp,function)
50
51#include "SYS.h"
52
53	ENTRY(setjmp)
54	movl	4(%esp),%eax	/ jmpbuf address
55	movl	%ebx,0(%eax)	/ save ebx
56	movl	%esi,4(%eax)	/ save esi
57	movl	%edi,8(%eax)	/ save edi
58	movl	%ebp,12(%eax)	/ save caller's ebp
59	popl	%edx		/ return address
60	movl	%esp,16(%eax)	/ save caller's esp
61	movl	%edx,20(%eax)
62	subl	%eax,%eax	/ return 0
63	pushl	%edx
64	ret
65	SET_SIZE(setjmp)
66
67	ENTRY(longjmp)
68	movl	4(%esp),%edx	/ first parameter after return addr
69	movl	8(%esp),%eax	/ second parameter
70	movl	0(%edx),%ebx	/ restore ebx
71	movl	4(%edx),%esi	/ restore esi
72	movl	8(%edx),%edi	/ restore edi
73	movl	12(%edx),%ebp	/ restore caller's ebp
74	movl	16(%edx),%esp	/ restore caller's esp
75	test	%eax,%eax	/ if val != 0
76	jnz	.ret		/ 	return val
77	incl	%eax		/ else return 1
78.ret:
79	jmp	*20(%edx)	/ return to caller
80	SET_SIZE(longjmp)
81