[RFC,v3,01/12] C-SKY: ABI related code

Message ID 1c2031c79377fb4edbb68a813cd27846534fa98a.1530246556.git.han_mao@c-sky.com
State New, archived
Headers

Commit Message

毛晗 June 29, 2018, 7:58 a.m. UTC
  Codes in this patch contains lots of C-SKY ABI related code. They are written
accroding to the registers assgnments, relocations, assemblly described
in C-SKY CPU ABI Standards and C-SKY CPU manual.
This does not contain any linux related code.

	* sysdeps/csky/abiv2/__longjmp.S: New file.
	* sysdeps/csky/abiv2/csky-mcount.S: Likewise.
	* sysdeps/csky/abiv2/dl-trampoline.S: Likewise.
	* sysdeps/csky/abiv2/memcpy.S: Likewise.
	* sysdeps/csky/abiv2/setjmp.S: Likewise.
	* sysdeps/csky/abiv2/start.S: Likewise.
	* sysdeps/csky/abiv2/strcmp.S: Likewise.
	* sysdeps/csky/abiv2/strcpy.S: Likewise.
	* sysdeps/csky/abort-instr.h: Likewise.
	* sysdeps/csky/bits/endian.h: Likewise.
	* sysdeps/csky/bits/link.h: Likewise.
	* sysdeps/csky/bits/setjmp.h: Likewise.
	* sysdeps/csky/bsd-_setjmp.S: Likewise.
	* sysdeps/csky/bsd-setjmp.S: Likewise.
	* sysdeps/csky/crti.S: Likewise.
	* sysdeps/csky/crtn.S: Likewise.
	* sysdeps/csky/gccframe.h: Likewise.
	* sysdeps/csky/jmpbuf-unwind.h: Likewise.
	* sysdeps/csky/machine-gmon.h: Likewise.
	* sysdeps/csky/memusage.h: Likewise.
	* sysdeps/csky/stackinfo.h: Likewise.
	* sysdeps/csky/sysdep.h: Likewise.
---
 sysdeps/csky/abiv2/__longjmp.S     |  61 +++++++++++
 sysdeps/csky/abiv2/csky-mcount.S   |  62 +++++++++++
 sysdeps/csky/abiv2/dl-trampoline.S |  48 +++++++++
 sysdeps/csky/abiv2/memcpy.S        | 205 +++++++++++++++++++++++++++++++++++++
 sysdeps/csky/abiv2/setjmp.S        |  77 ++++++++++++++
 sysdeps/csky/abiv2/start.S         | 115 +++++++++++++++++++++
 sysdeps/csky/abiv2/strcmp.S        | 187 +++++++++++++++++++++++++++++++++
 sysdeps/csky/abiv2/strcpy.S        | 138 +++++++++++++++++++++++++
 sysdeps/csky/abort-instr.h         |   2 +
 sysdeps/csky/bits/endian.h         |  10 ++
 sysdeps/csky/bits/link.h           |  55 ++++++++++
 sysdeps/csky/bits/setjmp.h         |  34 ++++++
 sysdeps/csky/bsd-_setjmp.S         |   1 +
 sysdeps/csky/bsd-setjmp.S          |   1 +
 sysdeps/csky/crti.S                |  96 +++++++++++++++++
 sysdeps/csky/crtn.S                |  50 +++++++++
 sysdeps/csky/gccframe.h            |  21 ++++
 sysdeps/csky/jmpbuf-unwind.h       |  48 +++++++++
 sysdeps/csky/machine-gmon.h        |  32 ++++++
 sysdeps/csky/memusage.h            |  21 ++++
 sysdeps/csky/stackinfo.h           |  29 ++++++
 sysdeps/csky/sysdep.h              |  45 ++++++++
 22 files changed, 1338 insertions(+)
 create mode 100644 sysdeps/csky/abiv2/__longjmp.S
 create mode 100644 sysdeps/csky/abiv2/csky-mcount.S
 create mode 100644 sysdeps/csky/abiv2/dl-trampoline.S
 create mode 100644 sysdeps/csky/abiv2/memcpy.S
 create mode 100644 sysdeps/csky/abiv2/setjmp.S
 create mode 100644 sysdeps/csky/abiv2/start.S
 create mode 100644 sysdeps/csky/abiv2/strcmp.S
 create mode 100644 sysdeps/csky/abiv2/strcpy.S
 create mode 100644 sysdeps/csky/abort-instr.h
 create mode 100644 sysdeps/csky/bits/endian.h
 create mode 100644 sysdeps/csky/bits/link.h
 create mode 100644 sysdeps/csky/bits/setjmp.h
 create mode 100644 sysdeps/csky/bsd-_setjmp.S
 create mode 100644 sysdeps/csky/bsd-setjmp.S
 create mode 100644 sysdeps/csky/crti.S
 create mode 100644 sysdeps/csky/crtn.S
 create mode 100644 sysdeps/csky/gccframe.h
 create mode 100644 sysdeps/csky/jmpbuf-unwind.h
 create mode 100644 sysdeps/csky/machine-gmon.h
 create mode 100644 sysdeps/csky/memusage.h
 create mode 100644 sysdeps/csky/stackinfo.h
 create mode 100644 sysdeps/csky/sysdep.h
  

Comments

Joseph Myers June 29, 2018, 4:40 p.m. UTC | #1
On Fri, 29 Jun 2018, Mao Han wrote:

> Codes in this patch contains lots of C-SKY ABI related code. They are written
> accroding to the registers assgnments, relocations, assemblly described
> in C-SKY CPU ABI Standards and C-SKY CPU manual.

Could you include direct URLs to PDFs of these manuals in the introduction 
to future versions of the patch series (like you gave URLs for your GCC / 
binutils / Linux git repositories)?

