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