Home | History | Annotate | Download | only in sys
      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 	.file	"door.s"
     28 
     29 #include "SYS.h"
     30 #include <sys/door.h>
     31 
     32 	/*
     33 	 * weak aliases for public interfaces
     34 	 */
     35 	ANSI_PRAGMA_WEAK2(door_bind,__door_bind,function)
     36 	ANSI_PRAGMA_WEAK2(door_getparam,__door_getparam,function)
     37 	ANSI_PRAGMA_WEAK2(door_info,__door_info,function)
     38 	ANSI_PRAGMA_WEAK2(door_revoke,__door_revoke,function)
     39 	ANSI_PRAGMA_WEAK2(door_setparam,__door_setparam,function)
     40 	ANSI_PRAGMA_WEAK2(door_unbind,__door_unbind,function)
     41 
     42 /*
     43  * Offsets within struct door_results
     44  */
     45 #define	DOOR_COOKIE	(SA(MINFRAME) + STACK_BIAS + 0*CLONGSIZE)
     46 #define	DOOR_DATA_PTR	(SA(MINFRAME) + STACK_BIAS + 1*CLONGSIZE)
     47 #define	DOOR_DATA_SIZE	(SA(MINFRAME) + STACK_BIAS + 2*CLONGSIZE)
     48 #define	DOOR_DESC_PTR	(SA(MINFRAME) + STACK_BIAS + 3*CLONGSIZE)
     49 #define	DOOR_DESC_SIZE	(SA(MINFRAME) + STACK_BIAS + 4*CLONGSIZE)
     50 #define	DOOR_PC		(SA(MINFRAME) + STACK_BIAS + 5*CLONGSIZE)
     51 #define	DOOR_SERVERS	(SA(MINFRAME) + STACK_BIAS + 6*CLONGSIZE)
     52 #define	DOOR_INFO_PTR	(SA(MINFRAME) + STACK_BIAS + 7*CLONGSIZE)
     53 
     54 /*
     55  * All of the syscalls except door_return() follow the same pattern.  The
     56  * subcode goes in %o5, after all of the other arguments.
     57  */
     58 #define	DOOR_SYSCALL(name, code)					\
     59 	ENTRY(name);							\
     60 	mov	code, %o5;		/* subcode */			\
     61 	SYSTRAP_RVAL1(door);						\
     62 	SYSCERROR;							\
     63 	RET;								\
     64 	SET_SIZE(name)
     65 
     66 	DOOR_SYSCALL(__door_bind,	DOOR_BIND)
     67 	DOOR_SYSCALL(__door_call,	DOOR_CALL)
     68 	DOOR_SYSCALL(__door_create,	DOOR_CREATE)
     69 	DOOR_SYSCALL(__door_getparam,	DOOR_GETPARAM)
     70 	DOOR_SYSCALL(__door_info,	DOOR_INFO)
     71 	DOOR_SYSCALL(__door_revoke,	DOOR_REVOKE)
     72 	DOOR_SYSCALL(__door_setparam,	DOOR_SETPARAM)
     73 	DOOR_SYSCALL(__door_ucred,	DOOR_UCRED)
     74 	DOOR_SYSCALL(__door_unbind,	DOOR_UNBIND)
     75 	DOOR_SYSCALL(__door_unref,	DOOR_UNREFSYS)
     76 
     77 /*
     78  * int
     79  * __door_return(
     80  *	void 			*data_ptr,
     81  *	size_t			data_size,	(in bytes)
     82  *	door_return_desc_t	*door_ptr,	(holds returned desc info)
     83  *	caddr_t			stack_base,
     84  *	size_t			stack_size)
     85  */
     86 	ENTRY(__door_return)
     87 door_restart:
     88 	mov	DOOR_RETURN, %o5	/* subcode */
     89 	SYSTRAP_RVAL1(door)
     90 	bcs,pn	%icc, 2f			/* errno is set */
     91 	ld	[%sp + DOOR_SERVERS], %g1	/* (delay) load nservers */
     92 	/*
     93 	 * On return, we're serving a door_call.  Our stack looks like this:
     94 	 *
     95 	 *		descriptors (if any)
     96 	 *		data (if any)
     97 	 *		struct door_results
     98 	 *		MINFRAME
     99 	 *	sp ->
    100 	 */
    101 	tst	%g1				/* test nservers */
    102 	bg	1f				/* everything looks o.k. */
    103 	ldn	[%sp + DOOR_COOKIE], %o0	/* (delay) load cookie */
    104 	/*
    105 	 * this is the last server thread - call creation func for more
    106 	 */
    107 	save	%sp, -SA(MINFRAME), %sp
    108 	PIC_SETUP(g1)
    109 #ifdef __sparcv9
    110 	sethi	%hi(door_server_func), %g5
    111 	or	%g5, %lo(door_server_func), %g5
    112 	ldn	[%g5 + %g1], %g1
    113 #else
    114 	ldn	[%g1 + door_server_func], %g1
    115 #endif
    116 	ldn	[%g1], %g1
    117 	jmpl	%g1, %o7			/* call create function */
    118 	ldn	[%fp + DOOR_INFO_PTR], %o0	/* (delay) load door_info ptr */
    119 	restore
    120 1:
    121 	/* Call the door server function now */
    122 	ldn	[%sp + DOOR_DATA_PTR], %o1
    123 	ldn	[%sp + DOOR_DATA_SIZE], %o2
    124 	ldn	[%sp + DOOR_DESC_PTR], %o3
    125 	ldn	[%sp + DOOR_PC], %g1
    126 	jmpl	%g1, %o7
    127 	ldn	[%sp + DOOR_DESC_SIZE], %o4
    128 
    129 	/* Exit the thread if we return here */
    130 	call	_thrp_terminate
    131 	mov	%g0, %o0
    132 	/* NOTREACHED */
    133 2:
    134 	/*
    135 	 * Error during door_return call.  Repark the thread in the kernel if
    136 	 * the error code is EINTR (or ERESTART) and this lwp is still part
    137 	 * of the same process.
    138 	 */
    139 	cmp	%o0, ERESTART		/* ERESTART is same as EINTR */
    140 	be,a	3f
    141 	mov	EINTR, %o0
    142 3:
    143 	cmp	%o0, EINTR		/* interrupted while waiting? */
    144 	bne	__cerror		/* if not, return the error */
    145 	nop
    146 
    147 	save	%sp, -SA(MINFRAME), %sp
    148 	call	getpid
    149 	nop
    150 	PIC_SETUP(g1)
    151 #ifdef __sparcv9
    152 	sethi	%hi(door_create_pid), %g5
    153 	or	%g5, %lo(door_create_pid), %g5
    154 	ldn	[%g1 + %g5], %g1
    155 #else
    156 	ldn	[%g1 + door_create_pid], %g1
    157 #endif
    158 	ld	[%g1], %g1
    159 	cmp	%o0, %g1		/* same process? */
    160 	mov	EINTR, %o0	/* if no, return EINTR (child of forkall) */
    161 	bne	__cerror
    162 	restore
    163 
    164 	clr	%o0			/* clear arguments and restart */
    165 	clr	%o1
    166 	ba	door_restart
    167 	clr	%o2
    168 	SET_SIZE(__door_return)
    169