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