Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys add support COMPAT_LINUX for aarch64



details:   https://anonhg.NetBSD.org/src/rev/43524b0e97f1
branches:  trunk
changeset: 1023691:43524b0e97f1
user:      ryo <ryo%NetBSD.org@localhost>
date:      Thu Sep 23 06:56:26 2021 +0000

description:
add support COMPAT_LINUX for aarch64

diffstat:

 sys/arch/aarch64/aarch64/linux_syscall.c            |    58 +
 sys/arch/aarch64/aarch64/syscall.c                  |    34 +-
 sys/arch/aarch64/conf/files.aarch64                 |    12 +-
 sys/arch/evbarm/conf/GENERIC64                      |     6 +-
 sys/compat/linux/arch/aarch64/Makefile              |     3 +
 sys/compat/linux/arch/aarch64/files.linux_aarch64   |     9 +
 sys/compat/linux/arch/aarch64/linux_commons.c       |    37 +
 sys/compat/linux/arch/aarch64/linux_errno.h         |    35 +
 sys/compat/linux/arch/aarch64/linux_exec.h          |    37 +
 sys/compat/linux/arch/aarch64/linux_fcntl.h         |    72 +
 sys/compat/linux/arch/aarch64/linux_machdep.c       |   258 +
 sys/compat/linux/arch/aarch64/linux_machdep.h       |    84 +
 sys/compat/linux/arch/aarch64/linux_mmap.h          |    40 +
 sys/compat/linux/arch/aarch64/linux_sigarray.c      |    95 +
 sys/compat/linux/arch/aarch64/linux_sigcode.S       |    43 +
 sys/compat/linux/arch/aarch64/linux_siginfo.h       |   107 +
 sys/compat/linux/arch/aarch64/linux_signal.h        |   117 +
 sys/compat/linux/arch/aarch64/linux_socket.h        |    34 +
 sys/compat/linux/arch/aarch64/linux_syscall.h       |   590 ++
 sys/compat/linux/arch/aarch64/linux_syscallargs.h   |  1357 ++++
 sys/compat/linux/arch/aarch64/linux_syscalls.c      |  1114 ++++
 sys/compat/linux/arch/aarch64/linux_sysent.c        |  1946 +++++++
 sys/compat/linux/arch/aarch64/linux_systrace_args.c |  5268 +++++++++++++++++++
 sys/compat/linux/arch/aarch64/linux_termios.h       |   225 +
 sys/compat/linux/arch/aarch64/linux_types.h         |    96 +
 sys/compat/linux/arch/aarch64/syscalls.conf         |    16 +
 sys/compat/linux/arch/aarch64/syscalls.master       |   676 ++
 sys/compat/linux/common/linux_break.c               |     6 +-
 sys/compat/linux/common/linux_errno.h               |     4 +-
 sys/compat/linux/common/linux_exec.h                |     4 +-
 sys/compat/linux/common/linux_fcntl.h               |     4 +-
 sys/compat/linux/common/linux_file.c                |    18 +-
 sys/compat/linux/common/linux_file64.c              |     6 +-
 sys/compat/linux/common/linux_ioctl.h               |     4 +-
 sys/compat/linux/common/linux_ipccall.c             |     6 +-
 sys/compat/linux/common/linux_ipccall.h             |     6 +-
 sys/compat/linux/common/linux_llseek.c              |     6 +-
 sys/compat/linux/common/linux_machdep.h             |     4 +-
 sys/compat/linux/common/linux_misc.c                |    12 +-
 sys/compat/linux/common/linux_misc_notalpha.c       |    31 +-
 sys/compat/linux/common/linux_mmap.h                |     4 +-
 sys/compat/linux/common/linux_oldmmap.c             |     6 +-
 sys/compat/linux/common/linux_oldmmap.h             |     4 +-
 sys/compat/linux/common/linux_oldolduname.c         |     6 +-
 sys/compat/linux/common/linux_oldolduname.h         |     4 +-
 sys/compat/linux/common/linux_oldselect.c           |     6 +-
 sys/compat/linux/common/linux_oldselect.h           |     4 +-
 sys/compat/linux/common/linux_olduname.c            |     6 +-
 sys/compat/linux/common/linux_olduname.h            |     4 +-
 sys/compat/linux/common/linux_pipe.c                |     8 +-
 sys/compat/linux/common/linux_sem.h                 |     4 +-
 sys/compat/linux/common/linux_sig_notalpha.c        |     6 +-
 sys/compat/linux/common/linux_sigaction.c           |     6 +-
 sys/compat/linux/common/linux_siginfo.h             |     4 +-
 sys/compat/linux/common/linux_signal.c              |    14 +-
 sys/compat/linux/common/linux_signal.h              |     8 +-
 sys/compat/linux/common/linux_signo.c               |     6 +-
 sys/compat/linux/common/linux_socket.c              |    12 +-
 sys/compat/linux/common/linux_socket.h              |     5 +-
 sys/compat/linux/common/linux_socketcall.c          |     6 +-
 sys/compat/linux/common/linux_socketcall.h          |     6 +-
 sys/compat/linux/common/linux_sysctl.c              |     7 +-
 sys/compat/linux/common/linux_termios.h             |     4 +-
 sys/compat/linux/common/linux_types.h               |     4 +-
 sys/compat/linux/linux_syscall.h                    |     4 +-
 sys/compat/linux/linux_syscallargs.h                |     4 +-
 sys/compat/linux/linux_syscalls.c                   |     6 +-
 67 files changed, 12523 insertions(+), 115 deletions(-)

