xref: /titanic_51/usr/src/lib/libc/sparc/threads/asm_subr.s (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
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 2005 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	ENTRY(lwp_yield)
132	SYSTRAP_RVAL1(yield)
133	RET
134	SET_SIZE(lwp_yield)
135
136/*
137 * __sighndlr(int sig, siginfo_t *si, ucontex_t *uc, void (*hndlr)())
138 *
139 * This is called from sigacthandler() for the entire purpose of
140 * communicating the ucontext to java's stack tracing functions.
141 */
142	ENTRY(__sighndlr)
143	.globl	__sighndlrend
144	save	%sp, -SA(MINFRAME), %sp
145	mov	%i0, %o0
146	mov	%i1, %o1
147	jmpl	%i3, %o7
148	mov	%i2, %o2
149	ret
150	restore
151__sighndlrend:
152	SET_SIZE(__sighndlr)
153
154/*
155 * int _sigsetjmp(sigjmp_buf env, int savemask)
156 *
157 * This version is faster than the old non-threaded version because we
158 * don't normally have to call __getcontext() to get the signal mask.
159 * (We have a copy of it in the ulwp_t structure.)
160 */
161
162#undef	sigsetjmp
163
164	ENTRY2(sigsetjmp,_sigsetjmp)
165	stn	%sp, [%o0 + SJS_SP]	! save caller's sp into env->sjs_sp
166	add	%o7, 8, %o2		! calculate caller's return pc
167	stn	%o2, [%o0 + SJS_PC]	! save caller's pc into env->sjs_pc
168	stn	%fp, [%o0 + SJS_FP]	! save caller's return linkage
169	stn	%i7, [%o0 + SJS_I7]
170	call	__csigsetjmp
171	sub	%o2, 8, %o7		! __csigsetjmp returns to caller
172	SET_SIZE(sigsetjmp)
173	SET_SIZE(_sigsetjmp)
174