xref: /titanic_50/usr/src/lib/libc/i386/unwind/unwind_frame.s (revision 694c35faa87b858ecdadfe4fc592615f4eefbb07)
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	"unwind_frame.s"
27
28#include <SYS.h>
29
30/* Cancellation/thr_exit() stuff */
31
32/*
33 * _ex_unwind_local(void)
34 *
35 * Called only from _t_cancel().
36 * Unwind two frames and invoke _t_cancel(fp) again.
37 *
38 * Before this the call stack is: f4 f3 f2 f1 _t_cancel
39 * After this the call stack is:  f4 f3 f2 _t_cancel
40 *	(as if "call f1" is replaced by "call _t_cancel(fp)" in f2)
41 */
42
43	ENTRY(_ex_unwind_local)
44	movl	(%ebp), %edx		/ pop first frame [ back to f1() ]
45	movl	(%edx), %ebp		/ pop second frame [ back to f2() ]
46	movl	4(%edx), %eax		/ save f2's return pc
47	movl	%eax, (%edx)		/ mov it up for one arg
48	movl	%edx, %esp		/ stack pointer at ret addr
49	movl	%ebp, 4(%esp)
50	jmp	_t_cancel
51	SET_SIZE(_ex_unwind_local)
52
53/*
54 * _ex_clnup_handler(void *arg, void  (*clnup)(void *))
55 *
56 * Called only from _t_cancel().
57 * Unwind one frame, call the cleanup handler with argument arg from the
58 * restored frame, then jump to _t_cancel(fp) again from the restored frame.
59 */
60
61	ENTRY(_ex_clnup_handler)
62	pushl	%ebp			/ save current frame pointer
63	pushl	8(%esp)			/ first argument [arg]
64	movl	(%ebp), %ebp		/ pop out one frame
65	call	*16(%esp)		/ call handler [clnup]
66	addl	$4, %esp
67	popl	%eax			/ old frame pointer
68	lea	4(%eax), %esp		/ stk points to old frame
69	movl	%ebp, 4(%esp)		/ _t_cancel() gets frame pointer arg
70	jmp	_t_cancel
71	SET_SIZE(_ex_clnup_handler)
72
73/*
74 * _thrp_unwind(void *arg)
75 *
76 * Ignore the argument; jump to _t_cancel(fp) with caller's fp
77 */
78	ENTRY(_thrp_unwind)
79	movl	%ebp, 4(%esp)
80	jmp	_t_cancel
81	SET_SIZE(_thrp_unwind)
82