xref: /titanic_50/usr/src/lib/libc/amd64/sys/door.s (revision 0e42dee69ed771bf604dd1789fca9d77b5bbe302)
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, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2005 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_call,function)
38	ANSI_PRAGMA_WEAK(_door_getparam,function)
39	ANSI_PRAGMA_WEAK(_door_info,function)
40	ANSI_PRAGMA_WEAK(_door_revoke,function)
41	ANSI_PRAGMA_WEAK(_door_setparam,function)
42	ANSI_PRAGMA_WEAK(_door_unbind,function)
43
44	ANSI_PRAGMA_WEAK(door_bind,function)
45	ANSI_PRAGMA_WEAK(door_call,function)
46	ANSI_PRAGMA_WEAK(door_getparam,function)
47	ANSI_PRAGMA_WEAK(door_info,function)
48	ANSI_PRAGMA_WEAK(door_revoke,function)
49	ANSI_PRAGMA_WEAK(door_setparam,function)
50	ANSI_PRAGMA_WEAK(door_unbind,function)
51
52#include <sys/door.h>
53#include "SYS.h"
54
55/*
56 * Offsets within struct door_results
57 */
58#define	DOOR_COOKIE	_MUL(0, CLONGSIZE)
59#define	DOOR_DATA_PTR	_MUL(1, CLONGSIZE)
60#define	DOOR_DATA_SIZE	_MUL(2, CLONGSIZE)
61#define	DOOR_DESC_PTR	_MUL(3, CLONGSIZE)
62#define	DOOR_DESC_SIZE	_MUL(4, CLONGSIZE)
63#define	DOOR_PC		_MUL(5, CLONGSIZE)
64#define	DOOR_SERVERS	_MUL(6, CLONGSIZE)
65#define	DOOR_INFO_PTR	_MUL(7, CLONGSIZE)
66
67/*
68 * All of the syscalls except door_return() follow the same pattern.  The
69 * subcode goes in %r9, after all of the other arguments.
70 */
71#define	DOOR_SYSCALL(name, code)					\
72	ENTRY(name);							\
73	movq	$code, %r9;		/* subcode */			\
74	SYSTRAP_RVAL1(door);						\
75	SYSCERROR;							\
76	RET;								\
77	SET_SIZE(name)
78
79	DOOR_SYSCALL(__door_bind,	DOOR_BIND)
80	DOOR_SYSCALL(__door_call,	DOOR_CALL)
81	DOOR_SYSCALL(__door_create,	DOOR_CREATE)
82	DOOR_SYSCALL(__door_getparam,	DOOR_GETPARAM)
83	DOOR_SYSCALL(__door_info,	DOOR_INFO)
84	DOOR_SYSCALL(__door_revoke,	DOOR_REVOKE)
85	DOOR_SYSCALL(__door_setparam,	DOOR_SETPARAM)
86	DOOR_SYSCALL(__door_ucred,	DOOR_UCRED)
87	DOOR_SYSCALL(__door_unbind,	DOOR_UNBIND)
88	DOOR_SYSCALL(__door_unref,	DOOR_UNREFSYS)
89
90/*
91 * int
92 * __door_return(
93 *	void 			*data_ptr,
94 *	size_t			data_size,	(in bytes)
95 *	door_return_desc_t	*door_ptr,	(holds returned desc info)
96 *	caddr_t			stack_base,
97 *	size_t			stack_size)
98 */
99	ENTRY(__door_return)
100door_restart:
101	movq	$DOOR_RETURN, %r9	/* subcode */
102	SYSTRAP_RVAL1(door)
103	jb	2f			/* errno is set */
104	/*
105	 * On return, we're serving a door_call.  Our stack looks like this:
106	 *
107	 *		descriptors (if any)
108	 *		data (if any)
109	 *	 sp->	struct door_results
110	 */
111	movl	DOOR_SERVERS(%rsp), %eax
112	andl	%eax, %eax	/* test nservers */
113	jg	1f
114	/*
115	 * this is the last server thread - call creation func for more
116	 */
117	movq	_daref_(door_server_func), %rax
118	movq	0(%rax), %rax
119	movq	DOOR_INFO_PTR(%rsp), %rdi
120	call	*%rax		/* call create function */
1211:
122	/* Call the door server function now */
123	movq	DOOR_COOKIE(%rsp), %rdi
124	movq	DOOR_DATA_PTR(%rsp), %rsi
125	movq	DOOR_DATA_SIZE(%rsp), %rdx
126	movq	DOOR_DESC_PTR(%rsp), %rcx
127	movq	DOOR_DESC_SIZE(%rsp), %r8
128	movq	DOOR_PC(%rsp), %rax
129	call	*%rax
130	/* Exit the thread if we return here */
131	movq	$0, %rdi
132	call	_thr_terminate
133	/* NOTREACHED */
1342:
135	/*
136	 * Error during door_return call.  Repark the thread in the kernel if
137	 * the error code is EINTR (or ERESTART) and this lwp is still part
138	 * of the same process.
139	 */
140	cmpl	$ERESTART, %eax		/* ERESTART is same as EINTR */
141	jne	3f
142	movl	$EINTR, %eax
1433:
144	cmpl	$EINTR, %eax		/* interrupted while waiting? */
145	jne	__cerror		/* if not, return the error */
146
147	call	_private_getpid		/* get current process id */
148	movq	_daref_(door_create_pid), %rdx
149	movl	0(%rdx), %edx
150	cmpl	%eax, %edx		/* same process? */
151	movl	$EINTR, %eax	/* if no, return EINTR (child of forkall) */
152	jne	__cerror
153
154	movq	$0, %rdi		/* clear arguments and restart */
155	movq	$0, %rsi
156	movq	$0, %rdx
157	jmp	door_restart
158	SET_SIZE(__door_return)
159