[02/11] nds32: ABI Implementation

Message ID 1525617685-32083-3-git-send-email-vincentc@andestech.com
State New, archived
Headers

Commit Message

Vincent Chen May 6, 2018, 2:41 p.m. UTC
  The implementation of these files in this patch is dependent
on nds32-ABI convention.
---
 sysdeps/nds32/__longjmp.S                      |  64 +++++++++++++
 sysdeps/nds32/backtrace.c                      |   1 +
 sysdeps/nds32/bits/endian.h                    |  27 ++++++
 sysdeps/nds32/bits/link.h                      |  54 +++++++++++
 sysdeps/nds32/bits/setjmp.h                    |  37 ++++++++
 sysdeps/nds32/bsd-_setjmp.S                    |   1 +
 sysdeps/nds32/bsd-setjmp.S                     |   1 +
 sysdeps/nds32/gccframe.h                       |  21 +++++
 sysdeps/nds32/jmpbuf-offsets.h                 |  34 +++++++
 sysdeps/nds32/jmpbuf-unwind.h                  |  47 ++++++++++
 sysdeps/nds32/linkmap.h                        |  26 ++++++
 sysdeps/nds32/machine-gmon.h                   |  32 +++++++
 sysdeps/nds32/memcpy.S                         | 123 +++++++++++++++++++++++++
 sysdeps/nds32/memset.S                         |  59 ++++++++++++
 sysdeps/nds32/memusage.h                       |  21 +++++
 sysdeps/nds32/nptl/pthreaddef.h                |  33 +++++++
 sysdeps/nds32/setjmp.S                         |  66 +++++++++++++
 sysdeps/nds32/sotruss-lib.c                    |  50 ++++++++++
 sysdeps/nds32/stackinfo.h                      |  32 +++++++
 sysdeps/nds32/strcmp.S                         | 105 +++++++++++++++++++++
 sysdeps/nds32/strcpy.S                         |  75 +++++++++++++++
 sysdeps/nds32/sysdep.h                         |  70 ++++++++++++++
 sysdeps/nds32/tst-audit.h                      |  23 +++++
 sysdeps/unix/sysv/linux/nds32/jmp_buf-macros.h |  26 ++++++
 sysdeps/unix/sysv/linux/nds32/localplt.data    |  19 ++++
 25 files changed, 1047 insertions(+)
 create mode 100644 sysdeps/nds32/__longjmp.S
 create mode 100644 sysdeps/nds32/backtrace.c
 create mode 100644 sysdeps/nds32/bits/endian.h
 create mode 100644 sysdeps/nds32/bits/link.h
 create mode 100644 sysdeps/nds32/bits/setjmp.h
 create mode 100644 sysdeps/nds32/bsd-_setjmp.S
 create mode 100644 sysdeps/nds32/bsd-setjmp.S
 create mode 100644 sysdeps/nds32/gccframe.h
 create mode 100644 sysdeps/nds32/jmpbuf-offsets.h
 create mode 100644 sysdeps/nds32/jmpbuf-unwind.h
 create mode 100644 sysdeps/nds32/linkmap.h
 create mode 100644 sysdeps/nds32/machine-gmon.h
 create mode 100644 sysdeps/nds32/memcpy.S
 create mode 100644 sysdeps/nds32/memset.S
 create mode 100644 sysdeps/nds32/memusage.h
 create mode 100644 sysdeps/nds32/nptl/pthreaddef.h
 create mode 100644 sysdeps/nds32/setjmp.S
 create mode 100644 sysdeps/nds32/sotruss-lib.c
 create mode 100644 sysdeps/nds32/stackinfo.h
 create mode 100644 sysdeps/nds32/strcmp.S
 create mode 100644 sysdeps/nds32/strcpy.S
 create mode 100644 sysdeps/nds32/sysdep.h
 create mode 100644 sysdeps/nds32/tst-audit.h
 create mode 100644 sysdeps/unix/sysv/linux/nds32/jmp_buf-macros.h
 create mode 100644 sysdeps/unix/sysv/linux/nds32/localplt.data
  

Comments

Florian Weimer May 12, 2018, 7:15 a.m. UTC | #1
On 05/06/2018 04:41 PM, vincentc wrote:
> +  $r26 - $r27 are temp registers for OS - no need to save.

Shouldn't you save them in case you decide to use them for a thread 
pointer eventually or something like that?

Thanks,
Florian
  
Vincent Chen May 14, 2018, 5:14 a.m. UTC | #2
On Sat, May 12, 2018 at 03:15:39PM +0800, Florian Weimer wrote:
> On 05/06/2018 04:41 PM, vincentc wrote:
> > +  $r26 - $r27 are temp registers for OS - no need to save.
> 
> Shouldn't you save them in case you decide to use them for a thread 
> pointer eventually or something like that?
> 
> Thanks,
> Florian


We do not save $r26, $r27 these two registers because these two register are
reserved for kernel space. In other words, these two registers shall not be used
in user space. Therefore, we needn't save these two registers to jmp_buf.

Thanks for your comment.

Best regards
Vincent Chen
  
