xref: /onnv-gate/usr/src/lib/libc/i386/threads/asm_subr.s (revision 10607:da3cc66100c3)
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/*
23*10607SRoger.Faulkner@Sun.COM * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
277298SMark.J.Nelson@Sun.COM	.file	"asm_subr.s"
280Sstevel@tonic-gate
290Sstevel@tonic-gate#include <SYS.h>
300Sstevel@tonic-gate
310Sstevel@tonic-gate	/ This is where execution resumes when a thread created with
320Sstevel@tonic-gate	/ thr_create() or pthread_create() returns (see setup_context()).
336812Sraf	/ We pass the (void *) return value to _thrp_terminate().
340Sstevel@tonic-gate	ENTRY(_lwp_start)
350Sstevel@tonic-gate	addl	$4, %esp
360Sstevel@tonic-gate	pushl	%eax
376812Sraf	call	_thrp_terminate
380Sstevel@tonic-gate	addl	$4, %esp	/ actually, never returns
390Sstevel@tonic-gate	SET_SIZE(_lwp_start)
400Sstevel@tonic-gate
410Sstevel@tonic-gate	/ All we need to do now is (carefully) call lwp_exit().
420Sstevel@tonic-gate	ENTRY(_lwp_terminate)
430Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_exit)
440Sstevel@tonic-gate	RET		/ if we return, it is very bad
450Sstevel@tonic-gate	SET_SIZE(_lwp_terminate)
460Sstevel@tonic-gate
470Sstevel@tonic-gate	ENTRY(set_curthread)
480Sstevel@tonic-gate	movl	4(%esp), %eax
490Sstevel@tonic-gate	movl	%eax, %gs:0
500Sstevel@tonic-gate	ret
510Sstevel@tonic-gate	SET_SIZE(set_curthread)
520Sstevel@tonic-gate
530Sstevel@tonic-gate	ENTRY(__lwp_park)
540Sstevel@tonic-gate	popl	%edx		/ add subcode; save return address
550Sstevel@tonic-gate	pushl	$0
560Sstevel@tonic-gate	pushl	%edx
570Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_park)
580Sstevel@tonic-gate	SYSLWPERR
590Sstevel@tonic-gate	popl	%edx		/ restore return address
600Sstevel@tonic-gate	movl	%edx, 0(%esp)
610Sstevel@tonic-gate	RET
620Sstevel@tonic-gate	SET_SIZE(__lwp_park)
630Sstevel@tonic-gate
640Sstevel@tonic-gate	ENTRY(__lwp_unpark)
650Sstevel@tonic-gate	popl	%edx		/ add subcode; save return address
660Sstevel@tonic-gate	pushl	$1
670Sstevel@tonic-gate	pushl	%edx
680Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_park)
690Sstevel@tonic-gate	SYSLWPERR
700Sstevel@tonic-gate	popl	%edx		/ restore return address
710Sstevel@tonic-gate	movl	%edx, 0(%esp)
720Sstevel@tonic-gate	RET
730Sstevel@tonic-gate	SET_SIZE(__lwp_unpark)
740Sstevel@tonic-gate
750Sstevel@tonic-gate	ENTRY(__lwp_unpark_all)
760Sstevel@tonic-gate	popl	%edx		/ add subcode; save return address
770Sstevel@tonic-gate	pushl	$2
780Sstevel@tonic-gate	pushl	%edx
790Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_park)
800Sstevel@tonic-gate	SYSLWPERR
810Sstevel@tonic-gate	popl	%edx		/ restore return address
820Sstevel@tonic-gate	movl	%edx, 0(%esp)
830Sstevel@tonic-gate	RET
840Sstevel@tonic-gate	SET_SIZE(__lwp_unpark_all)
850Sstevel@tonic-gate
860Sstevel@tonic-gate/*
870Sstevel@tonic-gate * __sighndlr(int sig, siginfo_t *si, ucontext_t *uc, void (*hndlr)())
880Sstevel@tonic-gate *
89*10607SRoger.Faulkner@Sun.COM * This is called from sigacthandler() for the purpose of
90*10607SRoger.Faulkner@Sun.COM * communicating the ucontext to java's stack tracing functions
91*10607SRoger.Faulkner@Sun.COM * and to ensure a 16-byte aligned stack pointer for the benefit
92*10607SRoger.Faulkner@Sun.COM * of gcc-compiled floating point code
930Sstevel@tonic-gate */
940Sstevel@tonic-gate	ENTRY(__sighndlr)
950Sstevel@tonic-gate	.globl	__sighndlrend
960Sstevel@tonic-gate	pushl	%ebp
970Sstevel@tonic-gate	movl	%esp, %ebp
98*10607SRoger.Faulkner@Sun.COM	andl	$-16,%esp	/ make sure handler is called with
99*10607SRoger.Faulkner@Sun.COM	subl	$4,%esp		/ a 16-byte aligned stack pointer
1000Sstevel@tonic-gate	pushl	16(%ebp)
1010Sstevel@tonic-gate	pushl	12(%ebp)
1020Sstevel@tonic-gate	pushl	8(%ebp)
1030Sstevel@tonic-gate	call	*20(%ebp)
1040Sstevel@tonic-gate	leave
1050Sstevel@tonic-gate	ret
1060Sstevel@tonic-gate__sighndlrend:
1070Sstevel@tonic-gate	SET_SIZE(__sighndlr)
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate/*
1100Sstevel@tonic-gate * int _sigsetjmp(sigjmp_buf env, int savemask)
1110Sstevel@tonic-gate *
1120Sstevel@tonic-gate * This version is faster than the old non-threaded version because we
1130Sstevel@tonic-gate * don't normally have to call __getcontext() to get the signal mask.
1140Sstevel@tonic-gate * (We have a copy of it in the ulwp_t structure.)
1150Sstevel@tonic-gate */
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate#undef	sigsetjmp
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate	ENTRY2(sigsetjmp,_sigsetjmp)	/ EIP already pushed
1200Sstevel@tonic-gate	pusha				/ EAX .. EDI
1210Sstevel@tonic-gate	push	%ds			/ segment registers
1220Sstevel@tonic-gate	push	%es
1230Sstevel@tonic-gate	push	%fs
1240Sstevel@tonic-gate	push	%gs
1250Sstevel@tonic-gate	push	%ss
1260Sstevel@tonic-gate	push	%cs
1270Sstevel@tonic-gate	/ args:  cs, ss, gs, ..., eip, env, savemask
1280Sstevel@tonic-gate	call	__csigsetjmp
1290Sstevel@tonic-gate	addl	$56, %esp		/ pop 14 words
1300Sstevel@tonic-gate	ret
1310Sstevel@tonic-gate	SET_SIZE(sigsetjmp)
1320Sstevel@tonic-gate	SET_SIZE(_sigsetjmp)
133