From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by sourceware.org (Postfix) with ESMTPS id B491A385840E for ; Tue, 4 Jan 2022 14:20:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B491A385840E Received: by mail-qv1-xf2e.google.com with SMTP id fo11so34413200qvb.4 for ; Tue, 04 Jan 2022 06:20:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:cc:in-reply-to :content-transfer-encoding; bh=TnGUQ/tDgnUceIuzQeucmmxInyZwrPqJGip5/dImSes=; b=0IvlIJyOlltubORotYmtGr6/V0zauRVnNlCJSf7hMKBuRlqAq8/iwKnp3ZRlDLbzp8 2pZST2D3ibe9JCJqVaB3TQEUn7S6oNZlr9QcQXMmecXBy4ew75anbSb37AfHRgAx2GSX WB2cbUMz3Uj3SUvxNpEqJcusHR0xn/28/7l56mczruu31f7uTy3VmFd3tvcUxLNKVZY9 5LrOQ0CALCql6SzQzY8ZROMMy4HjOCEdD6aineASm6/Phcib/3KKeFIFC3DMpZWKExvT hwvnYM2Gd8gecNdARjJd1K7STUC/OxxOj7vR5d/+8vzFi0JJ86E1fbKQu13Hy59hEB6C JOOw== X-Gm-Message-State: AOAM533nqcKPMWZZHkXs88dFf1oX9Df3qkz0OE/gnd8M6qhC2H22jTz5 EkMBlQZEAx7yOyt27v8m4aBNT4lLdSmPmg== X-Google-Smtp-Source: ABdhPJzAFbXlMS/6ZYhc4y+38j5GdlOnKIBAyJ8OYDlEe4MUj8b8FwWYLRFp270IOrBh3OKB1A6szA== X-Received: by 2002:a05:6214:202a:: with SMTP id 10mr23428693qvf.104.1641306039838; Tue, 04 Jan 2022 06:20:39 -0800 (PST) Received: from ?IPV6:2804:431:c7ca:a350:1960:9a87:fba4:a664? ([2804:431:c7ca:a350:1960:9a87:fba4:a664]) by smtp.gmail.com with ESMTPSA id ay42sm29645585qkb.40.2022.01.04.06.20.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Jan 2022 06:20:39 -0800 (PST) Message-ID: <4c6f299b-57cc-5de3-a6fc-d1d88987d20d@linaro.org> Date: Tue, 4 Jan 2022 11:20:37 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v2 08/14] LoongArch: Linux Syscall Interface Content-Language: en-US To: libc-alpha@sourceware.org, caiyinyu References: <20211231064455.1030051-1-caiyinyu@loongson.cn> <20211231064455.1030051-9-caiyinyu@loongson.cn> From: Adhemerval Zanella Cc: xuchenghua@loongson.cn, joseph_myers@mentor.com In-Reply-To: <20211231064455.1030051-9-caiyinyu@loongson.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jan 2022 14:20:43 -0000 On 31/12/2021 03:44, caiyinyu wrote: > Contains the Linux system call interface, as well as the definitions of > a handful of system calls. > --- > sysdeps/loongarch/abort-instr.h | 2 + > sysdeps/loongarch/hp-timing.h | 42 +++ > sysdeps/loongarch/nptl/nptl-sysdep.S | 2 + > .../unix/sysv/linux/loongarch/arch-syscall.h | 302 ++++++++++++++++ > .../unix/sysv/linux/loongarch/bits/signum.h | 58 ++++ > sysdeps/unix/sysv/linux/loongarch/clone.S | 100 ++++++ > sysdeps/unix/sysv/linux/loongarch/clone3.S | 87 +++++ > sysdeps/unix/sysv/linux/loongarch/ipc_priv.h | 22 ++ > sysdeps/unix/sysv/linux/loongarch/syscall.c | 35 ++ > sysdeps/unix/sysv/linux/loongarch/sysdep.S | 53 +++ > sysdeps/unix/sysv/linux/loongarch/sysdep.h | 321 ++++++++++++++++++ > sysdeps/unix/sysv/linux/loongarch/vfork.S | 50 +++ > 12 files changed, 1074 insertions(+) > create mode 100644 sysdeps/loongarch/abort-instr.h > create mode 100644 sysdeps/loongarch/hp-timing.h > create mode 100644 sysdeps/loongarch/nptl/nptl-sysdep.S > create mode 100644 sysdeps/unix/sysv/linux/loongarch/arch-syscall.h > create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/signum.h > create mode 100644 sysdeps/unix/sysv/linux/loongarch/clone.S > create mode 100644 sysdeps/unix/sysv/linux/loongarch/clone3.S > create mode 100644 sysdeps/unix/sysv/linux/loongarch/ipc_priv.h > create mode 100644 sysdeps/unix/sysv/linux/loongarch/syscall.c > create mode 100644 sysdeps/unix/sysv/linux/loongarch/sysdep.S > create mode 100644 sysdeps/unix/sysv/linux/loongarch/sysdep.h > create mode 100644 sysdeps/unix/sysv/linux/loongarch/vfork.S > > diff --git a/sysdeps/loongarch/abort-instr.h b/sysdeps/loongarch/abort-instr.h > new file mode 100644 > index 0000000000..92e22edfea > --- /dev/null > +++ b/sysdeps/loongarch/abort-instr.h > @@ -0,0 +1,2 @@ > +/* An instruction which should crash any program is a breakpoint. */ > +#define ABORT_INSTRUCTION asm("break 0") Missing space after asm. > diff --git a/sysdeps/loongarch/hp-timing.h b/sysdeps/loongarch/hp-timing.h > new file mode 100644 > index 0000000000..7b36a539f1 > --- /dev/null > +++ b/sysdeps/loongarch/hp-timing.h > @@ -0,0 +1,42 @@ > +/* High precision, low overhead timing functions. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#ifndef _HP_TIMING_H > +#define _HP_TIMING_H 1 > + > +/* We always assume having the timestamp register. */ > +#define HP_TIMING_AVAIL (1) > +#define HP_SMALL_TIMING_AVAIL (1) > + > +/* We indeed have inlined functions. */ > +#define HP_TIMING_INLINE (1) > + > +/* We use 64bit values for the times. */ > +typedef unsigned long long int hp_timing_t; > + > +/* Read the stable counter. */ > +#define HP_TIMING_NOW(Var) \ > + ({ \ > + unsigned long long int _count; \ > + asm volatile("rdtime.d\t%0,$r0" : "=r"(_count)); \ Missing space after volatile. > + (Var) = _count; \ > + }) > + > +#include > + > +#endif /* hp-timing.h */ > diff --git a/sysdeps/loongarch/nptl/nptl-sysdep.S b/sysdeps/loongarch/nptl/nptl-sysdep.S > new file mode 100644 > index 0000000000..3f5c2a364a > --- /dev/null > +++ b/sysdeps/loongarch/nptl/nptl-sysdep.S > @@ -0,0 +1,2 @@ > +/* Pull in __syscall_error. */ > +#include Why do you need this file? Newer Linux ports should have libpthread function on libc.so. > diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/signum.h b/sysdeps/unix/sysv/linux/loongarch/bits/signum.h > new file mode 100644 > index 0000000000..111759778b > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/loongarch/bits/signum.h > @@ -0,0 +1,58 @@ > +/* Signal number definitions. Linux version. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#ifndef _BITS_SIGNUM_H > +#define _BITS_SIGNUM_H 1 > + > +#ifndef _SIGNAL_H > +#error "Never include directly; use instead." > +#endif > + > +#include > + > +/* Adjustments and additions to the signal number constants for > + most Linux systems. */ > + > +#define SIGSTKFLT 16 /* Stack fault (obsolete). */ > +#define SIGPWR 30 /* Power failure imminent. */ > + > +#undef SIGBUS > +#define SIGBUS 7 > +#undef SIGUSR1 > +#define SIGUSR1 10 > +#undef SIGUSR2 > +#define SIGUSR2 12 > +#undef SIGCHLD > +#define SIGCHLD 17 > +#undef SIGCONT > +#define SIGCONT 18 > +#undef SIGSTOP > +#define SIGSTOP 19 > +#undef SIGTSTP > +#define SIGTSTP 20 > +#undef SIGURG > +#define SIGURG 23 > +#undef SIGPOLL > +#define SIGPOLL 29 > +#undef SIGSYS > +#define SIGSYS 31 > + > +#undef __SIGRTMAX > +#define __SIGRTMAX 64 > + > +#endif /* included. */ This file has been refactore by e4e11b1dba261cb650e6 (2.32), now ports that deviate from Linux generic ABI should provide a signum-arch.h header. And this seems not to be the case here. > diff --git a/sysdeps/unix/sysv/linux/loongarch/clone.S b/sysdeps/unix/sysv/linux/loongarch/clone.S > new file mode 100644 > index 0000000000..d2bed24440 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/loongarch/clone.S > @@ -0,0 +1,100 @@ > +/* The clone syscall wrapper. > + Copyright (C) 2021 Free Software Foundation, Inc. > + > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library. If not, see > + . */ > + > +/* clone() is even more special than fork() as it mucks with stacks > + and invokes a function in the right context after its all over. */ > + > +#include > +#include > +#define _ERRNO_H 1 > +#include > +#include > +#include "tcb-offsets.h" > + > +/* int clone(int (*fn)(void *arg), void *child_stack, int flags, void *arg, > + void *parent_tidptr, void *tls, void *child_tidptr) */ > + > +ENTRY (__clone) > + > + /* Align stack to 16 or 8 bytes per the ABI. */ > +#ifdef __loongarch_lp64 > + bstrins.d a1, zero, 3, 0 > +#else > +#error "32bit LoongArch systems are not supported" > +#endif As before, I think we should move the LP64 ABI tests to configure time instead of adding multiple checks on arch-specific code. > + > + /* Sanity check arguments. */ > + beqz a0, L (invalid) /* No NULL function pointers. */ > + beqz a1, L (invalid) /* No NULL stack pointers. */ > + > + addi.d a1, a1, -16 /* Reserve argument save space. */ > + st.d a0, a1, 0 /* Save function pointer. */ > + st.d a3, a1, SZREG /* Save argument pointer. */ > + > + /* The syscall expects the args to be in different slots. */ > + or a0, a2, zero > + or a2, a4, zero > + or a3, a6, zero > + or a4, a5, zero > + > + /* Do the system call. */ > + li.d a7,__NR_clone > + syscall 0 > + > + blt a0, zero ,L (error) > + beqz a0,L (thread_start) > + > + /* Successful return from the parent. */ > + ret > + > +L (invalid): > + li.d a0, -EINVAL > + > + /* Something bad happened -- no child created. */ > +L (error): > + b __syscall_error > + > +END (__clone) > + > +/* Load up the arguments to the function. Put this block of code in > + its own function so that we can terminate the stack trace with our > + debug info. */ > +ENTRY (__thread_start) > +L (thread_start): > + > +/* Terminate call stack by noting ra is undefined. Use a dummy > + .cfi_label to force starting the FDE. */ > + .cfi_label .Ldummy > + cfi_undefined (1) > + > + /* Restore the arg for user's function. */ > + ld.d a1, sp, 0 /* Function pointer. */ > + ld.d a0, sp, SZREG /* Argument pointer. */ > + > + /* Call the user's function. */ > + jirl ra, a1, 0 > + > + /* Call exit with the function's return value. */ > + li.d a7, __NR_exit > + syscall 0 > + > + END (__thread_start) > + > +libc_hidden_def (__clone) > +weak_alias (__clone, clone) > diff --git a/sysdeps/unix/sysv/linux/loongarch/ipc_priv.h b/sysdeps/unix/sysv/linux/loongarch/ipc_priv.h > new file mode 100644 > index 0000000000..dde8fa6989 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/loongarch/ipc_priv.h > @@ -0,0 +1,22 @@ > +/* Old SysV permission definition for Linux. > + Copyright (C) 2021 Loongson Technology, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include /* For __key_t */ > + > +#define __IPC_64 0x0 > +#include Why can't you use the generic sysdeps/unix/sysv/linux/ipc_priv.h here? I woudl asusme that LoongArch will have __ASSUME_SYSVIPC_DEFAULT_IPC_64 defined and thus __IPC_64 will be 0x0. > diff --git a/sysdeps/unix/sysv/linux/loongarch/syscall.c b/sysdeps/unix/sysv/linux/loongarch/syscall.c > new file mode 100644 > index 0000000000..d0067bc2d0 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/loongarch/syscall.c > @@ -0,0 +1,35 @@ > +/* system call interface. > + Copyright (C) 2021 Free Software Foundation, Inc. > + > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library. If not, see > + . */ > + > +#include > + > +long int > +syscall (long int syscall_number, long int arg1, long int arg2, long int arg3, > + long int arg4, long int arg5, long int arg6, long int arg7) > +{ > + long int ret; > + > + ret = INTERNAL_SYSCALL_NCS (syscall_number, 7, arg1, arg2, arg3, arg4, arg5, > + arg6, arg7); > + > + if (INTERNAL_SYSCALL_ERROR_P (ret)) > + return __syscall_error (ret); > + > + return ret; > +} Do you really need 7 arguments for syscall? Otherwise you should use the generic interface.