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