From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org, caiyinyu <caiyinyu@loongson.cn>
Cc: xuchenghua@loongson.cn, joseph_myers@mentor.com
Subject: Re: [PATCH v2 08/14] LoongArch: Linux Syscall Interface
Date: Tue, 4 Jan 2022 11:20:37 -0300 [thread overview]
Message-ID: <4c6f299b-57cc-5de3-a6fc-d1d88987d20d@linaro.org> (raw)
In-Reply-To: <20211231064455.1030051-9-caiyinyu@loongson.cn>
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
> + <https://www.gnu.org/licenses/>. */
> +
> +#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 <hp-timing-common.h>
> +
> +#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 <sysdep.S>
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
> + <https://www.gnu.org/licenses/>. */
> +
> +#ifndef _BITS_SIGNUM_H
> +#define _BITS_SIGNUM_H 1
> +
> +#ifndef _SIGNAL_H
> +#error "Never include <bits/signum.h> directly; use <signal.h> instead."
> +#endif
> +
> +#include <bits/signum-generic.h>
> +
> +/* 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 /* <signal.h> 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
> + <https://www.gnu.org/licenses/>. */
> +
> +/* 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 <sys/asm.h>
> +#include <sysdep.h>
> +#define _ERRNO_H 1
> +#include <bits/errno.h>
> +#include <tls.h>
> +#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
> + <https://www.gnu.org/licenses/>. */
> +
> +#include <sys/ipc.h> /* For __key_t */
> +
> +#define __IPC_64 0x0
> +#include <sysdeps/unix/sysv/linux/ipc_priv.h>
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
> + <https://www.gnu.org/licenses/>. */
> +
> +#include <sysdep.h>
> +
> +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.
next prev parent reply other threads:[~2022-01-04 14:20 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-31 6:44 [PATCH v2 00/14] GLIBC LoongArch PATCHES caiyinyu
2021-12-31 6:44 ` [PATCH v2 01/14] LoongArch: Update NEWS and README for the LoongArch port caiyinyu
2022-01-04 13:30 ` Adhemerval Zanella
2022-04-15 1:28 ` caiyinyu
2021-12-31 6:44 ` [PATCH v2 02/14] LoongArch: Add LoongArch entries to config.h.in caiyinyu
2021-12-31 6:44 ` [PATCH v2 03/14] LoongArch: Add relocations and ELF flags to elf.h caiyinyu
2021-12-31 6:44 ` [PATCH v2 04/14] LoongArch: ABI Implementation caiyinyu
2022-01-04 13:46 ` Adhemerval Zanella
2022-04-15 1:28 ` caiyinyu
2021-12-31 6:44 ` [PATCH v2 05/14] LoongArch: Thread-Local Storage Support caiyinyu
2022-01-04 14:01 ` Adhemerval Zanella
2022-04-15 1:28 ` caiyinyu
2021-12-31 6:44 ` [PATCH v2 06/14] LoongArch: Generic <math.h> and soft-fp Routines caiyinyu
2022-01-04 14:05 ` Adhemerval Zanella
2022-01-04 20:31 ` Joseph Myers
2021-12-31 6:44 ` [PATCH v2 07/14] LoongArch: Atomic and Locking Routines caiyinyu
2022-01-04 14:09 ` Adhemerval Zanella
2022-04-15 1:28 ` caiyinyu
2021-12-31 6:44 ` [PATCH v2 08/14] LoongArch: Linux Syscall Interface caiyinyu
2022-01-04 14:20 ` Adhemerval Zanella [this message]
2022-04-15 1:28 ` caiyinyu
2021-12-31 6:44 ` [PATCH v2 09/14] LoongArch: Linux ABI caiyinyu
2021-12-31 17:37 ` Joseph Myers
2022-04-15 1:27 ` caiyinyu
2022-01-04 14:24 ` Adhemerval Zanella
2022-04-15 1:28 ` caiyinyu
2021-12-31 6:44 ` [PATCH v2 10/14] LoongArch: Linux Startup and Dynamic Loading Code caiyinyu
2022-01-04 14:27 ` Adhemerval Zanella
2022-04-15 1:28 ` caiyinyu
2021-12-31 6:44 ` [PATCH v2 11/14] LoongArch: Add ABI Lists caiyinyu
2021-12-31 17:43 ` Joseph Myers
2022-04-15 1:27 ` caiyinyu
2021-12-31 6:44 ` [PATCH v2 12/14] LoongArch: Build Infastructure caiyinyu
2022-01-04 14:33 ` Adhemerval Zanella
2021-12-31 6:44 ` [PATCH v2 13/14] LoongArch: Hard Float Support caiyinyu
2021-12-31 17:47 ` Joseph Myers
2022-04-15 1:27 ` caiyinyu
2021-12-31 6:44 ` [PATCH v2 14/14] LoongArch: Update build-many-glibcs.py for the LoongArch Port caiyinyu
2021-12-31 17:34 ` [PATCH v2 00/14] GLIBC LoongArch PATCHES Joseph Myers
2022-04-15 1:27 ` caiyinyu
2022-01-04 13:27 ` Adhemerval Zanella
2022-04-15 1:28 ` caiyinyu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4c6f299b-57cc-5de3-a6fc-d1d88987d20d@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=caiyinyu@loongson.cn \
--cc=joseph_myers@mentor.com \
--cc=libc-alpha@sourceware.org \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).