xref: /titanic_50/usr/src/lib/libc/sparc/gen/setjmp.s (revision 711890bc9379ceea66272dc8d4981812224ea86e)
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 1987-2003 Sun Microsystems, Inc.  All rights reserved.
28 * Use is subject to license terms.
29 */
30
31.ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.4	*/
32
33	.file	"setjmp.s"
34
35#include <sys/asm_linkage.h>
36
37	ANSI_PRAGMA_WEAK(setjmp,function)
38	ANSI_PRAGMA_WEAK(longjmp,function)
39
40#include "synonyms.h"
41
42#include <sys/trap.h>
43
44JB_FLAGS	= (0*4)	! offsets in jmpbuf (see siglonglmp.c)
45JB_SP		= (1*4)	! words 5 through 11 are unused!
46JB_PC		= (2*4)
47JB_FP		= (3*4)
48JB_I7		= (4*4)
49
50/*
51 * setjmp(buf_ptr)
52 * buf_ptr points to a twelve word array (jmp_buf)
53 */
54	ENTRY(setjmp)
55	clr	[%o0 + JB_FLAGS]	! clear flags (used by sigsetjmp)
56	st	%sp, [%o0 + JB_SP]	! save caller's sp
57	add	%o7, 8, %o1		! comupte return pc
58	st	%o1, [%o0 + JB_PC]	! save pc
59	st	%fp, [%o0 + JB_FP]	! save fp
60	st	%i7, [%o0 + JB_I7]	! save %i7
61	retl
62	clr	%o0			! return (0)
63
64	SET_SIZE(setjmp)
65
66/*
67 * longjmp(buf_ptr, val)
68 * buf_ptr points to a jmpbuf which has been initialized by setjmp.
69 * val is the value we wish to return to setjmp's caller
70 *
71 * We flush the register file to the stack by doing a kernel call.
72 * This is necessary to ensure that the registers we want to
73 * pick up are stored on the stack, and that subsequent restores
74 * will function correctly.
75 *
76 * sp, fp, and %i7, the caller's return address, are all restored
77 * to the values they had at the time of the call to setjmp().  All
78 * other locals, ins and outs are set to potentially random values
79 * (as per the man page).  This is sufficient to permit the correct
80 * operation of normal code.
81 *
82 * Actually, the above description is not quite correct.  If the routine
83 * that called setjmp() has not altered the sp value of their frame we
84 * will restore the remaining locals and ins to the values these
85 * registers had in the this frame at the time of the call to longjmp()
86 * (not setjmp()!).  This is intended to help compilers, typically not
87 * C compilers, that have some registers assigned to fixed purposes,
88 * and that only alter the values of these registers on function entry
89 * and exit.
90 *
91 * Since a C routine could call setjmp() followed by alloca() and thus
92 * alter the sp this feature will typically not be helpful for a C
93 * compiler.
94 *
95 * Note also that because the caller of a routine compiled "flat" (without
96 * register windows) assumes that their ins and locals are preserved,
97 * routines that call setjmp() must not be flat.
98 */
99	ENTRY(longjmp)
100	ta	ST_FLUSH_WINDOWS	! flush all reg windows to the stack.
101	ld	[%o0 + JB_SP], %o2	! sp in %o2 until safe to puke there
102	ldd	[%o2 + (0*8)], %l0	! restore locals and ins if we can
103	ldd	[%o2 + (1*8)], %l2
104	ldd	[%o2 + (2*8)], %l4
105	ldd	[%o2 + (3*8)], %l6
106	ldd	[%o2 + (4*8)], %i0
107	ldd	[%o2 + (5*8)], %i2
108	ldd	[%o2 + (6*8)], %i4
109	ld	[%o0 + JB_FP], %fp	! restore fp
110	mov	%o2, %sp		! restore sp
111	ld	[%o0 + JB_I7], %i7	! restore %i7
112	ld	[%o0 + JB_PC], %o3	! get new return pc
113	tst	%o1			! is return value 0?
114	bnz	1f			! no - leave it alone
115	sub	%o3, 8, %o7		! normalize return (for adb) (dly slot)
116	mov	1, %o1			! yes - set it to one
1171:
118	retl
119	mov	%o1, %o0		! return (val)
120
121	SET_SIZE(longjmp)
122