17c478bd9Sstevel@tonic-gate/* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5a574db85Sraf * Common Development and Distribution License (the "License"). 6a574db85Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21a574db85Sraf 227c478bd9Sstevel@tonic-gate/* 23d00d0b26SSeth Goldberg * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 279a70fc3bSMark J. Nelson .file "door.s" 287c478bd9Sstevel@tonic-gate 297257d1b4Sraf#include "SYS.h" 307257d1b4Sraf#include <sys/door.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* 337c478bd9Sstevel@tonic-gate * weak aliases for public interfaces 347c478bd9Sstevel@tonic-gate */ 357257d1b4Sraf ANSI_PRAGMA_WEAK2(door_bind,__door_bind,function) 367257d1b4Sraf ANSI_PRAGMA_WEAK2(door_getparam,__door_getparam,function) 377257d1b4Sraf ANSI_PRAGMA_WEAK2(door_info,__door_info,function) 387257d1b4Sraf ANSI_PRAGMA_WEAK2(door_revoke,__door_revoke,function) 397257d1b4Sraf ANSI_PRAGMA_WEAK2(door_setparam,__door_setparam,function) 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate/* 427c478bd9Sstevel@tonic-gate * Offsets within struct door_results 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate#define DOOR_COOKIE _MUL(0, CLONGSIZE) 457c478bd9Sstevel@tonic-gate#define DOOR_DATA_PTR _MUL(1, CLONGSIZE) 467c478bd9Sstevel@tonic-gate#define DOOR_DATA_SIZE _MUL(2, CLONGSIZE) 477c478bd9Sstevel@tonic-gate#define DOOR_DESC_PTR _MUL(3, CLONGSIZE) 487c478bd9Sstevel@tonic-gate#define DOOR_DESC_SIZE _MUL(4, CLONGSIZE) 497c478bd9Sstevel@tonic-gate#define DOOR_PC _MUL(5, CLONGSIZE) 507c478bd9Sstevel@tonic-gate#define DOOR_SERVERS _MUL(6, CLONGSIZE) 517c478bd9Sstevel@tonic-gate#define DOOR_INFO_PTR _MUL(7, CLONGSIZE) 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate/* 547c478bd9Sstevel@tonic-gate * All of the syscalls except door_return() follow the same pattern. The 557c478bd9Sstevel@tonic-gate * subcode goes in %r9, after all of the other arguments. 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate#define DOOR_SYSCALL(name, code) \ 587c478bd9Sstevel@tonic-gate ENTRY(name); \ 597c478bd9Sstevel@tonic-gate movq $code, %r9; /* subcode */ \ 607c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(door); \ 617c478bd9Sstevel@tonic-gate SYSCERROR; \ 627c478bd9Sstevel@tonic-gate RET; \ 637c478bd9Sstevel@tonic-gate SET_SIZE(name) 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate DOOR_SYSCALL(__door_bind, DOOR_BIND) 667c478bd9Sstevel@tonic-gate DOOR_SYSCALL(__door_call, DOOR_CALL) 677c478bd9Sstevel@tonic-gate DOOR_SYSCALL(__door_create, DOOR_CREATE) 687c478bd9Sstevel@tonic-gate DOOR_SYSCALL(__door_getparam, DOOR_GETPARAM) 697c478bd9Sstevel@tonic-gate DOOR_SYSCALL(__door_info, DOOR_INFO) 707c478bd9Sstevel@tonic-gate DOOR_SYSCALL(__door_revoke, DOOR_REVOKE) 717c478bd9Sstevel@tonic-gate DOOR_SYSCALL(__door_setparam, DOOR_SETPARAM) 727c478bd9Sstevel@tonic-gate DOOR_SYSCALL(__door_ucred, DOOR_UCRED) 737c478bd9Sstevel@tonic-gate DOOR_SYSCALL(__door_unbind, DOOR_UNBIND) 747c478bd9Sstevel@tonic-gate DOOR_SYSCALL(__door_unref, DOOR_UNREFSYS) 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate/* 777c478bd9Sstevel@tonic-gate * int 787c478bd9Sstevel@tonic-gate * __door_return( 797c478bd9Sstevel@tonic-gate * void *data_ptr, 807c478bd9Sstevel@tonic-gate * size_t data_size, (in bytes) 817c478bd9Sstevel@tonic-gate * door_return_desc_t *door_ptr, (holds returned desc info) 827c478bd9Sstevel@tonic-gate * caddr_t stack_base, 837c478bd9Sstevel@tonic-gate * size_t stack_size) 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate ENTRY(__door_return) 86d00d0b26SSeth Goldberg pushq %rbp 87d00d0b26SSeth Goldberg movq %rsp, %rbp 88d00d0b26SSeth Goldberg subq $0x8, %rsp 89d00d0b26SSeth Goldberg /* 90d00d0b26SSeth Goldberg * Save stack_base (arg4), since %rcx will be trashed if the syscall 91d00d0b26SSeth Goldberg * returns via sysret 92d00d0b26SSeth Goldberg */ 93d00d0b26SSeth Goldberg movq %rcx, -0x8(%rbp) 94d00d0b26SSeth Goldberg 957c478bd9Sstevel@tonic-gatedoor_restart: 967c478bd9Sstevel@tonic-gate movq $DOOR_RETURN, %r9 /* subcode */ 977c478bd9Sstevel@tonic-gate SYSTRAP_RVAL1(door) 98c4ace179Sdm120769 jb 2f /* errno is set */ 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * On return, we're serving a door_call. Our stack looks like this: 1017c478bd9Sstevel@tonic-gate * 1027c478bd9Sstevel@tonic-gate * descriptors (if any) 1037c478bd9Sstevel@tonic-gate * data (if any) 1047c478bd9Sstevel@tonic-gate * sp-> struct door_results 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate movl DOOR_SERVERS(%rsp), %eax 1077c478bd9Sstevel@tonic-gate andl %eax, %eax /* test nservers */ 1087c478bd9Sstevel@tonic-gate jg 1f 1097c478bd9Sstevel@tonic-gate /* 1107c478bd9Sstevel@tonic-gate * this is the last server thread - call creation func for more 1117c478bd9Sstevel@tonic-gate */ 1127c478bd9Sstevel@tonic-gate movq DOOR_INFO_PTR(%rsp), %rdi 113*49b225e1SGavin Maltby call door_depletion_cb@PLT 1147c478bd9Sstevel@tonic-gate1: 1157c478bd9Sstevel@tonic-gate /* Call the door server function now */ 1167c478bd9Sstevel@tonic-gate movq DOOR_COOKIE(%rsp), %rdi 1177c478bd9Sstevel@tonic-gate movq DOOR_DATA_PTR(%rsp), %rsi 1187c478bd9Sstevel@tonic-gate movq DOOR_DATA_SIZE(%rsp), %rdx 1197c478bd9Sstevel@tonic-gate movq DOOR_DESC_PTR(%rsp), %rcx 1207c478bd9Sstevel@tonic-gate movq DOOR_DESC_SIZE(%rsp), %r8 1217c478bd9Sstevel@tonic-gate movq DOOR_PC(%rsp), %rax 1227c478bd9Sstevel@tonic-gate call *%rax 1237c478bd9Sstevel@tonic-gate /* Exit the thread if we return here */ 1247c478bd9Sstevel@tonic-gate movq $0, %rdi 1257257d1b4Sraf call _thrp_terminate 1267c478bd9Sstevel@tonic-gate /* NOTREACHED */ 127c4ace179Sdm1207692: 1287c478bd9Sstevel@tonic-gate /* 1297c478bd9Sstevel@tonic-gate * Error during door_return call. Repark the thread in the kernel if 1307c478bd9Sstevel@tonic-gate * the error code is EINTR (or ERESTART) and this lwp is still part 1317c478bd9Sstevel@tonic-gate * of the same process. 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate cmpl $ERESTART, %eax /* ERESTART is same as EINTR */ 1347c478bd9Sstevel@tonic-gate jne 3f 1357c478bd9Sstevel@tonic-gate movl $EINTR, %eax 1367c478bd9Sstevel@tonic-gate3: 1377c478bd9Sstevel@tonic-gate cmpl $EINTR, %eax /* interrupted while waiting? */ 138d00d0b26SSeth Goldberg jne 4f /* if not, return the error */ 1397c478bd9Sstevel@tonic-gate 1408cd45542Sraf call getpid /* get current process id */ 1417c478bd9Sstevel@tonic-gate movq _daref_(door_create_pid), %rdx 1427c478bd9Sstevel@tonic-gate movl 0(%rdx), %edx 1437c478bd9Sstevel@tonic-gate cmpl %eax, %edx /* same process? */ 1447c478bd9Sstevel@tonic-gate movl $EINTR, %eax /* if no, return EINTR (child of forkall) */ 145d00d0b26SSeth Goldberg jne 4f 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate movq $0, %rdi /* clear arguments and restart */ 1487c478bd9Sstevel@tonic-gate movq $0, %rsi 1497c478bd9Sstevel@tonic-gate movq $0, %rdx 150d00d0b26SSeth Goldberg movq -0x8(%rbp), %rcx /* Restore arg4 (stack_base) */ 1517c478bd9Sstevel@tonic-gate jmp door_restart 152d00d0b26SSeth Goldberg 153d00d0b26SSeth Goldberg4: 154d00d0b26SSeth Goldberg leave 155d00d0b26SSeth Goldberg jmp __cerror 1567c478bd9Sstevel@tonic-gate SET_SIZE(__door_return) 157