This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v4 02/11] nds32: ABI Implementation


The implementation of these files in this patch is dependent
on nds32-ABI convention.

2019-06-03  Vincent Chen  <vincentc@andestech.com>
2019-06-03  CheWei Chuang  <cnoize@andestech.com>

	* sysdeps/nds32/__longjmp.S: New file.
	* sysdeps/nds32/bits/endian.h: Likewise.
	* sysdeps/nds32/bits/link.h: Likewise.
	* sysdeps/nds32/bits/setjmp.h: Likewise.
	* sysdeps/nds32/bsd-_setjmp.S: Likewise.
	* sysdeps/nds32/bsd-setjmp.S: Likewise.
	* sysdeps/nds32/gccframe.h: Likewise.
	* sysdeps/nds32/jmpbuf-offsets.h: Likewise.
	* sysdeps/nds32/jmpbuf-unwind.h: Likewise.
	* sysdeps/nds32/linkmap.h: Likewise.
	* sysdeps/nds32/machine-gmon.h: Likewise.
	* sysdeps/nds32/memcpy.S: Likewise.
	* sysdeps/nds32/memset.S: Likewise.
	* sysdeps/nds32/memusage.h: Likewise.
	* sysdeps/nds32/nptl/pthreaddef.h: Likewise.
	* sysdeps/nds32/setjmp.S: Likewise.
	* sysdeps/nds32/sotruss-lib.c: Likewise.
	* sysdeps/nds32/stackinfo.h: Likewise.
	* sysdeps/nds32/strcmp.S: Likewise.
	* sysdeps/nds32/strcpy.S: Likewise.
	* sysdeps/nds32/sysdep.h: Likewise.
	* sysdeps/nds32/tst-audit.h: Likewise.
	* sysdeps/unix/sysv/linux/nds32/jmp_buf-macros.h: Likewise.
	* sysdeps/unix/sysv/linux/nds32/localplt.data: Likewise.
---
 locale/Makefile                                |   2 +-
 sysdeps/nds32/__longjmp.S                      |  67 ++++++++++++++
 sysdeps/nds32/bits/endian.h                    |  29 ++++++
 sysdeps/nds32/bits/link.h                      |  54 +++++++++++
 sysdeps/nds32/bits/setjmp.h                    |  60 +++++++++++++
 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                        |  25 ++++++
 sysdeps/nds32/machine-gmon.h                   |  34 +++++++
 sysdeps/nds32/memcpy.S                         | 101 +++++++++++++++++++++
 sysdeps/nds32/memset.S                         | 120 +++++++++++++++++++++++++
 sysdeps/nds32/memusage.h                       |  21 +++++
 sysdeps/nds32/nptl/pthreaddef.h                |  33 +++++++
 sysdeps/nds32/setjmp.S                         | 103 +++++++++++++++++++++
 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 |  33 +++++++
 sysdeps/unix/sysv/linux/nds32/localplt.data    |  19 ++++
 25 files changed, 1159 insertions(+), 1 deletion(-)
 create mode 100644 sysdeps/nds32/__longjmp.S
 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

diff --git a/locale/Makefile b/locale/Makefile
index 0ad99ec..803a3a5 100644
--- a/locale/Makefile
+++ b/locale/Makefile
@@ -113,5 +113,5 @@ lib := locale-programs
 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
 
 $(objpfx)tst-locale-locpath.out : tst-locale-locpath.sh $(objpfx)locale
-	$(SHELL) $< '$(common-objpfx)' '$(test-wrapper)' '$(test-wrapper-env)' > $@; \
+	$(SHELL) $< '$(common-objpfx)' '$(test-wrapper-env)' '$(run_program_env)'> $@; \
 	$(evaluate-test)
