diff --git a/sysdeps/unix/sysv/linux/nds32/bits/environments.h b/sysdeps/unix/sysv/linux/nds32/bits/environments.h
new file mode 100644
index 0000000..1e32020
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/nds32/bits/environments.h
@@ -0,0 +1,55 @@
+/* Copyright (C) 1999-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 _UNISTD_H
+# error "Never include this file directly. Use instead"
+#endif
+
+#include
+
+/* This header should define the following symbols under the described
+ situations. A value `1' means that the model is always supported,
+ `-1' means it is never supported. Undefined means it cannot be
+ statically decided.
+
+ _POSIX_V7_ILP32_OFF32 32bit int, long, pointers, and off_t type
+ _POSIX_V7_ILP32_OFFBIG 32bit int, long, and pointers and larger off_t type
+
+ The macros _POSIX_V6_ILP32_OFF32, _POSIX_V6_ILP32_OFFBIG,
+ _XBS5_ILP32_OFF32, _XBS5_ILP32_OFFBIG, were used in previous versions of the
+ Unix standard and are available only for compatibility.
+*/
+
+/* nds32 requires 64-bit off_t. */
+
+#define _POSIX_V7_ILP32_OFFBIG 1
+#define _POSIX_V6_ILP32_OFFBIG 1
+#define _XBS5_ILP32_OFFBIG 1
+
+/* We optionally provide an environment with the above size but an 64-bit
+ side `off_t'. Therefore we don't define _POSIX_V7_ILP32_OFFBIG. */
+
+/* We can never provide environments with 64-bit wide pointers. */
+#define _POSIX_V7_LP64_OFF64 -1
+#define _POSIX_V7_LPBIG_OFFBIG -1
+#define _POSIX_V6_LP64_OFF64 -1
+#define _POSIX_V6_LPBIG_OFFBIG -1
+#define _XBS5_LP64_OFF64 -1
+#define _XBS5_LPBIG_OFFBIG -1
+
+/* CFLAGS. */
+#define __ILP32_OFFBIG_CFLAGS "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
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..22a4746
--- /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/bits/stat.h b/sysdeps/unix/sysv/linux/nds32/bits/stat.h
new file mode 100644
index 0000000..68e70bd
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/nds32/bits/stat.h
@@ -0,0 +1,150 @@
+/* Copyright (C) 2011-2019 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf , 2011.
+
+ 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
+ . */
+
+#if !defined _SYS_STAT_H && !defined _FCNTL_H
+# error "Never include directly; use instead."
+#endif
+
+#ifndef _BITS_STAT_H
+#define _BITS_STAT_H 1
+
+#include
+#include
+
+#define _STAT_VER_KERNEL 0
+#define _STAT_VER_LINUX 0
+#define _STAT_VER _STAT_VER_KERNEL
+
+/* Versions of the `xmknod' interface. */
+#define _MKNOD_VER_LINUX 0
+
+struct stat
+ {
+ __dev_t st_dev; /* Device. */
+ __ino_t st_ino; /* File serial number. */
+ __mode_t st_mode; /* File mode. */
+ __nlink_t st_nlink; /* Link count. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ __dev_t st_rdev; /* Device number, if device. */
+ __dev_t __pad1;
+ __off_t st_size; /* Size of file, in bytes. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ int __pad2;
+ __blkcnt_t st_blocks; /* 512-byte blocks */
+#ifdef __USE_XOPEN2K8
+ /* Nanosecond resolution timestamps are stored in a format
+ equivalent to 'struct timespec'. This is the type used
+ whenever possible but the Unix namespace rules do not allow the
+ identifier 'timespec' to appear in the header.
+ Therefore we have to handle the use of this header in strictly
+ standard-compliant sources special. */
+ struct timespec st_atim; /* Time of last access. */
+ struct timespec st_mtim; /* Time of last modification. */
+ struct timespec st_ctim; /* Time of last status change. */
+# define st_atime st_atim.tv_sec /* Backward compatibility. */
+# define st_mtime st_mtim.tv_sec
+# define st_ctime st_ctim.tv_sec
+#else
+ __time_t st_atime; /* Time of last access. */
+ unsigned long int st_atimensec; /* Nscecs of last access. */
+ __time_t st_mtime; /* Time of last modification. */
+ unsigned long int st_mtimensec; /* Nsecs of last modification. */
+ __time_t st_ctime; /* Time of last status change. */
+ unsigned long int st_ctimensec; /* Nsecs of last status change. */
+#endif
+ int __glibc_reserved[2];
+ };
+
+#ifdef __USE_LARGEFILE64
+struct stat64
+ {
+ __dev_t st_dev; /* Device. */
+ __ino64_t st_ino; /* File serial number. */
+ __mode_t st_mode; /* File mode. */
+ __nlink_t st_nlink; /* Link count. */
+ __uid_t st_uid; /* User ID of the file's owner. */
+ __gid_t st_gid; /* Group ID of the file's group.*/
+ __dev_t st_rdev; /* Device number, if device. */
+ __dev_t __pad1;
+ __off64_t st_size; /* Size of file, in bytes. */
+ __blksize_t st_blksize; /* Optimal block size for I/O. */
+ int __pad2;
+ __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
+#ifdef __USE_XOPEN2K8
+ /* Nanosecond resolution timestamps are stored in a format
+ equivalent to 'struct timespec'. This is the type used
+ whenever possible but the Unix namespace rules do not allow the
+ identifier 'timespec' to appear in the header.
+ Therefore we have to handle the use of this header in strictly
+ standard-compliant sources special. */
+ struct timespec st_atim; /* Time of last access. */
+ struct timespec st_mtim; /* Time of last modification. */
+ struct timespec st_ctim; /* Time of last status change. */
+#else
+ __time_t st_atime; /* Time of last access. */
+ unsigned long int st_atimensec; /* Nscecs of last access. */
+ __time_t st_mtime; /* Time of last modification. */
+ unsigned long int st_mtimensec; /* Nsecs of last modification. */
+ __time_t st_ctime; /* Time of last status change. */
+ unsigned long int st_ctimensec; /* Nsecs of last status change. */
+#endif
+ int __glibc_reserved[2];
+ };
+#endif
+
+/* Tell code we have these members. */
+#define _STATBUF_ST_BLKSIZE
+#define _STATBUF_ST_RDEV
+/* Nanosecond resolution time values are supported. */
+#define _STATBUF_ST_NSEC
+
+/* Encoding of the file mode. */
+
+#define __S_IFMT 0170000 /* These bits determine file type. */
+
+/* File types. */
+#define __S_IFDIR 0040000 /* Directory. */
+#define __S_IFCHR 0020000 /* Character device. */
+#define __S_IFBLK 0060000 /* Block device. */
+#define __S_IFREG 0100000 /* Regular file. */
+#define __S_IFIFO 0010000 /* FIFO. */
+#define __S_IFLNK 0120000 /* Symbolic link. */
+#define __S_IFSOCK 0140000 /* Socket. */
+
+/* POSIX.1b objects. Note that these macros always evaluate to zero. But
+ they do it by enforcing the correct use of the macros. */
+#define __S_TYPEISMQ(buf) ((buf)->st_mode - (buf)->st_mode)
+#define __S_TYPEISSEM(buf) ((buf)->st_mode - (buf)->st_mode)
+#define __S_TYPEISSHM(buf) ((buf)->st_mode - (buf)->st_mode)
+
+/* Protection bits. */
+
+#define __S_ISUID 04000 /* Set user ID on execution. */
+#define __S_ISGID 02000 /* Set group ID on execution. */
+#define __S_ISVTX 01000 /* Save swapped text after use (sticky). */
+#define __S_IREAD 0400 /* Read by owner. */
+#define __S_IWRITE 0200 /* Write by owner. */
+#define __S_IEXEC 0100 /* Execute by owner. */
+
+#ifdef __USE_ATFILE
+# define UTIME_NOW ((1l << 30) - 1l)
+# define UTIME_OMIT ((1l << 30) - 2l)
+#endif
+
+#endif /* bits/stat.h */
diff --git a/sysdeps/unix/sysv/linux/nds32/bits/statfs.h b/sysdeps/unix/sysv/linux/nds32/bits/statfs.h
new file mode 100644
index 0000000..120f101
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/nds32/bits/statfs.h
@@ -0,0 +1,64 @@
+/* Copyright (C) 2011-2019 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf , 2011.
+
+ 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_STATFS_H
+# error "Never include directly; use instead."
+#endif
+
+#include
+#include
+#include
+
+struct statfs
+ {
+ __SWORD_TYPE f_type;
+ __SWORD_TYPE f_bsize;
+ __fsblkcnt_t f_blocks;
+ __fsblkcnt_t f_bfree;
+ __fsblkcnt_t f_bavail;
+ __fsfilcnt_t f_files;
+ __fsfilcnt_t f_ffree;
+ __fsid_t f_fsid;
+ __SWORD_TYPE f_namelen;
+ __SWORD_TYPE f_frsize;
+ __SWORD_TYPE f_flags;
+ __SWORD_TYPE f_spare[4];
+ };
+
+#ifdef __USE_LARGEFILE64
+struct statfs64
+ {
+ __SWORD_TYPE f_type;
+ __SWORD_TYPE f_bsize;
+ __fsblkcnt64_t f_blocks;
+ __fsblkcnt64_t f_bfree;
+ __fsblkcnt64_t f_bavail;
+ __fsfilcnt64_t f_files;
+ __fsfilcnt64_t f_ffree;
+ __fsid_t f_fsid;
+ __SWORD_TYPE f_namelen;
+ __SWORD_TYPE f_frsize;
+ __SWORD_TYPE f_flags;
+ __SWORD_TYPE f_spare[4];
+ };
+#endif
+
+/* Tell code we have these members. */
+#define _STATFS_F_NAMELEN
+#define _STATFS_F_FRSIZE
+#define _STATFS_F_FLAGS
diff --git a/sysdeps/unix/sysv/linux/nds32/bits/typesizes.h b/sysdeps/unix/sysv/linux/nds32/bits/typesizes.h
new file mode 100644
index 0000000..a0df40f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/nds32/bits/typesizes.h
@@ -0,0 +1,80 @@
+/* bits/typesizes.h -- underlying types for *_t. For the generic Linux ABI.
+ Copyright (C) 2011-2019 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf , 2011.
+
+ 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_TYPES_H
+# error "Never include directly; use instead."
+#endif
+
+#ifndef _BITS_TYPESIZES_H
+#define _BITS_TYPESIZES_H 1
+
+/* See for the meaning of these macros. This file exists so
+ that need not vary across different GNU platforms. */
+
+#define __DEV_T_TYPE __UQUAD_TYPE
+#define __UID_T_TYPE __U32_TYPE
+#define __GID_T_TYPE __U32_TYPE
+#define __INO_T_TYPE __UQUAD_TYPE
+#define __INO64_T_TYPE __UQUAD_TYPE
+#define __MODE_T_TYPE __U32_TYPE
+#define __NLINK_T_TYPE __U32_TYPE
+#define __OFF_T_TYPE __SQUAD_TYPE
+#define __OFF64_T_TYPE __SQUAD_TYPE
+#define __PID_T_TYPE __S32_TYPE
+#define __RLIM_T_TYPE __UQUAD_TYPE
+#define __RLIM64_T_TYPE __UQUAD_TYPE
+#define __BLKCNT_T_TYPE __SQUAD_TYPE
+#define __BLKCNT64_T_TYPE __SQUAD_TYPE
+#define __FSBLKCNT_T_TYPE __UQUAD_TYPE
+#define __FSBLKCNT64_T_TYPE __UQUAD_TYPE
+#define __FSFILCNT_T_TYPE __UQUAD_TYPE
+#define __FSFILCNT64_T_TYPE __UQUAD_TYPE
+#define __FSWORD_T_TYPE __SWORD_TYPE
+#define __ID_T_TYPE __U32_TYPE
+#define __CLOCK_T_TYPE __SLONGWORD_TYPE
+#define __TIME_T_TYPE __SLONGWORD_TYPE
+#define __USECONDS_T_TYPE __U32_TYPE
+#define __SUSECONDS_T_TYPE __SLONGWORD_TYPE
+#define __DADDR_T_TYPE __S32_TYPE
+#define __KEY_T_TYPE __S32_TYPE
+#define __CLOCKID_T_TYPE __S32_TYPE
+#define __TIMER_T_TYPE void *
+#define __BLKSIZE_T_TYPE __S32_TYPE
+#define __FSID_T_TYPE struct { int __val[2]; }
+#define __SSIZE_T_TYPE __SWORD_TYPE
+#define __SYSCALL_SLONG_TYPE __SLONGWORD_TYPE
+#define __SYSCALL_ULONG_TYPE __ULONGWORD_TYPE
+#define __CPU_MASK_TYPE __ULONGWORD_TYPE
+
+/* Tell the libc code that off_t and off64_t are actually the same type
+ for all ABI purposes, even if possibly expressed as different base types
+ for C type-checking purposes. */
+#define __OFF_T_MATCHES_OFF64_T 1
+
+/* Same for ino_t and ino64_t. */
+#define __INO_T_MATCHES_INO64_T 1
+
+/* And for __rlim_t and __rlim64_t. */
+#define __RLIM_T_MATCHES_RLIM64_T 1
+
+/* Number of descriptors that can fit in an `fd_set'. */
+#define __FD_SETSIZE 1024
+
+
+#endif /* bits/typesizes.h */
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..5b7f843
--- /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_KNOWN (linux4, LINUX_4);
+
+ 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/kernel_stat.h b/sysdeps/unix/sysv/linux/nds32/kernel_stat.h
new file mode 100644
index 0000000..e9052a3
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/nds32/kernel_stat.h
@@ -0,0 +1,23 @@
+/* Copyright (C) 2011-2019 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Chris Metcalf , 2011.
+
+ 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 STAT_IS_KERNEL_STAT 1
+#define XSTAT_IS_XSTAT64 1
+#define STATFS_IS_STATFS64 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..185c49f
--- /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..412706f
--- /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)