xref: /titanic_51/usr/src/lib/libc/i386/sys/door.s (revision f44071f6cdb4ecb73e329fbef93e79bb9f23f7cf)
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 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#pragma ident	"%Z%%M%	%I%	%E% SMI"
27
28	.file	"%M%"
29
30#include <sys/asm_linkage.h>
31
32	/*
33	 * weak aliases for public interfaces
34	 */
35	ANSI_PRAGMA_WEAK(_door_bind,function)
36	ANSI_PRAGMA_WEAK(_door_call,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_call,function)
45	ANSI_PRAGMA_WEAK(door_getparam,function)
46	ANSI_PRAGMA_WEAK(door_info,function)
47	ANSI_PRAGMA_WEAK(door_revoke,function)
48	ANSI_PRAGMA_WEAK(door_setparam,function)
49	ANSI_PRAGMA_WEAK(door_unbind,function)
50
51#include <sys/door.h>
52#include "SYS.h"
53
54/*
55 * Offsets within struct door_results
56 */
57#define	DOOR_COOKIE	_MUL(0, CLONGSIZE)
58#define	DOOR_DATA_PTR	_MUL(1, CLONGSIZE)
59#define	DOOR_DATA_SIZE	_MUL(2, CLONGSIZE)
60#define	DOOR_DESC_PTR	_MUL(3, CLONGSIZE)
61#define	DOOR_DESC_SIZE	_MUL(4, CLONGSIZE)
62#define	DOOR_PC		_MUL(5, CLONGSIZE)
63#define	DOOR_SERVERS	_MUL(6, CLONGSIZE)
64#define	DOOR_INFO_PTR	_MUL(7, CLONGSIZE)
65
66/*
67 * All of the syscalls except door_return() follow the same pattern.
68 * The subcode goes in argument 6, which means we have to copy our
69 * arguments into a new bit of stack, large enough to include the
70 * subcode.  We fill the unused positions with zeros.
71 */
72#define	DOOR_SYSCALL(name, code, copy_args)				\
73	ENTRY(name);							\
74	pushl	%ebp;							\
75	movl	%esp, %ebp;						\
76	pushl	$code;		/* syscall subcode, arg 6 */		\
77	pushl	$0;		/* dummy arg 5 */			\
78	pushl	$0;		/* dummy arg 4 */			\
79	copy_args;		/* args 1, 2, 3 */			\
80	pushl	$0;		/* dummy return PC */			\
81	SYSTRAP_RVAL1(door);						\
82	jae	1f;							\
83	addl	$28, %esp;						\
84	leave;								\
85	jmp	__cerror;						\
861:									\
87	addl	$28, %esp;						\
88	leave;								\
89	ret;								\
90	SET_SIZE(name)
91
92#define	COPY_0								\
93	pushl	$0;		/* dummy */				\
94	pushl	$0;		/* dummy */				\
95	pushl	$0		/* dummy */
96
97#define	COPY_1								\
98	pushl	$0;		/* dummy */				\
99	pushl	$0;		/* dummy */				\
100	pushl	8(%ebp)		/* 1 */
101
102#define	COPY_2								\
103	pushl	$0;		/* dummy */				\
104	pushl	12(%ebp);	/* 2 */					\
105	pushl	8(%ebp)		/* 1 */
106
107#define	COPY_3								\
108	pushl	16(%ebp);	/* 3 */					\
109	pushl	12(%ebp);	/* 2 */					\
110	pushl	8(%ebp)		/* 1 */
111
112	DOOR_SYSCALL(__door_bind,	DOOR_BIND,	COPY_1)
113	DOOR_SYSCALL(__door_call,	DOOR_CALL,	COPY_2)
114	DOOR_SYSCALL(__door_create,	DOOR_CREATE,	COPY_3)
115	DOOR_SYSCALL(__door_getparam,	DOOR_GETPARAM,	COPY_3)
116	DOOR_SYSCALL(__door_info,	DOOR_INFO,	COPY_2)
117	DOOR_SYSCALL(__door_revoke,	DOOR_REVOKE,	COPY_1)
118	DOOR_SYSCALL(__door_setparam,	DOOR_SETPARAM,	COPY_3)
119	DOOR_SYSCALL(__door_ucred,	DOOR_UCRED,	COPY_1)
120	DOOR_SYSCALL(__door_unbind,	DOOR_UNBIND,	COPY_0)
121	DOOR_SYSCALL(__door_unref,	DOOR_UNREFSYS,	COPY_0)
122
123/*
124 * int
125 * __door_return(
126 *	void 			*data_ptr,
127 *	size_t			data_size,	(in bytes)
128 *	door_return_desc_t	*door_ptr,	(holds returned desc info)
129 *	caddr_t			stack_base,
130 *	size_t			stack_size)
131 */
132	ENTRY(__door_return)
133	movl	%esp, %edx		/ Save pointer to args
134
135	pushl	%edi			/ save old %edi and %esi
136	pushl	%esi			/ and use them to hold the
137	movl	16(%edx), %esi		/ stack pointer and
138	movl	20(%edx), %edi		/ size.
139
140	pushl	$DOOR_RETURN		/ syscall subcode
141	pushl	%edi			/ size of user stack
142	pushl	%esi			/ base of user stack
143	pushl	12(%edx)		/ desc arguments ptr
144	pushl	8(%edx)			/ data size
145	pushl	4(%edx)			/ data ptr
146	pushl	0(%edx)			/ dummy return PC
147
148door_restart:
149	SYSTRAP_RVAL1(door)
150	jb	3f			/* errno is set */
151	/*
152	 * On return, we're serving a door_call.  Our stack looks like this:
153	 *
154	 *		descriptors (if any)
155	 *		data (if any)
156	 *	 sp->	struct door_results
157	 *
158	 * struct door_results has the arguments in place for the server proc,
159	 * so we just call it directly.
160	 */
161	movl	DOOR_SERVERS(%esp), %eax
162	andl	%eax, %eax	/* test nservers */
163	jg	1f
164	/*
165	 * this is the last server thread - call creation func for more
166	 */
167	movl	DOOR_INFO_PTR(%esp), %eax
168	_prologue_
169	pushl	%eax		/* door_info_t * */
170	movl	_daref_(door_server_func), %eax
171	movl	0(%eax), %eax
172	call	*%eax		/* call create function */
173	addl	$4, %esp
174	_epilogue_
1751:
176	/* Call the door server function now */
177	movl	DOOR_PC(%esp), %eax
178	call	*%eax
179
1802:
181	/* Exit the thread if we return here */
182	pushl	$0
183	call	_thr_terminate
184	/* NOTREACHED */
1853:
186	/*
187	 * Error during door_return call.  Repark the thread in the kernel if
188	 * the error code is EINTR (or ERESTART) and this lwp is still part
189	 * of the same process.
190	 *
191	 * If the error code is EINTR or ERESTART, our stack may have been
192	 * corrupted by a partial door call, so we refresh the system call
193	 * arguments.
194	 */
195	cmpl	$EEXIST, %eax		/* exit this thread if EEXIST */
196	je	2b
197	cmpl	$ERESTART, %eax		/* ERESTART is same as EINTR */
198	jne	4f
199	movl	$EINTR, %eax
2004:
201	cmpl	$EINTR, %eax		/* interrupted while waiting? */
202	jne	5f			/* if not, return the error */
203	_prologue_
204	call	_private_getpid		/* get current process id */
205	movl	_daref_(door_create_pid), %edx
206	movl	0(%edx), %edx
207	_epilogue_
208	cmpl	%eax, %edx		/* same process? */
209	movl	$EINTR, %eax	/* if no, return EINTR (child of forkall) */
210	jne	5f
211
212	movl	$0, 4(%esp)		/* clear arguments and restart */
213	movl	$0, 8(%esp)
214	movl	$0, 12(%esp)
215	movl	%esi, 16(%esp)		/* refresh sp */
216	movl	%edi, 20(%esp)		/* refresh ssize */
217	movl	$DOOR_RETURN, 24(%esp)	/* refresh syscall subcode */
218	jmp	door_restart
2195:
220	/* Something bad happened during the door_return */
221	addl	$28, %esp
222	popl	%esi
223	popl	%edi
224	jmp	__cerror
225	SET_SIZE(__door_return)
226