xref: /titanic_41/usr/src/lib/libc/sparc/threads/asm_subr.s (revision a31148363f598def767ac48c5d82e1572e44b935)
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 2009 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
86	ENTRY(_do_fix_align)
87	retl
88	ta	ST_FIX_ALIGN
89	SET_SIZE(_do_fix_align)
90#endif
91
92	ENTRY(_getfsr)
93	retl
94	stn	%fsr, [%o0]
95	SET_SIZE(_getfsr)
96
97	ENTRY(_setfsr)
98	retl
99	ldn	[%o0], %fsr
100	SET_SIZE(_setfsr)
101
102	ENTRY(_flush_windows)
103	retl
104	ta	ST_FLUSH_WINDOWS
105	SET_SIZE(_flush_windows)
106
107	ENTRY(__lwp_park)
108	mov	%o1, %o2
109	mov	%o0, %o1
110	mov	0, %o0
111	SYSTRAP_RVAL1(lwp_park)
112	SYSLWPERR
113	RET
114	SET_SIZE(__lwp_park)
115
116	ENTRY(__lwp_unpark)
117	mov	%o0, %o1
118	mov	1, %o0
119	SYSTRAP_RVAL1(lwp_park)
120	SYSLWPERR
121	RET
122	SET_SIZE(__lwp_unpark)
123
124	ENTRY(__lwp_unpark_all)
125	mov	%o1, %o2
126	mov	%o0, %o1
127	mov	2, %o0
128	SYSTRAP_RVAL1(lwp_park)
129	SYSLWPERR
130	RET
131	SET_SIZE(__lwp_unpark_all)
132
133/*
134 * __sighndlr(int sig, siginfo_t *si, ucontex_t *uc, void (*hndlr)())
135 *
136 * This is called from sigacthandler() for the entire purpose of
137 * communicating the ucontext to java's stack tracing functions.
138 */
139	ENTRY(__sighndlr)
140	.globl	__sighndlrend
141	save	%sp, -SA(MINFRAME), %sp
142	mov	%i0, %o0
143	mov	%i1, %o1
144	jmpl	%i3, %o7
145	mov	%i2, %o2
146	ret
147	restore
148__sighndlrend:
149	SET_SIZE(__sighndlr)
150
151/*
152 * int _sigsetjmp(sigjmp_buf env, int savemask)
153 *
154 * This version is faster than the old non-threaded version because we
155 * don't normally have to call __getcontext() to get the signal mask.
156 * (We have a copy of it in the ulwp_t structure.)
157 */
158
159#undef	sigsetjmp
160
161	ENTRY2(sigsetjmp,_sigsetjmp)
162	stn	%sp, [%o0 + SJS_SP]	! save caller's sp into env->sjs_sp
163	add	%o7, 8, %o2		! calculate caller's return pc
164	stn	%o2, [%o0 + SJS_PC]	! save caller's pc into env->sjs_pc
165	stn	%fp, [%o0 + SJS_FP]	! save caller's return linkage
166	stn	%i7, [%o0 + SJS_I7]
167	call	__csigsetjmp
168	sub	%o2, 8, %o7		! __csigsetjmp returns to caller
169	SET_SIZE(sigsetjmp)
170	SET_SIZE(_sigsetjmp)
171