From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 0796C3856DFB for ; Fri, 15 Apr 2022 01:28:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0796C3856DFB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from [10.20.4.187] (unknown [10.20.4.187]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxHxBLylhieckjAA--.16641S3; Fri, 15 Apr 2022 09:28:43 +0800 (CST) From: caiyinyu Subject: Re: [PATCH v2 08/14] LoongArch: Linux Syscall Interface To: Adhemerval Zanella , libc-alpha@sourceware.org Cc: xuchenghua@loongson.cn, joseph_myers@mentor.com References: <20211231064455.1030051-1-caiyinyu@loongson.cn> <20211231064455.1030051-9-caiyinyu@loongson.cn> <4c6f299b-57cc-5de3-a6fc-d1d88987d20d@linaro.org> Message-ID: <65e9e558-f10c-8116-fe92-6dea7529a075@loongson.cn> Date: Fri, 15 Apr 2022 09:28:43 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <4c6f299b-57cc-5de3-a6fc-d1d88987d20d@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-CM-TRANSID: AQAAf9DxHxBLylhieckjAA--.16641S3 X-Coremail-Antispam: 1UD129KBjvAXoW3CF1xGr18KF17tFy3XFyxZrb_yoW8Jw4kto WfXFWxtr4xGr4DAFs8u39rZry2gw40gF1UXay7Z3ykJF10yF4UuFW0ya9IgF43urn09Fs5 Ga4fGr9FqFWxuFn3n29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UjIYCTnIWjp_UUUYa7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xva j40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2 x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8 Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI 0_Cr1j6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xf McIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7 v_Jr0_Gr1lF7xvr2IY64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7Mxk0xIA0c2IEe2xF o4CEbIxvr21lc2xSY4AK6svPMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r 4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF 67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF0xvE2I x0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_JFI_Gr1lIxAIcVC2 z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnU UI43ZEXa7VUjTKZJUUUUU== X-CM-SenderInfo: 5fdl5xhq1xqz5rrqw2lrqou0/ X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, 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: Fri, 15 Apr 2022 01:28:52 -0000 在 2022/1/4 下午10:20, Adhemerval Zanella 写道: > 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. Fixed. >> 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. Fixed. >> + (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. Removed. >> 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. Removed. > >> 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. Fixed. >> + >> + /* 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. Fixed by using generic Linux files. >> 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. Fixed by removing syscall.c.