1*5d9d9091SRichard Lowe/* 2*5d9d9091SRichard Lowe * CDDL HEADER START 3*5d9d9091SRichard Lowe * 4*5d9d9091SRichard Lowe * The contents of this file are subject to the terms of the 5*5d9d9091SRichard Lowe * Common Development and Distribution License (the "License"). 6*5d9d9091SRichard Lowe * You may not use this file except in compliance with the License. 7*5d9d9091SRichard Lowe * 8*5d9d9091SRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*5d9d9091SRichard Lowe * or http://www.opensolaris.org/os/licensing. 10*5d9d9091SRichard Lowe * See the License for the specific language governing permissions 11*5d9d9091SRichard Lowe * and limitations under the License. 12*5d9d9091SRichard Lowe * 13*5d9d9091SRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each 14*5d9d9091SRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*5d9d9091SRichard Lowe * If applicable, add the following below this CDDL HEADER, with the 16*5d9d9091SRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying 17*5d9d9091SRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner] 18*5d9d9091SRichard Lowe * 19*5d9d9091SRichard Lowe * CDDL HEADER END 20*5d9d9091SRichard Lowe */ 21*5d9d9091SRichard Lowe 22*5d9d9091SRichard Lowe/* 23*5d9d9091SRichard Lowe * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24*5d9d9091SRichard Lowe * Use is subject to license terms. 25*5d9d9091SRichard Lowe */ 26*5d9d9091SRichard Lowe 27*5d9d9091SRichard Lowe .file "syscall.s" 28*5d9d9091SRichard Lowe 29*5d9d9091SRichard Lowe#include "SYS.h" 30*5d9d9091SRichard Lowe#include <sys/trap.h> 31*5d9d9091SRichard Lowe 32*5d9d9091SRichard Lowe ANSI_PRAGMA_WEAK(syscall,function) 33*5d9d9091SRichard Lowe 34*5d9d9091SRichard Lowe/* 35*5d9d9091SRichard Lowe * See sparc/sys/syscall.s to understand why _syscall6() exists. 36*5d9d9091SRichard Lowe * On x86, the implementation of the two are the same, the only 37*5d9d9091SRichard Lowe * difference being that _syscall6 is not an exported symbol. 38*5d9d9091SRichard Lowe */ 39*5d9d9091SRichard Lowe ENTRY2(syscall,_syscall6) 40*5d9d9091SRichard Lowe popl %edx / return address 41*5d9d9091SRichard Lowe popl %eax / system call number 42*5d9d9091SRichard Lowe pushl %edx 43*5d9d9091SRichard Lowe#if defined(_SYSC_INSN) 44*5d9d9091SRichard Lowe .byte 0xf, 0x5 /* syscall */ 45*5d9d9091SRichard Lowe#elif defined(_SEP_INSN) 46*5d9d9091SRichard Lowe call 8f 47*5d9d9091SRichard Lowe8: popl %edx 48*5d9d9091SRichard Lowe movl %esp, %ecx 49*5d9d9091SRichard Lowe addl $[9f - 8b], %edx 50*5d9d9091SRichard Lowe sysenter 51*5d9d9091SRichard Lowe9: 52*5d9d9091SRichard Lowe#else 53*5d9d9091SRichard Lowe int $T_SYSCALLINT 54*5d9d9091SRichard Lowe#endif 55*5d9d9091SRichard Lowe movl 0(%esp), %edx 56*5d9d9091SRichard Lowe pushl %edx / restore the return address 57*5d9d9091SRichard Lowe SYSCERROR 58*5d9d9091SRichard Lowe ret 59*5d9d9091SRichard Lowe SET_SIZE(syscall) 60*5d9d9091SRichard Lowe SET_SIZE(_syscall6) 61*5d9d9091SRichard Lowe 62*5d9d9091SRichard Lowe/* 63*5d9d9091SRichard Lowe * See sparc/sys/syscall.s to understand why __systemcall6() exists. 64*5d9d9091SRichard Lowe * On x86, the implementation of the two are the same, the only 65*5d9d9091SRichard Lowe * difference being that __systemcall6 is not an exported symbol. 66*5d9d9091SRichard Lowe * 67*5d9d9091SRichard Lowe * WARNING WARNING WARNING: 68*5d9d9091SRichard Lowe * The int $T_SYSCALL instruction below is needed by /proc when it scans a 69*5d9d9091SRichard Lowe * controlled process's text for a syscall instruction. It must be present in 70*5d9d9091SRichard Lowe * all libc variants because /proc cannot use an optimized syscall instruction 71*5d9d9091SRichard Lowe * to enter the kernel; optimized syscalls could be disabled by private LDT use. 72*5d9d9091SRichard Lowe * We must leave at least one int $T_SYSCALLINT in the text for /proc to find 73*5d9d9091SRichard Lowe * (see the Pscantext() routine). 74*5d9d9091SRichard Lowe */ 75*5d9d9091SRichard Lowe ENTRY2(__systemcall,__systemcall6) 76*5d9d9091SRichard Lowe popl %edx / return address 77*5d9d9091SRichard Lowe popl %ecx / structure return address 78*5d9d9091SRichard Lowe popl %eax / system call number 79*5d9d9091SRichard Lowe pushl %edx 80*5d9d9091SRichard Lowe int $T_SYSCALLINT 81*5d9d9091SRichard Lowe jae 1f 82*5d9d9091SRichard Lowe / error; clear syscall return values in the structure 83*5d9d9091SRichard Lowe movl $-1, 0(%ecx) / sys_rval1 84*5d9d9091SRichard Lowe movl $-1, 4(%ecx) / sys_rval2 85*5d9d9091SRichard Lowe jmp 2f / %eax contains the error number 86*5d9d9091SRichard Lowe1: 87*5d9d9091SRichard Lowe / no error; copy syscall return values to the structure 88*5d9d9091SRichard Lowe movl %eax, 0(%ecx) / sys_rval1 89*5d9d9091SRichard Lowe movl %edx, 4(%ecx) / sys_rval2 90*5d9d9091SRichard Lowe xorl %eax, %eax / no error, set %eax to zero 91*5d9d9091SRichard Lowe2: 92*5d9d9091SRichard Lowe movl 0(%esp), %edx / Restore the stack frame to original size 93*5d9d9091SRichard Lowe pushl %ecx 94*5d9d9091SRichard Lowe pushl %edx / restore the return address 95*5d9d9091SRichard Lowe ret 96*5d9d9091SRichard Lowe SET_SIZE(__systemcall) 97*5d9d9091SRichard Lowe SET_SIZE(__systemcall6) 98