xref: /titanic_44/usr/src/lib/libc/sparc/sys/door.s (revision 643e2e74e1c00e6b3d1896a6a67dbdb7308135c3)
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	(SA(MINFRAME) + STACK_BIAS + 0*CLONGSIZE)
48#define	DOOR_DATA_PTR	(SA(MINFRAME) + STACK_BIAS + 1*CLONGSIZE)
49#define	DOOR_DATA_SIZE	(SA(MINFRAME) + STACK_BIAS + 2*CLONGSIZE)
50#define	DOOR_DESC_PTR	(SA(MINFRAME) + STACK_BIAS + 3*CLONGSIZE)
51#define	DOOR_DESC_SIZE	(SA(MINFRAME) + STACK_BIAS + 4*CLONGSIZE)
52#define	DOOR_PC		(SA(MINFRAME) + STACK_BIAS + 5*CLONGSIZE)
53#define	DOOR_SERVERS	(SA(MINFRAME) + STACK_BIAS + 6*CLONGSIZE)
54#define	DOOR_INFO_PTR	(SA(MINFRAME) + STACK_BIAS + 7*CLONGSIZE)
55
56/*
57 * All of the syscalls except door_return() follow the same pattern.  The
58 * subcode goes in %o5, after all of the other arguments.
59 */
60#define	DOOR_SYSCALL(name, code)					\
61	ENTRY(name);							\
62	mov	code, %o5;		/* 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	mov	DOOR_RETURN, %o5	/* subcode */
91	SYSTRAP_RVAL1(door)
92	bcs,pn	%icc, 2f			/* errno is set */
93	ld	[%sp + DOOR_SERVERS], %g1	/* (delay) load nservers */
94	/*
95	 * On return, we're serving a door_call.  Our stack looks like this:
96	 *
97	 *		descriptors (if any)
98	 *		data (if any)
99	 *		struct door_results
100	 *		MINFRAME
101	 *	sp ->
102	 */
103	tst	%g1				/* test nservers */
104	bg	1f				/* everything looks o.k. */
105	ldn	[%sp + DOOR_COOKIE], %o0	/* (delay) load cookie */
106	/*
107	 * this is the last server thread - call creation func for more
108	 */
109	save	%sp, -SA(MINFRAME), %sp
110	PIC_SETUP(g1)
111#ifdef __sparcv9
112	sethi	%hi(door_server_func), %g5
113	or	%g5, %lo(door_server_func), %g5
114	ldn	[%g5 + %g1], %g1
115#else
116	ldn	[%g1 + door_server_func], %g1
117#endif
118	ldn	[%g1], %g1
119	jmpl	%g1, %o7			/* call create function */
120	ldn	[%fp + DOOR_INFO_PTR], %o0	/* (delay) load door_info ptr */
121	restore
1221:
123	/* Call the door server function now */
124	ldn	[%sp + DOOR_DATA_PTR], %o1
125	ldn	[%sp + DOOR_DATA_SIZE], %o2
126	ldn	[%sp + DOOR_DESC_PTR], %o3
127	ldn	[%sp + DOOR_PC], %g1
128	jmpl	%g1, %o7
129	ldn	[%sp + DOOR_DESC_SIZE], %o4
130
131	/* Exit the thread if we return here */
132	call	_thrp_terminate
133	mov	%g0, %o0
134	/* NOTREACHED */
1352:
136	/*
137	 * Error during door_return call.  Repark the thread in the kernel if
138	 * the error code is EINTR (or ERESTART) and this lwp is still part
139	 * of the same process.
140	 */
141	cmp	%o0, ERESTART		/* ERESTART is same as EINTR */
142	be,a	3f
143	mov	EINTR, %o0
1443:
145	cmp	%o0, EINTR		/* interrupted while waiting? */
146	bne	__cerror		/* if not, return the error */
147	nop
148
149	save	%sp, -SA(MINFRAME), %sp
150	call	getpid
151	nop
152	PIC_SETUP(g1)
153#ifdef __sparcv9
154	sethi	%hi(door_create_pid), %g5
155	or	%g5, %lo(door_create_pid), %g5
156	ldn	[%g1 + %g5], %g1
157#else
158	ldn	[%g1 + door_create_pid], %g1
159#endif
160	ld	[%g1], %g1
161	cmp	%o0, %g1		/* same process? */
162	mov	EINTR, %o0	/* if no, return EINTR (child of forkall) */
163	bne	__cerror
164	restore
165
166	clr	%o0			/* clear arguments and restart */
167	clr	%o1
168	ba	door_restart
169	clr	%o2
170	SET_SIZE(__door_return)
171