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