xref: /titanic_51/usr/src/lib/libbc/libc/sys/sys5/setjmp.c (revision e71ca95ca6de23d33b54cb55cefdef30bc7c969b)
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 /*	Copyright (c) 1988 AT&T */
23 /*	All Rights Reserved   */
24 
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 
34 #include <sys/setjmp.h>
35 #include "../common/ucontext.h"
36 
37 int _getsp();
38 
39 int
40 setjmp(env)
41 	jmp_buf env;
42 {
43 	register o_setjmp_struct_t *bp = (o_setjmp_struct_t *)env;
44 	register int sp = _getsp();
45 	ucontext_t uc;
46 
47 	/*
48 	 * Get the current machine context.
49 	 */
50 	uc.uc_flags = UC_STACK;
51 	__getcontext(&uc);
52 
53 	/*
54 	 * Note that the pc and former sp (fp) from the stack are valid
55 	 * because the call to __getcontext must flush the user windows
56 	 * to the stack.
57 	 */
58 	bp->sjs_flags = 0;
59 	bp->sjs_sp    = *((int *)sp+14);
60 	bp->sjs_pc    = *((int *)sp+15) + 0x8;
61 	bp->sjs_sigmask[0] = 0;
62 	bp->sjs_sigmask[1] = 0;
63 	bp->sjs_sigmask[2] = 0;
64 	bp->sjs_stack = uc.uc_stack;
65 
66 	return (0);
67 }
68 
69 
70 void
71 longjmp(env, val)
72 	jmp_buf env;
73 	int val;
74 {
75 	o_setjmp_struct_t *bp = (o_setjmp_struct_t *)env;
76 	setjmp_struct_t sjmp, *sp;
77 
78 	sp = &sjmp;
79 	sp->sjs_flags = bp->sjs_flags;
80 	sp->sjs_sp = bp->sjs_sp;
81 	sp->sjs_pc = bp->sjs_pc;
82 	sp->sjs_fp = 0;
83 	sp->sjs_i7 = 0;
84 	sp->sjs_uclink = 0;
85 	sp->sjs_sigmask[0] = bp->sjs_sigmask[0];
86 	sp->sjs_sigmask[1] = bp->sjs_sigmask[1];
87 	sp->sjs_sigmask[2] = bp->sjs_sigmask[2];
88 	sp->sjs_sigmask[3] = 0;
89 	sp->sjs_stack = bp->sjs_stack;
90 	_siglongjmp(sjmp, val);
91 }
92