From patchwork Thu Jun 20 06:40:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 33237 Received: (qmail 61787 invoked by alias); 20 Jun 2019 06:41:53 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 61660 invoked by uid 89); 20 Jun 2019 06:41:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RDNS_DYNAMIC, SPF_PASS, TVD_RCVD_IP autolearn=ham version=3.3.1 spammy=8th X-HELO: ATCSQR.andestech.com From: Vincent Chen To: CC: , , Vincent Chen Subject: [PATCH v5 08/11] nds32: Linux ABI Date: Thu, 20 Jun 2019 14:40:35 +0800 Message-ID: <1561012838-11352-9-git-send-email-vincentc@andestech.com> In-Reply-To: <1561012838-11352-1-git-send-email-vincentc@andestech.com> References: <1561012838-11352-1-git-send-email-vincentc@andestech.com> MIME-Version: 1.0 X-DNSRBL: X-MAIL: ATCSQR.andestech.com x5K6YEpn068254 Linux-specific code that is required for maintaining ABI compatibility. This doesn't contain the actual system call interface, that is split out in order to avoid having a patch that's too big. 2019-06-03 Vincent Chen 2019-06-03 CheWei Chuang * sysdeps/unix/sysv/linux/nds32/bits/procfs.h: New file. * sysdeps/unix/sysv/linux/nds32/bits/shmlba.h: Likewise. * sysdeps/unix/sysv/linux/nds32/getcontext.S: Likewise. * sysdeps/unix/sysv/linux/nds32/init-first.c: Likewise. * sysdeps/unix/sysv/linux/nds32/ipc_priv.h: Likewise. * sysdeps/unix/sysv/linux/nds32/kernel-features.h: Likewise. * sysdeps/unix/sysv/linux/nds32/libc-vdso.h: Likewise. * sysdeps/unix/sysv/linux/nds32/makecontext.c: Likewise. * sysdeps/unix/sysv/linux/nds32/setcontext.S: Likewise. * sysdeps/unix/sysv/linux/nds32/sigcontextinfo.h: Likewise. * sysdeps/unix/sysv/linux/nds32/swapcontext.S: Likewise. * sysdeps/unix/sysv/linux/nds32/sys/cachectl.h: Likewise. * sysdeps/unix/sysv/linux/nds32/sys/ucontext.h: Likewise. * sysdeps/unix/sysv/linux/nds32/sys/user.h: Likewise. * sysdeps/unix/sysv/linux/nds32/sysctl.mk: Likewise. * sysdeps/unix/sysv/linux/nds32/ucontext_i.sym: Likewise. * sysdeps/unix/sysv/linux/nds32/vfork.S: Likewise. --- sysdeps/unix/sysv/linux/nds32/bits/procfs.h | 35 +++++++++++ sysdeps/unix/sysv/linux/nds32/bits/shmlba.h | 24 ++++++++ sysdeps/unix/sysv/linux/nds32/getcontext.S | 51 ++++++++++++++++ sysdeps/unix/sysv/linux/nds32/init-first.c | 52 ++++++++++++++++ sysdeps/unix/sysv/linux/nds32/ipc_priv.h | 22 +++++++ sysdeps/unix/sysv/linux/nds32/kernel-features.h | 31 ++++++++++ sysdeps/unix/sysv/linux/nds32/libc-vdso.h | 32 ++++++++++ sysdeps/unix/sysv/linux/nds32/makecontext.c | 57 +++++++++++++++++ sysdeps/unix/sysv/linux/nds32/setcontext.S | 65 ++++++++++++++++++++ sysdeps/unix/sysv/linux/nds32/sigcontextinfo.h | 35 +++++++++++ sysdeps/unix/sysv/linux/nds32/swapcontext.S | 57 +++++++++++++++++ sysdeps/unix/sysv/linux/nds32/sys/cachectl.h | 33 ++++++++++ sysdeps/unix/sysv/linux/nds32/sys/ucontext.h | 81 +++++++++++++++++++++++++ sysdeps/unix/sysv/linux/nds32/sys/user.h | 22 +++++++ sysdeps/unix/sysv/linux/nds32/sysctl.mk | 1 + sysdeps/unix/sysv/linux/nds32/ucontext_i.sym | 25 ++++++++ sysdeps/unix/sysv/linux/nds32/vfork.S | 46 ++++++++++++++ 17 files changed, 669 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/nds32/bits/procfs.h create mode 100644 sysdeps/unix/sysv/linux/nds32/bits/shmlba.h create mode 100644 sysdeps/unix/sysv/linux/nds32/getcontext.S create mode 100644 sysdeps/unix/sysv/linux/nds32/init-first.c create mode 100644 sysdeps/unix/sysv/linux/nds32/ipc_priv.h create mode 100644 sysdeps/unix/sysv/linux/nds32/kernel-features.h create mode 100644 sysdeps/unix/sysv/linux/nds32/libc-vdso.h create mode 100644 sysdeps/unix/sysv/linux/nds32/makecontext.c create mode 100644 sysdeps/unix/sysv/linux/nds32/setcontext.S create mode 100644 sysdeps/unix/sysv/linux/nds32/sigcontextinfo.h create mode 100644 sysdeps/unix/sysv/linux/nds32/swapcontext.S create mode 100644 sysdeps/unix/sysv/linux/nds32/sys/cachectl.h create mode 100644 sysdeps/unix/sysv/linux/nds32/sys/ucontext.h create mode 100644 sysdeps/unix/sysv/linux/nds32/sys/user.h create mode 100644 sysdeps/unix/sysv/linux/nds32/sysctl.mk create mode 100644 sysdeps/unix/sysv/linux/nds32/ucontext_i.sym create mode 100644 sysdeps/unix/sysv/linux/nds32/vfork.S diff --git a/sysdeps/unix/sysv/linux/nds32/bits/procfs.h b/sysdeps/unix/sysv/linux/nds32/bits/procfs.h new file mode 100644 index 0000000..cbecc8b --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/bits/procfs.h @@ -0,0 +1,35 @@ +/* Types for registers for sys/procfs.h. Andes nds32 version. + Copyright (C) 2018-2019 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 _SYS_PROCFS_H +# error "Never include directly; use instead." +#endif + +#include + +/* Type for a general-purpose register. */ +typedef unsigned long int elf_greg_t; +/* Type for a floating-point registers. */ +typedef long long int elf_fpreg_t; + +#define ELF_NGREG (sizeof (struct user_pt_regs) / sizeof (elf_greg_t)) +typedef elf_greg_t elf_gregset_t[ELF_NGREG]; + +/* Register set for the floating-point registers. */ +#define ELF_NFPREG 33 +typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG]; diff --git a/sysdeps/unix/sysv/linux/nds32/bits/shmlba.h b/sysdeps/unix/sysv/linux/nds32/bits/shmlba.h new file mode 100644 index 0000000..2a1e0d6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/bits/shmlba.h @@ -0,0 +1,24 @@ +/* Define SHMLBA. Andes nds32 version. + Copyright (C) 2018-2019 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 _SYS_SHM_H +# error "Never use directly; include instead." +#endif + +/* Segment low boundary address multiple. */ +#define SHMLBA 0x8000 diff --git a/sysdeps/unix/sysv/linux/nds32/getcontext.S b/sysdeps/unix/sysv/linux/nds32/getcontext.S new file mode 100644 index 0000000..e2f4c83 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/getcontext.S @@ -0,0 +1,51 @@ +/* Save current context. Andes LINUX/nds32 version. + Copyright (C) 2018-2019 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 +#include "ucontext_i.h" + +/* int getcontext (const ucontext_t *ucp). */ + +ENTRY (__getcontext) + swi $lp, [$r0 + UCONTEXT_PC] + addi $r15, $r0, UCONTEXT_GREGS + xor $r1, $r1, $r1 + smw.bim $r1, [$r15], $r1 + addi $r15, $r15, 20 + smw.bim $r6, [$r15], $r14 + addi $r15, $r15, 4 + smw.bim $r16, [$r15], $r25, #0xf + +/* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8). */ + move $r3, _NSIG8 + addi $r2, $r0, UCONTEXT_SIGMASK + movi $r1, 0 + movi $r0, SIG_BLOCK + movi $r15, SYS_ify(rt_sigprocmask) + syscall 0x0 + bnez $r0, .err + + ret + +.err: + j SYSCALL_ERROR_LABEL + +PSEUDO_END (__getcontext) + +weak_alias (__getcontext, getcontext) + diff --git a/sysdeps/unix/sysv/linux/nds32/init-first.c b/sysdeps/unix/sysv/linux/nds32/init-first.c new file mode 100644 index 0000000..f3412c6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/init-first.c @@ -0,0 +1,52 @@ +/* VDSO initialization. Andes Nds32 version + Copyright (C) 2018-2019 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 +#include + +int (*VDSO_SYMBOL (gettimeofday)) (struct timeval *, void *) + attribute_hidden; +int (*VDSO_SYMBOL (clock_getres)) (clockid_t, struct timespec *) + attribute_hidden; +int (*VDSO_SYMBOL (clock_gettime)) (clockid_t, struct timespec *) + attribute_hidden; + +static inline void +_libc_vdso_platform_setup (void) +{ + PREPARE_VERSION (linux4, "LINUX_4", 14921332); + + void *p = _dl_vdso_vsym ("__vdso_gettimeofday", &linux4); + + PTR_MANGLE (p); + VDSO_SYMBOL (gettimeofday) = p; + + p = _dl_vdso_vsym ("__vdso_clock_getres", &linux4); + PTR_MANGLE (p); + VDSO_SYMBOL (clock_getres) = p; + + p = _dl_vdso_vsym ("__vdso_clock_gettime", &linux4); + PTR_MANGLE (p); + VDSO_SYMBOL (clock_gettime) = p; + +} + +#define VDSO_SETUP _libc_vdso_platform_setup + +#include diff --git a/sysdeps/unix/sysv/linux/nds32/ipc_priv.h b/sysdeps/unix/sysv/linux/nds32/ipc_priv.h new file mode 100644 index 0000000..c88bbb1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/ipc_priv.h @@ -0,0 +1,22 @@ +/* Old SysV permission definition for Linux. Andes nds32 version. + Copyright (C) 2018-2019 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 /* For __key_t. */ + +#define __IPC_64 0x0 + diff --git a/sysdeps/unix/sysv/linux/nds32/kernel-features.h b/sysdeps/unix/sysv/linux/nds32/kernel-features.h new file mode 100644 index 0000000..4ab663e --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/kernel-features.h @@ -0,0 +1,31 @@ +/* Set flags signalling availability of kernel features based on given + kernel version number. Andes nds32 version. + Copyright (C) 2018-2019 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_next + + +#undef __ASSUME_CLONE_DEFAULT +#define __ASSUME_CLONE_BACKWARDS 1 + +/* Define this if your 32-bit syscall API requires 64-bit register + pairs to start with an even-number register. */ +#define __ASSUME_ALIGNED_REGISTER_PAIRS 1 + +/* nds32 fadvise64_64 reorganize the syscall arguments. */ +#define __ASSUME_FADVISE64_64_6ARG 1 diff --git a/sysdeps/unix/sysv/linux/nds32/libc-vdso.h b/sysdeps/unix/sysv/linux/nds32/libc-vdso.h new file mode 100644 index 0000000..3247e09 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/libc-vdso.h @@ -0,0 +1,32 @@ +/* VDSO function declaration, Andes nds32 version. + Copyright (C) 2018-2019 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 _LIBC_VDSO_H +#define _LIBC_VDSO_H + +# include + +extern int (*VDSO_SYMBOL (gettimeofday)) (struct timeval *, void *) + attribute_hidden; +extern int (*VDSO_SYMBOL (clock_gettime)) (clockid_t, struct timespec *) + attribute_hidden; +extern int (*VDSO_SYMBOL (clock_getres)) (clockid_t, struct timespec *) + attribute_hidden; + +#endif /* _LIBC_VDSO_H. */ diff --git a/sysdeps/unix/sysv/linux/nds32/makecontext.c b/sysdeps/unix/sysv/linux/nds32/makecontext.c new file mode 100644 index 0000000..cbe9093 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/makecontext.c @@ -0,0 +1,57 @@ +/* Create new context. Andes nds32 version. + Copyright (C) 2018-2019 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 +#include +#include + +void +__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...) +{ + extern void __startcontext (void); + unsigned long int *sp; + unsigned long int *regptr; + va_list ap; + int i; + + sp = (unsigned long int *) + ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size); + + /* Allocate stack for 7-th, 8-th, ..., n-th arguments. */ + sp -= argc <= 6 ? 0 : argc - 6; + + /* Keep the stack aligned. */ + sp = (unsigned long int *) (((uintptr_t) sp) & -8L); + + ucp->uc_mcontext.__nds32_r6 = (uintptr_t) ucp->uc_link; + ucp->uc_mcontext.__nds32_sp = (uintptr_t) sp; + ucp->uc_mcontext.__nds32_ipc = (uintptr_t) func; + ucp->uc_mcontext.__nds32_lp = (uintptr_t) &__startcontext; + + va_start (ap, argc); + regptr = &ucp->uc_mcontext.__nds32_r0; + for (i = 0; i < argc; ++i) + if (i < 6) + *regptr++ = va_arg (ap, unsigned long int); + else + sp[i - 6] = va_arg (ap, unsigned long int); + + va_end (ap); + +} +weak_alias (__makecontext, makecontext) diff --git a/sysdeps/unix/sysv/linux/nds32/setcontext.S b/sysdeps/unix/sysv/linux/nds32/setcontext.S new file mode 100644 index 0000000..22f5f0a --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/setcontext.S @@ -0,0 +1,65 @@ +/* Set current context. Andes nds32 version. + Copyright (C) 2018-2019 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 + +#include "ucontext_i.h" + +/* int __setcontext (const ucontext_t *ucp). */ + +ENTRY (__setcontext) + move $r4, $r0 + +/* sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8). */ + move $r0, SIG_SETMASK + addi $r1, $r4, UCONTEXT_SIGMASK + movi $r2, 0 + movi $r3, _NSIG8 + movi $r15, SYS_ify(rt_sigprocmask) + syscall SYS_ify(rt_sigprocmask) + bnez $r0, .err + + move $r0, $r4 + addi $r15, $r0, UCONTEXT_GREGS + 4 + lmw.bim $r1, [$r15], $r14 + addi $r15, $r15, 4 + lmw.bim $r16, [$r15], $r25, #0xf + lwi $r15, [$r0 + UCONTEXT_PC] + lwi $r0, [$r0 + UCONTEXT_GREGS] + jr $r15 +.err: + j SYSCALL_ERROR_LABEL +PSEUDO_END (__setcontext) + +weak_alias (__setcontext, setcontext) + + cfi_startproc + cfi_undefined (lp) + nop16 + cfi_endproc +ENTRY (__startcontext) + beqz $r6, 1f + move $r0, $r6 + jal __setcontext +1: + move $r0, 0 + j HIDDEN_JUMPTARGET(exit) +END (__startcontext) + +.hidden __startcontext + diff --git a/sysdeps/unix/sysv/linux/nds32/sigcontextinfo.h b/sysdeps/unix/sysv/linux/nds32/sigcontextinfo.h new file mode 100644 index 0000000..5ee58be --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/sigcontextinfo.h @@ -0,0 +1,35 @@ +/* Definitions for signal handling calling conventions. Andes nds32 version. + Copyright (C) 2018-2019 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 + +#define SIGCONTEXT siginfo_t *_si, struct ucontext_t * +#define GET_PC(ctx) ((void *) (ctx)->uc_mcontext.__nds32_ipc) + + +/* There is no reliable way to get the sigcontext unless we use a + three-argument signal handler. */ +#define __sigaction(sig, act, oact) ({ \ + (act)->sa_flags |= SA_SIGINFO; \ + (__sigaction) (sig, act, oact); \ +}) + +#define sigaction(sig, act, oact) ({ \ + (act)->sa_flags |= SA_SIGINFO; \ + (sigaction) (sig, act, oact); \ +}) diff --git a/sysdeps/unix/sysv/linux/nds32/swapcontext.S b/sysdeps/unix/sysv/linux/nds32/swapcontext.S new file mode 100644 index 0000000..5691a5e --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/swapcontext.S @@ -0,0 +1,57 @@ +/* Save and set current context. Andes nds32 version + Copyright (C) 2018-2019 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 +#include "ucontext_i.h" + +/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp). */ + +ENTRY (__swapcontext) + move $r5, $r1 + swi $lp, [$r0 + UCONTEXT_PC] + addi $r15, $r0, UCONTEXT_GREGS + xor $r1, $r1, $r1 + smw.bim $r1, [$r15], $r1 + addi $r15, $r15, 20 + smw.bim $r6, [$r15], $r14 + addi $r15, $r15, 4 + smw.bim $r16, [$r15], $r25, #0xf + +/* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, &oucp->uc_sigmask, _NSIG8). */ + move $r3, _NSIG8 + addi $r2, $r0, UCONTEXT_SIGMASK + addi $r1, $r5, UCONTEXT_SIGMASK + move $r0, SIG_SETMASK + movi $r15, SYS_ify(rt_sigprocmask) + syscall SYS_ify(rt_sigprocmask) + bnez $r0, .err + + move $r0, $r5 + addi $r15, $r5, UCONTEXT_GREGS + 4 + lmw.bim $r1, [$r15], $r14 + addi $r15, $r15, 4 + lmw.bim $r16, [$r15], $r25, #0xf + lwi $r15, [$r0 + UCONTEXT_PC] + lwi $r0, [$r0 + UCONTEXT_GREGS] + jr $r15 + +.err: + j SYSCALL_ERROR_LABEL +PSEUDO_END (__swapcontext) + +weak_alias (__swapcontext, swapcontext) diff --git a/sysdeps/unix/sysv/linux/nds32/sys/cachectl.h b/sysdeps/unix/sysv/linux/nds32/sys/cachectl.h new file mode 100644 index 0000000..688602d --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/sys/cachectl.h @@ -0,0 +1,33 @@ +/* Andes nds32 cache flushing interface + Copyright (C) 2018-2019 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 _SYS_CACHECTL_H +#define _SYS_CACHECTL_H 1 + +#include + +/* Get the kernel definition for the __op argument. */ +#include + +__BEGIN_DECLS + +extern int cacheflush (void *__addr, const int __end, const int __op) __THROW; + +__END_DECLS + +#endif /* sys/cachectl.h. */ diff --git a/sysdeps/unix/sysv/linux/nds32/sys/ucontext.h b/sysdeps/unix/sysv/linux/nds32/sys/ucontext.h new file mode 100644 index 0000000..79d2327 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/sys/ucontext.h @@ -0,0 +1,81 @@ +/* struct ucontext definition, Andes nds32 version. + Copyright (C) 2018-2019 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 _SYS_UCONTEXT_H +#define _SYS_UCONTEXT_H 1 + +#include +#include +#include + +/* Context to describe whole processor state. */ + +typedef struct { + unsigned long int __trap_no; + unsigned long int __error_code; + unsigned long int __oldmask; + unsigned long int __nds32_r0; + unsigned long int __nds32_r1; + unsigned long int __nds32_r2; + unsigned long int __nds32_r3; + unsigned long int __nds32_r4; + unsigned long int __nds32_r5; + unsigned long int __nds32_r6; + unsigned long int __nds32_r7; + unsigned long int __nds32_r8; + unsigned long int __nds32_r9; + unsigned long int __nds32_r10; + unsigned long int __nds32_r11; + unsigned long int __nds32_r12; + unsigned long int __nds32_r13; + unsigned long int __nds32_r14; + unsigned long int __nds32_r15; + unsigned long int __nds32_r16; + unsigned long int __nds32_r17; + unsigned long int __nds32_r18; + unsigned long int __nds32_r19; + unsigned long int __nds32_r20; + unsigned long int __nds32_r21; + unsigned long int __nds32_r22; + unsigned long int __nds32_r23; + unsigned long int __nds32_r24; + unsigned long int __nds32_r25; + unsigned long int __nds32_fp; + unsigned long int __nds32_gp; + unsigned long int __nds32_lp; + unsigned long int __nds32_sp; + unsigned long int __nds32_ipc; + unsigned long int __fault_address; + unsigned long int __used_math_flag; + unsigned long long int __fd_regs[32]; + unsigned long int __fpcsr; + unsigned long int __UDF_trap; + unsigned long int __zol[3]; +} mcontext_t; + + +/* Userlevel context. */ +typedef struct ucontext_t + { + unsigned long int __uc_flags; + struct ucontext_t *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + __sigset_t uc_sigmask; + } ucontext_t; +#endif /* _SYS_UCONTEXT_H. */ diff --git a/sysdeps/unix/sysv/linux/nds32/sys/user.h b/sysdeps/unix/sysv/linux/nds32/sys/user.h new file mode 100644 index 0000000..b529a0b --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/sys/user.h @@ -0,0 +1,22 @@ +/* Copyright (C) 2018-2019 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 _SYS_USER_H +#define _SYS_USER_H 1 + + +#endif /* _SYS_USER_H. */ diff --git a/sysdeps/unix/sysv/linux/nds32/sysctl.mk b/sysdeps/unix/sysv/linux/nds32/sysctl.mk new file mode 100644 index 0000000..cd10656 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/sysctl.mk @@ -0,0 +1 @@ +# nds32 doesn't support sysctl. diff --git a/sysdeps/unix/sysv/linux/nds32/ucontext_i.sym b/sysdeps/unix/sysv/linux/nds32/ucontext_i.sym new file mode 100644 index 0000000..c0cfafc --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/ucontext_i.sym @@ -0,0 +1,25 @@ +#include +#include +#include + +-- + +SIG_BLOCK +SIG_SETMASK + +_NSIG8 (_NSIG / 8) + +-- Offsets of the fields in the ucontext_t structure. +#define ucontext(member) offsetof (ucontext_t, member) +#define mcontext(member) ucontext (uc_mcontext.member) + + +UCONTEXT_GREGS mcontext (__nds32_r0) +UCONTEXT_PC mcontext (__nds32_ipc) + + +UCONTEXT_FLAGS ucontext (__uc_flags) +UCONTEXT_LINK ucontext (uc_link) +UCONTEXT_STACK ucontext (uc_stack) +UCONTEXT_MCONTEXT ucontext (uc_mcontext) +UCONTEXT_SIGMASK ucontext (uc_sigmask) diff --git a/sysdeps/unix/sysv/linux/nds32/vfork.S b/sysdeps/unix/sysv/linux/nds32/vfork.S new file mode 100644 index 0000000..0bd72de --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/vfork.S @@ -0,0 +1,46 @@ +/* vfork for Linux. Andes Linux/nds32 version. + Copyright (C) 2018-2019 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 +#define _ERRNO_H 1 +#include + + +ENTRY (__libc_vfork) +#ifdef PIC +.pic +#endif + + movi $r0, #0x4111 /* 0x4111 = CLONE_VM | CLONE_VFORK | SIGCHLD. */ + move $r1, $sp + movi $r15, __NR_clone + syscall #0x0 + bltz $r0, 2f +1: + ret +2: + sltsi $r1, $r0, -4096 + bnez $r1, 1b; + + j SYSCALL_ERROR_LABEL + +PSEUDO_END (__libc_vfork) + +weak_alias (__libc_vfork, vfork) +strong_alias (__libc_vfork, __vfork) +libc_hidden_def (__vfork)