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