1*b7a2c575Schristos /* $NetBSD: h_syscall.c,v 1.1 2023/08/19 22:56:44 christos Exp $ */
2*b7a2c575Schristos
3*b7a2c575Schristos /*-
4*b7a2c575Schristos * Copyright (c) 2023 The NetBSD Foundation, Inc.
5*b7a2c575Schristos * All rights reserved.
6*b7a2c575Schristos *
7*b7a2c575Schristos * This code is derived from software contributed to The NetBSD Foundation
8*b7a2c575Schristos * by Theodore Preduta.
9*b7a2c575Schristos *
10*b7a2c575Schristos * Redistribution and use in source and binary forms, with or without
11*b7a2c575Schristos * modification, are permitted provided that the following conditions
12*b7a2c575Schristos * are met:
13*b7a2c575Schristos * 1. Redistributions of source code must retain the above copyright
14*b7a2c575Schristos * notice, this list of conditions and the following disclaimer.
15*b7a2c575Schristos * 2. Redistributions in binary form must reproduce the above copyright
16*b7a2c575Schristos * notice, this list of conditions and the following disclaimer in the
17*b7a2c575Schristos * documentation and/or other materials provided with the distribution.
18*b7a2c575Schristos *
19*b7a2c575Schristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*b7a2c575Schristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*b7a2c575Schristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*b7a2c575Schristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*b7a2c575Schristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*b7a2c575Schristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*b7a2c575Schristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*b7a2c575Schristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*b7a2c575Schristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*b7a2c575Schristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*b7a2c575Schristos * POSSIBILITY OF SUCH DAMAGE.
30*b7a2c575Schristos */
31*b7a2c575Schristos #include <sys/cdefs.h>
32*b7a2c575Schristos __RCSID("$NetBSD: h_syscall.c,v 1.1 2023/08/19 22:56:44 christos Exp $");
33*b7a2c575Schristos #include "h_linux.h"
34*b7a2c575Schristos
35*b7a2c575Schristos long
syscall6(long number,register_t arg1,register_t arg2,register_t arg3,register_t arg4,register_t arg5,register_t arg6,...)36*b7a2c575Schristos syscall6(long number, register_t arg1, register_t arg2, register_t arg3,
37*b7a2c575Schristos register_t arg4, register_t arg5, register_t arg6, ...)
38*b7a2c575Schristos {
39*b7a2c575Schristos long retval;
40*b7a2c575Schristos register register_t r10 __asm__ ("r10") = arg4;
41*b7a2c575Schristos register register_t r8 __asm__ ("r8") = arg5;
42*b7a2c575Schristos register register_t r9 __asm__ ("r9") = arg6;
43*b7a2c575Schristos
44*b7a2c575Schristos __asm__ __volatile__ ("syscall"
45*b7a2c575Schristos : "=a"(retval)
46*b7a2c575Schristos : "a"(number), "D"(arg1), "S"(arg2), "d"(arg3), "r"(r10), "r"(r8), "r"(r9)
47*b7a2c575Schristos : "rcx", "r11", "memory");
48*b7a2c575Schristos
49*b7a2c575Schristos if (retval < 0) {
50*b7a2c575Schristos errno = -retval;
51*b7a2c575Schristos return -1;
52*b7a2c575Schristos }
53*b7a2c575Schristos
54*b7a2c575Schristos return retval;
55*b7a2c575Schristos }
56