> +#ifndef __CSKYABIV2__
> +#error "No support for C-SKY ABIV1"

Preprocessor indentation, "# error" inside #if.

> +#else
> +# define CSKY_ABIV2
> +#endif

Why do you need this macro rather than just using the predefined 
__CSKYABIV2__ anywhere needing an ABI conditional?  (Right now, of course, 
any such ABI conditionals will just have #error for the ABIv1 case, like 
the one here.)
  
毛晗 July 3, 2018, 8:03 a.m. UTC | #2
On Fri, Jun 29, 2018 at 04:40:10PM +0000, Joseph Myers wrote:
> On Fri, 29 Jun 2018, Mao Han wrote:
> 
> > Codes in this patch contains lots of C-SKY ABI related code. They are written
> > accroding to the registers assgnments, relocations, assemblly described
> > in C-SKY CPU ABI Standards and C-SKY CPU manual.
> 
> Could you include direct URLs to PDFs of these manuals in the introduction 
> to future versions of the patch series (like you gave URLs for your GCC / 
> binutils / Linux git repositories)?
>

We currently don't have any technical document put on the internet. I've
asked our toolchain principal to release some. Hopefully they will be
available next time.
 
> Preprocessor indentation, "# error" inside #if.
> 
> > +#else
> > +# define CSKY_ABIV2
> > +#endif
> 
> Why do you need this macro rather than just using the predefined 
> __CSKYABIV2__ anywhere needing an ABI conditional?  (Right now, of course, 
> any such ABI conditionals will just have #error for the ABIv1 case, like 
> the one here.)
It is some legacy code from our first port on 2013. I don't what it is
used for. I think I'll just remove it.

Best Regards,
Mao Han
  

Patch

