xref: /titanic_51/usr/src/lib/libc/amd64/sys/door.s (revision fd9e7635fa85e33de5aff912b955d797589f6f87)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29	.file	"%M%"
30
31#include "SYS.h"
32#include <sys/door.h>
33
34	/*
35	 * weak aliases for public interfaces
36	 */
37	ANSI_PRAGMA_WEAK2(door_bind,__door_bind,function)
38	ANSI_PRAGMA_WEAK2(door_getparam,__door_getparam,function)
39	ANSI_PRAGMA_WEAK2(door_info,__door_info,function)
40	ANSI_PRAGMA_WEAK2(door_revoke,__door_revoke,function)
41	ANSI_PRAGMA_WEAK2(door_setparam,__door_setparam,function)
42	ANSI_PRAGMA_WEAK2(door_unbind,__door_unbind,function)
43
44/*
45 * Offsets within struct door_results
46 */
47#define	DOOR_COOKIE	_MUL(0, CLONGSIZE)
48#define	DOOR_DATA_PTR	_MUL(1, CLONGSIZE)
49#define	DOOR_DATA_SIZE	_MUL(2, CLONGSIZE)
50#define	DOOR_DESC_PTR	_MUL(3, CLONGSIZE)
51#define	DOOR_DESC_SIZE	_MUL(4, CLONGSIZE)
52#define	DOOR_PC		_MUL(5, CLONGSIZE)
53#define	DOOR_SERVERS	_MUL(6, CLONGSIZE)
54#define	DOOR_INFO_PTR	_MUL(7, CLONGSIZE)
55
56/*
57 * All of the syscalls except door_return() follow the same pattern.  The
58 * subcode goes in %r9, after all of the other arguments.
59 */
60#define	DOOR_SYSCALL(name, code)					\
61	ENTRY(name);							\
62	movq	$code, %r9;		/* subcode */			\
63	SYSTRAP_RVAL1(door);						\
64	SYSCERROR;							\
65	RET;								\
66	SET_SIZE(name)
67
68	DOOR_SYSCALL(__door_bind,	DOOR_BIND)
69	DOOR_SYSCALL(__door_call,	DOOR_CALL)
70	DOOR_SYSCALL(__door_create,	DOOR_CREATE)
71	DOOR_SYSCALL(__door_getparam,	DOOR_GETPARAM)
72	DOOR_SYSCALL(__door_info,	DOOR_INFO)
73	DOOR_SYSCALL(__door_revoke,	DOOR_REVOKE)
74	DOOR_SYSCALL(__door_setparam,	DOOR_SETPARAM)
75	DOOR_SYSCALL(__door_ucred,	DOOR_UCRED)
76	DOOR_SYSCALL(__door_unbind,	DOOR_UNBIND)
77	DOOR_SYSCALL(__door_unref,	DOOR_UNREFSYS)
78
79/*
80 * int
81 * __door_return(
82 *	void 			*data_ptr,
83 *	size_t			data_size,	(in bytes)
84 *	door_return_desc_t	*door_ptr,	(holds returned desc info)
85 *	caddr_t			stack_base,
86 *	size_t			stack_size)
87 */
88	ENTRY(__door_return)
89door_restart:
90	movq	$DOOR_RETURN, %r9	/* subcode */
91	SYSTRAP_RVAL1(door)
92	jb	2f			/* errno is set */
93	/*
94	 * On return, we're serving a door_call.  Our stack looks like this:
95	 *
96	 *		descriptors (if any)
97	 *		data (if any)
98	 *	 sp->	struct door_results
99	 */
100	movl	DOOR_SERVERS(%rsp), %eax
101	andl	%eax, %eax	/* test nservers */
102	jg	1f
103	/*
104	 * this is the last server thread - call creation func for more
105	 */
106	movq	_daref_(door_server_func), %rax
107	movq	0(%rax), %rax
108	movq	DOOR_INFO_PTR(%rsp), %rdi
109	call	*%rax		/* call create function */
1101:
111	/* Call the door server function now */
112	movq	DOOR_COOKIE(%rsp), %rdi
113	movq	DOOR_DATA_PTR(%rsp), %rsi
114	movq	DOOR_DATA_SIZE(%rsp), %rdx
115	movq	DOOR_DESC_PTR(%rsp), %rcx
116	movq	DOOR_DESC_SIZE(%rsp), %r8
117	movq	DOOR_PC(%rsp), %rax
118	call	*%rax
119	/* Exit the thread if we return here */
120	movq	$0, %rdi
121	call	_thrp_terminate
122	/* NOTREACHED */
1232:
124	/*
125	 * Error during door_return call.  Repark the thread in the kernel if
126	 * the error code is EINTR (or ERESTART) and this lwp is still part
127	 * of the same process.
128	 */
129	cmpl	$ERESTART, %eax		/* ERESTART is same as EINTR */
130	jne	3f
131	movl	$EINTR, %eax
1323:
133	cmpl	$EINTR, %eax		/* interrupted while waiting? */
134	jne	__cerror		/* if not, return the error */
135
136	call	getpid			/* get current process id */
137	movq	_daref_(door_create_pid), %rdx
138	movl	0(%rdx), %edx
139	cmpl	%eax, %edx		/* same process? */
140	movl	$EINTR, %eax	/* if no, return EINTR (child of forkall) */
141	jne	__cerror
142
143	movq	$0, %rdi		/* clear arguments and restart */
144	movq	$0, %rsi
145	movq	$0, %rdx
146	jmp	door_restart
147	SET_SIZE(__door_return)
148