xref: /titanic_52/usr/src/lib/libc/amd64/sys/syscall.s (revision 9a70fc3be3b1e966bf78825cdb8d509963a6f0a1)
17c478bd9Sstevel@tonic-gate/*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57257d1b4Sraf * Common Development and Distribution License (the "License").
67257d1b4Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217257d1b4Sraf
227c478bd9Sstevel@tonic-gate/*
237257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27*9a70fc3bSMark J. Nelson	.file	"syscall.s"
287c478bd9Sstevel@tonic-gate
297257d1b4Sraf#include "SYS.h"
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate	ANSI_PRAGMA_WEAK(syscall,function)
327c478bd9Sstevel@tonic-gate
337257d1b4Sraf	ENTRY(syscall)
347c478bd9Sstevel@tonic-gate	pushq	%rbp
357c478bd9Sstevel@tonic-gate	movq	%rsp, %rbp
367c478bd9Sstevel@tonic-gate	/* construct a new call stack frame */
377c478bd9Sstevel@tonic-gate	movl	%edi, %eax	/* sysnum */
387c478bd9Sstevel@tonic-gate	movq	%rsi, %rdi	/* arg0 */
397c478bd9Sstevel@tonic-gate	movq	%rdx, %rsi	/* arg1 */
407c478bd9Sstevel@tonic-gate	movq	%rcx, %rdx	/* arg2 */
417c478bd9Sstevel@tonic-gate	movq	%r8, %rcx	/* arg3 */
427c478bd9Sstevel@tonic-gate	movq	%r9, %r8	/* arg4 */
437c478bd9Sstevel@tonic-gate	movq	16(%rbp), %r9	/* arg5 */
447c478bd9Sstevel@tonic-gate	movq	32(%rbp), %r10
457c478bd9Sstevel@tonic-gate	pushq	%r10		/* arg7 */
467c478bd9Sstevel@tonic-gate	movq	24(%rbp), %r10
477c478bd9Sstevel@tonic-gate	pushq	%r10		/* arg6 */
487c478bd9Sstevel@tonic-gate	movq	8(%rbp), %r10
497c478bd9Sstevel@tonic-gate	pushq	%r10		/* return addr */
507c478bd9Sstevel@tonic-gate	/* issue the system call */
517c478bd9Sstevel@tonic-gate	movq	%rcx, %r10
527c478bd9Sstevel@tonic-gate	syscall
537c478bd9Sstevel@tonic-gate	/* restore the stack frame */
547c478bd9Sstevel@tonic-gate	leave
557c478bd9Sstevel@tonic-gate	SYSCERROR
567c478bd9Sstevel@tonic-gate	ret
577257d1b4Sraf	SET_SIZE(syscall)
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate/*
607c478bd9Sstevel@tonic-gate * Same as _syscall(), but restricted to 6 syscall arguments
617c478bd9Sstevel@tonic-gate * so it doesn't need to incur the overhead of a new call stack frame.
627c478bd9Sstevel@tonic-gate * Implemented for use only within libc; symbol is not exported.
637c478bd9Sstevel@tonic-gate */
647c478bd9Sstevel@tonic-gate	ENTRY(_syscall6)
657c478bd9Sstevel@tonic-gate	movl	%edi, %eax	/* sysnum */
667c478bd9Sstevel@tonic-gate	movq	%rsi, %rdi	/* arg0 */
677c478bd9Sstevel@tonic-gate	movq	%rdx, %rsi	/* arg1 */
687c478bd9Sstevel@tonic-gate	movq	%rcx, %rdx	/* arg2 */
697c478bd9Sstevel@tonic-gate	movq	%r8, %rcx	/* arg3 */
707c478bd9Sstevel@tonic-gate	movq	%r9, %r8	/* arg4 */
717c478bd9Sstevel@tonic-gate	movq	8(%rsp), %r9	/* arg5 */
727c478bd9Sstevel@tonic-gate	movq	%rcx, %r10
737c478bd9Sstevel@tonic-gate	syscall
747c478bd9Sstevel@tonic-gate	SYSCERROR
757c478bd9Sstevel@tonic-gate	ret
767c478bd9Sstevel@tonic-gate	SET_SIZE(_syscall6)
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate	ENTRY(__systemcall)
797c478bd9Sstevel@tonic-gate	pushq	%rbp
807c478bd9Sstevel@tonic-gate	movq	%rsp, %rbp
817c478bd9Sstevel@tonic-gate	/* construct a new call stack frame */
827c478bd9Sstevel@tonic-gate	pushq	%rdi		/* sysret_t pointer */
837c478bd9Sstevel@tonic-gate	movl	%esi, %eax	/* sysnum */
847c478bd9Sstevel@tonic-gate	movq	%rdx, %rdi	/* arg0 */
857c478bd9Sstevel@tonic-gate	movq	%rcx, %rsi	/* arg1 */
867c478bd9Sstevel@tonic-gate	movq	%r8, %rdx	/* arg2 */
877c478bd9Sstevel@tonic-gate	movq	%r9, %rcx	/* arg3 */
887c478bd9Sstevel@tonic-gate	movq	16(%rbp), %r8	/* arg4 */
897c478bd9Sstevel@tonic-gate	movq	24(%rbp), %r9	/* arg5 */
907c478bd9Sstevel@tonic-gate	movq	40(%rbp), %r10
917c478bd9Sstevel@tonic-gate	pushq	%r10		/* arg7 */
927c478bd9Sstevel@tonic-gate	movq	32(%rbp), %r10
937c478bd9Sstevel@tonic-gate	pushq	%r10		/* arg6 */
947c478bd9Sstevel@tonic-gate	movq	8(%rbp), %r10
957c478bd9Sstevel@tonic-gate	pushq	%r10		/* return addr */
967c478bd9Sstevel@tonic-gate	/* issue the system call */
977c478bd9Sstevel@tonic-gate	movq	%rcx, %r10
987c478bd9Sstevel@tonic-gate	syscall
997c478bd9Sstevel@tonic-gate	movq	-8(%rbp), %r10	/* sysret_t pointer */
1007c478bd9Sstevel@tonic-gate	jb	1f
1017c478bd9Sstevel@tonic-gate	movq	%rax, 0(%r10)	/* no error */
1027c478bd9Sstevel@tonic-gate	movq	%rdx, 8(%r10)
1037c478bd9Sstevel@tonic-gate	xorq	%rax, %rax
1047c478bd9Sstevel@tonic-gate	/* restore the stack frame */
1057c478bd9Sstevel@tonic-gate	leave
1067c478bd9Sstevel@tonic-gate	ret
1077c478bd9Sstevel@tonic-gate1:
1087c478bd9Sstevel@tonic-gate	movq	$-1, 0(%r10)	/* error */
1097c478bd9Sstevel@tonic-gate	movq	$-1, 8(%r10)
1107c478bd9Sstevel@tonic-gate	/* restore the stack frame */
1117c478bd9Sstevel@tonic-gate	leave
1127c478bd9Sstevel@tonic-gate	ret
1137c478bd9Sstevel@tonic-gate	SET_SIZE(__systemcall)
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate/*
1167c478bd9Sstevel@tonic-gate * Same as __systemcall(), but restricted to 6 syscall arguments
1177c478bd9Sstevel@tonic-gate * so it doesn't need to incur the overhead of a new call stack frame.
1187c478bd9Sstevel@tonic-gate * Implemented for use only within libc; symbol is not exported.
1197c478bd9Sstevel@tonic-gate */
1207c478bd9Sstevel@tonic-gate	ENTRY(__systemcall6)
1217c478bd9Sstevel@tonic-gate	pushq	%rdi		/* sysret_t pointer */
1227c478bd9Sstevel@tonic-gate	movl	%esi, %eax	/* sysnum */
1237c478bd9Sstevel@tonic-gate	movq	%rdx, %rdi	/* arg0 */
1247c478bd9Sstevel@tonic-gate	movq	%rcx, %rsi	/* arg1 */
1257c478bd9Sstevel@tonic-gate	movq	%r8, %rdx	/* arg2 */
1267c478bd9Sstevel@tonic-gate	movq	%r9, %rcx	/* arg3 */
1277c478bd9Sstevel@tonic-gate	movq	16(%rsp), %r8	/* arg4 */
1287c478bd9Sstevel@tonic-gate	movq	24(%rsp), %r9	/* arg5 */
1297c478bd9Sstevel@tonic-gate	/* issue the system call */
1307c478bd9Sstevel@tonic-gate	movq	%rcx, %r10
1317c478bd9Sstevel@tonic-gate	syscall
1327c478bd9Sstevel@tonic-gate	popq	%r10		/* sysret_t pointer */
1337c478bd9Sstevel@tonic-gate	jb	1f
1347c478bd9Sstevel@tonic-gate	movq	%rax, 0(%r10)	/* no error */
1357c478bd9Sstevel@tonic-gate	movq	%rdx, 8(%r10)
1367c478bd9Sstevel@tonic-gate	xorq	%rax, %rax
1377c478bd9Sstevel@tonic-gate	ret
1387c478bd9Sstevel@tonic-gate1:
1397c478bd9Sstevel@tonic-gate	movq	$-1, 0(%r10)	/* error */
1407c478bd9Sstevel@tonic-gate	movq	$-1, 8(%r10)
1417c478bd9Sstevel@tonic-gate	ret
1427c478bd9Sstevel@tonic-gate	SET_SIZE(__systemcall6)
143