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