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