xref: /titanic_51/usr/src/lib/libc/sparc/sys/door.s (revision 49b225e1cfa7bbf7738d4df0a03f18e3283426eb)
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
5a574db85Sraf * Common Development and Distribution License (the "License").
6a574db85Sraf * 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 */
21a574db85Sraf
227c478bd9Sstevel@tonic-gate/*
23*49b225e1SGavin Maltby * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
279a70fc3bSMark J. Nelson	.file	"door.s"
287c478bd9Sstevel@tonic-gate
297257d1b4Sraf#include "SYS.h"
307257d1b4Sraf#include <sys/door.h>
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate	/*
337c478bd9Sstevel@tonic-gate	 * weak aliases for public interfaces
347c478bd9Sstevel@tonic-gate	 */
357257d1b4Sraf	ANSI_PRAGMA_WEAK2(door_bind,__door_bind,function)
367257d1b4Sraf	ANSI_PRAGMA_WEAK2(door_getparam,__door_getparam,function)
377257d1b4Sraf	ANSI_PRAGMA_WEAK2(door_info,__door_info,function)
387257d1b4Sraf	ANSI_PRAGMA_WEAK2(door_revoke,__door_revoke,function)
397257d1b4Sraf	ANSI_PRAGMA_WEAK2(door_setparam,__door_setparam,function)
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate/*
427c478bd9Sstevel@tonic-gate * Offsets within struct door_results
437c478bd9Sstevel@tonic-gate */
447c478bd9Sstevel@tonic-gate#define	DOOR_COOKIE	(SA(MINFRAME) + STACK_BIAS + 0*CLONGSIZE)
457c478bd9Sstevel@tonic-gate#define	DOOR_DATA_PTR	(SA(MINFRAME) + STACK_BIAS + 1*CLONGSIZE)
467c478bd9Sstevel@tonic-gate#define	DOOR_DATA_SIZE	(SA(MINFRAME) + STACK_BIAS + 2*CLONGSIZE)
477c478bd9Sstevel@tonic-gate#define	DOOR_DESC_PTR	(SA(MINFRAME) + STACK_BIAS + 3*CLONGSIZE)
487c478bd9Sstevel@tonic-gate#define	DOOR_DESC_SIZE	(SA(MINFRAME) + STACK_BIAS + 4*CLONGSIZE)
497c478bd9Sstevel@tonic-gate#define	DOOR_PC		(SA(MINFRAME) + STACK_BIAS + 5*CLONGSIZE)
507c478bd9Sstevel@tonic-gate#define	DOOR_SERVERS	(SA(MINFRAME) + STACK_BIAS + 6*CLONGSIZE)
517c478bd9Sstevel@tonic-gate#define	DOOR_INFO_PTR	(SA(MINFRAME) + STACK_BIAS + 7*CLONGSIZE)
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate/*
547c478bd9Sstevel@tonic-gate * All of the syscalls except door_return() follow the same pattern.  The
557c478bd9Sstevel@tonic-gate * subcode goes in %o5, after all of the other arguments.
567c478bd9Sstevel@tonic-gate */
577c478bd9Sstevel@tonic-gate#define	DOOR_SYSCALL(name, code)					\
587c478bd9Sstevel@tonic-gate	ENTRY(name);							\
597c478bd9Sstevel@tonic-gate	mov	code, %o5;		/* subcode */			\
607c478bd9Sstevel@tonic-gate	SYSTRAP_RVAL1(door);						\
617c478bd9Sstevel@tonic-gate	SYSCERROR;							\
627c478bd9Sstevel@tonic-gate	RET;								\
637c478bd9Sstevel@tonic-gate	SET_SIZE(name)
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate	DOOR_SYSCALL(__door_bind,	DOOR_BIND)
667c478bd9Sstevel@tonic-gate	DOOR_SYSCALL(__door_call,	DOOR_CALL)
677c478bd9Sstevel@tonic-gate	DOOR_SYSCALL(__door_create,	DOOR_CREATE)
687c478bd9Sstevel@tonic-gate	DOOR_SYSCALL(__door_getparam,	DOOR_GETPARAM)
697c478bd9Sstevel@tonic-gate	DOOR_SYSCALL(__door_info,	DOOR_INFO)
707c478bd9Sstevel@tonic-gate	DOOR_SYSCALL(__door_revoke,	DOOR_REVOKE)
717c478bd9Sstevel@tonic-gate	DOOR_SYSCALL(__door_setparam,	DOOR_SETPARAM)
727c478bd9Sstevel@tonic-gate	DOOR_SYSCALL(__door_ucred,	DOOR_UCRED)
737c478bd9Sstevel@tonic-gate	DOOR_SYSCALL(__door_unbind,	DOOR_UNBIND)
747c478bd9Sstevel@tonic-gate	DOOR_SYSCALL(__door_unref,	DOOR_UNREFSYS)
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate/*
777c478bd9Sstevel@tonic-gate * int
787c478bd9Sstevel@tonic-gate * __door_return(
797c478bd9Sstevel@tonic-gate *	void 			*data_ptr,
807c478bd9Sstevel@tonic-gate *	size_t			data_size,	(in bytes)
817c478bd9Sstevel@tonic-gate *	door_return_desc_t	*door_ptr,	(holds returned desc info)
827c478bd9Sstevel@tonic-gate *	caddr_t			stack_base,
837c478bd9Sstevel@tonic-gate *	size_t			stack_size)
847c478bd9Sstevel@tonic-gate */
857c478bd9Sstevel@tonic-gate	ENTRY(__door_return)
867c478bd9Sstevel@tonic-gatedoor_restart:
877c478bd9Sstevel@tonic-gate	mov	DOOR_RETURN, %o5	/* subcode */
887c478bd9Sstevel@tonic-gate	SYSTRAP_RVAL1(door)
89c4ace179Sdm120769	bcs,pn	%icc, 2f			/* errno is set */
907c478bd9Sstevel@tonic-gate	ld	[%sp + DOOR_SERVERS], %g1	/* (delay) load nservers */
917c478bd9Sstevel@tonic-gate	/*
927c478bd9Sstevel@tonic-gate	 * On return, we're serving a door_call.  Our stack looks like this:
937c478bd9Sstevel@tonic-gate	 *
947c478bd9Sstevel@tonic-gate	 *		descriptors (if any)
957c478bd9Sstevel@tonic-gate	 *		data (if any)
967c478bd9Sstevel@tonic-gate	 *		struct door_results
977c478bd9Sstevel@tonic-gate	 *		MINFRAME
987c478bd9Sstevel@tonic-gate	 *	sp ->
997c478bd9Sstevel@tonic-gate	 */
1007c478bd9Sstevel@tonic-gate	tst	%g1				/* test nservers */
1017c478bd9Sstevel@tonic-gate	bg	1f				/* everything looks o.k. */
1027c478bd9Sstevel@tonic-gate	ldn	[%sp + DOOR_COOKIE], %o0	/* (delay) load cookie */
1037c478bd9Sstevel@tonic-gate	/*
1047c478bd9Sstevel@tonic-gate	 * this is the last server thread - call creation func for more
1057c478bd9Sstevel@tonic-gate	 */
1067c478bd9Sstevel@tonic-gate	save	%sp, -SA(MINFRAME), %sp
107*49b225e1SGavin Maltby	call	door_depletion_cb
1087c478bd9Sstevel@tonic-gate	ldn	[%fp + DOOR_INFO_PTR], %o0	/* (delay) load door_info ptr */
1097c478bd9Sstevel@tonic-gate	restore
1107c478bd9Sstevel@tonic-gate1:
1117c478bd9Sstevel@tonic-gate	/* Call the door server function now */
1127c478bd9Sstevel@tonic-gate	ldn	[%sp + DOOR_DATA_PTR], %o1
1137c478bd9Sstevel@tonic-gate	ldn	[%sp + DOOR_DATA_SIZE], %o2
1147c478bd9Sstevel@tonic-gate	ldn	[%sp + DOOR_DESC_PTR], %o3
1157c478bd9Sstevel@tonic-gate	ldn	[%sp + DOOR_PC], %g1
1167c478bd9Sstevel@tonic-gate	jmpl	%g1, %o7
1177c478bd9Sstevel@tonic-gate	ldn	[%sp + DOOR_DESC_SIZE], %o4
1187c478bd9Sstevel@tonic-gate
1197c478bd9Sstevel@tonic-gate	/* Exit the thread if we return here */
1207257d1b4Sraf	call	_thrp_terminate
1217c478bd9Sstevel@tonic-gate	mov	%g0, %o0
1227c478bd9Sstevel@tonic-gate	/* NOTREACHED */
123c4ace179Sdm1207692:
1247c478bd9Sstevel@tonic-gate	/*
1257c478bd9Sstevel@tonic-gate	 * Error during door_return call.  Repark the thread in the kernel if
1267c478bd9Sstevel@tonic-gate	 * the error code is EINTR (or ERESTART) and this lwp is still part
127c4ace179Sdm120769	 * of the same process.
1287c478bd9Sstevel@tonic-gate	 */
1297c478bd9Sstevel@tonic-gate	cmp	%o0, ERESTART		/* ERESTART is same as EINTR */
130c4ace179Sdm120769	be,a	3f
1317c478bd9Sstevel@tonic-gate	mov	EINTR, %o0
132c4ace179Sdm1207693:
1337c478bd9Sstevel@tonic-gate	cmp	%o0, EINTR		/* interrupted while waiting? */
1347c478bd9Sstevel@tonic-gate	bne	__cerror		/* if not, return the error */
1357c478bd9Sstevel@tonic-gate	nop
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate	save	%sp, -SA(MINFRAME), %sp
1388cd45542Sraf	call	getpid
1397c478bd9Sstevel@tonic-gate	nop
1407c478bd9Sstevel@tonic-gate	PIC_SETUP(g1)
1417c478bd9Sstevel@tonic-gate#ifdef __sparcv9
1427c478bd9Sstevel@tonic-gate	sethi	%hi(door_create_pid), %g5
1437c478bd9Sstevel@tonic-gate	or	%g5, %lo(door_create_pid), %g5
1447c478bd9Sstevel@tonic-gate	ldn	[%g1 + %g5], %g1
1457c478bd9Sstevel@tonic-gate#else
1467c478bd9Sstevel@tonic-gate	ldn	[%g1 + door_create_pid], %g1
1477c478bd9Sstevel@tonic-gate#endif
1487c478bd9Sstevel@tonic-gate	ld	[%g1], %g1
1497c478bd9Sstevel@tonic-gate	cmp	%o0, %g1		/* same process? */
1507c478bd9Sstevel@tonic-gate	mov	EINTR, %o0	/* if no, return EINTR (child of forkall) */
1517c478bd9Sstevel@tonic-gate	bne	__cerror
1527c478bd9Sstevel@tonic-gate	restore
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate	clr	%o0			/* clear arguments and restart */
1557c478bd9Sstevel@tonic-gate	clr	%o1
1567c478bd9Sstevel@tonic-gate	ba	door_restart
1577c478bd9Sstevel@tonic-gate	clr	%o2
1587c478bd9Sstevel@tonic-gate	SET_SIZE(__door_return)
159