diff --git a/sysdeps/nds32/__longjmp.S b/sysdeps/nds32/__longjmp.S
new file mode 100644
index 0000000..abf86d2
--- /dev/null
+++ b/sysdeps/nds32/__longjmp.S
@@ -0,0 +1,67 @@
+/* longjmp, 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+#define _SETJMP_H
+#define _ASM
+#include <bits/setjmp.h>
+	.section .text
+
+ENTRY(__longjmp)
+	/* Restore registers.  */
+	lmw.bim  $r6, [$r0], $r14, #0xf
+
+#ifdef __NDS32_ABI_2FP_PLUS__
+	lwi.bi	$r20, [$r0], #4	/* Load $fpcfg.freg to $r20.  */
+
+	/* Case switch for $r20 as $fpcfg.freg.  */
+	beqz    $r20, .LCFG0         /* Branch if $fpcfg.freg = 0b00.  */
+	xori    $r15, $r20, #0b10
+	beqz    $r15, .LCFG2         /* Branch if $fpcfg.freg = 0b10.  */
+	srli    $r20, $r20, #0b01
+	beqz    $r20, .LCFG1         /* Branch if $fpcfg.freg = 0b01.  */
+	/* Fall-through if $fpcfg.freg = 0b11.  */
+.LCFG3:
+	fldi.bi	$fd31, [$r0], #8
+	fldi.bi	$fd30, [$r0], #8
+	fldi.bi	$fd29, [$r0], #8
+	fldi.bi	$fd28, [$r0], #8
+	fldi.bi	$fd27, [$r0], #8
+	fldi.bi	$fd26, [$r0], #8
+	fldi.bi	$fd25, [$r0], #8
+	fldi.bi	$fd24, [$r0], #8
+.LCFG2:
+	fldi.bi	$fd10, [$r0], #8
+	fldi.bi	$fd9, [$r0], #8
+	fldi.bi	$fd8, [$r0], #8
+.LCFG1:
+	fldi.bi	$fd7, [$r0], #8
+	fldi.bi	$fd6, [$r0], #8
+	fldi.bi	$fd5, [$r0], #8
+	fldi.bi	$fd4, [$r0], #8
+.LCFG0:
+	fldi.bi	$fd3, [$r0], #8
+#endif /* __NDS32_ABI_2FP_PLUS__.  */
+
+	/* 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/bits/endian.h b/sysdeps/nds32/bits/endian.h
new file mode 100644
index 0000000..37f4d81
--- /dev/null
+++ b/sysdeps/nds32/bits/endian.h
@@ -0,0 +1,29 @@
+/* Define __BYTE_ORDER. 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
+   <http://www.gnu.org/licenses/>.  */
+#ifndef _ENDIAN_H
+# error "Never use <bits/endian.h> directly; include <endian.h> instead."
+#endif
+
+
+
+#if defined __NDS32_EB__
+# error "Big-endian is un-supported."
+#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..463bad2
--- /dev/null
+++ b/sysdeps/nds32/bits/link.h
@@ -0,0 +1,54 @@
+/* Machine-specific declarations for dynamic linker interface.  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
+   <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..80703ae
--- /dev/null
+++ b/sysdeps/nds32/bits/setjmp.h
@@ -0,0 +1,60 @@
+/* Define the machine-dependent type `jmp_buf'.  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 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
+
+/* For nds32, there are 32 general purpose registers.
+  1. Caller saved register for parameter passing: $r0 - $r5
+  2. Callee saved register: $r6 - $r14
+  3. Assembler reserved register: $r15
+  4. Caller saved register: $r6 - $r24
+  5. Thread pointer register: $r25
+  6. Reserved register for kernel space: $r26 - $27
+  7. Frame pointer: $r28
+  8. Global pointer: $r29
+  9. Link register: $r30
+  10.Stack pointer: $r31
+
+  Only callee saved register and $r28-$r31 needs to store in jmp_buf.
+  Reserved(For 8-byte align if needed).  */
+
+typedef struct __jmp_buf_internal_tag
+  {
+    /* Callee-saved registers: $r6 - $r14, $fp, $gp, $lp, $sp: $r28 - $r31.  */
+    int __regs[13];
+#ifdef __NDS32_ABI_2FP_PLUS__
+    /* Floating-Point Configuration Register.  */
+    int __fpcfg;
+
+    /* Callee-saved fp registers pointer.  */
+    int __fpregs[32];
+#endif /* __NDS32_ABI_2FP_PLUS__.  */
+
+  } __jmp_buf[1] __attribute__((__aligned__ (8)));
+
+#endif /* _ASM.  */
+
+#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..04f01c4
--- /dev/null
+++ b/sysdeps/nds32/gccframe.h
@@ -0,0 +1,21 @@
+/* Definition of object in frame unwind info.  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
+   <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..8a02f43
--- /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-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
+   <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..f4cc3db
--- /dev/null
+++ b/sysdeps/nds32/jmpbuf-unwind.h
@@ -0,0 +1,47 @@
+/* Examine __jmp_buf for unwinding frames.  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
+   <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..34e1cef
--- /dev/null
+++ b/sysdeps/nds32/linkmap.h
@@ -0,0 +1,25 @@
+/* Define nds32 link_map_machine
+   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
+   <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..17a29f2
--- /dev/null
+++ b/sysdeps/nds32/machine-gmon.h
@@ -0,0 +1,34 @@
+/* profiling support for 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+static void __attribute_used__ __mcount_internal (unsigned long int frompc,
+						  unsigned long int selfpc);
+
+#define _MCOUNT_DECL(frompc, selfpc) \
+static void __mcount_internal (unsigned long int frompc, \
+unsigned long int selfpc)
+
+
+#define MCOUNT								\
+void _mcount (unsigned long int frompc)		      			\
+{									\
+  __mcount_internal (frompc, (unsigned long int) RETURN_ADDRESS (0));	\
+}
+
diff --git a/sysdeps/nds32/memcpy.S b/sysdeps/nds32/memcpy.S
new file mode 100644
index 0000000..2fd9b82
--- /dev/null
+++ b/sysdeps/nds32/memcpy.S
@@ -0,0 +1,101 @@
+/* Memory copy.  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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sysdep.h>
+
+/* void *memcpy(void *dst, const void *src, int n);
+
+   dst: $r0
+   src: $r1
+   n  : $r2
+   ret: $r0 - pointer to the memory area dst.  */
+
+ENTRY (memcpy)
+	/* Set $r3 as the dest. Keep value of $r0.  */
+	move    $r3, $r0
+	/* if len<4, go to byte-mode.  */
+	slti	$ta, $r2, 4
+	bnez	$ta, .Lbyte_mode
+	andi	$r4, $r3, 0x3
+	andi	$r5, $r1, 0x3
+
+	/* handle unligned leading bytes.  */
+	beqz	$r5, .LWord_aligned
+	subri	$r5, $r5, #4
+	sub	$r2, $r2, $r5
+	add	$r5, $r5, $r1
+
+.align	2
+1:
+	/* byte-mode copy loop.  */
+	lbi.bi	$r4, [$r1], 1
+	sbi.bi	$r4, [$r3], 1
+	bne	$r1, $r5, 1b
+
+.align  2
+.LWord_aligned:
+	/* assume cache-line size is 32 bytes.  */
+	srli	$r5, $r2, 5
+	beqz	$r5, .Lword_mode
+	slli	$r5, $r5, 5
+	add	$r5, $r5, $r1
+	andi	$r2, $r2, 0x1f
+
+	/* cache-line-mode copy loop.  */
+.align	2
+5:
+	lmw.bim	$r16, [$r1], $r23, #0
+	smw.bim	$r16, [$r3], $r23, #0
+	/* Next cache-line.  */
+	bne	$r1, $r5, 5b
+
+.align  2
+.Lword_mode:
+	srli	$r5, $r2, 2
+	beqz	$r5, .Lbyte_mode
+	slli	$r5, $r5, 2
+	add	$r5, $r5, $r1
+	andi	$r2, $r2, 0x3
+
+	/* word-mode copy loop.  */
+.align	2
+3:
+	lmw.bim	$r4, [$r1], $r4, #0
+	smw.bim	$r4, [$r3], $r4, #0
+	/* Next word.  */
+	bne	$r1, $r5, 3b
+
+.align  2
+.Lbyte_mode:
+	beqz	$r2, .Lend
+	add	$r5, $r1, $r2
+
+.align	2
+4:
+	/* byte-mode copy loop.  */
+	lbi.bi	$r4, [$r1], #1
+	sbi.bi	$r4, [$r3], #1
+	bne	$r1, $r5, 4b
+
+.align  2
+.Lend:
+	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..e853804
--- /dev/null
+++ b/sysdeps/nds32/memset.S
@@ -0,0 +1,120 @@
+/* Optimized version for Andes nds32.
+   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
+   <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)
+	/* Set $r3 as the dest. Keep value of $r0.  */
+	move	$r3, $r0
+	/* if len<4, go to byte-mode.  */
+	slti	$ta, $r2, 4
+	bnez	$ta, .Lbyte_mode
+	andi	$r5, $r3, 0x3
+	beqz	$r5, .Lword_prepare
+	/* size to next word-aligned addres.  */
+	subri	$r5, $r5, #4
+	/* $r2: bytes left.  */
+	sub	$r2, $r2, $r5
+	add	$r5, $r5, $r0
+
+.align	2
+1:
+	/* byte-mode set loop.  */
+	sbi.bi	$r1, [$r3], 1
+	bne	$r3, $r5, 1b
+
+.align  2
+.Lword_prepare:
+	/* prepare word.  */
+
+	/* $r1  <- 0x000000ab.  */
+	andi    $r1, $r1, 0xff
+	/* $r4  <- 0x0000ab00.  */
+	slli    $r4, $r1, 8
+	/* $r1  <- 0x0000abab.  */
+	or      $r1, $r1, $r4
+	/* $r4  <- 0xabab0000.  */
+	slli    $r4, $r1, 16
+	/* $r1  <- 0xabababab.  */
+	or      $r1, $r1, $r4
+
+	/* assume cache-line size is 32 bytes.  */
+	srli	$r5, $r2, 5
+	beqz	$r5, .Lword_mode
+	slli	$r5, $r5, 5
+	add	$r5, $r5, $r3
+	andi	$r2, $r2, 0x1f
+
+	/* cache-line-mode set loop.  */
+	move $r16,$r1
+	move $r17,$r1
+	move $r18,$r1
+	move $r19,$r1
+	move $r20,$r1
+	move $r21,$r1
+	move $r22,$r1
+	move $r23,$r1
+
+.align	2
+4:
+	/* $r3 is dst.  */
+	smw.bim	$r16, [$r3], $r23, #0
+	/* Next cache-line.  */
+	bne	$r3, $r5, 4b
+
+.align  2
+.Lword_mode:
+	/* $r5 <- n words to set.  */
+	srli	$r5, $r2, 2
+	beqz	$r5, .Lbyte_mode
+	slli	$r5, $r5, 2
+	add	$r5, $r5, $r3
+	andi	$r2, $r2, 0x3
+
+	/* word-mode set loop.  */
+.align	2
+2:
+	smw.bim	$r1, [$r3], $r1, #0
+	/* Next word.  */
+	bne $r3, $r5, 2b
+
+.align  2
+.Lbyte_mode:
+	beqz	$r2, .Lend
+	add	$r5, $r3, $r2
+
+.align	2
+3:
+	/* byte-mode set loops.  */
+	sbi.bi	$r1, [$r3], #1
+	bne	$r3, $r5, 3b
+.align  2
+.Lend:
+	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..b346a0a
--- /dev/null
+++ b/sysdeps/nds32/memusage.h
@@ -0,0 +1,21 @@
+/* Machine-specific definitions for memory usage profiling, 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
+   <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..23d5581
--- /dev/null
+++ b/sysdeps/nds32/nptl/pthreaddef.h
@@ -0,0 +1,33 @@
+/* pthread machine parameter definitions,  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
+   <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..7bcdd92
--- /dev/null
+++ b/sysdeps/nds32/setjmp.S
@@ -0,0 +1,103 @@
+/* setjmp for Andes nds32.
+   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
+   <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
+
+#ifdef __NDS32_ABI_2FP_PLUS__
+/* Process for FPU registers.  */
+        fmfcfg  $r20    /* Keep $fpcfg in $r20.  */
+        slli    $r20, $r20, #28
+        srli    $r20, $r20, #30 /* Set $r20 as $fpcfg.freg.  */
+        swi.bi  $r20, [$r2], #4
+
+        /* Case switch for $r20 as $fpcfg.freg.  */
+        beqz    $r20, .LCFG0            /* Branch if $fpcfg.freg = 0b00.  */
+        xori    $r15, $r20, #0b10
+        beqz    $r15, .LCFG2            /* Branch if $fpcfg.freg = 0b10.  */
+        srli    $r20, $r20, #0b01
+        beqz    $r20, .LCFG1            /* Branch if $fpcfg.freg = 0b01.  */
+        /* Fall-through if $fpcfg.freg = 0b11.  */
+.LCFG3:
+        fsdi.bi $fd31, [$r2], #8
+        fsdi.bi $fd30, [$r2], #8
+        fsdi.bi $fd29, [$r2], #8
+        fsdi.bi $fd28, [$r2], #8
+        fsdi.bi $fd27, [$r2], #8
+        fsdi.bi $fd26, [$r2], #8
+        fsdi.bi $fd25, [$r2], #8
+        fsdi.bi $fd24, [$r2], #8
+.LCFG2:
+        fsdi.bi $fd10, [$r2], #8
+        fsdi.bi $fd9, [$r2], #8
+        fsdi.bi $fd8, [$r2], #8
+.LCFG1:
+        fsdi.bi $fd7, [$r2], #8
+        fsdi.bi $fd6, [$r2], #8
+        fsdi.bi $fd5, [$r2], #8
+        fsdi.bi $fd4, [$r2], #8
+.LCFG0:
+        fsdi.bi $fd3, [$r2], #8
+#endif /* __NDS32_ABI_2FP_PLUS__ */
+
+        /* 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..afa1acb
--- /dev/null
+++ b/sysdeps/nds32/sotruss-lib.c
@@ -0,0 +1,50 @@
+/* Override generic sotruss-lib.c to define actual functions.
+   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
+   <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..e1d1813
--- /dev/null
+++ b/sysdeps/nds32/stackinfo.h
@@ -0,0 +1,32 @@
+/* Stack environment definitions.  Andes nds32.
+   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
+   <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..7136391
--- /dev/null
+++ b/sysdeps/nds32/strcmp.S
@@ -0,0 +1,105 @@
+/* Optimized version for Andes nds32.
+   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
+   <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".  */
+        /* A difference was detected, so search bytewise.  */
+	bne	$r5, $r3, .Lbyte_mode
+.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..9189172
--- /dev/null
+++ b/sysdeps/nds32/strcpy.S
@@ -0,0 +1,75 @@
+/* Optimized version for Andes nds32.
+   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
+   <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..8e853a4
--- /dev/null
+++ b/sysdeps/nds32/sysdep.h
@@ -0,0 +1,70 @@
+/* Assembler macros.  Andes nds32.
+   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
+   <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..0ef3791
--- /dev/null
+++ b/sysdeps/nds32/tst-audit.h
@@ -0,0 +1,23 @@
+/* Definitions for testing PLT entry/exit auditing.  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
+   <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..20e7b9c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/nds32/jmp_buf-macros.h
@@ -0,0 +1,33 @@
+/* jump buffer constants.  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
+   <http://www.gnu.org/licenses/>.  */
+#ifdef __NDS32_ABI_2FP_PLUS__
+# define JMP_BUF_SIZE 320
+# define SIGJMP_BUF_SIZE 320
+# define JMP_BUF_ALIGN 8
+# define SIGJMP_BUF_ALIGN 8
+# define MASK_WAS_SAVED_OFFSET 184
+# define SAVED_MASK_OFFSET 188
+#else
+# 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
+#endif
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
-- 
1.9.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]