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