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