diff --git a/sysdeps/csky/abiv2/__longjmp.S b/sysdeps/csky/abiv2/__longjmp.S
new file mode 100644
index 0000000..ba4445e
--- /dev/null
+++ b/sysdeps/csky/abiv2/__longjmp.S
@@ -0,0 +1,61 @@ 
+/* longjmp for C-SKY ABIV2
+   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/>.  */
+
+#include <sysdep.h>
+
+ENTRY (__longjmp)
+	mov	a2, a0
+	mov	a0, a1		/* get the return value in place */
+	cmpnei	a0, 0
+	bt	have_return
+	movi	a0, 1		/* can't let setjmp() return zero! */
+have_return:
+#ifdef CHECK_SP
+	ldw	r10, (a2, 0)	/* jmpbuf's sp */
+# ifdef PTR_MANGLE
+	PTR_DEMANGLE (r10, r10, a3)
+# endif
+	CHECK_SP (r10)
+#endif
+	ldw	sp, (a2, 0)
+	ldw	lr, (a2, 4)
+	ldw	r4, (a2, 8)
+	ldw	r5, (a2, 12)
+	ldw	r6, (a2, 16)
+	ldw	r7, (a2, 20)
+	ldw	r8, (a2, 24)
+	ldw	r9, (a2, 28)
+	ldw	r10, (a2, 32)
+	ldw	r11, (a2, 36)
+	ldw	r16, (a2, 40)
+	ldw	r17, (a2, 44)
+	ldw	r26, (a2, 48)
+	ldw	r27, (a2, 52)
+	ldw	r28, (a2, 56)
+	ldw	r29, (a2, 60)
+	ldw	r30, (a2, 64)
+	ldw	r31, (a2, 68)
+	addi	a2, 72
+
+#ifdef PTR_MANGLE
+	PTR_DEMANGLE (sp, sp, a3)
+	PTR_DEMANGLE2 (lr, lr, a3)
+#endif
+	jmp	lr
+
+END (__longjmp)
diff --git a/sysdeps/csky/abiv2/csky-mcount.S b/sysdeps/csky/abiv2/csky-mcount.S
new file mode 100644
index 0000000..61ecf6c
--- /dev/null
+++ b/sysdeps/csky/abiv2/csky-mcount.S
@@ -0,0 +1,62 @@ 
+/* Implementation of profiling support.  C-SKY ABIV2 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/>.  */
+
+/* Don't call mcount when calling mcount...  */
+#undef PROF
+
+#include <sysdep.h>
+
+/* Use an assembly stub with a special ABI.  The calling lr has been
+   pushed to the stack (which will be misaligned).  We should preserve
+   all registers except ip and pop a word off the stack.
+
+   NOTE: This assumes mcount_internal does not clobber any non-core
+   (coprocessor) registers.  Currently this is true, but may require
+   additional attention in the future.
+
+   The calling sequence looks something like:
+func:
+   push lr
+   jbsr __gnu_mount_nc
+   <function body>
+*/
+
+ENTRY (_mcount)
+	subi	sp,20
+	stw	a0,(sp, 0)
+	stw	a1,(sp, 4)
+	stw	a2,(sp, 8)
+	stw	a3,(sp, 12)
+	stw	lr,(sp, 16)
+	mov	a1, lr
+	ldw	a0, (sp, 20)
+	jbsr	__mcount_internal
+	ldw	a0,(sp, 0)
+	ldw	a1,(sp, 4)
+	ldw	a2,(sp, 8)
+	ldw	a3,(sp, 12)
+	ldw	t1,(sp, 16)
+	ldw	lr,(sp, 20)
+	addi	sp,24
+	jmp	t1
+END (_mcount)
+
+/* The canonical name for the function is `_mcount' in both C and asm,
+   but some old asm code might assume it's `mcount'.  */
+#undef mcount
+weak_alias (_mcount, mcount)
diff --git a/sysdeps/csky/abiv2/dl-trampoline.S b/sysdeps/csky/abiv2/dl-trampoline.S
new file mode 100644
index 0000000..6771efe
--- /dev/null
+++ b/sysdeps/csky/abiv2/dl-trampoline.S
@@ -0,0 +1,48 @@ 
+/* PLT trampolines.  C-SKY ABIV2 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/>.  */
+
+/* This function is not called directly. It is jumped when attempting to use a
+   symbol that has not yet been resolved.
+
+   .plt*:
+     subi r0, 32
+     stw r2, (r0, 0)
+     stw r3, (r0, 4)
+     lrw r3, #offset
+     ldw r2, (gb, 8)
+     jmp r2
+ */
+
+#include <sysdep.h>
+
+	.text
+ENTRY (_dl_runtime_resolve)
+	subi	sp, 20
+	stm	a0-a3, (sp)
+	stw	lr, (sp, 16)
+	# a0 = id, a1 = offset(do it in plt*)
+	ldw	a0,  (gb, 4)
+	movi	a1, 12
+	mult	a1, t1
+	bsr	_dl_fixup
+	mov	t0, a0
+	ldw	lr, (sp, 16)
+	ldm	a0-a3, (sp)
+	addi	sp, 20
+	jmp	t0
+END (_dl_runtime_resolve)
diff --git a/sysdeps/csky/abiv2/memcpy.S b/sysdeps/csky/abiv2/memcpy.S
new file mode 100644
index 0000000..67c2f84
--- /dev/null
+++ b/sysdeps/csky/abiv2/memcpy.S
@@ -0,0 +1,205 @@ 
+/* The assembly function for memcpy.  C-SKY ABIV2 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/>.  */
+
+#include <sysdep.h>
+
+.macro	GET_FRONT_BITS rx ry
+#ifdef	__cskyLE__
+	lsr	\rx, \ry
+#else
+	lsl	\rx, \ry
+#endif
+.endm
+
+.macro	GET_AFTER_BITS rx ry
+#ifdef	__cskyLE__
+	lsl	\rx, \ry
+#else
+	lsr	\rx, \ry
+#endif
+.endm
+
+ENTRY (memcpy)
+	/* If len less than 4 bytes */
+	mov	r3, r0
+	cmplti	r2, 4
+	jbt	.L_copy_by_byte
+
+	mov	r12, r0
+	andi	r12, 3
+	/* If dest is not 4 bytes aligned */
+	bnez	r12, .L_dest_not_aligned
+.L0:
+	/* If dest is aligned, but src is not aligned */
+	mov	r12, r1
+	andi	r12, 3
+	bnez	r12, .L_dest_aligned_but_src_not_aligned
+
+	/* dest and src are all aligned */
+	cmplti	r2, 16
+	/* If len less than 16 bytes */
+	jbt	.L_aligned_and_len_less_16bytes
+
+	/* src and dst are all aligned, and len > 16 bytes */
+.L_aligned_and_len_larger_16bytes:
+	ldw	r18, (r1, 0)
+	ldw	r19, (r1, 4)
+	ldw	r20, (r1, 8)
+	ldw	r21, (r1, 12)
+	stw	r18, (r3, 0)
+	stw	r19, (r3, 4)
+	stw	r20, (r3, 8)
+	stw	r21, (r3, 12)
+	subi	r2, 16
+	addi	r1, 16
+	addi	r3, 16
+	cmplti	r2, 16
+	jbf	.L_aligned_and_len_larger_16bytes
+
+.L_aligned_and_len_less_16bytes:
+	cmplti	r2, 4
+	jbt	.L_copy_by_byte
+	ldw	r18, (r1, 0)
+	stw	r18, (r3, 0)
+	subi	r2, 4
+	addi	r1, 4
+	addi	r3, 4
+	jbr	.L_aligned_and_len_less_16bytes
+
+	/* len less than 4 bytes */
+.L_copy_by_byte:
+	cmpnei	r2, 0
+	jbf	.L_return
+	ldb	r18, (r1, 0)
+	stb	r18, (r3, 0)
+	subi	r2, 1
+	addi	r1, 1
+	addi	r3, 1
+	jbr	.L_copy_by_byte
+
+.L_return:
+	rts
+
+	/* If dest is not aligned, just copying some bytes makes the dest align.
+	After that, we judge whether the src is aligned. */
+
+	/* consider overlapped case */
+.L_dest_not_aligned:
+	rsub	r13, r1, r3
+	abs	r13, r13
+	cmplt	r13, r2
+	jbt	.L_copy_by_byte
+
+.L1:
+	/* makes the dest align. */
+	ldb	r18, (r1, 0)
+	stb	r18, (r3, 0)
+	addi	r12, 1
+	subi	r2, 1
+	addi	r1, 1
+	addi	r3, 1
+	cmpnei	r12, 4
+	jbt	.L1
+	cmplti	r2, 4
+	jbt	.L_copy_by_byte
+	/* judge whether the src is aligned. */
+	jbf	.L0
+
+	/* consider overlapped case */
+.L_dest_aligned_but_src_not_aligned:
+	rsub	r13, r1, r3
+	abs	r13, r13
+	cmplt	r13, r2
+	jbt	.L_copy_by_byte
+
+	bclri	r1, 0
+	bclri	r1, 1
+	ldw	r18, (r1, 0)
+	addi	r1, 4
+
+	/* r12 is used to store the misaligned bits */
+	movi	r13, 8
+	mult	r13, r12
+	mov	r24, r13
+	rsubi	r13, 32
+	mov	r25, r13
+
+	cmplti	r2, 16
+	jbt	.L_not_aligned_and_len_less_16bytes
+
+.L_not_aligned_and_len_larger_16bytes:
+	ldw	r20, (r1, 0)
+	ldw	r21, (r1, 4)
+	ldw	r22, (r1, 8)
+	ldw	r23, (r1, 12)
+
+	/* little or big endian? */
+	GET_FRONT_BITS	r18 r24
+	mov	r19, r20
+	GET_AFTER_BITS	r20 r25
+	or	r20, r18
+
+	GET_FRONT_BITS	r19 r24
+	mov	r18, r21
+	GET_AFTER_BITS	r21 r13
+	or	r21, r19
+
+	GET_FRONT_BITS	r18 r24
+	mov	r19, r22
+	GET_AFTER_BITS	r22 r25
+	or	r22, r18
+
+	GET_FRONT_BITS	r19 r24
+	mov	r18, r23
+	GET_AFTER_BITS	r23 r25
+	or	r23, r19
+
+	stw	r20, (r3, 0)
+	stw	r21, (r3, 4)
+	stw	r22, (r3, 8)
+	stw	r23, (r3, 12)
+	subi	r2, 16
+	addi	r1, 16
+	addi	r3, 16
+	cmplti	r2, 16
+	jbf	.L_not_aligned_and_len_larger_16bytes
+
+	.L_not_aligned_and_len_less_16bytes:
+	cmplti	r2, 4
+	jbf	.L2
+	/* r12 is used to stored the misaligned bits */
+	rsubi	r12, 4
+	/* initial the position */
+	subu	r1, r12
+	jbr	.L_copy_by_byte
+	.L2:
+	ldw	r21, (r1, 0)
+	GET_FRONT_BITS	r18 r24
+	mov	r19, r18
+	mov	r18, r21
+	GET_AFTER_BITS	r21 r25
+	or	r21, r19
+	stw	r21, (r3, 0)
+	subi	r2, 4
+	addi	r1, 4
+	addi	r3, 4
+	jbr	.L_not_aligned_and_len_less_16bytes
+END (memcpy)
+
+libc_hidden_builtin_def (memcpy)
+.weak memcpy
diff --git a/sysdeps/csky/abiv2/setjmp.S b/sysdeps/csky/abiv2/setjmp.S
new file mode 100644
index 0000000..a2dff37
--- /dev/null
+++ b/sysdeps/csky/abiv2/setjmp.S
@@ -0,0 +1,77 @@ 
+/* setjmp for C-SKY ABIV2
+   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/>.  */
+
+#include <sysdep.h>
+
+ENTRY (setjmp)
+	movi	a1, 1
+	br	__sigsetjmp
+END (setjmp)
+
+ENTRY (_setjmp)
+	movi	a1, 0
+	br	__sigsetjmp
+END (_setjmp)
+
+libc_hidden_def (_setjmp)
+
+ENTRY (__sigsetjmp)
+	mov	a2, a0
+	/* Save registers */
+
+#ifdef PTR_MANGLE
+	PTR_MANGLE (t0, sp, a3)
+	stw	t0, (a2, 0)
+	PTR_MANGLE2 (t0, lr, a3)
+	stw	t0, (a2, 4)
+#else
+	stw	sp, (a2, 0)
+	stw	lr, (a2, 4)
+#endif
+	stw	r4, (a2, 8)
+	stw	r5, (a2, 12)
+	stw	r6, (a2, 16)
+	stw	r7, (a2, 20)
+	stw	r8, (a2, 24)
+	stw	r9, (a2, 28)
+	stw	r10, (a2, 32)
+	stw	r11, (a2, 36)
+	stw	r16, (a2, 40)
+	stw	r17, (a2, 44)
+	stw	r26, (a2, 48)
+	stw	r27, (a2, 52)
+	stw	r28, (a2, 56)
+	stw	r29, (a2, 60)
+	stw	r30, (a2, 64)
+	stw	r31, (a2, 68)
+	addi	a2, 72
+
+#ifdef __PIC__
+	grs	t1, .Lgetpc
+.Lgetpc:
+	lrw	t0, .Lgetpc@GOTPC
+	addu	t1, t0
+	lrw	a2, __sigjmp_save@PLT
+	ldr.w	a2, (t1, a2 << 0)
+	jmp	a2
+#else
+	jmpi	__sigjmp_save
+#endif	/* !__PIC__ */
+END (__sigsetjmp)
+
+hidden_def (__sigsetjmp)
diff --git a/sysdeps/csky/abiv2/start.S b/sysdeps/csky/abiv2/start.S
new file mode 100644
index 0000000..3327a0d
--- /dev/null
+++ b/sysdeps/csky/abiv2/start.S
@@ -0,0 +1,115 @@ 
+/* Startup code compliant to the ELF C-SKY ABIV2.
+   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.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file with other
+   programs, and to distribute those programs without any restriction
+   coming from the use of this file. (The GNU Lesser General Public
+   License restrictions do apply in other respects; for example, they
+   cover modification of the file, and distribution when not linked
+   into another program.)
+
+   Note that people who make modified versions of this file are not
+   obligated to grant this special exception for their modified
+   versions; it is their choice whether to do so. The GNU Lesser
+   General Public License gives permission to release a modified
+   version without this exception; this exception also makes it
+   possible to release a modified version which carries forward this
+   exception.
+
+   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/>.  */
+
+/* We need to call:
+   __libc_start_main (int (*main) (int, char **, char **), int argc,
+		      char **argv, void (*init) (void), void (*fini) (void),
+		      void (*rtld_fini) (void), void *stack_end)
+*/
+
+#include <sysdep.h>
+
+.text
+ENTRY (_start)
+	/* Clear the frame pointer and link register since this is the outermost frame. */
+	movi	lr, 0
+	/* Pop argc off the stack and save a pointer to argv */
+	ldw	a1, (sp, 0)	/* __libc_start_main(arg1): argc */
+	addi	sp, 4
+	mov	a2, sp		/* __libc_start_main(arg2): argv */
+
+	subi	sp, 4
+	/* Push stack limit */
+	stw	a2, (sp, 0)
+	/* Push rtld_fini */
+	subi	sp, 4
+	stw	a0, (sp, 0)
+
+#ifdef SHARED
+	subi	sp, 8
+	stw	lr, (sp, 0)
+	stw	gb, (sp, 4)
+	bsr	.Lgetpc
+.Lgetpc:
+	lrw	gb, .Lgetpc@GOTPC
+	addu	gb, lr
+	lrw	a3, __libc_csu_fini@GOT
+	addu	a3, gb
+	ldw	a3, (a3)
+
+	subi	sp, 4
+	stw	a3, (sp, 0)
+
+	lrw	a3, __libc_csu_init@GOT
+	addu	a3, gb
+	ldw	a3, (a3, 0)
+
+	lrw	t0, main@GOT
+	addu	t0, gb
+	ldw	a0,(t0,0)
+	lrw	t1,__libc_start_main@PLT
+	addu	t1, gb
+	ldw	t1, (t1, 0)
+	jsr	t1
+
+	ldw	lr,(sp,0)
+	ldw	gb,(sp,4)
+	addi	sp, 8
+#else
+	/* Fetch address of __libc_csu_fini */
+	lrw	a0, __libc_csu_fini
+	/* Push __libc_csu_fini */
+	subi	sp,4
+	stw	a0, (sp,0)
+
+	/* Set up the other arguments in registers */
+	lrw	a0, main
+	lrw	a3, __libc_csu_init
+	/* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
+	/* Let the libc call main and exit with its return code.  */
+	jsri	__libc_start_main
+#endif	/* !SHARED */
+
+	/* should never get here....*/
+	jsri	abort
+END (_start)
+
+/* Define a symbol for the first piece of initialized data.  */
+	.data
+	.globl __data_start
+__data_start:
+	.long 0
+	.weak data_start
+	data_start = __data_start
diff --git a/sysdeps/csky/abiv2/strcmp.S b/sysdeps/csky/abiv2/strcmp.S
new file mode 100644
index 0000000..b33cafd
--- /dev/null
+++ b/sysdeps/csky/abiv2/strcmp.S
@@ -0,0 +1,187 @@ 
+/* The assembly function for string compare. C-SKY ABIV2 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/>.  */
+
+#include <sysdep.h>
+
+ENTRY (strcmp)
+	mov	a3, a0
+
+	or	a0, a1
+	andi	a0, 0x3
+	bnez	a0, 4f
+
+1:
+	/* if aligned, load word each time. */
+	ldw	a0, (a3, 0)
+	ldw	t0, (a1, 0)
+	/* if d[i] != s[i], goto 1f */
+	cmpne	a0, t0
+	bt	1f
+	/* if d[i] == s[i], check if d or s is at the end. */
+	tstnbz	a0
+	/* if at the end, goto 3f (finish comparing) */
+	bf	3f
+
+	ldw	a0, (a3, 4)
+	ldw	t0, (a1, 4)
+	cmpne	a0, t0
+	bt	1f
+	tstnbz	a0
+	bf	3f
+
+	ldw	a0, (a3, 8)
+	ldw	t0, (a1, 8)
+	cmpne	a0, t0
+	bt	1f
+	tstnbz	a0
+	bf	3f
+
+	ldw	a0, (a3, 12)
+	ldw	t0, (a1, 12)
+	cmpne	a0, t0
+	bt	1f
+	tstnbz	a0
+	bf	3f
+
+	ldw	a0, (a3, 16)
+	ldw	t0, (a1, 16)
+	cmpne	a0, t0
+	bt	1f
+	tstnbz	a0
+	bf	3f
+
+	ldw	a0, (a3, 20)
+	ldw	t0, (a1, 20)
+	cmpne	a0, t0
+	bt	1f
+	tstnbz	a0
+	bf	3f
+
+	ldw	a0, (a3, 24)
+	ldw	t0, (a1, 24)
+	cmpne	a0, t0
+	bt	1f
+	tstnbz	a0
+	bf	3f
+
+	ldw	a0, (a3, 28)
+	ldw	t0, (a1, 28)
+	cmpne	a0, t0
+	bt	1f
+	tstnbz	a0
+	bf	3f
+
+	addi	a3, 32
+	addi	a1, 32
+
+	br	1b
+
+# ifdef __CSKYBE__
+	/* d[i] != s[i] in word, so we check byte 0 ? */
+1:
+	xtrb0	t1, a0
+	mov	a2, t1
+	xtrb0	t1, t0
+	cmpne	a2, t1
+	bt	2f
+	cmpnei	a2, 0
+	bf	2f
+
+	/* d[i] != s[i] in word, so we check byte 1 ? */
+	xtrb1	t1, a0
+	mov	a2, t1
+	xtrb1	t1, t0
+	cmpne	a2, t1
+	bt	2f
+	cmpnei	a2, 0
+	bf	2f
+
+	/* d[i] != s[i] in word, so we check byte 1 ? */
+	xtrb2	t1, a0
+	mov	a2, t1
+	xtrb2	t1, t0
+	cmpne	a2, t1
+        bt	2f
+	cmpnei	a2, 0
+	bf	2f
+
+	/* d[i] != s[i] in word, so we check byte 1 ? */
+	xtrb3	t1, a0
+	mov	a2, t1
+	xtrb3	t1, t0
+
+# else
+	/* d[i] != s[i] in word, so we check byte 0 ? */
+1:
+	xtrb3	t1, a0
+	mov	a2, t1
+	xtrb3	t1, t0
+	cmpne	a2, t1
+	bt	2f
+	cmpnei	a2, 0
+	bf	2f
+
+	/* d[i] != s[i] in word, so we check byte 1 ? */
+	xtrb2	t1, a0
+	mov	a2, t1
+	xtrb2	t1, t0
+	cmpne	a2, t1
+	bt	2f
+	cmpnei	a2, 0
+	bf	2f
+
+	/* d[i] != s[i] in word, so we check byte 1 ? */
+	xtrb1	t1, a0
+	mov	a2, t1
+	xtrb1	t1, t0
+	cmpne	a2, t1
+	bt	2f
+	cmpnei	a2, 0
+	bf	2f
+
+	/* d[i] != s[i] in word, so we check byte 1 ? */
+	xtrb0	t1, a0
+	mov	a2, t1
+	xtrb0	t1, t0
+
+# endif /* !__CSKYBE__ */
+	/* get the result when d[i] != s[i] */
+2:
+	subu	a2, t1
+	mov	a0, a2
+	jmp	r15
+
+	/* return when d[i] == s[i] */
+3:
+	subu	a0, t0
+	jmp	r15
+
+	/* cmp when d or s is not aligned */
+4:
+	ldb	a0, (a3, 0)
+	ldb	t0, (a1, 0)
+	cmpne	a0, t0
+	bt	3b
+	addi	a1, 1
+	addi	a3, 1
+	bnez	a0, 4b
+	jmp	r15
+END (strcmp)
+
+libc_hidden_def (strcmp)
+.weak strcmp
diff --git a/sysdeps/csky/abiv2/strcpy.S b/sysdeps/csky/abiv2/strcpy.S
new file mode 100644
index 0000000..bb39f8f
--- /dev/null
+++ b/sysdeps/csky/abiv2/strcpy.S
@@ -0,0 +1,138 @@ 
+/* The assembly function for string copy.  C-SKY ABIV2 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/>.  */
+
+#include <sysdep.h>
+
+ENTRY (strcpy)
+	mov	a3, a0
+	or	a2, a1, a3
+	andi	t0, a2, 3
+	bez	t0, 2f
+	mov	t0, a1
+1:
+	ld.b	a2, (t0)
+	stb	a2, (a3)
+	addi	t0, t0, 1
+	addi	a3, a3, 1
+	bnez	a2, 1b
+
+	jmp	r15
+
+2:
+	ldw	a2, (a1)
+	tstnbz	a2
+	bf	11f
+	stw	a2, (a3)
+
+	ldw	a2, (a1, 4)
+	tstnbz	a2
+	bf	4f
+	stw	a2, (a3, 4)
+
+	ldw	a2, (a1, 8)
+	tstnbz	a2
+	bf	5f
+	stw	a2, (a3, 8)
+
+	ldw	a2, (a1, 12)
+	tstnbz	a2
+	bf	6f
+	stw	a2, (a3, 12)
+
+	ldw	a2, (a1, 16)
+	tstnbz	a2
+	bf	7f
+	stw	a2, (a3, 16)
+
+	ldw	a2, (a1, 20)
+	tstnbz	a2
+	bf	8f
+	stw	a2, (a3, 20)
+
+	ldw	a2, (a1, 24)
+	tstnbz	a2
+	bf	9f
+	stw	a2, (a3, 24)
+
+	ldw	a2, (a1, 28)
+	tstnbz	a2
+	bf	10f
+	stw	a2, (a3, 28)
+
+	addi	a3, 32
+	addi	a1, 32
+	br	2b
+
+
+4:
+	addi	a3, 4
+	br	11f
+
+5:
+	addi	a3, 8
+	br	11f
+
+6:
+	addi	a3, 12
+	br	11f
+
+7:
+	addi	a3, 16
+	br	11f
+
+8:
+	addi	a3, 20
+	br	11f
+
+9:
+	addi	a3, 24
+	br	11f
+
+10:
+	addi	a3, 28
+11:
+# ifdef __CSKYBE__
+	xtrb0	t0, a2
+	st.b	t0, (a3)
+	bez	t0, 5f
+	xtrb1	t0, a2
+	st.b	t0, (a3, 1)
+	bez	t0, 5f
+	xtrb2	t0, a2
+	st.b	t0, (a3, 2)
+	bez	t0, 5f
+	stw	a2, (a3)
+# else
+	xtrb3	t0, a2
+	st.b	t0, (a3)
+	bez	t0, 5f
+	xtrb2	t0, a2
+	st.b	t0, (a3, 1)
+	bez	t0, 5f
+	xtrb1	t0, a2
+	st.b	t0, (a3, 2)
+	bez	t0, 5f
+	stw	a2, (a3)
+# endif	/* !__CSKYBE__ */
+5:
+	jmp	r15
+
+END (strcpy)
+
+libc_hidden_def (strcpy)
+.weak strcpy
diff --git a/sysdeps/csky/abort-instr.h b/sysdeps/csky/abort-instr.h
new file mode 100644
index 0000000..27a3536
--- /dev/null
+++ b/sysdeps/csky/abort-instr.h
@@ -0,0 +1,2 @@ 
+/* An instruction which should crash any program is a breakpoint.  */
+#define ABORT_INSTRUCTION asm ("bkpt")
diff --git a/sysdeps/csky/bits/endian.h b/sysdeps/csky/bits/endian.h
new file mode 100644
index 0000000..faee072
--- /dev/null
+++ b/sysdeps/csky/bits/endian.h
@@ -0,0 +1,10 @@ 
+#ifndef _ENDIAN_H
+# error "Never use <bits/endian.h> directly; include <endian.h> instead."
+#endif
+
+/* C-SKY can be either big or little endian.  */
+#ifdef __CSKYBE__
+# define __BYTE_ORDER __BIG_ENDIAN
+#else
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
diff --git a/sysdeps/csky/bits/link.h b/sysdeps/csky/bits/link.h
new file mode 100644
index 0000000..4cd2846
--- /dev/null
+++ b/sysdeps/csky/bits/link.h
@@ -0,0 +1,55 @@ 
+/* Machine-specific declarations for dynamic linker interface.  C-SKY 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/>.  */
+
+#ifndef	_LINK_H
+# error "Never include <bits/link.h> directly; use <link.h> instead."
+#endif
+
+/* Registers for entry into PLT on C-SKY.  */
+typedef struct La_csky_regs
+{
+  uint32_t lr_reg[4];
+  uint32_t lr_sp;
+  uint32_t lr_lr;
+} La_csky_regs;
+
+/* Return values for calls from PLT on C-SKY.  */
+typedef struct La_csky_retval
+{
+  /* Up to four integer registers can be used for a return value.  */
+  uint32_t lrv_reg[4];
+  uint32_t lrv_v0;
+} La_csky_retval;
+
+__BEGIN_DECLS
+
+extern Elf32_Addr la_csky_gnu_pltenter (Elf32_Sym *__sym, unsigned int __ndx,
+				        uintptr_t *__refcook,
+				        uintptr_t *__defcook,
+				        La_csky_regs *__regs,
+				        unsigned int *__flags,
+				        const char *__symname,
+				        long int *__framesizep);
+extern unsigned int la_csky_gnu_pltexit (Elf32_Sym *__sym, unsigned int __ndx,
+					 uintptr_t *__refcook,
+					 uintptr_t *__defcook,
+					 const La_csky_regs *__inregs,
+					 La_csky_retval *__outregs,
+					 const char *__symname);
+
+__END_DECLS
diff --git a/sysdeps/csky/bits/setjmp.h b/sysdeps/csky/bits/setjmp.h
new file mode 100644
index 0000000..e5f71a6
--- /dev/null
+++ b/sysdeps/csky/bits/setjmp.h
@@ -0,0 +1,34 @@ 
+/* Define the machine-dependent type `jmp_buf'. C-SKY 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/>.  */
+
+#ifndef _CSKY_BITS_SETJMP_H
+#define _CSKY_BITS_SETJMP_H 1
+
+typedef struct __jmp_buf_str
+  {
+    /* Stack pointer.  */
+    int __sp;
+    int __lr;
+    /* The actual core defines which registers should be saved. The
+       buffer contains 32 words, keep space for future growth.
+       Callee-saved registers:
+       r4 ~ r11, r16 ~ r17, r26 ~r31 for abiv2; r8 ~ r14 for abiv1. */
+    int __regs[32];
+  } __jmp_buf[1];
+
+#endif
diff --git a/sysdeps/csky/bsd-_setjmp.S b/sysdeps/csky/bsd-_setjmp.S
new file mode 100644
index 0000000..4e6a2da
--- /dev/null
+++ b/sysdeps/csky/bsd-_setjmp.S
@@ -0,0 +1 @@ 
+/* _setjmp is in setjmp.S  */
diff --git a/sysdeps/csky/bsd-setjmp.S b/sysdeps/csky/bsd-setjmp.S
new file mode 100644
index 0000000..1da848d
--- /dev/null
+++ b/sysdeps/csky/bsd-setjmp.S
@@ -0,0 +1 @@ 
+/* setjmp is in setjmp.S  */
diff --git a/sysdeps/csky/crti.S b/sysdeps/csky/crti.S
new file mode 100644
index 0000000..3f4b7fb
--- /dev/null
+++ b/sysdeps/csky/crti.S
@@ -0,0 +1,96 @@ 
+/* Special .init and .fini section support for C-SKY.
+   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.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file with other
+   programs, and to distribute those programs without any restriction
+   coming from the use of this file. (The GNU Lesser General Public
+   License restrictions do apply in other respects; for example, they
+   cover modification of the file, and distribution when not linked
+   into another program.)
+
+   Note that people who make modified versions of this file are not
+   obligated to grant this special exception for their modified
+   versions; it is their choice whether to do so. The GNU Lesser
+   General Public License gives permission to release a modified
+   version without this exception; this exception also makes it
+   possible to release a modified version which carries forward this
+   exception.
+
+   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/>.  */
+
+/* crti.S puts a function prologue at the beginning of the .init and
+   .fini sections and defines global symbols for those addresses, so
+   they can be called as functions.  The symbols _init and _fini are
+   magic and cause the linker to emit DT_INIT and DT_FINI.  */
+
+#include <libc-symbols.h>
+#include <sysdep.h>
+
+#ifndef PREINIT_FUNCTION
+# define PREINIT_FUNCTION __gmon_start__
+#endif
+
+#ifndef PREINIT_FUNCTION_WEAK
+# define PREINIT_FUNCTION_WEAK 1
+#endif
+
+#if PREINIT_FUNCTION_WEAK
+	weak_extern (PREINIT_FUNCTION)
+#else
+	.hidden PREINIT_FUNCTION
+#endif
+
+	.section .init,"ax",@progbits
+	.align 4
+	.globl _init
+	.type _init, @function
+_init:
+	subi	sp, 8
+	stw	lr, (sp, 0)
+	stw	gb, (sp, 4)
+	bsr	.Lgetpc
+.Lgetpc:
+	lrw	gb, .Lgetpc@GOTPC
+	add	gb, lr
+#if PREINIT_FUNCTION_WEAK
+	lrw	a2, PREINIT_FUNCTION@GOT
+	addu	a2, gb
+	ldw	a2, (a2)
+	cmpnei	a2, 0
+	bf	1f
+	jsr	a2
+1:
+#else
+	jsri	PREINIT_FUNCTION
+#endif /* PREINIT_FUNCTION_WEAK */
+	br	2f
+	.literals
+	.align 4
+2:
+
+	.section .fini,"ax",@progbits
+	.align 4
+	.globl _fini
+	.type _fini, @function
+_fini:
+	subi	sp,8
+	stw	lr, (sp, 0)
+	br	2f
+	.literals
+	.align 4
+2:
diff --git a/sysdeps/csky/crtn.S b/sysdeps/csky/crtn.S
new file mode 100644
index 0000000..c7d5fbe
--- /dev/null
+++ b/sysdeps/csky/crtn.S
@@ -0,0 +1,50 @@ 
+/* Special .init and .fini section support for C-SKY.
+   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.
+
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file with other
+   programs, and to distribute those programs without any restriction
+   coming from the use of this file. (The GNU Lesser General Public
+   License restrictions do apply in other respects; for example, they
+   cover modification of the file, and distribution when not linked
+   into another program.)
+
+   Note that people who make modified versions of this file are not
+   obligated to grant this special exception for their modified
+   versions; it is their choice whether to do so. The GNU Lesser
+   General Public License gives permission to release a modified
+   version without this exception; this exception also makes it
+   possible to release a modified version which carries forward this
+   exception.
+
+   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>
+
+/* crtn.S puts function epilogues in the .init and .fini sections
+   corresponding to the prologues in crti.S. */
+
+	.section .init,"ax",@progbits
+	ldw	lr, (sp, 0)
+	ldw     gb, (sp, 4)
+	addi	sp, 8
+	rts
+
+	.section .fini,"ax",@progbits
+	ldw	lr, (sp, 0)
+	addi	sp,8
+	rts
diff --git a/sysdeps/csky/gccframe.h b/sysdeps/csky/gccframe.h
new file mode 100644
index 0000000..9451101
--- /dev/null
+++ b/sysdeps/csky/gccframe.h
@@ -0,0 +1,21 @@ 
+/* Definition of object in frame unwind info.  C-SKY 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 FIRST_PSEUDO_REGISTER 71
+
+#include <sysdeps/generic/gccframe.h>
diff --git a/sysdeps/csky/jmpbuf-unwind.h b/sysdeps/csky/jmpbuf-unwind.h
new file mode 100644
index 0000000..954d7e0
--- /dev/null
+++ b/sysdeps/csky/jmpbuf-unwind.h
@@ -0,0 +1,48 @@ 
+/* Examine __jmp_buf for unwinding frames.  C-SkY 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/>.  */
+
+#include <setjmp.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) < (void *) demangle ((jmpbuf)[0].__sp))
+
+#define _JMPBUF_CFA_UNWINDS_ADJ(_jmpbuf, _context, _adj)		      \
+  _JMPBUF_UNWINDS_ADJ (_jmpbuf,						      \
+		       (void *) (_Unwind_Ptr) _Unwind_GetCFA (_context),      \
+		       _adj)
+
+static inline uintptr_t __attribute__ ((unused))
+_jmpbuf_sp (__jmp_buf regs)
+{
+  uintptr_t sp = (uintptr_t) regs[0].__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/csky/machine-gmon.h b/sysdeps/csky/machine-gmon.h
new file mode 100644
index 0000000..4ef9ca7
--- /dev/null
+++ b/sysdeps/csky/machine-gmon.h
@@ -0,0 +1,32 @@ 
+/* Machine-dependent definitions for profiling support.  C-SKY 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/>.  */
+
+#include <sysdep.h>
+
+/* GCC for the C-SKY cannot compile __builtin_return_address (N) for N != 0,
+   so we must use an assembly stub.  */
+
+/* We must not pollute the global namespace.  */
+#define mcount_internal __mcount_internal
+
+extern void mcount_internal (u_long frompc, u_long selfpc);
+#define _MCOUNT_DECL(frompc, selfpc) \
+  void mcount_internal (u_long frompc, u_long selfpc)
+
+/* Define MCOUNT as empty since we have the implementation in another file.  */
+#define MCOUNT
diff --git a/sysdeps/csky/memusage.h b/sysdeps/csky/memusage.h
new file mode 100644
index 0000000..67f36cc
--- /dev/null
+++ b/sysdeps/csky/memusage.h
@@ -0,0 +1,21 @@ 
+/* Machine-specific definitions for memory usage profiling, C-SKY 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 GETSP() ({ register uintptr_t stack_ptr asm ("sp"); stack_ptr; })
+
+#include <sysdeps/generic/memusage.h>
diff --git a/sysdeps/csky/stackinfo.h b/sysdeps/csky/stackinfo.h
new file mode 100644
index 0000000..9b915ba
--- /dev/null
+++ b/sysdeps/csky/stackinfo.h
@@ -0,0 +1,29 @@ 
+/* Stack environment definitions.  C-SKY 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/>.  */
+
+#ifndef _STACKINFO_H
+#define _STACKINFO_H	1
+
+#include <elf.h>
+
+/* On C-SKY the stack grows down.  */
+#define _STACK_GROWS_DOWN	1
+
+#define DEFAULT_STACK_PERMS (PF_R|PF_W)
+
+#endif	/* stackinfo.h */
diff --git a/sysdeps/csky/sysdep.h b/sysdeps/csky/sysdep.h
new file mode 100644
index 0000000..a5c221d
--- /dev/null
+++ b/sysdeps/csky/sysdep.h
@@ -0,0 +1,45 @@ 
+/* Assembler macros for C-SKY.
+   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/>.  */
+
+#include <sysdeps/generic/sysdep.h>
+#include <features.h>
+
+#ifndef __CSKYABIV2__
+#error "No support for C-SKY ABIV1"
+#else
+# define CSKY_ABIV2
+#endif
+
+#ifdef __ASSEMBLER__
+
+#define ASM_SIZE_DIRECTIVE(name) .size name,.-name
+
+/* Define an entry point visible from C.  */
+#define ENTRY(name)	\
+  .globl name;		\
+  .type name,@function;	\
+  .align 4;		\
+  name##:;		\
+  cfi_startproc;	\
+
+#undef  END
+#define END(name)	\
+  cfi_endproc;		\
+  ASM_SIZE_DIRECTIVE(name)
+
+#endif