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