xref: /onnv-gate/usr/src/lib/libc/amd64/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 2004 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
33*0Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(syscall,function)
34*0Sstevel@tonic-gate
35*0Sstevel@tonic-gate#include "SYS.h"
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate#undef _syscall		/* override "synonyms.h" */
38*0Sstevel@tonic-gate#undef __systemcall
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate	ENTRY(_syscall)
41*0Sstevel@tonic-gate	pushq	%rbp
42*0Sstevel@tonic-gate	movq	%rsp, %rbp
43*0Sstevel@tonic-gate	/* construct a new call stack frame */
44*0Sstevel@tonic-gate	movl	%edi, %eax	/* sysnum */
45*0Sstevel@tonic-gate	movq	%rsi, %rdi	/* arg0 */
46*0Sstevel@tonic-gate	movq	%rdx, %rsi	/* arg1 */
47*0Sstevel@tonic-gate	movq	%rcx, %rdx	/* arg2 */
48*0Sstevel@tonic-gate	movq	%r8, %rcx	/* arg3 */
49*0Sstevel@tonic-gate	movq	%r9, %r8	/* arg4 */
50*0Sstevel@tonic-gate	movq	16(%rbp), %r9	/* arg5 */
51*0Sstevel@tonic-gate	movq	32(%rbp), %r10
52*0Sstevel@tonic-gate	pushq	%r10		/* arg7 */
53*0Sstevel@tonic-gate	movq	24(%rbp), %r10
54*0Sstevel@tonic-gate	pushq	%r10		/* arg6 */
55*0Sstevel@tonic-gate	movq	8(%rbp), %r10
56*0Sstevel@tonic-gate	pushq	%r10		/* return addr */
57*0Sstevel@tonic-gate	/* issue the system call */
58*0Sstevel@tonic-gate	movq	%rcx, %r10
59*0Sstevel@tonic-gate	syscall
60*0Sstevel@tonic-gate	/* restore the stack frame */
61*0Sstevel@tonic-gate	leave
62*0Sstevel@tonic-gate	SYSCERROR
63*0Sstevel@tonic-gate	ret
64*0Sstevel@tonic-gate	SET_SIZE(_syscall)
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate/*
67*0Sstevel@tonic-gate * Same as _syscall(), but restricted to 6 syscall arguments
68*0Sstevel@tonic-gate * so it doesn't need to incur the overhead of a new call stack frame.
69*0Sstevel@tonic-gate * Implemented for use only within libc; symbol is not exported.
70*0Sstevel@tonic-gate */
71*0Sstevel@tonic-gate	ENTRY(_syscall6)
72*0Sstevel@tonic-gate	movl	%edi, %eax	/* sysnum */
73*0Sstevel@tonic-gate	movq	%rsi, %rdi	/* arg0 */
74*0Sstevel@tonic-gate	movq	%rdx, %rsi	/* arg1 */
75*0Sstevel@tonic-gate	movq	%rcx, %rdx	/* arg2 */
76*0Sstevel@tonic-gate	movq	%r8, %rcx	/* arg3 */
77*0Sstevel@tonic-gate	movq	%r9, %r8	/* arg4 */
78*0Sstevel@tonic-gate	movq	8(%rsp), %r9	/* arg5 */
79*0Sstevel@tonic-gate	movq	%rcx, %r10
80*0Sstevel@tonic-gate	syscall
81*0Sstevel@tonic-gate	SYSCERROR
82*0Sstevel@tonic-gate	ret
83*0Sstevel@tonic-gate	SET_SIZE(_syscall6)
84*0Sstevel@tonic-gate
85*0Sstevel@tonic-gate	ENTRY(__systemcall)
86*0Sstevel@tonic-gate	pushq	%rbp
87*0Sstevel@tonic-gate	movq	%rsp, %rbp
88*0Sstevel@tonic-gate	/* construct a new call stack frame */
89*0Sstevel@tonic-gate	pushq	%rdi		/* sysret_t pointer */
90*0Sstevel@tonic-gate	movl	%esi, %eax	/* sysnum */
91*0Sstevel@tonic-gate	movq	%rdx, %rdi	/* arg0 */
92*0Sstevel@tonic-gate	movq	%rcx, %rsi	/* arg1 */
93*0Sstevel@tonic-gate	movq	%r8, %rdx	/* arg2 */
94*0Sstevel@tonic-gate	movq	%r9, %rcx	/* arg3 */
95*0Sstevel@tonic-gate	movq	16(%rbp), %r8	/* arg4 */
96*0Sstevel@tonic-gate	movq	24(%rbp), %r9	/* arg5 */
97*0Sstevel@tonic-gate	movq	40(%rbp), %r10
98*0Sstevel@tonic-gate	pushq	%r10		/* arg7 */
99*0Sstevel@tonic-gate	movq	32(%rbp), %r10
100*0Sstevel@tonic-gate	pushq	%r10		/* arg6 */
101*0Sstevel@tonic-gate	movq	8(%rbp), %r10
102*0Sstevel@tonic-gate	pushq	%r10		/* return addr */
103*0Sstevel@tonic-gate	/* issue the system call */
104*0Sstevel@tonic-gate	movq	%rcx, %r10
105*0Sstevel@tonic-gate	syscall
106*0Sstevel@tonic-gate	movq	-8(%rbp), %r10	/* sysret_t pointer */
107*0Sstevel@tonic-gate	jb	1f
108*0Sstevel@tonic-gate	movq	%rax, 0(%r10)	/* no error */
109*0Sstevel@tonic-gate	movq	%rdx, 8(%r10)
110*0Sstevel@tonic-gate	xorq	%rax, %rax
111*0Sstevel@tonic-gate	/* restore the stack frame */
112*0Sstevel@tonic-gate	leave
113*0Sstevel@tonic-gate	ret
114*0Sstevel@tonic-gate1:
115*0Sstevel@tonic-gate	movq	$-1, 0(%r10)	/* error */
116*0Sstevel@tonic-gate	movq	$-1, 8(%r10)
117*0Sstevel@tonic-gate	/* restore the stack frame */
118*0Sstevel@tonic-gate	leave
119*0Sstevel@tonic-gate	ret
120*0Sstevel@tonic-gate	SET_SIZE(__systemcall)
121*0Sstevel@tonic-gate
122*0Sstevel@tonic-gate/*
123*0Sstevel@tonic-gate * Same as __systemcall(), but restricted to 6 syscall arguments
124*0Sstevel@tonic-gate * so it doesn't need to incur the overhead of a new call stack frame.
125*0Sstevel@tonic-gate * Implemented for use only within libc; symbol is not exported.
126*0Sstevel@tonic-gate */
127*0Sstevel@tonic-gate	ENTRY(__systemcall6)
128*0Sstevel@tonic-gate	pushq	%rdi		/* sysret_t pointer */
129*0Sstevel@tonic-gate	movl	%esi, %eax	/* sysnum */
130*0Sstevel@tonic-gate	movq	%rdx, %rdi	/* arg0 */
131*0Sstevel@tonic-gate	movq	%rcx, %rsi	/* arg1 */
132*0Sstevel@tonic-gate	movq	%r8, %rdx	/* arg2 */
133*0Sstevel@tonic-gate	movq	%r9, %rcx	/* arg3 */
134*0Sstevel@tonic-gate	movq	16(%rsp), %r8	/* arg4 */
135*0Sstevel@tonic-gate	movq	24(%rsp), %r9	/* arg5 */
136*0Sstevel@tonic-gate	/* issue the system call */
137*0Sstevel@tonic-gate	movq	%rcx, %r10
138*0Sstevel@tonic-gate	syscall
139*0Sstevel@tonic-gate	popq	%r10		/* sysret_t pointer */
140*0Sstevel@tonic-gate	jb	1f
141*0Sstevel@tonic-gate	movq	%rax, 0(%r10)	/* no error */
142*0Sstevel@tonic-gate	movq	%rdx, 8(%r10)
143*0Sstevel@tonic-gate	xorq	%rax, %rax
144*0Sstevel@tonic-gate	ret
145*0Sstevel@tonic-gate1:
146*0Sstevel@tonic-gate	movq	$-1, 0(%r10)	/* error */
147*0Sstevel@tonic-gate	movq	$-1, 8(%r10)
148*0Sstevel@tonic-gate	ret
149*0Sstevel@tonic-gate	SET_SIZE(__systemcall6)
150