xref: /illumos-gate/usr/src/lib/libc/i386/sys/syscall.S (revision 5d9d9091)
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
57257d1b4Sraf * Common Development and Distribution License (the "License").
67257d1b4Sraf * 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 */
217257d1b4Sraf
227c478bd9Sstevel@tonic-gate/*
237257d1b4Sraf * Copyright 2008 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	"syscall.s"
287c478bd9Sstevel@tonic-gate
297257d1b4Sraf#include "SYS.h"
307c478bd9Sstevel@tonic-gate#include <sys/trap.h>
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(syscall,function)
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate/*
357257d1b4Sraf * See sparc/sys/syscall.s to understand why _syscall6() exists.
367c478bd9Sstevel@tonic-gate * On x86, the implementation of the two are the same, the only
377257d1b4Sraf * difference being that _syscall6 is not an exported symbol.
387c478bd9Sstevel@tonic-gate */
397257d1b4Sraf	ENTRY2(syscall,_syscall6)
407c478bd9Sstevel@tonic-gate	popl	%edx		/ return address
417c478bd9Sstevel@tonic-gate	popl	%eax		/ system call number
427c478bd9Sstevel@tonic-gate	pushl	%edx
437c478bd9Sstevel@tonic-gate#if defined(_SYSC_INSN)
447c478bd9Sstevel@tonic-gate	.byte	0xf, 0x5	/* syscall */
457c478bd9Sstevel@tonic-gate#elif defined(_SEP_INSN)
467c478bd9Sstevel@tonic-gate	call	8f
477c478bd9Sstevel@tonic-gate8:	popl	%edx
487c478bd9Sstevel@tonic-gate	movl	%esp, %ecx
497c478bd9Sstevel@tonic-gate	addl	$[9f - 8b], %edx
507c478bd9Sstevel@tonic-gate	sysenter
517c478bd9Sstevel@tonic-gate9:
527c478bd9Sstevel@tonic-gate#else
537c478bd9Sstevel@tonic-gate	int	$T_SYSCALLINT
547c478bd9Sstevel@tonic-gate#endif
557c478bd9Sstevel@tonic-gate	movl	0(%esp), %edx
567c478bd9Sstevel@tonic-gate	pushl	%edx		/ restore the return address
577c478bd9Sstevel@tonic-gate	SYSCERROR
587c478bd9Sstevel@tonic-gate	ret
597257d1b4Sraf	SET_SIZE(syscall)
607c478bd9Sstevel@tonic-gate	SET_SIZE(_syscall6)
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate/*
637c478bd9Sstevel@tonic-gate * See sparc/sys/syscall.s to understand why __systemcall6() exists.
647c478bd9Sstevel@tonic-gate * On x86, the implementation of the two are the same, the only
657c478bd9Sstevel@tonic-gate * difference being that __systemcall6 is not an exported symbol.
667c478bd9Sstevel@tonic-gate *
677c478bd9Sstevel@tonic-gate * WARNING WARNING WARNING:
687c478bd9Sstevel@tonic-gate * The int $T_SYSCALL instruction below is needed by /proc when it scans a
697c478bd9Sstevel@tonic-gate * controlled process's text for a syscall instruction.  It must be present in
707c478bd9Sstevel@tonic-gate * all libc variants because /proc cannot use an optimized syscall instruction
717c478bd9Sstevel@tonic-gate * to enter the kernel; optimized syscalls could be disabled by private LDT use.
727c478bd9Sstevel@tonic-gate * We must leave at least one int $T_SYSCALLINT in the text for /proc to find
737c478bd9Sstevel@tonic-gate * (see the Pscantext() routine).
747c478bd9Sstevel@tonic-gate */
757c478bd9Sstevel@tonic-gate	ENTRY2(__systemcall,__systemcall6)
767c478bd9Sstevel@tonic-gate	popl	%edx		/ return address
777c478bd9Sstevel@tonic-gate	popl	%ecx		/ structure return address
787c478bd9Sstevel@tonic-gate	popl	%eax		/ system call number
797c478bd9Sstevel@tonic-gate	pushl	%edx
807c478bd9Sstevel@tonic-gate	int	$T_SYSCALLINT
817c478bd9Sstevel@tonic-gate	jae	1f
827c478bd9Sstevel@tonic-gate	/ error; clear syscall return values in the structure
837c478bd9Sstevel@tonic-gate	movl	$-1, 0(%ecx)	/ sys_rval1
847c478bd9Sstevel@tonic-gate	movl	$-1, 4(%ecx)	/ sys_rval2
857c478bd9Sstevel@tonic-gate	jmp	2f		/ %eax contains the error number
867c478bd9Sstevel@tonic-gate1:
877c478bd9Sstevel@tonic-gate	/ no error; copy syscall return values to the structure
887c478bd9Sstevel@tonic-gate	movl	%eax, 0(%ecx)	/ sys_rval1
897c478bd9Sstevel@tonic-gate	movl	%edx, 4(%ecx)	/ sys_rval2
907c478bd9Sstevel@tonic-gate	xorl	%eax, %eax	/ no error, set %eax to zero
917c478bd9Sstevel@tonic-gate2:
927c478bd9Sstevel@tonic-gate	movl	0(%esp), %edx	/ Restore the stack frame to original size
937c478bd9Sstevel@tonic-gate	pushl	%ecx
947c478bd9Sstevel@tonic-gate	pushl	%edx		/ restore the return address
957c478bd9Sstevel@tonic-gate	ret
967c478bd9Sstevel@tonic-gate	SET_SIZE(__systemcall)
977c478bd9Sstevel@tonic-gate	SET_SIZE(__systemcall6)
98