import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / amd64 / sys / door.s
blob15061adf95526ddd6a2a7912f8cb28afa01dff09
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 .file "door.s"
29 #include "SYS.h"
30 #include <sys/door.h>
33 * weak aliases for public interfaces
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)
42 * Offsets within struct door_results
44 #define DOOR_COOKIE _MUL(0, CLONGSIZE)
45 #define DOOR_DATA_PTR _MUL(1, CLONGSIZE)
46 #define DOOR_DATA_SIZE _MUL(2, CLONGSIZE)
47 #define DOOR_DESC_PTR _MUL(3, CLONGSIZE)
48 #define DOOR_DESC_SIZE _MUL(4, CLONGSIZE)
49 #define DOOR_PC _MUL(5, CLONGSIZE)
50 #define DOOR_SERVERS _MUL(6, CLONGSIZE)
51 #define DOOR_INFO_PTR _MUL(7, CLONGSIZE)
54 * All of the syscalls except door_return() follow the same pattern. The
55 * subcode goes in %r9, after all of the other arguments.
57 #define DOOR_SYSCALL(name, code) \
58 ENTRY(name); \
59 movq $code, %r9; /* subcode */ \
60 SYSTRAP_RVAL1(door); \
61 SYSCERROR; \
62 RET; \
63 SET_SIZE(name)
65 DOOR_SYSCALL(__door_bind, DOOR_BIND)
66 DOOR_SYSCALL(__door_call, DOOR_CALL)
67 DOOR_SYSCALL(__door_create, DOOR_CREATE)
68 DOOR_SYSCALL(__door_getparam, DOOR_GETPARAM)
69 DOOR_SYSCALL(__door_info, DOOR_INFO)
70 DOOR_SYSCALL(__door_revoke, DOOR_REVOKE)
71 DOOR_SYSCALL(__door_setparam, DOOR_SETPARAM)
72 DOOR_SYSCALL(__door_ucred, DOOR_UCRED)
73 DOOR_SYSCALL(__door_unbind, DOOR_UNBIND)
74 DOOR_SYSCALL(__door_unref, DOOR_UNREFSYS)
77 * int
78 * __door_return(
79 * void *data_ptr,
80 * size_t data_size, (in bytes)
81 * door_return_desc_t *door_ptr, (holds returned desc info)
82 * caddr_t stack_base,
83 * size_t stack_size)
85 ENTRY(__door_return)
86 pushq %rbp
87 movq %rsp, %rbp
88 subq $0x8, %rsp
90 * Save stack_base (arg4), since %rcx will be trashed if the syscall
91 * returns via sysret
93 movq %rcx, -0x8(%rbp)
95 door_restart:
96 movq $DOOR_RETURN, %r9 /* subcode */
97 SYSTRAP_RVAL1(door)
98 jb 2f /* errno is set */
100 * On return, we're serving a door_call. Our stack looks like this:
102 * descriptors (if any)
103 * data (if any)
104 * sp-> struct door_results
106 movl DOOR_SERVERS(%rsp), %eax
107 andl %eax, %eax /* test nservers */
108 jg 1f
110 * this is the last server thread - call creation func for more
112 movq DOOR_INFO_PTR(%rsp), %rdi
113 call door_depletion_cb@PLT
115 /* Call the door server function now */
116 movq DOOR_COOKIE(%rsp), %rdi
117 movq DOOR_DATA_PTR(%rsp), %rsi
118 movq DOOR_DATA_SIZE(%rsp), %rdx
119 movq DOOR_DESC_PTR(%rsp), %rcx
120 movq DOOR_DESC_SIZE(%rsp), %r8
121 movq DOOR_PC(%rsp), %rax
122 call *%rax
123 /* Exit the thread if we return here */
124 movq $0, %rdi
125 call _thrp_terminate
126 /* NOTREACHED */
129 * Error during door_return call. Repark the thread in the kernel if
130 * the error code is EINTR (or ERESTART) and this lwp is still part
131 * of the same process.
133 cmpl $ERESTART, %eax /* ERESTART is same as EINTR */
134 jne 3f
135 movl $EINTR, %eax
137 cmpl $EINTR, %eax /* interrupted while waiting? */
138 jne 4f /* if not, return the error */
140 call getpid /* get current process id */
141 movq _daref_(door_create_pid), %rdx
142 movl 0(%rdx), %edx
143 cmpl %eax, %edx /* same process? */
144 movl $EINTR, %eax /* if no, return EINTR (child of forkall) */
145 jne 4f
147 movq $0, %rdi /* clear arguments and restart */
148 movq $0, %rsi
149 movq $0, %rdx
150 movq -0x8(%rbp), %rcx /* Restore arg4 (stack_base) */
151 jmp door_restart
154 leave
155 jmp __cerror
156 SET_SIZE(__door_return)