2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A .file "door.s"
2N/A
2N/A#include "SYS.h"
2N/A#include <sys/door.h>
2N/A
2N/A /*
2N/A * weak aliases for public interfaces
2N/A */
2N/A ANSI_PRAGMA_WEAK2(door_bind,__door_bind,function)
2N/A ANSI_PRAGMA_WEAK2(door_getparam,__door_getparam,function)
2N/A ANSI_PRAGMA_WEAK2(door_info,__door_info,function)
2N/A ANSI_PRAGMA_WEAK2(door_revoke,__door_revoke,function)
2N/A ANSI_PRAGMA_WEAK2(door_setparam,__door_setparam,function)
2N/A
2N/A/*
2N/A * Offsets within struct door_results
2N/A */
2N/A#define DOOR_COOKIE _MUL(0, CLONGSIZE)
2N/A#define DOOR_DATA_PTR _MUL(1, CLONGSIZE)
2N/A#define DOOR_DATA_SIZE _MUL(2, CLONGSIZE)
2N/A#define DOOR_DESC_PTR _MUL(3, CLONGSIZE)
2N/A#define DOOR_DESC_SIZE _MUL(4, CLONGSIZE)
2N/A#define DOOR_PC _MUL(5, CLONGSIZE)
2N/A#define DOOR_SERVERS _MUL(6, CLONGSIZE)
2N/A#define DOOR_INFO_PTR _MUL(7, CLONGSIZE)
2N/A
2N/A/*
2N/A * All of the syscalls except door_return() follow the same pattern. The
2N/A * subcode goes in %r9, after all of the other arguments.
2N/A */
2N/A#define DOOR_SYSCALL(name, code) \
2N/A ENTRY(name); \
2N/A movq $code, %r9; /* subcode */ \
2N/A SYSTRAP_RVAL1(door); \
2N/A SYSCERROR; \
2N/A RET; \
2N/A SET_SIZE(name)
2N/A
2N/A DOOR_SYSCALL(__door_bind, DOOR_BIND)
2N/A DOOR_SYSCALL(__door_call, DOOR_CALL)
2N/A DOOR_SYSCALL(__door_create, DOOR_CREATE)
2N/A DOOR_SYSCALL(__door_getparam, DOOR_GETPARAM)
2N/A DOOR_SYSCALL(__door_info, DOOR_INFO)
2N/A DOOR_SYSCALL(__door_revoke, DOOR_REVOKE)
2N/A DOOR_SYSCALL(__door_setparam, DOOR_SETPARAM)
2N/A DOOR_SYSCALL(__door_ucred, DOOR_UCRED)
2N/A DOOR_SYSCALL(__door_unbind, DOOR_UNBIND)
2N/A DOOR_SYSCALL(__door_unref, DOOR_UNREFSYS)
2N/A
2N/A/*
2N/A * int
2N/A * __door_return(
2N/A * void *data_ptr,
2N/A * size_t data_size, (in bytes)
2N/A * door_return_desc_t *door_ptr, (holds returned desc info)
2N/A * caddr_t stack_base,
2N/A * size_t stack_size)
2N/A */
2N/A ENTRY(__door_return)
2N/A pushq %rbp
2N/A movq %rsp, %rbp
2N/A subq $0x8, %rsp
2N/A /*
2N/A * Save stack_base (arg4), since %rcx will be trashed if the syscall
2N/A * returns via sysret
2N/A */
2N/A movq %rcx, -0x8(%rbp)
2N/A
2N/Adoor_restart:
2N/A movq $DOOR_RETURN, %r9 /* subcode */
2N/A SYSTRAP_RVAL1(door)
2N/A jb 2f /* errno is set */
2N/A /*
2N/A * On return, we're serving a door_call. Our stack looks like this:
2N/A *
2N/A * descriptors (if any)
2N/A * data (if any)
2N/A * sp-> struct door_results
2N/A */
2N/A movl DOOR_SERVERS(%rsp), %eax
2N/A andl %eax, %eax /* test nservers */
2N/A jg 1f
2N/A /*
2N/A * this is the last server thread - call creation func for more
2N/A */
2N/A movq DOOR_INFO_PTR(%rsp), %rdi
2N/A call door_depletion_cb@PLT
2N/A1:
2N/A /* Call the door server function now */
2N/A movq DOOR_COOKIE(%rsp), %rdi
2N/A movq DOOR_DATA_PTR(%rsp), %rsi
2N/A movq DOOR_DATA_SIZE(%rsp), %rdx
2N/A movq DOOR_DESC_PTR(%rsp), %rcx
2N/A movq DOOR_DESC_SIZE(%rsp), %r8
2N/A movq DOOR_PC(%rsp), %rax
2N/A call *%rax
2N/A /* Exit the thread if we return here */
2N/A movq $0, %rdi
2N/A call _thrp_terminate
2N/A /* NOTREACHED */
2N/A2:
2N/A /*
2N/A * Error during door_return call. Repark the thread in the kernel if
2N/A * the error code is EINTR (or ERESTART) and this lwp is still part
2N/A * of the same process.
2N/A */
2N/A cmpl $ERESTART, %eax /* ERESTART is same as EINTR */
2N/A jne 3f
2N/A movl $EINTR, %eax
2N/A3:
2N/A cmpl $EINTR, %eax /* interrupted while waiting? */
2N/A jne 4f /* if not, return the error */
2N/A
2N/A call getpid /* get current process id */
2N/A movq _daref_(door_create_pid), %rdx
2N/A movl 0(%rdx), %edx
2N/A cmpl %eax, %edx /* same process? */
2N/A movl $EINTR, %eax /* if no, return EINTR (child of forkall) */
2N/A jne 4f
2N/A
2N/A movq $0, %rdi /* clear arguments and restart */
2N/A movq $0, %rsi
2N/A movq $0, %rdx
2N/A movq -0x8(%rbp), %rcx /* Restore arg4 (stack_base) */
2N/A jmp door_restart
2N/A
2N/A4:
2N/A leave
2N/A jmp __cerror
2N/A SET_SIZE(__door_return)