diffs (truncated from 13818 to 300 lines):

diff -r 8b8853dbfe21 -r 43524b0e97f1 sys/arch/aarch64/aarch64/linux_syscall.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/aarch64/aarch64/linux_syscall.c  Thu Sep 23 06:56:26 2021 +0000
@@ -0,0 +1,58 @@
+/*     $NetBSD: linux_syscall.c,v 1.1 2021/09/23 06:56:26 ryo Exp $    */
+
+/*
+ * Copyright (c) 2021 Ryo Shimizu <ryo%nerv.org@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: linux_syscall.c,v 1.1 2021/09/23 06:56:26 ryo Exp $");
+
+#if defined(_KERNEL_OPT)
+#include "opt_compat_linux.h"
+#endif
+
+#include <compat/linux/linux_syscall.h>
+#include <compat/linux/common/linux_errno.h>
+
+#define EMULNAME(x)            __CONCAT(linux_,x)
+#define EMULNAMEU(x)           __CONCAT(LINUX_,x)
+
+
+/*
+ * syscall.c behavior options
+ */
+
+/*
+ * linux/arm64 always uses indirect syscall, and ignores code of 'svc #<code>'.
+ * The system call number is specified by the x8 register.
+ */
+#define SYSCALL_CODE_REG       8
+#define SYSCALL_NO_INDIRECT
+
+/* used when __HAVE_MINIMAL_EMUL is not defined */
+#define SYSCALL_EMUL_ERRNO(x)  native_to_linux_errno[x]
+
+
+#include "syscall.c"
diff -r 8b8853dbfe21 -r 43524b0e97f1 sys/arch/aarch64/aarch64/syscall.c
--- a/sys/arch/aarch64/aarch64/syscall.c        Thu Sep 23 06:34:00 2021 +0000
+++ b/sys/arch/aarch64/aarch64/syscall.c        Thu Sep 23 06:56:26 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: syscall.c,v 1.6 2019/04/10 06:30:05 ryo Exp $  */
+/*     $NetBSD: syscall.c,v 1.7 2021/09/23 06:56:26 ryo Exp $  */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -29,8 +29,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* DO NOT INCLUDE opt_compat_XXX.h */
-
 #include <sys/param.h>
 #include <sys/cpu.h>
 #include <sys/ktrace.h>
@@ -58,10 +56,12 @@
 #ifndef EMULNAME
 #include <sys/syscall.h>
 
+#define SYSCALL_INDIRECT_CODE_REG      17      /* netbsd/aarch64 use x17 */
+
 #define EMULNAME(x)    (x)
 #define EMULNAMEU(x)   (x)
 
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.6 2019/04/10 06:30:05 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.7 2021/09/23 06:56:26 ryo Exp $");
 
 void
 cpu_spawn_return(struct lwp *l)
@@ -99,18 +99,33 @@
 
        curcpu()->ci_data.cpu_nsyscall++;
 
