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