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