xref: /netbsd/lib/libc/arch/aarch64/sys/__syscall.S (revision 67d1b467)
1*67d1b467Smatt/* $NetBSD: __syscall.S,v 1.1 2014/08/10 05:47:37 matt Exp $ */
2*67d1b467Smatt
3*67d1b467Smatt/*-
4*67d1b467Smatt * Copyright (c) 2014 The NetBSD Foundation, Inc.
5*67d1b467Smatt * All rights reserved.
6*67d1b467Smatt *
7*67d1b467Smatt * This code is derived from software contributed to The NetBSD Foundation
8*67d1b467Smatt * by Matt Thomas of 3am Software Foundry.
9*67d1b467Smatt *
10*67d1b467Smatt * Redistribution and use in source and binary forms, with or without
11*67d1b467Smatt * modification, are permitted provided that the following conditions
12*67d1b467Smatt * are met:
13*67d1b467Smatt * 1. Redistributions of source code must retain the above copyright
14*67d1b467Smatt *    notice, this list of conditions and the following disclaimer.
15*67d1b467Smatt * 2. Redistributions in binary form must reproduce the above copyright
16*67d1b467Smatt *    notice, this list of conditions and the following disclaimer in the
17*67d1b467Smatt *    documentation and/or other materials provided with the distribution.
18*67d1b467Smatt *
19*67d1b467Smatt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*67d1b467Smatt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*67d1b467Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*67d1b467Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*67d1b467Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*67d1b467Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*67d1b467Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*67d1b467Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*67d1b467Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*67d1b467Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*67d1b467Smatt * POSSIBILITY OF SUCH DAMAGE.
30*67d1b467Smatt */
31*67d1b467Smatt
32*67d1b467Smatt#include "SYS.h"
33*67d1b467Smatt
34*67d1b467Smatt#ifndef FUNCNAME
35*67d1b467Smatt#define	FUNCNAME	__syscall
36*67d1b467Smatt#define SYSTRAP_SYSCALL	SYSTRAP(__syscall)
37*67d1b467Smatt#endif
38*67d1b467Smatt
39*67d1b467Smatt#if SYS_MAXSYSARGS > 8
40*67d1b467Smatt#error SYS_MAXSYSARGS is greater than 8
41*67d1b467Smatt#endif
42*67d1b467Smatt
43*67d1b467SmattENTRY(FUNCNAME)
44*67d1b467Smatt	/*
45*67d1b467Smatt	 * AAPCS64 supplies the first 8 arguments in registers but since
46*67d1b467Smatt	 * the first argument is the syscall #, we only have room for 7
47*67d1b467Smatt	 * arguments.  Thus if the syscall uses all 8 arguments, the last
48*67d1b467Smatt	 * argument will have been placed on the stack.  Rather than
49*67d1b467Smatt	 * complicating the kernel syscall code to deal with that, we fixup
50*67d1b467Smatt	 * things here.
51*67d1b467Smatt	 *
52*67d1b467Smatt	 * First we move the syscall number to x17 freeing a register.
53*67d1b467Smatt	 * Then we move the rest of the arguments to their proper register.
54*67d1b467Smatt	 * Finally, load x7 from the stack.
55*67d1b467Smatt	 *
56*67d1b467Smatt	 * Now everything looks as if the syscall wrapper was directly called.
57*67d1b467Smatt	 * (unless it was for pipe, fork, vfork, ptrace, or __clone).
58*67d1b467Smatt	 */
59*67d1b467Smatt	mov	x17, x0
60*67d1b467Smatt	mov	x0, x1
61*67d1b467Smatt	mov	x1, x2
62*67d1b467Smatt	mov	x2, x3
63*67d1b467Smatt	mov	x3, x4
64*67d1b467Smatt	mov	x4, x5
65*67d1b467Smatt	mov	x5, x6
66*67d1b467Smatt	mov	x6, x7
67*67d1b467Smatt	ldr	x7, [sp, #0]
68*67d1b467Smatt	SYSTRAP_SYSCALL
69*67d1b467Smatt	_INVOKE_CERROR()
70*67d1b467Smatt	ret
71*67d1b467SmattEND(FUNCNAME)
72