xref: /titanic_41/usr/src/lib/libc/sparc/threads/asm_subr.s (revision 895ca178e38ac3583d0c0d8317d51dc5f388df6e)
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/*
23 * Copyright 2008 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	"asm_subr.s"
30
31#include <sys/asm_linkage.h>
32#include <sys/trap.h>
33#include <../assym.h>
34#include "SYS.h"
35
36	! This is where execution resumes when a thread created with
37	! thr_create() or pthread_create() returns (see setup_context()).
38	! We pass the (void *) return value to _thr_terminate().
39	ENTRY(_lwp_start)
40	nop	! this is the location from which the func() was "called"
41	nop
42	call	_thr_terminate	! %o0 contains the return value
43	nop
44	SET_SIZE(_lwp_start)
45
46	ENTRY(_lwp_terminate)
47	! Flush the register windows so the stack can be reused.
48	ta	ST_FLUSH_WINDOWS
49	! All we need to do now is (carefully) call lwp_exit().
50	mov	SYS_lwp_exit, %g1
51	ta	SYSCALL_TRAPNUM
52	RET		! if we return, it is very bad
53	SET_SIZE(_lwp_terminate)
54
55	ENTRY(set_curthread)
56	retl
57	mov	%o0, %g7
58	SET_SIZE(set_curthread)
59
60#ifdef __sparcv9
61#define	GREGSIZE	8
62#else
63#define	GREGSIZE	4
64#endif
65	! void _fetch_globals(greg_t *);
66	! (called from siglongjmp())
67	ENTRY(_fetch_globals)
68	stn	%g1, [%o0 + 0*GREGSIZE]
69	stn	%g2, [%o0 + 1*GREGSIZE]
70	stn	%g3, [%o0 + 2*GREGSIZE]
71	stn	%g4, [%o0 + 3*GREGSIZE]
72	stn	%g5, [%o0 + 4*GREGSIZE]
73	stn	%g6, [%o0 + 5*GREGSIZE]
74	retl
75	stn	%g7, [%o0 + 6*GREGSIZE]
76	SET_SIZE(_fetch_globals)
77
78#ifdef __sparcv9
79	ENTRY(_getfprs)
80	retl
81	mov	%fprs, %o0
82	SET_SIZE(_getfprs)
83#else
84	ENTRY(_getpsr)
85	retl
86	ta	ST_GETPSR
87	SET_SIZE(_getpsr)
88#endif
89
90	ENTRY(_getfsr)
91	retl
92	stn	%fsr, [%o0]
93	SET_SIZE(_getfsr)
94
95	ENTRY(_setfsr)
96	retl
97	ldn	[%o0], %fsr
98	SET_SIZE(_setfsr)
99
100	ENTRY(_flush_windows)
101	retl
102	ta	ST_FLUSH_WINDOWS
103	SET_SIZE(_flush_windows)
104
105	ENTRY(__lwp_park)
106	mov	%o1, %o2
107	mov	%o0, %o1
108	mov	0, %o0
109	SYSTRAP_RVAL1(lwp_park)
110	SYSLWPERR
111	RET
112	SET_SIZE(__lwp_park)
113
114	ENTRY(__lwp_unpark)
115	mov	%o0, %o1
116	mov	1, %o0
117	SYSTRAP_RVAL1(lwp_park)
118	SYSLWPERR
119	RET
120	SET_SIZE(__lwp_unpark)
121
122	ENTRY(__lwp_unpark_all)
123	mov	%o1, %o2
124	mov	%o0, %o1
125	mov	2, %o0
126	SYSTRAP_RVAL1(lwp_park)
127	SYSLWPERR
128	RET
129	SET_SIZE(__lwp_unpark_all)
130
131/*
132 * __sighndlr(int sig, siginfo_t *si, ucontex_t *uc, void (*hndlr)())
133 *
134 * This is called from sigacthandler() for the entire purpose of
135 * communicating the ucontext to java's stack tracing functions.
136 */
137	ENTRY(__sighndlr)
138	.globl	__sighndlrend
139	save	%sp, -SA(MINFRAME), %sp
140	mov	%i0, %o0
141	mov	%i1, %o1
142	jmpl	%i3, %o7
143	mov	%i2, %o2
144	ret
145	restore
146__sighndlrend:
147	SET_SIZE(__sighndlr)
148
149/*
150 * int _sigsetjmp(sigjmp_buf env, int savemask)
151 *
152 * This version is faster than the old non-threaded version because we
153 * don't normally have to call __getcontext() to get the signal mask.
154 * (We have a copy of it in the ulwp_t structure.)
155 */
156
157#undef	sigsetjmp
158
159	ENTRY2(sigsetjmp,_sigsetjmp)
160	stn	%sp, [%o0 + SJS_SP]	! save caller's sp into env->sjs_sp
161	add	%o7, 8, %o2		! calculate caller's return pc
162	stn	%o2, [%o0 + SJS_PC]	! save caller's pc into env->sjs_pc
163	stn	%fp, [%o0 + SJS_FP]	! save caller's return linkage
164	stn	%i7, [%o0 + SJS_I7]
165	call	__csigsetjmp
166	sub	%o2, 8, %o7		! __csigsetjmp returns to caller
167	SET_SIZE(sigsetjmp)
168	SET_SIZE(_sigsetjmp)
169