xref: /titanic_50/usr/src/lib/libc/sparc/sys/door.s (revision 080575042aba2197b425ebfd52061dea061a9aa1)
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	(SA(MINFRAME) + STACK_BIAS + 0*CLONGSIZE)
59#define	DOOR_DATA_PTR	(SA(MINFRAME) + STACK_BIAS + 1*CLONGSIZE)
60#define	DOOR_DATA_SIZE	(SA(MINFRAME) + STACK_BIAS + 2*CLONGSIZE)
61#define	DOOR_DESC_PTR	(SA(MINFRAME) + STACK_BIAS + 3*CLONGSIZE)
62#define	DOOR_DESC_SIZE	(SA(MINFRAME) + STACK_BIAS + 4*CLONGSIZE)
63#define	DOOR_PC		(SA(MINFRAME) + STACK_BIAS + 5*CLONGSIZE)
64#define	DOOR_SERVERS	(SA(MINFRAME) + STACK_BIAS + 6*CLONGSIZE)
65#define	DOOR_INFO_PTR	(SA(MINFRAME) + STACK_BIAS + 7*CLONGSIZE)
66
67/*
68 * All of the syscalls except door_return() follow the same pattern.  The
69 * subcode goes in %o5, after all of the other arguments.
70 */
71#define	DOOR_SYSCALL(name, code)					\
72	ENTRY(name);							\
73	mov	code, %o5;		/* 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	mov	DOOR_RETURN, %o5	/* subcode */
102	SYSTRAP_RVAL1(door)
103	bcs,pn	%icc, 2f			/* errno is set */
104	ld	[%sp + DOOR_SERVERS], %g1	/* (delay) load nservers */
105	/*
106	 * On return, we're serving a door_call.  Our stack looks like this:
107	 *
108	 *		descriptors (if any)
109	 *		data (if any)
110	 *		struct door_results
111	 *		MINFRAME
112	 *	sp ->
113	 */
114	tst	%g1				/* test nservers */
115	bg	1f				/* everything looks o.k. */
116	ldn	[%sp + DOOR_COOKIE], %o0	/* (delay) load cookie */
117	/*
118	 * this is the last server thread - call creation func for more
119	 */
120	save	%sp, -SA(MINFRAME), %sp
121	PIC_SETUP(g1)
122#ifdef __sparcv9
123	sethi	%hi(door_server_func), %g5
124	or	%g5, %lo(door_server_func), %g5
125	ldn	[%g5 + %g1], %g1
126#else
127	ldn	[%g1 + door_server_func], %g1
128#endif
129	ldn	[%g1], %g1
130	jmpl	%g1, %o7			/* call create function */
131	ldn	[%fp + DOOR_INFO_PTR], %o0	/* (delay) load door_info ptr */
132	restore
1331:
134	/* Call the door server function now */
135	ldn	[%sp + DOOR_DATA_PTR], %o1
136	ldn	[%sp + DOOR_DATA_SIZE], %o2
137	ldn	[%sp + DOOR_DESC_PTR], %o3
138	ldn	[%sp + DOOR_PC], %g1
139	jmpl	%g1, %o7
140	ldn	[%sp + DOOR_DESC_SIZE], %o4
141
142	/* Exit the thread if we return here */
143	call	_thr_terminate
144	mov	%g0, %o0
145	/* NOTREACHED */
1462:
147	/*
148	 * Error during door_return call.  Repark the thread in the kernel if
149	 * the error code is EINTR (or ERESTART) and this lwp is still part
150	 * of the same process.
151	 */
152	cmp	%o0, ERESTART		/* ERESTART is same as EINTR */
153	be,a	3f
154	mov	EINTR, %o0
1553:
156	cmp	%o0, EINTR		/* interrupted while waiting? */
157	bne	__cerror		/* if not, return the error */
158	nop
159
160	save	%sp, -SA(MINFRAME), %sp
161	call	_private_getpid		/* get current process id */
162	nop
163	PIC_SETUP(g1)
164#ifdef __sparcv9
165	sethi	%hi(door_create_pid), %g5
166	or	%g5, %lo(door_create_pid), %g5
167	ldn	[%g1 + %g5], %g1
168#else
169	ldn	[%g1 + door_create_pid], %g1
170#endif
171	ld	[%g1], %g1
172	cmp	%o0, %g1		/* same process? */
173	mov	EINTR, %o0	/* if no, return EINTR (child of forkall) */
174	bne	__cerror
175	restore
176
177	clr	%o0			/* clear arguments and restart */
178	clr	%o1
179	ba	door_restart
180	clr	%o2
181	SET_SIZE(__door_return)
182