Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / lib / libc / i386 / sys / syscall.s
blob6c1f05f217d991a4a0de5b82fbf4e608ac4c959e
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 .file "syscall.s"
29 #include "SYS.h"
30 #include <sys/trap.h>
32 ANSI_PRAGMA_WEAK(syscall,function)
35 * See sparc/sys/syscall.s to understand why _syscall6() exists.
36 * On x86, the implementation of the two are the same, the only
37 * difference being that _syscall6 is not an exported symbol.
39 ENTRY2(syscall,_syscall6)
40 popl %edx / return address
41 popl %eax / system call number
42 pushl %edx
43 int $T_SYSCALLINT
44 movl 0(%esp), %edx
45 pushl %edx / restore the return address
46 SYSCERROR
47 ret
48 SET_SIZE(syscall)
49 SET_SIZE(_syscall6)
52 * See sparc/sys/syscall.s to understand why __systemcall6() exists.
53 * On x86, the implementation of the two are the same, the only
54 * difference being that __systemcall6 is not an exported symbol.
56 * WARNING WARNING WARNING:
57 * The int $T_SYSCALL instruction below is needed by /proc when it scans a
58 * controlled process's text for a syscall instruction. It must be present in
59 * all libc variants because /proc cannot use an optimized syscall instruction
60 * to enter the kernel; optimized syscalls could be disabled by private LDT use.
61 * We must leave at least one int $T_SYSCALLINT in the text for /proc to find
62 * (see the Pscantext() routine).
64 ENTRY2(__systemcall,__systemcall6)
65 popl %edx / return address
66 popl %ecx / structure return address
67 popl %eax / system call number
68 pushl %edx
69 int $T_SYSCALLINT
70 jae 1f
71 / error; clear syscall return values in the structure
72 movl $-1, 0(%ecx) / sys_rval1
73 movl $-1, 4(%ecx) / sys_rval2
74 jmp 2f / %eax contains the error number
76 / no error; copy syscall return values to the structure
77 movl %eax, 0(%ecx) / sys_rval1
78 movl %edx, 4(%ecx) / sys_rval2
79 xorl %eax, %eax / no error, set %eax to zero
81 movl 0(%esp), %edx / Restore the stack frame to original size
82 pushl %ecx
83 pushl %edx / restore the return address
84 ret
85 SET_SIZE(__systemcall)
86 SET_SIZE(__systemcall6)