xref: /onnv-gate/usr/src/lib/libc/sparc/threads/asm_subr.s (revision 6812:febeba71273d)
10Sstevel@tonic-gate/*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
56515Sraf * Common Development and Distribution License (the "License").
66515Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
216515Sraf
220Sstevel@tonic-gate/*
236515Sraf * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate
29*6812Sraf	.file	"%M%"
300Sstevel@tonic-gate
31*6812Sraf#include "SYS.h"
320Sstevel@tonic-gate#include <sys/trap.h>
330Sstevel@tonic-gate#include <../assym.h>
340Sstevel@tonic-gate
350Sstevel@tonic-gate	! This is where execution resumes when a thread created with
360Sstevel@tonic-gate	! thr_create() or pthread_create() returns (see setup_context()).
37*6812Sraf	! We pass the (void *) return value to _thrp_terminate().
380Sstevel@tonic-gate	ENTRY(_lwp_start)
390Sstevel@tonic-gate	nop	! this is the location from which the func() was "called"
400Sstevel@tonic-gate	nop
41*6812Sraf	call	_thrp_terminate	! %o0 contains the return value
420Sstevel@tonic-gate	nop
430Sstevel@tonic-gate	SET_SIZE(_lwp_start)
440Sstevel@tonic-gate
450Sstevel@tonic-gate	ENTRY(_lwp_terminate)
460Sstevel@tonic-gate	! Flush the register windows so the stack can be reused.
470Sstevel@tonic-gate	ta	ST_FLUSH_WINDOWS
480Sstevel@tonic-gate	! All we need to do now is (carefully) call lwp_exit().
490Sstevel@tonic-gate	mov	SYS_lwp_exit, %g1
500Sstevel@tonic-gate	ta	SYSCALL_TRAPNUM
510Sstevel@tonic-gate	RET		! if we return, it is very bad
520Sstevel@tonic-gate	SET_SIZE(_lwp_terminate)
530Sstevel@tonic-gate
540Sstevel@tonic-gate	ENTRY(set_curthread)
550Sstevel@tonic-gate	retl
560Sstevel@tonic-gate	mov	%o0, %g7
570Sstevel@tonic-gate	SET_SIZE(set_curthread)
580Sstevel@tonic-gate
590Sstevel@tonic-gate#ifdef __sparcv9
600Sstevel@tonic-gate#define	GREGSIZE	8
610Sstevel@tonic-gate#else
620Sstevel@tonic-gate#define	GREGSIZE	4
630Sstevel@tonic-gate#endif
640Sstevel@tonic-gate	! void _fetch_globals(greg_t *);
650Sstevel@tonic-gate	! (called from siglongjmp())
660Sstevel@tonic-gate	ENTRY(_fetch_globals)
670Sstevel@tonic-gate	stn	%g1, [%o0 + 0*GREGSIZE]
680Sstevel@tonic-gate	stn	%g2, [%o0 + 1*GREGSIZE]
690Sstevel@tonic-gate	stn	%g3, [%o0 + 2*GREGSIZE]
700Sstevel@tonic-gate	stn	%g4, [%o0 + 3*GREGSIZE]
710Sstevel@tonic-gate	stn	%g5, [%o0 + 4*GREGSIZE]
720Sstevel@tonic-gate	stn	%g6, [%o0 + 5*GREGSIZE]
730Sstevel@tonic-gate	retl
740Sstevel@tonic-gate	stn	%g7, [%o0 + 6*GREGSIZE]
750Sstevel@tonic-gate	SET_SIZE(_fetch_globals)
760Sstevel@tonic-gate
770Sstevel@tonic-gate#ifdef __sparcv9
780Sstevel@tonic-gate	ENTRY(_getfprs)
790Sstevel@tonic-gate	retl
800Sstevel@tonic-gate	mov	%fprs, %o0
810Sstevel@tonic-gate	SET_SIZE(_getfprs)
820Sstevel@tonic-gate#else
830Sstevel@tonic-gate	ENTRY(_getpsr)
840Sstevel@tonic-gate	retl
850Sstevel@tonic-gate	ta	ST_GETPSR
860Sstevel@tonic-gate	SET_SIZE(_getpsr)
870Sstevel@tonic-gate#endif
880Sstevel@tonic-gate
890Sstevel@tonic-gate	ENTRY(_getfsr)
900Sstevel@tonic-gate	retl
910Sstevel@tonic-gate	stn	%fsr, [%o0]
920Sstevel@tonic-gate	SET_SIZE(_getfsr)
930Sstevel@tonic-gate
940Sstevel@tonic-gate	ENTRY(_setfsr)
950Sstevel@tonic-gate	retl
960Sstevel@tonic-gate	ldn	[%o0], %fsr
970Sstevel@tonic-gate	SET_SIZE(_setfsr)
980Sstevel@tonic-gate
990Sstevel@tonic-gate	ENTRY(_flush_windows)
1000Sstevel@tonic-gate	retl
1010Sstevel@tonic-gate	ta	ST_FLUSH_WINDOWS
1020Sstevel@tonic-gate	SET_SIZE(_flush_windows)
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate	ENTRY(__lwp_park)
1050Sstevel@tonic-gate	mov	%o1, %o2
1060Sstevel@tonic-gate	mov	%o0, %o1
1070Sstevel@tonic-gate	mov	0, %o0
1080Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_park)
1090Sstevel@tonic-gate	SYSLWPERR
1100Sstevel@tonic-gate	RET
1110Sstevel@tonic-gate	SET_SIZE(__lwp_park)
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate	ENTRY(__lwp_unpark)
1140Sstevel@tonic-gate	mov	%o0, %o1
1150Sstevel@tonic-gate	mov	1, %o0
1160Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_park)
1170Sstevel@tonic-gate	SYSLWPERR
1180Sstevel@tonic-gate	RET
1190Sstevel@tonic-gate	SET_SIZE(__lwp_unpark)
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate	ENTRY(__lwp_unpark_all)
1220Sstevel@tonic-gate	mov	%o1, %o2
1230Sstevel@tonic-gate	mov	%o0, %o1
1240Sstevel@tonic-gate	mov	2, %o0
1250Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_park)
1260Sstevel@tonic-gate	SYSLWPERR
1270Sstevel@tonic-gate	RET
1280Sstevel@tonic-gate	SET_SIZE(__lwp_unpark_all)
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate/*
1310Sstevel@tonic-gate * __sighndlr(int sig, siginfo_t *si, ucontex_t *uc, void (*hndlr)())
1320Sstevel@tonic-gate *
1330Sstevel@tonic-gate * This is called from sigacthandler() for the entire purpose of
1340Sstevel@tonic-gate * communicating the ucontext to java's stack tracing functions.
1350Sstevel@tonic-gate */
1360Sstevel@tonic-gate	ENTRY(__sighndlr)
1370Sstevel@tonic-gate	.globl	__sighndlrend
1380Sstevel@tonic-gate	save	%sp, -SA(MINFRAME), %sp
1390Sstevel@tonic-gate	mov	%i0, %o0
1400Sstevel@tonic-gate	mov	%i1, %o1
1410Sstevel@tonic-gate	jmpl	%i3, %o7
1420Sstevel@tonic-gate	mov	%i2, %o2
1430Sstevel@tonic-gate	ret
1440Sstevel@tonic-gate	restore
1450Sstevel@tonic-gate__sighndlrend:
1460Sstevel@tonic-gate	SET_SIZE(__sighndlr)
1470Sstevel@tonic-gate
1480Sstevel@tonic-gate/*
1490Sstevel@tonic-gate * int _sigsetjmp(sigjmp_buf env, int savemask)
1500Sstevel@tonic-gate *
1510Sstevel@tonic-gate * This version is faster than the old non-threaded version because we
1520Sstevel@tonic-gate * don't normally have to call __getcontext() to get the signal mask.
1530Sstevel@tonic-gate * (We have a copy of it in the ulwp_t structure.)
1540Sstevel@tonic-gate */
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate#undef	sigsetjmp
1570Sstevel@tonic-gate
1580Sstevel@tonic-gate	ENTRY2(sigsetjmp,_sigsetjmp)
1590Sstevel@tonic-gate	stn	%sp, [%o0 + SJS_SP]	! save caller's sp into env->sjs_sp
1600Sstevel@tonic-gate	add	%o7, 8, %o2		! calculate caller's return pc
1610Sstevel@tonic-gate	stn	%o2, [%o0 + SJS_PC]	! save caller's pc into env->sjs_pc
1620Sstevel@tonic-gate	stn	%fp, [%o0 + SJS_FP]	! save caller's return linkage
1630Sstevel@tonic-gate	stn	%i7, [%o0 + SJS_I7]
1640Sstevel@tonic-gate	call	__csigsetjmp
1650Sstevel@tonic-gate	sub	%o2, 8, %o7		! __csigsetjmp returns to caller
1660Sstevel@tonic-gate	SET_SIZE(sigsetjmp)
1670Sstevel@tonic-gate	SET_SIZE(_sigsetjmp)
168