xref: /onnv-gate/usr/src/lib/libc/i386/sys/syscall.s (revision 7298:b69e27387f74)
10Sstevel@tonic-gate/*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
56812Sraf * Common Development and Distribution License (the "License").
66812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
216812Sraf
220Sstevel@tonic-gate/*
236812Sraf * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
27*7298SMark.J.Nelson@Sun.COM	.file	"syscall.s"
280Sstevel@tonic-gate
296812Sraf#include "SYS.h"
300Sstevel@tonic-gate#include <sys/trap.h>
310Sstevel@tonic-gate
320Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(syscall,function)
330Sstevel@tonic-gate
340Sstevel@tonic-gate/*
356812Sraf * See sparc/sys/syscall.s to understand why _syscall6() exists.
360Sstevel@tonic-gate * On x86, the implementation of the two are the same, the only
376812Sraf * difference being that _syscall6 is not an exported symbol.
380Sstevel@tonic-gate */
396812Sraf	ENTRY2(syscall,_syscall6)
400Sstevel@tonic-gate	popl	%edx		/ return address
410Sstevel@tonic-gate	popl	%eax		/ system call number
420Sstevel@tonic-gate	pushl	%edx
430Sstevel@tonic-gate#if defined(_SYSC_INSN)
440Sstevel@tonic-gate	.byte	0xf, 0x5	/* syscall */
450Sstevel@tonic-gate#elif defined(_SEP_INSN)
460Sstevel@tonic-gate	call	8f
470Sstevel@tonic-gate8:	popl	%edx
480Sstevel@tonic-gate	movl	%esp, %ecx
490Sstevel@tonic-gate	addl	$[9f - 8b], %edx
500Sstevel@tonic-gate	sysenter
510Sstevel@tonic-gate9:
520Sstevel@tonic-gate#else
530Sstevel@tonic-gate	int	$T_SYSCALLINT
540Sstevel@tonic-gate#endif
550Sstevel@tonic-gate	movl	0(%esp), %edx
560Sstevel@tonic-gate	pushl	%edx		/ restore the return address
570Sstevel@tonic-gate	SYSCERROR
580Sstevel@tonic-gate	ret
596812Sraf	SET_SIZE(syscall)
600Sstevel@tonic-gate	SET_SIZE(_syscall6)
610Sstevel@tonic-gate
620Sstevel@tonic-gate/*
630Sstevel@tonic-gate * See sparc/sys/syscall.s to understand why __systemcall6() exists.
640Sstevel@tonic-gate * On x86, the implementation of the two are the same, the only
650Sstevel@tonic-gate * difference being that __systemcall6 is not an exported symbol.
660Sstevel@tonic-gate *
670Sstevel@tonic-gate * WARNING WARNING WARNING:
680Sstevel@tonic-gate * The int $T_SYSCALL instruction below is needed by /proc when it scans a
690Sstevel@tonic-gate * controlled process's text for a syscall instruction.  It must be present in
700Sstevel@tonic-gate * all libc variants because /proc cannot use an optimized syscall instruction
710Sstevel@tonic-gate * to enter the kernel; optimized syscalls could be disabled by private LDT use.
720Sstevel@tonic-gate * We must leave at least one int $T_SYSCALLINT in the text for /proc to find
730Sstevel@tonic-gate * (see the Pscantext() routine).
740Sstevel@tonic-gate */
750Sstevel@tonic-gate	ENTRY2(__systemcall,__systemcall6)
760Sstevel@tonic-gate	popl	%edx		/ return address
770Sstevel@tonic-gate	popl	%ecx		/ structure return address
780Sstevel@tonic-gate	popl	%eax		/ system call number
790Sstevel@tonic-gate	pushl	%edx
800Sstevel@tonic-gate	int	$T_SYSCALLINT
810Sstevel@tonic-gate	jae	1f
820Sstevel@tonic-gate	/ error; clear syscall return values in the structure
830Sstevel@tonic-gate	movl	$-1, 0(%ecx)	/ sys_rval1
840Sstevel@tonic-gate	movl	$-1, 4(%ecx)	/ sys_rval2
850Sstevel@tonic-gate	jmp	2f		/ %eax contains the error number
860Sstevel@tonic-gate1:
870Sstevel@tonic-gate	/ no error; copy syscall return values to the structure
880Sstevel@tonic-gate	movl	%eax, 0(%ecx)	/ sys_rval1
890Sstevel@tonic-gate	movl	%edx, 4(%ecx)	/ sys_rval2
900Sstevel@tonic-gate	xorl	%eax, %eax	/ no error, set %eax to zero
910Sstevel@tonic-gate2:
920Sstevel@tonic-gate	movl	0(%esp), %edx	/ Restore the stack frame to original size
930Sstevel@tonic-gate	pushl	%ecx
940Sstevel@tonic-gate	pushl	%edx		/ restore the return address
950Sstevel@tonic-gate	ret
960Sstevel@tonic-gate	SET_SIZE(__systemcall)
970Sstevel@tonic-gate	SET_SIZE(__systemcall6)
98