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