Florian Weimer May 15, 2018, 11:32 a.m. UTC | #3
On 05/14/2018 07:14 AM, Vincent Chen wrote:
> On Sat, May 12, 2018 at 03:15:39PM +0800, Florian Weimer wrote:
>> On 05/06/2018 04:41 PM, vincentc wrote:
>>> +  $r26 - $r27 are temp registers for OS - no need to save.
>>
>> Shouldn't you save them in case you decide to use them for a thread
>> pointer eventually or something like that?
>>
>> Thanks,
>> Florian
> 
> 
> We do not save $r26, $r27 these two registers because these two register are
> reserved for kernel space. In other words, these two registers shall not be used
> in user space. Therefore, we needn't save these two registers to jmp_buf.

Okay, in this case, you could update the register list at the top of the 
file.  Perhaps also mention the register used for the thread pointer?

Thanks,
Florian
  
Vincent Chen May 15, 2018, 11:50 a.m. UTC | #4
On Tue, May 15, 2018 at 07:32:29PM +0800, Florian Weimer wrote:
> On 05/14/2018 07:14 AM, Vincent Chen wrote:
> > On Sat, May 12, 2018 at 03:15:39PM +0800, Florian Weimer wrote:
> >> On 05/06/2018 04:41 PM, vincentc wrote:
> >>> +  $r26 - $r27 are temp registers for OS - no need to save.
> >>
> >> Shouldn't you save them in case you decide to use them for a thread
> >> pointer eventually or something like that?
> >>
> >> Thanks,
> >> Florian
> > 
> > 
> > We do not save $r26, $r27 these two registers because these two register are
> > reserved for kernel space. In other words, these two registers shall not be used
> > in user space. Therefore, we needn't save these two registers to jmp_buf.
> 
> Okay, in this case, you could update the register list at the top of the 
> file.  Perhaps also mention the register used for the thread pointer?
> 
> Thanks,
> Florian
>

In nds32 port, the $r25 register is used for thread pointer. Thanks for your
suggestions. We will update the register list in next version patch.


Best regards
Vincent Chen
  

Patch

