From patchwork Sun May 6 14:41:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Chen X-Patchwork-Id: 27136 Received: (qmail 37415 invoked by alias); 6 May 2018 14:42:39 -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 37326 invoked by uid 89); 6 May 2018 14:42:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=resident, Allocation, Signal, unlock X-HELO: ATCSQR.andestech.com From: vincentc To: CC: , , vincentc Subject: [PATCH 08/11] nds32: Linux ABI Date: Sun, 6 May 2018 22:41:22 +0800 Message-ID: <1525617685-32083-9-git-send-email-vincentc@andestech.com> In-Reply-To: <1525617685-32083-1-git-send-email-vincentc@andestech.com> References: <1525617685-32083-1-git-send-email-vincentc@andestech.com> MIME-Version: 1.0 X-DNSRBL: X-MAIL: ATCSQR.andestech.com w46EYU0h047206 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. --- sysdeps/unix/sysv/linux/nds32/bits/fcntl.h | 54 ++++++++++ sysdeps/unix/sysv/linux/nds32/bits/mman.h | 36 +++++++ sysdeps/unix/sysv/linux/nds32/bits/shm.h | 102 +++++++++++++++++++ sysdeps/unix/sysv/linux/nds32/getcontext.S | 52 ++++++++++ sysdeps/unix/sysv/linux/nds32/init-first.c | 50 +++++++++ sysdeps/unix/sysv/linux/nds32/ipc_priv.h | 22 ++++ sysdeps/unix/sysv/linux/nds32/kernel-features.h | 29 ++++++ sysdeps/unix/sysv/linux/nds32/kernel_sigaction.h | 30 ++++++ sysdeps/unix/sysv/linux/nds32/libc-vdso.h | 36 +++++++ sysdeps/unix/sysv/linux/nds32/makecontext.c | 57 +++++++++++ sysdeps/unix/sysv/linux/nds32/setcontext.S | 65 ++++++++++++ sysdeps/unix/sysv/linux/nds32/sigcontextinfo.h | 40 ++++++++ sysdeps/unix/sysv/linux/nds32/swapcontext.S | 57 +++++++++++ sysdeps/unix/sysv/linux/nds32/sys/cachectl.h | 34 +++++++ sysdeps/unix/sysv/linux/nds32/sys/procfs.h | 123 +++++++++++++++++++++++ sysdeps/unix/sysv/linux/nds32/sys/ucontext.h | 85 ++++++++++++++++ sysdeps/unix/sysv/linux/nds32/sys/user.h | 26 +++++ 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 +++++++++ 20 files changed, 970 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/nds32/bits/fcntl.h create mode 100644 sysdeps/unix/sysv/linux/nds32/bits/mman.h create mode 100644 sysdeps/unix/sysv/linux/nds32/bits/shm.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/kernel_sigaction.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/procfs.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/fcntl.h b/sysdeps/unix/sysv/linux/nds32/bits/fcntl.h new file mode 100644 index 0000000..6a4a5b7 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/bits/fcntl.h @@ -0,0 +1,54 @@ +/* O_*, F_*, FD_* bit values for Andes Linux/nds32. + Copyright (C) 2011-2018 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 _FCNTL_H +# error "Never use directly; include instead." +#endif + +#include + +typedef struct flock + { + short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */ + short int l_whence; /* Where `l_start' is relative to (like `lseek'). */ +#ifndef __USE_FILE_OFFSET64 + __off_t l_start; /* Offset where the lock begins. */ + __off_t l_len; /* Size of the locked area; zero means until EOF. */ +#else + __off64_t l_start; /* Offset where the lock begins. */ + __off64_t l_len; /* Size of the locked area; zero means until EOF. */ +#endif + __pid_t l_pid; /* Process holding the lock. */ +} flock_t; + +#ifdef __USE_LARGEFILE64 +struct flock64 + { + short int l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */ + short int l_whence; /* Where `l_start' is relative to (like `lseek'). */ + __off64_t l_start; /* Offset where the lock begins. */ + __off64_t l_len; /* Size of the locked area; zero means until EOF. */ + __pid_t l_pid; /* Process holding the lock. */ + }; +#endif + + +/* Include generic Linux declarations. */ +#include + diff --git a/sysdeps/unix/sysv/linux/nds32/bits/mman.h b/sysdeps/unix/sysv/linux/nds32/bits/mman.h new file mode 100644 index 0000000..045be1f --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/bits/mman.h @@ -0,0 +1,36 @@ +/* Definitions for POSIX memory map interface, Andes Linux/nds32 version. + Copyright (C) 1997-2018 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_MMAN_H +# error "Never use directly; include instead." +#endif + +#ifdef __USE_MISC +# define MAP_GROWSDOWN 0x00100 /* stack-like segment. */ +# define MAP_DENYWRITE 0x00800 /* ETXTBSY. */ +# define MAP_EXECUTABLE 0x01000 /* mark it as an executable. */ +# define MAP_LOCKED 0x02000 /* pages are locked. */ +# define MAP_NORESERVE 0x04000 /* don't check for reservations. */ +# define MAP_POPULATE 0x08000 /* populate (prefault) pagetables. */ +# define MAP_NONBLOCK 0x10000 /* do not block on IO. */ +# define MAP_STACK 0x20000 /* Allocation is for a stack. */ +# define MAP_HUGETLB 0x40000 /* Create huge page mapping. */ +#endif + +/* Include generic Linux declarations. */ +#include diff --git a/sysdeps/unix/sysv/linux/nds32/bits/shm.h b/sysdeps/unix/sysv/linux/nds32/bits/shm.h new file mode 100644 index 0000000..fe96fa2 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/bits/shm.h @@ -0,0 +1,102 @@ +/* The definition for POSIX shared memory, Andes nds32 version + Copyright (C) 1995-2018 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 include directly; use instead." +#endif + +#include + +/* Permission flag for shmget. */ +#define SHM_R 0400 /* or S_IRUGO from . */ +#define SHM_W 0200 /* or S_IWUGO from . */ + +/* Flags for `shmat'. */ +#define SHM_RDONLY 010000 /* attach read-only else read-write. */ +#define SHM_RND 020000 /* round attach address to SHMLBA. */ +#define SHM_REMAP 040000 /* take-over region on attach. */ +#define SHM_EXEC 0100000 /* execution access. */ + +/* Commands for `shmctl'. */ +#define SHM_LOCK 11 /* lock segment (root only). */ +#define SHM_UNLOCK 12 /* unlock segment (root only). */ + +__BEGIN_DECLS + +/* Segment low boundary address multiple. */ +#define SHMLBA 0x8000 + +/* Type to count number of attaches. */ +typedef unsigned long int shmatt_t; + +/* Data structure describing a shared memory segment. */ +struct shmid_ds + { + struct ipc_perm shm_perm; /* operation permission struct. */ + size_t shm_segsz; /* size of segment in bytes. */ + __time_t shm_atime; /* time of last shmat(). */ + unsigned long int __glibc_reserved1; + __time_t shm_dtime; /* time of last shmdt(). */ + unsigned long int __glibc_reserved2; + __time_t shm_ctime; /* time of last change by shmctl(). */ + unsigned long int __glibc_reserved3; + __pid_t shm_cpid; /* pid of creator. */ + __pid_t shm_lpid; /* pid of last shmop. */ + shmatt_t shm_nattch; /* number of current attaches. */ + unsigned long int __glibc_reserved4; + unsigned long int __glibc_reserved5; + }; + +#ifdef __USE_MISC + +/* ipcs ctl commands. */ +# define SHM_STAT 13 +# define SHM_INFO 14 + +/* shm_mode upper byte flags. */ +# define SHM_DEST 01000 /* segment will be destroyed on last detach. */ +# define SHM_LOCKED 02000 /* segment will not be swapped. */ +# define SHM_HUGETLB 04000 /* segment is mapped via hugetlb. */ +# define SHM_NORESERVE 010000 /* don't check for reservations. */ + +struct shminfo + { + unsigned long int shmmax; + unsigned long int shmmin; + unsigned long int shmmni; + unsigned long int shmseg; + unsigned long int shmall; + unsigned long int __glibc_reserved1; + unsigned long int __glibc_reserved2; + unsigned long int __glibc_reserved3; + unsigned long int __glibc_reserved4; + }; + +struct shm_info + { + int used_ids; + unsigned long int shm_tot; /* total allocated shm. */ + unsigned long int shm_rss; /* total resident shm. */ + unsigned long int shm_swp; /* total swapped shm. */ + unsigned long int swap_attempts; + unsigned long int swap_successes; + }; + +#endif /* __USE_MISC */ + +__END_DECLS diff --git a/sysdeps/unix/sysv/linux/nds32/getcontext.S b/sysdeps/unix/sysv/linux/nds32/getcontext.S new file mode 100644 index 0000000..e0b4c63 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/getcontext.S @@ -0,0 +1,52 @@ +/* Save current context. + Copyright (C) 2009-2018 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" + +/* __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, 1f + + ret + +1: + 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..0a2b916 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/init-first.c @@ -0,0 +1,50 @@ +/* VDSO initialization. Andes Nds32 version + Copyright (C) 2007-2018 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 + . */ + +#ifdef SHARED +# include +# include + +int (*VDSO_SYMBOL(gettimeofday)) (struct timeval *, void *) attribute_hidden; +int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *); +int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); + +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 +#endif /* SHARED */ + +#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..e0732b9 --- /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 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..c2bbd38 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/kernel-features.h @@ -0,0 +1,29 @@ +/* Set flags signalling availability of kernel features based on given + kernel version number, Andes nds32 version. + Copyright (C) 2006-2018 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 + + + +/* 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/kernel_sigaction.h b/sysdeps/unix/sysv/linux/nds32/kernel_sigaction.h new file mode 100644 index 0000000..d7fab19 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/kernel_sigaction.h @@ -0,0 +1,30 @@ +/* Define struct old_kernel_sigaction and kernel_sigaction for Andes nds32. + Copyright (C) 2006-2018 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 + . */ + + +struct old_kernel_sigaction { + __sighandler_t k_sa_handler; + unsigned long sa_mask; + unsigned long sa_flags; +}; + +struct kernel_sigaction { + __sighandler_t k_sa_handler; + unsigned long sa_flags; + sigset_t sa_mask; +}; 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..bbc709b --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/libc-vdso.h @@ -0,0 +1,36 @@ +/* VDSO function declaration, Andes nds32 version. + Copyright (C) 2017-2018 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 + +#ifdef SHARED + +# 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 + +#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..1be7f54 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/makecontext.c @@ -0,0 +1,57 @@ +/* Create new context, Andes nds32 version. + Copyright (C) 2001-2018 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 *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..808cbb6 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/setcontext.S @@ -0,0 +1,65 @@ +/* Set current context. + Copyright (C) 2009-2018 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, 1f + + 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 +1: + 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..e96e737 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/sigcontextinfo.h @@ -0,0 +1,40 @@ +/* Definitions for signal handling calling conventions, Andes nds32 version. + Copyright (C) 2000-2018 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 SIGCONTEXT_EXTRA_ARGS _si, +#define GET_PC(ctx) ((void *) (ctx)->uc_mcontext.nds32_ipc) +#define GET_FRAME(ctx) ((void *) (ctx)->uc_mcontext.nds32_fp) +#define GET_STACK(ctx) ((void *) (ctx)->uc_mcontext.nds32_sp) + +#define CALL_SIGHANDLER(handler, signo, ctx) \ + (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx)) + +/* 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..dd4929c --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/swapcontext.S @@ -0,0 +1,57 @@ +/* Save and set current context. + Copyright (C) 2009-2018 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, 1f + + 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 + +1: + 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..2f24724 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/sys/cachectl.h @@ -0,0 +1,34 @@ +/* Andes nds32 cache flushing interface + Copyright (C) 2017-2018 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/procfs.h b/sysdeps/unix/sysv/linux/nds32/sys/procfs.h new file mode 100644 index 0000000..06dce6b --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/sys/procfs.h @@ -0,0 +1,123 @@ +/* Core image file related definitions, Andes nds32 version. + Copyright (C) 1996-2018 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 +#define _SYS_PROCFS_H 1 + +/* This is somewhat modelled after the file of the same name on SVR4 + systems. It provides a definition of the core file format for ELF + used on Linux. It doesn't have anything to do with the /proc file + system, even though Linux has one. + + Anyway, the whole purpose of this file is for GDB and GDB only. + Don't read too much into it. Don't use it for anything other than + GDB unless you know what you are doing. */ + +#include +#include +#include +#include + +__BEGIN_DECLS + +/* Type for a general-purpose register. */ +typedef unsigned long elf_greg_t; + +/* And the whole bunch of them. We could have used `struct + user_regs' directly in the typedef, but tradition says that + the register set is an array, which does have some peculiar + semantics, so leave it that way. */ + +#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. */ +typedef struct user_fpregs elf_fpregset_t; + +/* Signal info. */ +struct elf_siginfo + { + int si_signo; /* Signal number. */ + int si_code; /* Extra code. */ + int si_errno; /* Errno. */ + }; + +/* Definitions to generate Intel SVR4-like core files. These mostly + have the same names as the SVR4 types with "elf_" tacked on the + front to prevent clashes with Linux definitions, and the typedef + forms have been avoided. This is mostly like the SVR4 structure, + but more Linuxy, with things that Linux does not support and which + GDB doesn't really use excluded. */ + +struct elf_prstatus + { + struct elf_siginfo pr_info; /* Info associated with signal. */ + short int pr_cursig; /* Current signal. */ + unsigned long int pr_sigpend; /* Set of pending signals. */ + unsigned long int pr_sighold; /* Set of held signals. */ + __pid_t pr_pid; + __pid_t pr_ppid; + __pid_t pr_pgrp; + __pid_t pr_sid; + struct timeval pr_utime; /* User time. */ + struct timeval pr_stime; /* System time. */ + struct timeval pr_cutime; /* Cumulative user time. */ + struct timeval pr_cstime; /* Cumulative system time. */ + elf_gregset_t pr_reg; /* GP registers. */ + int pr_fpvalid; /* True if math copro being used. */ + }; + + +#define ELF_PRARGSZ (80) /* Number of chars for args. */ + +struct elf_prpsinfo + { + char pr_state; /* Numeric process state. */ + char pr_sname; /* Char for pr_state. */ + char pr_zomb; /* Zombie. */ + char pr_nice; /* Nice val. */ + unsigned long int pr_flag; /* Flags. */ + unsigned short int pr_uid; + unsigned short int pr_gid; + int pr_pid, pr_ppid, pr_pgrp, pr_sid; + char pr_fname[16]; /* Filename of executable. */ + char pr_psargs[ELF_PRARGSZ]; /* Initial part of arg list. */ + }; + +/* The rest of this file provides the types for emulation of the + Solaris interfaces that should be implemented by + users of libthread_db. */ + +/* Addresses. */ +typedef void *psaddr_t; + +/* Register sets. Linux has different names. */ +typedef elf_gregset_t prgregset_t; +typedef elf_fpregset_t prfpregset_t; + +/* We don't have any differences between processes and threads, + therefore have only one PID type. */ +typedef __pid_t lwpid_t; + +/* Process status and info. In the end we do provide typedefs for them. */ +typedef struct elf_prstatus prstatus_t; +typedef struct elf_prpsinfo prpsinfo_t; + +__END_DECLS + +#endif /* sys/procfs.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..7a853b3 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/sys/ucontext.h @@ -0,0 +1,85 @@ +/* struct ucontext definition, Andes nds32 version. + Copyright (C) 1997-2018 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 + + +#ifdef __USE_MISC +# define __ctx(fld) fld +#else +# define __ctx(fld) __ ## fld +#endif + +/* Context to describe whole processor state. */ + +typedef struct { + unsigned long __ctx(trap_no); + unsigned long __ctx(error_code); + unsigned long __ctx(oldmask); + unsigned long __ctx(nds32_r0); + unsigned long __ctx(nds32_r1); + unsigned long __ctx(nds32_r2); + unsigned long __ctx(nds32_r3); + unsigned long __ctx(nds32_r4); + unsigned long __ctx(nds32_r5); + unsigned long __ctx(nds32_r6); + unsigned long __ctx(nds32_r7); + unsigned long __ctx(nds32_r8); + unsigned long __ctx(nds32_r9); + unsigned long __ctx(nds32_r10); + unsigned long __ctx(nds32_r11); + unsigned long __ctx(nds32_r12); + unsigned long __ctx(nds32_r13); + unsigned long __ctx(nds32_r14); + unsigned long __ctx(nds32_r15); + unsigned long __ctx(nds32_r16); + unsigned long __ctx(nds32_r17); + unsigned long __ctx(nds32_r18); + unsigned long __ctx(nds32_r19); + unsigned long __ctx(nds32_r20); + unsigned long __ctx(nds32_r21); + unsigned long __ctx(nds32_r22); + unsigned long __ctx(nds32_r23); + unsigned long __ctx(nds32_r24); + unsigned long __ctx(nds32_r25); + unsigned long __ctx(nds32_fp); + unsigned long __ctx(nds32_gp); + unsigned long __ctx(nds32_lp); + unsigned long __ctx(nds32_sp); + unsigned long __ctx(nds32_ipc); + unsigned long __ctx(fault_address); + unsigned long __ctx(used_math_flag); + unsigned long __ctx(zol)[3]; +} mcontext_t; + + +/* Userlevel context. */ +typedef struct ucontext_t + { + unsigned long int __ctx(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..5a4ab70 --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/sys/user.h @@ -0,0 +1,26 @@ +/* Copyright (C) 2017-2018 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 + +#include + +struct user_fpregs +{ +}; +#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..a341805 --- /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..be5060f --- /dev/null +++ b/sysdeps/unix/sysv/linux/nds32/vfork.S @@ -0,0 +1,46 @@ +/* vfork for Linux, Andes Linux/nds32 version. + Copyright (C) 2005-2018 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)