xref: /titanic_52/usr/src/lib/libc/amd64/threads/asm_subr.s (revision 9a70fc3be3b1e966bf78825cdb8d509963a6f0a1)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
58cd45542Sraf * Common Development and Distribution License (the "License").
68cd45542Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
218cd45542Sraf
227c478bd9Sstevel@tonic-gate/*
238cd45542Sraf * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27*9a70fc3bSMark J. Nelson	.file	"asm_subr.s"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate#include <SYS.h>
307c478bd9Sstevel@tonic-gate#include <sys/regset.h>
317c478bd9Sstevel@tonic-gate#include <../assym.h>
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate	/*
347c478bd9Sstevel@tonic-gate	 * This is where execution resumes when a thread created with
357c478bd9Sstevel@tonic-gate	 * thr_create() or pthread_create() returns (see setup_context()).
367257d1b4Sraf	 * We pass the (void *) return value to _thrp_terminate().
377c478bd9Sstevel@tonic-gate	 */
387c478bd9Sstevel@tonic-gate	ENTRY(_lwp_start)
397c478bd9Sstevel@tonic-gate	movq	%rax, %rdi
407257d1b4Sraf	call	_thrp_terminate
417c478bd9Sstevel@tonic-gate	RET		/* actually, never returns */
427c478bd9Sstevel@tonic-gate	SET_SIZE(_lwp_start)
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate	/* All we need to do now is (carefully) call lwp_exit(). */
457c478bd9Sstevel@tonic-gate	ENTRY(_lwp_terminate)
467c478bd9Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_exit)
477c478bd9Sstevel@tonic-gate	RET		/* if we return, it is very bad */
487c478bd9Sstevel@tonic-gate	SET_SIZE(_lwp_terminate)
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate	ENTRY(set_curthread)
517c478bd9Sstevel@tonic-gate	movq	%rdi, %fs:0
527c478bd9Sstevel@tonic-gate	ret
537c478bd9Sstevel@tonic-gate	SET_SIZE(set_curthread)
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate	ENTRY(__lwp_park)
567c478bd9Sstevel@tonic-gate	movq	%rsi, %rdx
577c478bd9Sstevel@tonic-gate	movq	%rdi, %rsi
587c478bd9Sstevel@tonic-gate	movq	$0, %rdi
597c478bd9Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_park)
607c478bd9Sstevel@tonic-gate	SYSLWPERR
617c478bd9Sstevel@tonic-gate	RET
627c478bd9Sstevel@tonic-gate	SET_SIZE(__lwp_park)
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate	ENTRY(__lwp_unpark)
657c478bd9Sstevel@tonic-gate	movq	%rdi, %rsi
667c478bd9Sstevel@tonic-gate	movq	$1, %rdi
677c478bd9Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_park)
687c478bd9Sstevel@tonic-gate	SYSLWPERR
697c478bd9Sstevel@tonic-gate	RET
707c478bd9Sstevel@tonic-gate	SET_SIZE(__lwp_unpark)
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate	ENTRY(__lwp_unpark_all)
737c478bd9Sstevel@tonic-gate	movq	%rsi, %rdx
747c478bd9Sstevel@tonic-gate	movq	%rdi, %rsi
757c478bd9Sstevel@tonic-gate	movq	$2, %rdi
767c478bd9Sstevel@tonic-gate	SYSTRAP_RVAL1(lwp_park)
777c478bd9Sstevel@tonic-gate	SYSLWPERR
787c478bd9Sstevel@tonic-gate	RET
797c478bd9Sstevel@tonic-gate	SET_SIZE(__lwp_unpark_all)
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate/*
827c478bd9Sstevel@tonic-gate * __sighndlr(int sig, siginfo_t *si, ucontext_t *uc, void (*hndlr)())
837c478bd9Sstevel@tonic-gate *
847c478bd9Sstevel@tonic-gate * This is called from sigacthandler() for the entire purpose of
857c478bd9Sstevel@tonic-gate * communicating the ucontext to java's stack tracing functions.
867c478bd9Sstevel@tonic-gate */
877c478bd9Sstevel@tonic-gate	ENTRY(__sighndlr)
887c478bd9Sstevel@tonic-gate	.globl	__sighndlrend
897c478bd9Sstevel@tonic-gate	pushq	%rbp
907c478bd9Sstevel@tonic-gate	movq	%rsp, %rbp
917c478bd9Sstevel@tonic-gate	call	*%rcx
927c478bd9Sstevel@tonic-gate	leave
937c478bd9Sstevel@tonic-gate	ret
947c478bd9Sstevel@tonic-gate__sighndlrend:
957c478bd9Sstevel@tonic-gate	SET_SIZE(__sighndlr)
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate/*
987c478bd9Sstevel@tonic-gate * int _sigsetjmp(sigjmp_buf env, int savemask)
997c478bd9Sstevel@tonic-gate *
1007c478bd9Sstevel@tonic-gate * This version is faster than the old non-threaded version because we
1017c478bd9Sstevel@tonic-gate * don't normally have to call __getcontext() to get the signal mask.
1027c478bd9Sstevel@tonic-gate * (We have a copy of it in the ulwp_t structure.)
1037c478bd9Sstevel@tonic-gate */
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate#undef	sigsetjmp
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate#if SIZEOF_SIGJMP_BUF < SIZEOF_UCONTEXT_T
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate#error "sigjmp_buf is too small to contain a ucontext_t"
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate#else
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate#if defined(__GNUC_AS__)
1147c478bd9Sstevel@tonic-gate#define	REGOFF(reg)	( reg * CLONGSIZE )
1157c478bd9Sstevel@tonic-gate#else
1167c478bd9Sstevel@tonic-gate#define	REGOFF(reg)	[ reg \* CLONGSIZE ]
1177c478bd9Sstevel@tonic-gate#endif
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate	ENTRY2(sigsetjmp,_sigsetjmp)
1207c478bd9Sstevel@tonic-gate	pushq	%rbp
1217c478bd9Sstevel@tonic-gate	movq	%rsp, %rbp
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate	/* construct a complete gregset_t for __csigsetjmp */
1247c478bd9Sstevel@tonic-gate	subq	$REGOFF(_NGREG), %rsp
1257c478bd9Sstevel@tonic-gate	movq	%r15,	REGOFF(REG_R15) (%rsp)
1267c478bd9Sstevel@tonic-gate	movq	%r14,	REGOFF(REG_R14) (%rsp)
1277c478bd9Sstevel@tonic-gate	movq	%r13,	REGOFF(REG_R13) (%rsp)
1287c478bd9Sstevel@tonic-gate	movq	%r12,	REGOFF(REG_R12) (%rsp)
1297c478bd9Sstevel@tonic-gate	movq	%r11,	REGOFF(REG_R11) (%rsp)
1307c478bd9Sstevel@tonic-gate	movq	%r10,	REGOFF(REG_R10) (%rsp)
1317c478bd9Sstevel@tonic-gate	movq	%r9,	REGOFF(REG_R9) (%rsp)
1327c478bd9Sstevel@tonic-gate	movq	%r8,	REGOFF(REG_R8) (%rsp)
1337c478bd9Sstevel@tonic-gate	movq	%rdi,	REGOFF(REG_RDI) (%rsp)
1347c478bd9Sstevel@tonic-gate	movq	%rsi,	REGOFF(REG_RSI) (%rsp)
1357c478bd9Sstevel@tonic-gate	movq	%rbx,	REGOFF(REG_RBX) (%rsp)
1367c478bd9Sstevel@tonic-gate	movq	%rdx,	REGOFF(REG_RDX) (%rsp)
1377c478bd9Sstevel@tonic-gate	movq	%rcx,	REGOFF(REG_RCX) (%rsp)
1387c478bd9Sstevel@tonic-gate	movq	$0,	REGOFF(REG_RAX) (%rsp)
1397c478bd9Sstevel@tonic-gate	movq	$0,	REGOFF(REG_TRAPNO) (%rsp)
1407c478bd9Sstevel@tonic-gate	movq	$0,	REGOFF(REG_ERR) (%rsp)
1417c478bd9Sstevel@tonic-gate	xorq	%rax, %rax
1427c478bd9Sstevel@tonic-gate	movw	%cs, %ax
1437c478bd9Sstevel@tonic-gate	movq	%rax,	REGOFF(REG_CS) (%rsp)
1447c478bd9Sstevel@tonic-gate	movq	$0,	REGOFF(REG_RFL) (%rsp)
1457c478bd9Sstevel@tonic-gate	movw	%ss, %ax
1467c478bd9Sstevel@tonic-gate	movq	%rax,	REGOFF(REG_SS) (%rsp)
1477c478bd9Sstevel@tonic-gate	movw	%fs, %ax
1487c478bd9Sstevel@tonic-gate	movq	%rax,	REGOFF(REG_FS) (%rsp)
1497c478bd9Sstevel@tonic-gate	movw	%gs, %ax
1507c478bd9Sstevel@tonic-gate	movq	%rax,	REGOFF(REG_GS) (%rsp)
1517c478bd9Sstevel@tonic-gate	movw	%es, %ax
1527c478bd9Sstevel@tonic-gate	movq	%rax,	REGOFF(REG_ES) (%rsp)
1537c478bd9Sstevel@tonic-gate	movw	%ds, %ax
1547c478bd9Sstevel@tonic-gate	movq	%rax,	REGOFF(REG_DS) (%rsp)
1557c478bd9Sstevel@tonic-gate	movq	%fs:0, %rax
1567c478bd9Sstevel@tonic-gate	movq	%rax,	REGOFF(REG_FSBASE) (%rsp)
1577c478bd9Sstevel@tonic-gate	movq	$0,	REGOFF(REG_GSBASE) (%rsp)
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate	movq	(%rbp), %rax		/* previous %rbp */
1607c478bd9Sstevel@tonic-gate	movq	%rax,	REGOFF(REG_RBP) (%rsp)
1617c478bd9Sstevel@tonic-gate	movq	8(%rbp), %rax		/* previous %rip */
1627c478bd9Sstevel@tonic-gate	movq	%rax,	REGOFF(REG_RIP) (%rsp)
1637c478bd9Sstevel@tonic-gate	leaq	16(%rbp), %rax		/* previous %rsp */
1647c478bd9Sstevel@tonic-gate	movq	%rax,	REGOFF(REG_RSP) (%rsp)
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate	movq	%rsp, %rdx	/* pointer to gregset_t */
1677c478bd9Sstevel@tonic-gate	call	__csigsetjmp
1687c478bd9Sstevel@tonic-gate	xorq	%rax, %rax
1697c478bd9Sstevel@tonic-gate	leave
1707c478bd9Sstevel@tonic-gate	ret
1717c478bd9Sstevel@tonic-gate	SET_SIZE(sigsetjmp)
1727c478bd9Sstevel@tonic-gate	SET_SIZE(_sigsetjmp)
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate#endif	/* SIZEOF_SIGJMP_BUF < SIZEOF_UCONTEXT_T */
175