diff --git a/sysdeps/nds32/__longjmp.S b/sysdeps/nds32/__longjmp.S
new file mode 100644
index 0000000..608216c
--- /dev/null
+++ b/sysdeps/nds32/__longjmp.S
@@ -0,0 +1,64 @@ 
+/* longjmp, 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
+   <http://www.gnu.org/licenses/>.  */
+
+/*
+  $r0 - $r5 are for paramter passing - no need to save.
+  $r6 - $r14 are callee saved - needs to save.
+  $r15 is temp register for assembler - no need to save.
+  $r16 - $r25 are caller saved - no need to save.
+  $r26 - $r27 are temp registers for OS - no need to save.
+  $r28 is $fp - need to save.
+  $r29 is $gp - need to save.
+  $r30 is $ra - need to save.
+  $r31 is $sp - need to save.
+  So we need to save $r6 - $r14 and $r28 - $r31.
+  The jmpbuf looks like this:
+  $r6
+  $r7
+  $r8
+  $r9
+  $r10
+  $r11
+  $r12
+  $r13
+  $r14
+  $fp
+  $gp
+  $ra
+  $sp
+  Reserved(For 8-byte align if needed)
+*/
+
+#include <sysdep.h>
+#define _SETJMP_H
+#define _ASM
+#include <bits/setjmp.h>
+	.section .text
+
+/* __longjmp (env[0].__jmpbuf, val ?: 1);  */
+ENTRY(__longjmp)
+	/* Restore registers.  */
+	lmw.bim  $r6, [$r0], $r14, #0xf
+
+	/* Return error code. Make sure error code is not 0.  */
+	bnez  $r1, .Ldone
+	movi  $r1, #1
+.Ldone:
+	addi  $r0, $r1, #0
+	ret
+END(__longjmp)
diff --git a/sysdeps/nds32/backtrace.c b/sysdeps/nds32/backtrace.c
new file mode 100644
index 0000000..27ce597
--- /dev/null
+++ b/sysdeps/nds32/backtrace.c
@@ -0,0 +1 @@ 
+#include <sysdeps/x86_64/backtrace.c>
diff --git a/sysdeps/nds32/bits/endian.h b/sysdeps/nds32/bits/endian.h
new file mode 100644
index 0000000..262ffea
--- /dev/null
+++ b/sysdeps/nds32/bits/endian.h
@@ -0,0 +1,27 @@ 
+/* Define __BYTE_ORDER. 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
+   <http://www.gnu.org/licenses/>.  */
+#ifndef _ENDIAN_H
+# error "Never use <bits/endian.h> directly; include <endian.h> instead."
+#endif
+
+#if defined __NDS32_EB__
+# define __BYTE_ORDER __BIG_ENDIAN
+#else
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
diff --git a/sysdeps/nds32/bits/link.h b/sysdeps/nds32/bits/link.h
new file mode 100644
index 0000000..7b3f078
--- /dev/null
+++ b/sysdeps/nds32/bits/link.h
@@ -0,0 +1,54 @@ 
+/* Machine-specific declarations for dynamic linker interface.  Andes 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
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef	_LINK_H
+# error "Never include <bits/link.h> directly; use <link.h> instead."
+#endif
+
+/* Registers for entry into PLT on NDS32.  */
+typedef struct La_nds32_regs
+{
+  uint32_t lr_reg[6];
+  uint32_t lr_gp;
+  uint32_t lr_lp;
+  uint32_t lr_sp;
+} La_nds32_regs;
+
+/* Return values for calls from PLT on NDS32.  */
+typedef struct La_nds32_retval
+{
+  uint32_t lrv_reg[2];
+} La_nds32_retval;
+
+__BEGIN_DECLS
+
+extern ElfW(Addr) la_nds32_gnu_pltenter (ElfW(Sym) *__sym, unsigned int __ndx,
+					 uintptr_t *__refcook,
+					 uintptr_t *__defcook,
+					 La_nds32_regs *__regs,
+					 unsigned int *__flags,
+					 const char *__symname,
+					 long int *__framesizep);
+extern unsigned int la_nds32_gnu_pltexit (ElfW(Sym) *__sym, unsigned int __ndx,
+					  uintptr_t *__refcook,
+					  uintptr_t *__defcook,
+					  const La_nds32_regs *__inregs,
+					  La_nds32_retval *__outregs,
+					  const char *__symname);
+
+__END_DECLS
diff --git a/sysdeps/nds32/bits/setjmp.h b/sysdeps/nds32/bits/setjmp.h
new file mode 100644
index 0000000..5ac5217
--- /dev/null
+++ b/sysdeps/nds32/bits/setjmp.h
@@ -0,0 +1,37 @@ 
+/* Define the machine-dependent type `jmp_buf'.  Andes nds32 version.
+   Copyright (C) 2003-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 Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#ifndef _BITS_SETJMP_H
+#define _BITS_SETJMP_H  1
+
+#if !defined _SETJMP_H && !defined _PTHREAD_H
+# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
+#endif
+
+#ifndef _ASM
+
+typedef struct __jmp_buf_internal_tag
+  {
+    /* Callee-saved registers: $r6 - $r14, $fp, $gp, $lp, $sp: $r28 - $r31.  */
+    int __regs[13];
+  } __jmp_buf[1] __attribute__((__aligned__ (8)));
+
+#endif
+
+#endif  /* bits/setjmp.h */
diff --git a/sysdeps/nds32/bsd-_setjmp.S b/sysdeps/nds32/bsd-_setjmp.S
new file mode 100644
index 0000000..90b99cd
--- /dev/null
+++ b/sysdeps/nds32/bsd-_setjmp.S
@@ -0,0 +1 @@ 
+/* _setjmp is in setjmp.S.  */
diff --git a/sysdeps/nds32/bsd-setjmp.S b/sysdeps/nds32/bsd-setjmp.S
new file mode 100644
index 0000000..d3b823c
--- /dev/null
+++ b/sysdeps/nds32/bsd-setjmp.S
@@ -0,0 +1 @@ 
+/* setjmp is in setjmp.S.  */
diff --git a/sysdeps/nds32/gccframe.h b/sysdeps/nds32/gccframe.h
new file mode 100644
index 0000000..2ef5bc2
--- /dev/null
+++ b/sysdeps/nds32/gccframe.h
@@ -0,0 +1,21 @@ 
+/* Definition of object in frame unwind info.  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
+   <http://www.gnu.org/licenses/>.  */
+
+#define FIRST_PSEUDO_REGISTER 34
+
+#include <sysdeps/generic/gccframe.h>
diff --git a/sysdeps/nds32/jmpbuf-offsets.h b/sysdeps/nds32/jmpbuf-offsets.h
new file mode 100644
index 0000000..7026c90
--- /dev/null
+++ b/sysdeps/nds32/jmpbuf-offsets.h
@@ -0,0 +1,34 @@ 
+/* Private macros for accessing __jmp_buf contents. 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
+   <http://www.gnu.org/licenses/>.  */
+
+#define JB_R6   0
+#define JB_R7   1
+#define JB_R8   2
+#define JB_R9   3
+#define JB_R10  4
+#define JB_R11  5
+#define JB_R12  6
+#define JB_R13  7
+#define JB_R14  8
+#define JB_FP   9
+#define JB_GP   10
+#define JB_LP   11
+#define JB_SP   12
+
+#define JB_FRAME_ADDRESS(buf) \
+	 ((void *)buf[0].__regs[JB_SP])
diff --git a/sysdeps/nds32/jmpbuf-unwind.h b/sysdeps/nds32/jmpbuf-unwind.h
new file mode 100644
index 0000000..373f114
--- /dev/null
+++ b/sysdeps/nds32/jmpbuf-unwind.h
@@ -0,0 +1,47 @@ 
+/* Examine __jmp_buf for unwinding frames.  Andes nds32 version.
+   Copyright (C) 2003-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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <setjmp.h>
+#include <jmpbuf-offsets.h>
+#include <stdint.h>
+#include <unwind.h>
+#include <sysdep.h>
+
+/* Test if longjmp to JMPBUF would unwind the frame
+   containing a local variable at ADDRESS.  */
+#define _JMPBUF_UNWINDS(jmpbuf, address, demangle) \
+  ((void *) (address) < &(jmpbuf)[0].__regs[JB_SP])
+
+#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj) \
+  _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj)
+
+static inline uintptr_t __attribute__ ((unused))
+_jmpbuf_sp (__jmp_buf regs)
+{
+  uintptr_t sp = (uintptr_t) &(regs)[0].__regs[JB_SP];
+#ifdef PTR_DEMANGLE
+  PTR_DEMANGLE (sp);
+#endif
+  return sp;
+}
+
+#define _JMPBUF_UNWINDS_ADJ(_jmpbuf, _address, _adj) \
+  ((uintptr_t) (_address) - (_adj) < _jmpbuf_sp (_jmpbuf) - (_adj))
+
+/* We use the normal longjmp for unwinding.  */
+#define __libc_unwind_longjmp(buf, val) __libc_longjmp (buf, val)
diff --git a/sysdeps/nds32/linkmap.h b/sysdeps/nds32/linkmap.h
new file mode 100644
index 0000000..89e912a
--- /dev/null
+++ b/sysdeps/nds32/linkmap.h
@@ -0,0 +1,26 @@ 
+/* Define nds32 link_map_machine
+   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
+   <http://www.gnu.org/licenses/>.  */
+
+struct link_map_machine
+  {
+    ElfW(Addr) plt; /* Address of .plt.  */
+    ElfW(Addr) gotplt; /* Address of .got.  */
+    void *tlsdesc_table;
+  };
+
diff --git a/sysdeps/nds32/machine-gmon.h b/sysdeps/nds32/machine-gmon.h
new file mode 100644
index 0000000..64679d9
--- /dev/null
+++ b/sysdeps/nds32/machine-gmon.h
@@ -0,0 +1,32 @@ 
+/* profiling support for 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+static void __mcount_internal (u_long frompc, u_long selfpc) __attribute_used__;
+
+#define _MCOUNT_DECL(frompc, selfpc) \
+static void __mcount_internal (u_long frompc, u_long selfpc)
+
+
+#define MCOUNT							\
+void _mcount (u_long frompc)		      			\
+{								\
+  __mcount_internal (frompc, (u_long) RETURN_ADDRESS (0));	\
+}
+
diff --git a/sysdeps/nds32/memcpy.S b/sysdeps/nds32/memcpy.S
new file mode 100644
index 0000000..80d38ef
--- /dev/null
+++ b/sysdeps/nds32/memcpy.S
@@ -0,0 +1,123 @@ 
+/* Memory copy, Andes nds32 version
+   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
+   <http://www.gnu.org/licenses/>.  */
+
+/* void *memcpy(void *dst, const void *src, int n);
+
+   dst: $r0
+   src: $r1
+   n  : $r2
+   ret: $r0 - pointer to the memory area dst.  */
+
+
+#include <sysdep.h>
+	.text
+
+ENTRY(memcpy)
+	beq	$r0, $r1, .Lquit_memcpy2
+	beqz	$r2, .Lquit_memcpy2
+	move	$r5, $r0
+	srli    $r3, $r2, #5	/* Check if len < cache-line size 32.  */
+	beqz	$r3, .Lword_copy_entry
+	andi	$r4, $r0, #0x3	/* Check byte-align.  */
+	beqz	$r4, .Lunalign_word_copy_entry
+
+	addi	$r4, $r4,#-4
+	abs	$r4, $r4	/* Check how many un-align byte to copy.  */
+	sub	$r2, $r2, $r4	/* Update $r2.  */
+
+.Lunalign_byte_copy:
+	lbi.bi	$r3, [$r1], #1
+	addi	$r4, $r4, #-1
+	sbi.bi	$r3, [$r0], #1
+	bnez	$r4, .Lunalign_byte_copy
+	beqz	$r2, .Lquit_memcpy
+
+.Lunalign_word_copy_entry:
+	andi	$r3, $r0, 0x1f	/* Check cache-line unaligncount.  */
+	beqz	$r3, .Lcache_copy
+
+	addi	$r3, $r3, #-32
+	abs	$r3, $r3
+	sub	$r2, $r2, $r3	/* Update $r2.  */
+
+.Lunalign_word_copy:
+	lmw.bim	$r4, [$r1], $r4
+	addi	$r3, $r3, #-4
+	smw.bim	$r4, [$r0], $r4
+	bnez	$r3, .Lunalign_word_copy
+	beqz	$r2, .Lquit_memcpy
+	
+	addi	$r3, $r2, #-32	/* To check $r2 < cache_line, than go to .Lword_copy.  */
+	bltz	$r3, .Lword_copy_entry
+.Lcache_copy:
+	srli	$r3, $r2, #5
+	beqz	$r3, .Lword_copy_entry
+	pushm	$r6, $r13
+	.cfi_adjust_cfa_offset 32
+	.cfi_rel_offset r6, 0
+	.cfi_rel_offset r7, 4
+	.cfi_rel_offset r8, 8
+	.cfi_rel_offset r9, 12
+	.cfi_rel_offset r10, 16
+	.cfi_rel_offset r11, 20
+	.cfi_rel_offset r12, 24
+	.cfi_rel_offset r13, 28
+3:
+	lmw.bim	$r6, [$r1], $r13
+	addi	$r3, $r3, #-1
+	smw.bim	$r6, [$r0], $r13
+	bnez	$r3, 3b
+	popm	$r6, $r13
+	.cfi_adjust_cfa_offset -32
+	.cfi_restore r6
+	.cfi_restore r7
+	.cfi_restore r8
+	.cfi_restore r9
+	.cfi_restore r10
+	.cfi_restore r11
+	.cfi_restore r12
+	.cfi_restore r13
+
+.Lword_copy_entry:
+	andi	$r2, $r2, #31
+
+	beqz	$r2, .Lquit_memcpy 
+	srli	$r3, $r2, #2
+	beqz	$r3, .Lbyte_copy
+.Lword_copy:
+	lmw.bim	$r4, [$r1], $r4
+	addi	$r3, $r3, #-1
+	smw.bim	$r4, [$r0], $r4
+	bnez	$r3, .Lword_copy
+	andi	$r2, $r2, #3
+	beqz	$r2, .Lquit_memcpy
+.Lbyte_copy:
+	lbi.bi	$r3, [$r1], #1
+	addi	$r2, $r2, #-1
+
+	sbi.bi	$r3, [$r0], #1
+	bnez	$r2, .Lbyte_copy
+.Lquit_memcpy:
+	move	$r0, $r5
+.Lquit_memcpy2:
+	ret
+
+END(memcpy)
+libc_hidden_builtin_def (memcpy)
+
diff --git a/sysdeps/nds32/memset.S b/sysdeps/nds32/memset.S
new file mode 100644
index 0000000..74e7852
--- /dev/null
+++ b/sysdeps/nds32/memset.S
@@ -0,0 +1,59 @@ 
+/* Optimized version 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* void *memset(void *dst, int val, int len);
+ 
+         dst: $r0
+         val: $r1
+         len: $r2
+         ret: $r0 - pointer to the memory area dst.  */
+
+ENTRY(memset)
+	move	$r5, $r0		/* Return value.  */
+	beqz    $r2, .Lend_memset	/* Exit when len = 0.  */
+	srli	$r3, $r2, 2		/* $r3 is how many words to copy.  */
+	andi	$r2, $r2, 3		/* How many bytes are less than a word.  */
+	beqz	$r3, .Lbyte_set		/* When n is less than a word.  */
+
+	/* set $r1 from ??????ab to abababab.  */
+	andi    $r1, $r1, 0x00ff	/* $r1 = 000000ab.  */
+	slli    $r4, $r1, 8		/* $r4 = 0000ab00.  */
+	or      $r1, $r1, $r4		/* $r1 = 0000abab.  */
+	slli    $r4, $r1, 16		/* $r4 = abab0000.  */
+	or      $r1, $r1, $r4		/* $r1 = abababab.  */
+
+.Lword_set:
+	addi	$r3, $r3, -1		/* How many words left to copy.  */
+	smw.bim $r1, [$r5], $r1		/* Copy the word to det.  */
+	bnez    $r3, .Lword_set		/* Still words to set, continue looping.  */
+	beqz	$r2, .Lend_memset	/* No left byte to set.  */
+
+.Lbyte_set:				/* Less than 4 bytes left to set.  */
+	addi	$r2, $r2, -1		/* Decrease len by 1.  */
+	sbi.p	$r1, [$r5], 1		/* Set data of the next byte to $r1.  */
+	bnez	$r2, .Lbyte_set		/* Still bytes left to set.  */
+
+.Lend_memset:
+	ret
+
+END(memset)
+libc_hidden_builtin_def (memset)
+
diff --git a/sysdeps/nds32/memusage.h b/sysdeps/nds32/memusage.h
new file mode 100644
index 0000000..e227c90
--- /dev/null
+++ b/sysdeps/nds32/memusage.h
@@ -0,0 +1,21 @@ 
+/* Machine-specific definitions for memory usage profiling, 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
+   <http://www.gnu.org/licenses/>.  */
+
+#define GETSP() ({ register uintptr_t stack_ptr asm ("$sp"); stack_ptr; })
+
+#include <sysdeps/generic/memusage.h>
diff --git a/sysdeps/nds32/nptl/pthreaddef.h b/sysdeps/nds32/nptl/pthreaddef.h
new file mode 100644
index 0000000..6ba4596
--- /dev/null
+++ b/sysdeps/nds32/nptl/pthreaddef.h
@@ -0,0 +1,33 @@ 
+/* pthread machine parameter definitions,  Andes nds32 version.
+   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
+   <http://www.gnu.org/licenses/>.  */
+
+/* Default stack size.  */
+#define ARCH_STACK_DEFAULT_SIZE	(2 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning.  */
+#define STACK_ALIGN		16
+
+/* Minimal stack size after allocating thread descriptor and guard size.  */
+#define MINIMAL_REST_STACK	2048
+
+/* Alignment requirement for TCB.  */
+#define TCB_ALIGNMENT		16
+
+
+/* Location of current stack frame.  */
+#define CURRENT_STACK_FRAME	__builtin_frame_address (0)
diff --git a/sysdeps/nds32/setjmp.S b/sysdeps/nds32/setjmp.S
new file mode 100644
index 0000000..dc9c658
--- /dev/null
+++ b/sysdeps/nds32/setjmp.S
@@ -0,0 +1,66 @@ 
+/* setjmp for Andes nds32.
+   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
+   <http://www.gnu.org/licenses/>.  */
+
+
+#include <sysdep.h>
+#define _SETJMP_H
+#define _ASM
+#include <bits/setjmp.h>
+	.section .text
+#ifdef PIC
+# define JMP_BY_R2(symbol)						\
+	sethi   $r3, hi20(symbol@PLT);					\
+	ori     $r3, $r3, lo12(symbol@PLT);				\
+	add     $r3, $r3, $r2;						\
+	jr      $r3
+# define TCALL_SIGJMP_SAVE						\
+	GET_GTABLE ($r2);						\
+	JMP_BY_R2 (__sigjmp_save)
+#else
+# define JMP_BY_R2(symbol)						\
+	la	$r15, C_SYMBOL_NAME(symbol);				\
+	jr	$r15
+# define TCALL_SIGJMP_SAVE						\
+	JMP_BY_R2 (__sigjmp_save)
+#endif
+
+ENTRY(_setjmp)
+	move	$r1, #0
+	/* Initialize $r2 as $gp value.  */
+	GET_GTABLE ($r2)
+        /* Make a tail call to __sigsetjmp.  */
+	JMP_BY_R2 (HIDDEN_JUMPTARGET (__sigsetjmp))
+END(_setjmp)
+ENTRY(setjmp)
+	move	$r1, #1
+	/* Initialize $r2 as $gp value.  */
+	GET_GTABLE ($r2)
+        /* Make a tail call to __sigsetjmp.  */
+	JMP_BY_R2 (HIDDEN_JUMPTARGET (__sigsetjmp))
+END(setjmp)
+
+ENTRY(__sigsetjmp)
+	move	$r2, $r0
+	/* Save callee-saved registers into buffer.  */
+	smw.bim	$r6, [$r2], $r14, #0xf
+        /* Make a tail call to __sigjmp_save.  */
+	TCALL_SIGJMP_SAVE
+
+END(__sigsetjmp)
+hidden_def(__sigsetjmp)
+weak_alias (_setjmp, __GI__setjmp)
diff --git a/sysdeps/nds32/sotruss-lib.c b/sysdeps/nds32/sotruss-lib.c
new file mode 100644
index 0000000..d77b7fa
--- /dev/null
+++ b/sysdeps/nds32/sotruss-lib.c
@@ -0,0 +1,50 @@ 
+/* Override generic sotruss-lib.c to define actual functions for Andes nds32.
+   Copyright (C) 2013-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
+   <http://www.gnu.org/licenses/>.  */
+
+#define HAVE_ARCH_PLTENTER
+#define HAVE_ARCH_PLTEXIT
+
+#include <elf/sotruss-lib.c>
+
+
+ElfW(Addr)
+la_nds32_gnu_pltenter (ElfW(Sym) *sym __attribute__ ((unused)),
+		       unsigned int ndx __attribute__ ((unused)),
+		       uintptr_t *refcook, uintptr_t *defcook,
+		       La_nds32_regs *regs, unsigned int *flags,
+		       const char *symname, long int *framesizep)
+{
+  print_enter (refcook, defcook, symname,
+	       regs->lr_reg[0], regs->lr_reg[1], regs->lr_reg[2],
+	       *flags);
+
+  /* No need to copy anything, we will not need the parameters in any case.  */
+  *framesizep = 0;
+
+  return sym->st_value;
+}
+
+unsigned int
+la_nds32_gnu_pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook,
+		      uintptr_t *defcook, const struct La_nds32_regs *inregs,
+		      struct La_nds32_retval *outregs, const char *symname)
+{
+  print_exit (refcook, defcook, symname, outregs->lrv_reg[0]);
+
+  return 0;
+}
diff --git a/sysdeps/nds32/stackinfo.h b/sysdeps/nds32/stackinfo.h
new file mode 100644
index 0000000..51790e7
--- /dev/null
+++ b/sysdeps/nds32/stackinfo.h
@@ -0,0 +1,32 @@ 
+/* Stack environment definitions for Andes 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
+   <http://www.gnu.org/licenses/>.  */
+
+/* This file contains a bit of information about the stack allocation
+   of the processor.  */
+
+#ifndef _STACKINFO_H
+#define _STACKINFO_H 1
+
+#include <elf.h>
+
+#define _STACK_GROWS_DOWN 1
+
+/* Default to a non-executable stack.  */
+#define DEFAULT_STACK_PERMS (PF_R|PF_W)
+
+#endif /* stackinfo.h  */
diff --git a/sysdeps/nds32/strcmp.S b/sysdeps/nds32/strcmp.S
new file mode 100644
index 0000000..4462354
--- /dev/null
+++ b/sysdeps/nds32/strcmp.S
@@ -0,0 +1,105 @@ 
+/* Optimized version for Andes nds32.
+   Copyright (C) 2015-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
+   <http://www.gnu.org/licenses/>.  */
+
+/*
+    Function:
+       strcmp - compare two strings.
+    Syntax:
+       int strcmp(const char *s1, const char *s2);
+    Description:
+       The strcmp function compares the string pointed to by s1 to the string
+       pointed to by s2.
+    Return value:
+       Return n integer greater than, equal to, or less than zero, accordingly
+       as the string pointed to by s1 is greater than, equal to, or less than
+       the string pointed to by s2.
+*/
+#include <sysdep.h>
+        .text
+
+ENTRY(strcmp)
+#if defined (__NDS32_EXT_STRING__)
+1:
+	lmwzb.bm	$r2, [$r0], $r2, #0
+	lmwzb.bm	$r3, [$r1], $r3, #0
+	ffzmism	$r4, $r2, $r3
+	beqz	$r4, 1b
+	lb	$r2, [$r0+$r4]
+	lb	$r3, [$r1+$r4]
+	sub	$r0, $r2, $r3
+	ret $lp
+#else /* not (__NDS32_EXT_STRING__) */
+	/* If s1 or s2 are unaligned, then compare bytes.  */
+	or	$r5, $r1, $r0
+	andi    $r5, $r5, #3
+	bnez    $r5, .Lbyte_mode
+
+	/* If s1 and s2 are word-aligned, compare them a word at a time.  */
+	lwi	$r5, [$r0+(0)]
+	lwi	$r3, [$r1+(0)]
+.off_16bit	/* Dedicate 4-byte to eliminate NOP caused by ".align 2".  */
+	bne	$r5, $r3, .Lbyte_mode	/* A difference was detected, so
+					   search bytewise. */
+.restore_16bit
+
+
+	/* It's more efficient to set bit mask outside the word_mode loop.  */
+	sethi	$r4, hi20(0xFEFEFEFF)	/* Set $r4 as -0x01010101.  */
+	ori	$r4, $r4, lo12(0xFEFEFEFF)
+	sethi	$r2, hi20(0x80808080)	/* Set $r2 as 0x80808080.  */
+	ori	$r2, $r2, lo12(0x80808080)
+
+.align	2
+.Lword_mode_loop:
+	/* #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
+	   DETECTNULL returns nonzero if (long)X contains a NULL byte.  */
+
+/* Force 32-bit instruction to gain better performance.  */
+.off_16bit
+	nor	$r3, $r5, $r5		/* $r3 = ~(X).  */
+	add	$r5, $r5, $r4		/* $r5 = ((X) - 0x01010101).  */
+	and	$r5, $r5, $r3		/* $r5 = ~(X) & ((X) - 0x01010101).  */
+	and	$r5, $r5, $r2		/* $r5= r5 & 0x80808080.  */
+.restore_16bit
+
+	bnez	$r5, .Lfound_null	/* Branch if $r5 is nonzero.  */
+	lmw.aim	$r5, [$r0], $r5, 0
+	lmw.aim	$r3, [$r1], $r3, 0
+	beq	$r5, $r3, .Lword_mode_loop
+
+.align	2
+.Lbyte_mode:
+	/* Byte-mode compare.  */
+	lbi.bi	$r5, [$r0], #1
+	lbi.bi	$r3, [$r1], #1
+	bne	$r5, $r3, 1f	/* Mismatch, done.  */
+	bnez	$r5, .Lbyte_mode
+1:
+	sub $r0, $r5, $r3
+	ret $lp
+
+.align	2
+.Lfound_null:
+	/* To get here, *a1 == *a2, thus if we find a null in *a1,
+	   then the strings must be equal, so return zero.  */
+	movi	$r0, #0
+	ret $lp
+
+#endif /* not (__NDS32_EXT_STRING__) */
+END(strcmp)
+libc_hidden_builtin_def (strcmp)
diff --git a/sysdeps/nds32/strcpy.S b/sysdeps/nds32/strcpy.S
new file mode 100644
index 0000000..31fc282
--- /dev/null
+++ b/sysdeps/nds32/strcpy.S
@@ -0,0 +1,75 @@ 
+/* Optimized version for Andes nds32.
+   Copyright (C) 2013-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
+   <http://www.gnu.org/licenses/>.  */
+
+/*  Function:
+       strcpy - copy a string.
+    Syntax:
+       char *strcpy(char *dest, const char *src);
+    Description:
+       This function copies the string pointed to by src into the array
+       point to by dest (include the teminating null character).
+    Return value:
+       strcpy returns the dest as given.  */
+#include <sysdep.h>
+        .text
+
+ENTRY(strcpy)
+	move	$r3, $r0	/* Keep $r0 as reture value.  */
+#if defined (__NDS32_EXT_STRING__)
+1:
+	lmwzb.bm	$r4, [$r1], $r4, #0
+	smwzb.bm	$r4, [$r3], $r4, #0
+	ffzmism	$r2, $r4, $r4
+	beqz	$r2, 1b		/* $r2 = 0, no zero byte exist.  */
+	ret $lp
+
+#else /* not (__NDS32_EXT_STRING__) */
+	GET_GTABLE ($gp)
+	/* If SRC or DEST is unaligned, then copy bytes.  */
+	or	$r2, $r1, $r0
+	andi	$r2, $r2, #3
+	bnez	$r2, .Lbyte_mode
+
+.Lword_mode:
+	/* SRC and DEST are both "long int" aligned, try to do "long int"
+	   sized copies.  */
+	/* #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
+	   DETECTNULL returns nonzero if (long)X contains a NULL byte.  */
+	lwi	$r2, [$r1+(0)]		/* $r2 is X.  */
+	sethi	$r4, hi20(0xFEFEFEFF)
+	ori	$r4, $r4, lo12(0xFEFEFEFF)
+	add	$r4, $r2, $r4		/* $r4 = ((X) - 0x01010101).  */
+	nor	$r5, $r2, $r2		/* $r5 = ~(X).  */
+	and	$r4, $r5, $r4		/* $r4 = ~(X) & ((X) - 0x01010101).  */
+	sethi	$r5, hi20(0x80808080)
+	ori	$r5, $r5, lo12(0x80808080)
+	and	$r4, $r4, $r5		/* $r4 = $r4 & 0x80808080.  */
+	bnez	$r4, .Lbyte_mode	/* Contains a NULL byte.  */
+	swi.bi	$r2, [$r3], #4
+	addi	$r1, $r1, #4
+	b	.Lword_mode
+
+.Lbyte_mode:
+	lbi.bi	$r4, [$r1], #1		/* $r4  <- *src++.  */
+	sbi.bi	$r4, [$r3], #1		/* $r4  -> *dest++.  */
+	bnez	$r4, .Lbyte_mode
+	ret $lp
+#endif /* not (__NDS32_EXT_STRING__) */
+END(strcpy)
+libc_hidden_builtin_def (strcpy)
diff --git a/sysdeps/nds32/sysdep.h b/sysdeps/nds32/sysdep.h
new file mode 100644
index 0000000..e82121c
--- /dev/null
+++ b/sysdeps/nds32/sysdep.h
@@ -0,0 +1,70 @@ 
+/* Assembler macros for Andes nds32.
+   Copyright (C) 2015-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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdeps/generic/sysdep.h>
+
+#ifdef	__ASSEMBLER__
+
+/* Define an entry point visible from C.  */
+# ifdef PIC
+#  define ENTRY(name)                     \
+   .pic					  \
+   .align 2;                              \
+   .globl C_SYMBOL_NAME(name);            \
+   .func  C_SYMBOL_NAME(name);            \
+   .type  C_SYMBOL_NAME(name), @function; \
+   C_SYMBOL_NAME(name):			  \
+   cfi_startproc;
+# else
+#  define ENTRY(name)                     \
+   .align 2;                              \
+   .globl C_SYMBOL_NAME(name);            \
+   .func  C_SYMBOL_NAME(name);            \
+   .type  C_SYMBOL_NAME(name), @function; \
+   C_SYMBOL_NAME(name):			  \
+   cfi_startproc;
+# endif
+
+
+# undef END
+# define END(name)    \
+  cfi_endproc;	      \
+  .endfunc;           \
+  .size C_SYMBOL_NAME(name), .-C_SYMBOL_NAME(name)
+
+/* If compiled for profiling, call `mcount' at the start of each function.  */
+# ifdef HAVE_ELF
+#  undef NO_UNDERSCORES
+#  define NO_UNDERSCORES
+# endif
+
+# ifdef NO_UNDERSCORES
+#  define syscall_error __syscall_error
+# endif
+
+
+# define GET_GTABLE(reg)					\
+	sethi	reg,	hi20(_GLOBAL_OFFSET_TABLE_ - 8);	\
+	ori	reg,	reg,	lo12(_GLOBAL_OFFSET_TABLE_ - 4);\
+	add5.pc reg;
+
+
+
+#endif	/* __ASSEMBLER__ */
+  
+
diff --git a/sysdeps/nds32/tst-audit.h b/sysdeps/nds32/tst-audit.h
new file mode 100644
index 0000000..4294bc0
--- /dev/null
+++ b/sysdeps/nds32/tst-audit.h
@@ -0,0 +1,23 @@ 
+/* Definitions for testing PLT entry/exit auditing.  Andes nds32 version.
+   Copyright (C) 2013-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
+   <http://www.gnu.org/licenses/>.  */
+
+#define pltenter la_nds32_gnu_pltenter
+#define pltexit la_nds32_gnu_pltexit
+#define La_regs La_nds32_regs
+#define La_retval La_nds32_retval
+#define int_retval lrv_reg[0]
diff --git a/sysdeps/unix/sysv/linux/nds32/jmp_buf-macros.h b/sysdeps/unix/sysv/linux/nds32/jmp_buf-macros.h
new file mode 100644
index 0000000..7d7a141
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/nds32/jmp_buf-macros.h
@@ -0,0 +1,26 @@ 
+/* jump buffer constants, Andes nds32.
+   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
+   <http://www.gnu.org/licenses/>.  */
+
+#define JMP_BUF_SIZE 184
+#define SIGJMP_BUF_SIZE 184
+#define JMP_BUF_ALIGN 8
+#define SIGJMP_BUF_ALIGN 8
+#define MASK_WAS_SAVED_OFFSET 52
+#define SAVED_MASK_OFFSET 56
+
diff --git a/sysdeps/unix/sysv/linux/nds32/localplt.data b/sysdeps/unix/sysv/linux/nds32/localplt.data
new file mode 100644
index 0000000..14c02cb
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/nds32/localplt.data
@@ -0,0 +1,19 @@ 
+# See scripts/check-localplt.awk for how this file is processed.
+# PLT use is required for the malloc family and for matherr because
+# users can define their own functions and have library internals call them.
+libc.so: calloc
+libc.so: free
+libc.so: malloc
+libc.so: memalign
+libc.so: realloc
+# The main malloc is interposed into the dynamic linker, for
+# allocations after the initial link (when dlopen is used).
+ld.so: malloc
+ld.so: calloc
+ld.so: realloc
+ld.so: free
+# The TLS-enabled version of these functions is interposed from libc.so.
+ld.so: _dl_signal_error
+ld.so: _dl_catch_error
+ld.so: _dl_signal_exception
+ld.so: _dl_catch_exception