-       size_t code = tf->tf_esr & 0xffff;
        register_t *params = (void *)tf->tf_reg;
        size_t nargs = NARGREG;
+#ifdef SYSCALL_CODE_REG
+       /*
+        * mov x<SYSCALL_CODE_REG>, #<syscall_no>
+        * svc #<optional>
+        */
+       size_t code = tf->tf_reg[SYSCALL_CODE_REG];
+#if (SYSCALL_CODE_REG == 0)
+       params++;
+#endif
+#else /* SYSCALL_CODE_REG */
+       /*
+        * svc #<syscall_no>
+        */
+       size_t code = tf->tf_esr & 0xffff;
+#endif /* SYSCALL_CODE_REG */
 
+#ifndef SYSCALL_NO_INDIRECT
        switch (code) {
        case EMULNAMEU(SYS_syscall):
-#if !defined(COMPAT_LINUX)
        case EMULNAMEU(SYS___syscall):
-               code = tf->tf_reg[17];
-#else
+#if (SYSCALL_INDIRECT_CODE_REG == 0)
                code = *params++;
                nargs -= 1;
+#else
+               code = tf->tf_reg[SYSCALL_INDIRECT_CODE_REG];
 #endif
                /*
                 * code is first argument,
@@ -120,6 +135,7 @@
        default:
                break;
        }
+#endif /* !SYSCALL_NO_INDIRECT */
 
        code &= EMULNAMEU(SYS_NSYSENT) - 1;
        const struct sysent * const callp = p->p_emul->e_sysent + code;
@@ -209,6 +225,8 @@
 #ifndef __HAVE_MINIMAL_EMUL
                        if (p->p_emul->e_errno)
                                error = p->p_emul->e_errno[error];
+#elif defined(SYSCALL_EMUL_ERRNO)
+                       error = SYSCALL_EMUL_ERRNO(error);
 #endif
                        tf->tf_reg[0] = error;
                        tf->tf_spsr |= NZCV_C;
diff -r 8b8853dbfe21 -r 43524b0e97f1 sys/arch/aarch64/conf/files.aarch64
--- a/sys/arch/aarch64/conf/files.aarch64       Thu Sep 23 06:34:00 2021 +0000
+++ b/sys/arch/aarch64/conf/files.aarch64       Thu Sep 23 06:56:26 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.aarch64,v 1.32 2021/08/06 19:38:53 jmcneill Exp $
+#      $NetBSD: files.aarch64,v 1.33 2021/09/23 06:56:26 ryo Exp $
 
 defflag opt_cpuoptions.h       AARCH64_ALIGNMENT_CHECK
 defflag opt_cpuoptions.h       AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -126,12 +126,10 @@
 file   arch/aarch64/aarch64/netbsd32_syscall.c         compat_netbsd32
 
 # Linux binary compatibility (COMPAT_LINUX)
-#include "compat/ossaudio/files.ossaudio"
-#include "compat/linux/files.linux"
-#include "compat/linux/arch/aarch64/files.linux_aarch64"
-#file  arch/aarch64/aarch64/linux_sigcode.S    compat_linux
-#file  arch/aarch64/aarch64/linux_syscall.c    compat_linux
-#file  arch/aarch64/aarch64/linux_trap.c       compat_linux
+include "compat/ossaudio/files.ossaudio"
+include "compat/linux/files.linux"
+include "compat/linux/arch/aarch64/files.linux_aarch64"
+file   arch/aarch64/aarch64/linux_syscall.c    compat_linux
 
 # profiling support
 file   dev/tprof/tprof_armv8.c                 tprof   needs-flag
diff -r 8b8853dbfe21 -r 43524b0e97f1 sys/arch/evbarm/conf/GENERIC64
--- a/sys/arch/evbarm/conf/GENERIC64    Thu Sep 23 06:34:00 2021 +0000
+++ b/sys/arch/evbarm/conf/GENERIC64    Thu Sep 23 06:56:26 2021 +0000
@@ -1,5 +1,5 @@
 #
-#      $NetBSD: GENERIC64,v 1.185 2021/09/13 23:31:23 jmcneill Exp $
+#      $NetBSD: GENERIC64,v 1.186 2021/09/23 06:56:27 ryo Exp $
 #
 #      GENERIC ARM (aarch64) kernel
 #
@@ -89,6 +89,10 @@
 options        COMPAT_NETBSD32
 options        EXEC_ELF32
 
+#options       COMPAT_LINUX    # binary compatibility with Linux
+#options       COMPAT_50       # COMPAT_LINUX depends on
+#options       COMPAT_OSSAUDIO # binary compatibility with Linux
+
 # EFI runtime support
 options        EFI_RUNTIME
 
diff -r 8b8853dbfe21 -r 43524b0e97f1 sys/compat/linux/arch/aarch64/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/linux/arch/aarch64/Makefile    Thu Sep 23 06:56:26 2021 +0000
@@ -0,0 +1,3 @@
+#      $NetBSD: Makefile,v 1.1 2021/09/23 06:56:27 ryo Exp $
+
+.include <../../Makefile.inc>
diff -r 8b8853dbfe21 -r 43524b0e97f1 sys/compat/linux/arch/aarch64/files.linux_aarch64
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/linux/arch/aarch64/files.linux_aarch64 Thu Sep 23 06:56:26 2021 +0000
@@ -0,0 +1,9 @@
+#      $NetBSD: files.linux_aarch64,v 1.1 2021/09/23 06:56:27 ryo Exp $
+#
+# Config file description for aarch64-dependent Linux compat code.
+
+file   compat/linux/arch/aarch64/linux_machdep.c       compat_linux
+file   compat/linux/arch/aarch64/linux_commons.c       compat_linux
+file   compat/linux/arch/aarch64/linux_syscalls.c      compat_linux
+file   compat/linux/arch/aarch64/linux_sysent.c        compat_linux
+file   compat/linux/arch/aarch64/linux_sigcode.S       compat_linux
diff -r 8b8853dbfe21 -r 43524b0e97f1 sys/compat/linux/arch/aarch64/linux_commons.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/linux/arch/aarch64/linux_commons.c     Thu Sep 23 06:56:26 2021 +0000
@@ -0,0 +1,37 @@
+/*     $NetBSD: linux_commons.c,v 1.1 2021/09/23 06:56:27 ryo Exp $    */
+
+/*
+ * This file includes C files from the common
+ * area to decrese the number of files to compile
+ * in order to make building a kernel go faster.
+ *
+ * Option headers and headers which depend on
+ * certain options being set need to be included
+ * here.  This ensures that a header file sees
+ * the options it needs even if one of included
+ * C files doesn't use it.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: linux_commons.c,v 1.1 2021/09/23 06:56:27 ryo Exp $");
+
+#if defined(_KERNEL_OPT)
+#include "opt_sysv.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/signal.h>
+#include <sys/syscallargs.h>
+
+#include <compat/linux/common/linux_signal.h>
+#include <compat/linux/common/linux_types.h>
+#include <compat/linux/common/linux_ipc.h>
+#include <compat/linux/common/linux_sem.h>
+
+#include <compat/linux/linux_syscallargs.h>
+
+#include "../../common/linux_pipe.c"
+#include "../../common/linux_file64.c"
+#include "../../common/linux_misc_notalpha.c"
+#include "../../common/linux_fadvise64.c"
diff -r 8b8853dbfe21 -r 43524b0e97f1 sys/compat/linux/arch/aarch64/linux_errno.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/linux/arch/aarch64/linux_errno.h       Thu Sep 23 06:56:26 2021 +0000
@@ -0,0 +1,35 @@
+/*     $NetBSD: linux_errno.h,v 1.1 2021/09/23 06:56:27 ryo Exp $      */
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _AARCH64_LINUX_ERRNO_H
+#define _AARCH64_LINUX_ERRNO_H
+
+#include <compat/linux/common/linux_errno_generic.h>
+#define LINUX_SCERR_SIGN -
+
+#endif /* !_AARCH64_LINUX_ERRNO_H */
diff -r 8b8853dbfe21 -r 43524b0e97f1 sys/compat/linux/arch/aarch64/linux_exec.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/linux/arch/aarch64/linux_exec.h        Thu Sep 23 06:56:26 2021 +0000
@@ -0,0 +1,37 @@



Home | Main Index | Thread Index | Old Index