diff --git a/sysdeps/csky/abiv2/__longjmp.S b/sysdeps/csky/abiv2/__longjmp.S
new file mode 100644
index 0000000..cef4d83
--- /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..e59d20f
--- /dev/null
+++ b/sysdeps/csky/abiv2/csky-mcount.S
@@ -0,0 +1,67 @@
+/* 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/>.  */
+
+#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 _mount
+   <function body>
+*/
+
+/* Don't call mcount when calling mcount...  */
+#undef PROF
+
+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)
+#ifdef __PIC__
+	grs	t1, .Lgetpc
+.Lgetpc:
+	lrw	t0, .Lgetpc@GOTPC
+	addu	t1, t0
+	lrw	t0, __mcount_internal@PLT
+	ldr.w	t0, (t1, t0 << 0)
+	jsr	t0
+#else
+	jsri    __mcount_internal
+#endif /* !__PIC__ */
+	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)
diff --git a/sysdeps/csky/abiv2/dl-trampoline.S b/sysdeps/csky/abiv2/dl-trampoline.S
new file mode 100644
index 0000000..b6d6268
--- /dev/null
+++ b/sysdeps/csky/abiv2/dl-trampoline.S
@@ -0,0 +1,50 @@
+/* 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>
+
+	.globl _dl_runtime_resolve;
+	.type _dl_runtime_resolve,@function;
+	.align 4;
+_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
+	.size _dl_runtime_resolve,.-_dl_runtime_resolve
diff --git a/sysdeps/csky/abiv2/memcmp.S b/sysdeps/csky/abiv2/memcmp.S
new file mode 100644
index 0000000..d23f7e7
--- /dev/null
+++ b/sysdeps/csky/abiv2/memcmp.S
@@ -0,0 +1,142 @@
+/* The assembly function for memory 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 (memcmp)
+	/* Test if len less than 4 bytes.  */
+	mov	r3, r0
+	movi	r0, 0
+	mov	r12, r4
+	cmplti	r2, 4
+	jbt	.L_compare_by_byte
+
+	andi	r13, r0, 3
+	movi	r19, 4
+	/* Test if s1 is not 4 bytes aligned.  */
+	bnez	r13, .L_s1_not_aligned
+
+	LABLE_ALIGN
+.L_s1_aligned:
+	/* If dest is aligned, then copy.  */
+	zext	r18, r2, 31, 4
+	/* Test if len less than 16 bytes.  */
+	bez	r18, .L_compare_by_word
+
+.L_compare_by_4word:
+	/* If aligned, load word each time.  */
+	ldw	r20, (r3, 0)
+	ldw	r21, (r1, 0)
+	/* If s1[i] != s2[i], goto .L_byte_check.  */
+	cmpne	r20, r21
+	bt	.L_byte_check
+
+	ldw	r20, (r3, 4)
+	ldw	r21, (r1, 4)
+	cmpne	r20, r21
+	bt	.L_byte_check
+
+	ldw	r20, (r3, 8)
+	ldw	r21, (r1, 8)
+	cmpne	r20, r21
+	bt	.L_byte_check
+
+	ldw	r20, (r3, 12)
+	ldw	r21, (r1, 12)
+	cmpne	r20, r21
+	bt	.L_byte_check
+
+	PRE_BNEZAD (r18)
+	addi	a3, 16
+	addi	a1, 16
+
+	BNEZAD (r18, .L_compare_by_4word)
+
+.L_compare_by_word:
+	zext	r18, r2, 3, 2
+	bez	r18, .L_compare_by_byte
+.L_compare_by_word_loop:
+	ldw	r20, (r3, 0)
+	ldw	r21, (r1, 0)
+	addi	r3, 4
+	PRE_BNEZAD (r18)
+	cmpne	r20, r21
+	addi	r1, 4
+	bt	.L_byte_check
+	BNEZAD (r18, .L_compare_by_word_loop)
+
+.L_compare_by_byte:
+	zext	r18, r2, 1, 0
+	bez	r18, .L_return
+.L_compare_by_byte_loop:
+	ldb	r0, (r3, 0)
+	ldb	r4, (r1, 0)
+	addi	r3, 1
+	subu	r0, r4
+	PRE_BNEZAD (r18)
+	addi	r1, 1
+	bnez	r0, .L_return
+	BNEZAD (r18, .L_compare_by_byte_loop)
+
+.L_return:
+	mov	r4, r12
+	rts
+
+	/* s1[i] != s2[i] in word, so we check byte 3.  */
+.L_byte_check:
+	xtrb3	r0, r20
+	xtrb3	r2, r21
+	subu	r0, r2
+	bnez	r0, .L_return
+
+	/* check byte 2 */
+	xtrb2	r0, r20
+	xtrb2	r2, r21
+	subu	r0, r2
+	bnez	r0, .L_return
+
+	/* check byte 1 */
+	xtrb1	r0, r20
+	xtrb1	r2, r21
+	subu	r0, r2
+	bnez	r0, .L_return
+
+	/* check byte 0 */
+	xtrb0	r0, r20
+	xtrb0	r2, r21
+	subu	r0, r2
+	br	.L_return
+
+	/* Compare when s1 is not aligned.  */
+.L_s1_not_aligned:
+	sub	r13, r19, r13
+	sub	r2, r13
+.L_s1_not_aligned_loop:
+	ldb	r0, (r3, 0)
+	ldb	r4, (r1, 0)
+	addi	r3, 1
+	subu	r0, r4
+	PRE_BNEZAD (r13)
+	addi	r1, 1
+	bnez	r0, .L_return
+	BNEZAD (r13, .L_s1_not_aligned_loop)
+	br	.L_s1_aligned
+END (memcmp)
+weak_alias (memcmp, bcmp)
+libc_hidden_def (memcmp)
+.weak memcmp
diff --git a/sysdeps/csky/abiv2/memcpy.S b/sysdeps/csky/abiv2/memcpy.S
new file mode 100644
index 0000000..812bdd4
--- /dev/null
+++ b/sysdeps/csky/abiv2/memcpy.S
@@ -0,0 +1,238 @@
+/* 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>
+
+ENTRY (memcpy)
+	/* Test if len less than 4 bytes.  */
+	mov	r12, r0
+	cmplti	r2, 4
+	bt	.L_copy_by_byte
+
+	andi	r13, r0, 3
+	movi	r19, 4
+	/* Test if dest is not 4 bytes aligned.  */
+	bnez	r13, .L_dest_not_aligned
+.L_dest_aligned:
+	/* If dest is aligned, then copy.  */
+	zext	r18, r2, 31, 4
+	/* Test if len less than 16 bytes.  */
+	bez	r18, .L_len_less_16bytes
+	movi	r19, 0
+
+	LABLE_ALIGN
+.L_len_larger_16bytes:
+#if defined (__CSKY_VDSPV2__)
+	vldx.8	vr0, (r1), r19
+	PRE_BNEZAD (r18)
+	addi	r1, 16
+	vstx.8	vr0, (r0), r19
+	addi	r0, 16
+#elif defined (__csky_fpuv2__) && defined(__CK810__)
+	fldd	fr4, (r1, 0)
+	PRE_BNEZAD (r18)
+	fstd	fr4, (r0, 0)
+	fldd	fr4, (r1, 8)
+	addi	r1, 16
+	fstd	fr4, (r0, 8)
+	addi	r0, 16
+#elif defined (__CK860__)
+	ldw	r3, (r1, 0)
+	stw	r3, (r0, 0)
+	ldw	r3, (r1, 4)
+	stw	r3, (r0, 4)
+	ldw	r3, (r1, 8)
+	stw	r3, (r0, 8)
+	ldw	r3, (r1, 12)
+	addi	r1, 16
+	stw	r3, (r0, 12)
+	addi	r0, 16
+#else
+	ldw	r20, (r1, 0)
+	ldw	r21, (r1, 4)
+	ldw	r22, (r1, 8)
+	ldw	r23, (r1, 12)
+	stw	r20, (r0, 0)
+	stw	r21, (r0, 4)
+	stw	r22, (r0, 8)
+	stw	r23, (r0, 12)
+	PRE_BNEZAD (r18)
+	addi	r1, 16
+	addi	r0, 16
+#endif
+	BNEZAD (r18, .L_len_larger_16bytes)
+
+.L_len_less_16bytes:
+	zext	r18, r2, 3, 2
+	bez	r18, .L_copy_by_byte
+.L_len_less_16bytes_loop:
+	ldw	r3, (r1, 0)
+	PRE_BNEZAD (r18)
+	addi	r1, 4
+	stw	r3, (r0, 0)
+	addi	r0, 4
+	BNEZAD (r18, .L_len_less_16bytes_loop)
+
+	/* Test if len less than 4 bytes.  */
+.L_copy_by_byte:
+	zext	r18, r2, 1, 0
+	bez	r18, .L_return
+.L_copy_by_byte_loop:
+	ldb	r3, (r1, 0)
+	PRE_BNEZAD (r18)
+	addi	r1, 1
+	stb	r3, (r0, 0)
+	addi	r0, 1
+	BNEZAD (r18, .L_copy_by_byte_loop)
+
+.L_return:
+	mov	r0, r12
+	rts
+
+	/* If dest is not aligned, just copying some bytes makes the dest
+	   align.  */
+
+.L_dest_not_aligned:
+	sub	r13, r19, r13
+	mov	r19, r13
+.L_dest_not_aligned_loop:
+	/* Makes the dest align.  */
+	ldb	r3, (r1, 0)
+	PRE_BNEZAD (r13)
+	addi	r1, 1
+	stb	r3, (r0, 0)
+	addi	r0, 1
+	BNEZAD (r13, .L_dest_not_aligned_loop)
+	sub	r2, r19
+	cmplti	r2, 4
+	bt	.L_copy_by_byte
+	/* Check whether the src is aligned.  */
+	br	.L_dest_aligned
+END (memcpy)
+
+libc_hidden_builtin_def (memcpy)
+.weak memcpy
+
+
+ENTRY (memmove)
+	subu	r3, r0, r1
+	cmphs	r3, r2
+	bt	memcpy
+
+	mov	r12, r0
+	addu	r0, r0, r2
+	addu	r1, r1, r2
+
+	/* Test if len less than 4 bytes.  */
+	cmplti	r2, 4
+	bt	.L_copy_by_byte_m
+
+	andi	r13, r0, 3
+	/* Test if dest is not 4 bytes aligned.  */
+	bnez	r13, .L_dest_not_aligned_m
+.L_dest_aligned_m:
+	/* If dest is aligned, then copy.  */
+	zext	r18, r2, 31, 4
+	/* Test if len less than 16 bytes.  */
+	bez	r18, .L_len_less_16bytes_m
+	movi	r19, 0
+
+	/* len > 16 bytes */
+	LABLE_ALIGN
+.L_len_larger_16bytes_m:
+	subi	r1, 16
+	subi	r0, 16
+#if defined (__CSKY_VDSPV2__)
+	vldx.8	vr0, (r1), r19
+	PRE_BNEZAD (r18)
+	vstx.8	vr0, (r0), r19
+#elif defined (__csky_fpuv2__) && defined(__CK810__)
+	fldd	fr4, (r1, 8)
+	PRE_BNEZAD (r18)
+	fstd	fr4, (r0, 8)
+	fldd	fr4, (r1, 0)
+	fstd	fr4, (r0, 0)
+#elif defined (__CK860__)
+	ldw	r3, (r1, 12)
+	stw	r3, (r0, 12)
+	ldw	r3, (r1, 8)
+	stw	r3, (r0, 8)
+	ldw	r3, (r1, 4)
+	stw	r3, (r0, 4)
+	ldw	r3, (r1, 0)
+	stw	r3, (r0, 0)
+#else
+	ldw	r20, (r1, 0)
+	ldw	r21, (r1, 4)
+	ldw	r22, (r1, 8)
+	ldw	r23, (r1, 12)
+	stw	r20, (r0, 0)
+	stw	r21, (r0, 4)
+	stw	r22, (r0, 8)
+	stw	r23, (r0, 12)
+	PRE_BNEZAD (r18)
+#endif
+	BNEZAD (r18, .L_len_larger_16bytes_m)
+
+.L_len_less_16bytes_m:
+	zext	r18, r2, 3, 2
+	bez	r18, .L_copy_by_byte_m
+.L_len_less_16bytes_loop_m:
+	subi	r1, 4
+	subi	r0, 4
+	ldw	r3, (r1, 0)
+	PRE_BNEZAD (r18)
+	stw	r3, (r0, 0)
+	BNEZAD (r18, .L_len_less_16bytes_loop_m)
+
+	/* Test if len less than 4 bytes.  */
+.L_copy_by_byte_m:
+	zext	r18, r2, 1, 0
+	bez	r18, .L_return_m
+.L_copy_by_byte_loop_m:
+	subi	r1, 1
+	subi	r0, 1
+	ldb	r3, (r1, 0)
+	PRE_BNEZAD (r18)
+	stb	r3, (r0, 0)
+	BNEZAD (r18, .L_copy_by_byte_loop_m)
+
+.L_return_m:
+	mov	r0, r12
+	rts
+
+	/* If dest is not aligned, just copying some bytes makes the dest
+	   align.  */
+.L_dest_not_aligned_m:
+	sub	r2, r13
+.L_dest_not_aligned_loop_m:
+	subi	r1, 1
+	subi	r0, 1
+	/* Makes the dest align.  */
+	ldb	r3, (r1, 0)
+	PRE_BNEZAD (r13)
+	stb	r3, (r0, 0)
+	BNEZAD (r13, .L_dest_not_aligned_loop_m)
+	cmplti	r2, 4
+	bt	.L_copy_by_byte_m
+	/* Check whether the src is aligned.  */
+	br	.L_dest_aligned_m
+END (memmove)
+
+libc_hidden_builtin_def (memmove)
+.weak memmove
diff --git a/sysdeps/csky/abiv2/memmove.S b/sysdeps/csky/abiv2/memmove.S
new file mode 100644
index 0000000..5a35458
--- /dev/null
+++ b/sysdeps/csky/abiv2/memmove.S
@@ -0,0 +1 @@
+/* memmove is in memcpy.S.  */
diff --git a/sysdeps/csky/abiv2/memset.S b/sysdeps/csky/abiv2/memset.S
new file mode 100644
index 0000000..dd54a4e
--- /dev/null
+++ b/sysdeps/csky/abiv2/memset.S
@@ -0,0 +1,98 @@
+/* The assembly function for memset.  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 (memset)
+	/* Test if len less than 4 bytes.  */
+	mov	r12, r0
+	cmplti	r2, 8
+	bt	.L_set_by_byte
+
+	andi	r13, r0, 3
+	movi	r19, 4
+	/* Test if dest is not 4 bytes aligned.  */
+	bnez	r13, .L_dest_not_aligned
+	/* Hardware can handle unaligned access directly.  */
+.L_dest_aligned:
+	zextb	r1, r1
+	mov	r3, r1
+	lsli	r1, 8
+	or	r1, r3
+	lsli	r3, r1, 16
+	or	r3, r1
+
+	/* If dest is aligned, then copy.  */
+	zext	r18, r2, 31, 4
+	/* Test if len less than 16 bytes.  */
+	bez	r18, .L_len_less_16bytes
+
+	LABLE_ALIGN
+.L_len_larger_16bytes:
+	stw	r3, (r0, 0)
+	stw	r3, (r0, 4)
+	stw	r3, (r0, 8)
+	stw	r3, (r0, 12)
+	PRE_BNEZAD (r18)
+	addi	r0, 16
+	BNEZAD (r18, .L_len_larger_16bytes)
+
+.L_len_less_16bytes:
+	zext	r18, r2, 3, 2
+	andi	r2, 3
+	bez	r18, .L_set_by_byte
+.L_len_less_16bytes_loop:
+	stw	r3, (r0, 0)
+	PRE_BNEZAD (r18)
+	addi	r0, 4
+	BNEZAD (r18, .L_len_less_16bytes_loop)
+
+	/* Test if len less than 4 bytes.  */
+.L_set_by_byte:
+	zext	r18, r2, 2, 0
+	bez	r18, .L_return
+.L_set_by_byte_loop:
+	stb	r1, (r0, 0)
+	PRE_BNEZAD (r18)
+	addi	r0, 1
+	BNEZAD (r18, .L_set_by_byte_loop)
+
+.L_return:
+	mov	r0, r12
+	rts
+
+	/* If dest is not aligned, just set some bytes makes the dest
+	   align.  */
+
+.L_dest_not_aligned:
+	sub	r13, r19, r13
+	sub	r2, r13
+.L_dest_not_aligned_loop:
+	/* Makes the dest align.  */
+	stb	r1, (r0, 0)
+	PRE_BNEZAD (r13)
+	addi	r0, 1
+	BNEZAD (r13, .L_dest_not_aligned_loop)
+	cmplti	r2, 8
+	bt	.L_set_by_byte
+	/* Check whether the src is aligned.  */
+	br	.L_dest_aligned
+END (memset)
+
+libc_hidden_builtin_def (memset)
+.weak memset
diff --git a/sysdeps/csky/abiv2/setjmp.S b/sysdeps/csky/abiv2/setjmp.S
new file mode 100644
index 0000000..a6cc7e5
--- /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..bad3cac
--- /dev/null
+++ b/sysdeps/csky/abiv2/start.S
@@ -0,0 +1,108 @@
+/* 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
+	.globl _start;
+	.type _start,@function;
+	.align 4;
+_start:
+	subi	sp, 8
+	/* Clear the 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, 8)	/* Init argc for __libc_start_main.  */
+	addi	a2, sp, 12	/* Init argv for __libc_start_main.  */
+
+	/* Push stack limit.  */
+	stw	a2, (sp, 8)
+	/* Push rtld_fini.  */
+	stw	a0, (sp, 4)
+
+#ifdef SHARED
+	grs	t0, .Lgetpc
+.Lgetpc:
+	lrw	gb, .Lgetpc@GOTPC
+	addu	gb, t0
+	lrw	a3, __libc_csu_fini@GOT
+	ldr.w	a3, (gb, a3 << 0)
+	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
+	ldr.w	t1, (gb, t1 << 0)
+	jsr	t1
+
+	lrw	t1, abort@PLT
+	ldr.w	t1, (gb, t1 << 0)
+	jsr	t1
+#else
+	/* Fetch address of __libc_csu_fini.  */
+	lrw	a0, __libc_csu_fini
+	/* Push __libc_csu_fini */
+	stw	a0, (sp, 0)
+
+	/* Set up the other arguments in registers.  */
+	lrw	a0, main
+	lrw	a3, __libc_csu_init
+	/* Let the libc call main and exit with its return code.  */
+	jsri	__libc_start_main
+
+	/* Should never get here.  */
+	jsri	abort
+#endif	/* !SHARED */
+	.size _start,.-_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..b0fee81
--- /dev/null
+++ b/sysdeps/csky/abiv2/strcmp.S
@@ -0,0 +1,156 @@
+/* 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
+	/* Check if the s1 addr is aligned.  */
+	xor	a2, a3, a1
+	andi	a2, 0x3
+	bnez	a2, 7f
+	andi	t1, a0, 0x3
+	bnez	t1, 5f
+
+1:
+	/* If aligned, load word each time.  */
+	ldw	t0, (a3, 0)
+	ldw	t1, (a1, 0)
+	/* If s1[i] != s2[i], goto 2f.  */
+	cmpne	t0, t1
+	bt	2f
+	/* If s1[i] == s2[i], check if s1 or s2 is at the end.  */
+	tstnbz	t0
+	/* If at the end, goto 3f (finish comparing).  */
+	bf	3f
+
+	ldw	t0, (a3, 4)
+	ldw	t1, (a1, 4)
+	cmpne	t0, t1
+	bt	2f
+	tstnbz	t0
+	bf	3f
+
+	ldw	t0, (a3, 8)
+	ldw	t1, (a1, 8)
+	cmpne	t0, t1
+	bt	2f
+	tstnbz	t0
+	bf	3f
+
+	ldw	t0, (a3, 12)
+	ldw	t1, (a1, 12)
+	cmpne	t0, t1
+	bt	2f
+	tstnbz	t0
+	bf	3f
+
+	ldw	t0, (a3, 16)
+	ldw	t1, (a1, 16)
+	cmpne	t0, t1
+	bt	2f
+	tstnbz	t0
+	bf	3f
+
+	ldw	t0, (a3, 20)
+	ldw	t1, (a1, 20)
+	cmpne	t0, t1
+	bt	2f
+	tstnbz	t0
+	bf	3f
+
+	ldw	t0, (a3, 24)
+	ldw	t1, (a1, 24)
+	cmpne	t0, t1
+	bt	2f
+	tstnbz	t0
+	bf	3f
+
+	ldw	t0, (a3, 28)
+	ldw	t1, (a1, 28)
+	cmpne	t0, t1
+	bt	2f
+	tstnbz	t0
+	bf	3f
+
+	addi	a3, 32
+	addi	a1, 32
+
+	br	1b
+
+	/* s1[i] != s2[i] in word, so we check byte 3.  */
+2:
+	xtrb3	a0, t0
+	xtrb3	a2, t1
+	subu	a0, a2
+	bez	a2, 4f
+	bnez	a0, 4f
+
+	/* Check byte 2.  */
+	xtrb2	a0, t0
+	xtrb2	a2, t1
+	subu	a0, a2
+	bez	a2, 4f
+	bnez	a0, 4f
+
+	/* Check byte 1.  */
+	xtrb1	a0, t0
+	xtrb1	a2, t1
+	subu	a0, a2
+	bez	a2, 4f
+	bnez	a0, 4f
+
+	/* Check byte 0.  */
+	xtrb0	a0, t0
+	xtrb0	a2, t1
+	subu	a0, a2
+
+	jmp	lr
+3:
+	movi	a0, 0
+4:
+	jmp	lr
+
+	/* Compare when s1 or s2 is not aligned.  */
+5:
+	subi	t1, 4
+6:
+	ldb	a0, (a3, 0)
+	ldb	a2, (a1, 0)
+	subu	a0, a2
+	bnez	a0, 4b
+	addi	t1, 1
+	bez	a2, 4b
+	addi	a1, 1
+	addi	a3, 1
+	bez	t1, 1b
+	br	6b
+
+7:
+	ldb	a0, (a3, 0)
+	addi	a3, 1
+	ldb	a2, (a1, 0)
+	addi	a1, 1
+	subu	a0, a2
+	bnez	a0, 4b
+	bnez	a2, 7b
+	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..3da4fbe
--- /dev/null
+++ b/sysdeps/csky/abiv2/strcpy.S
@@ -0,0 +1,127 @@
+/* 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
+	/* Check if the src addr is aligned.  */
+	andi	t0, a1, 3
+	bnez	t0, 11f
+1:
+	/* Check if all the bytes in the word are not zero.  */
+	ldw	a2, (a1)
+	tstnbz	a2
+	bf	9f
+	stw	a2, (a3)
+
+	ldw	a2, (a1, 4)
+	tstnbz	a2
+	bf	2f
+	stw	a2, (a3, 4)
+
+	ldw	a2, (a1, 8)
+	tstnbz	a2
+	bf	3f
+	stw	a2, (a3, 8)
+
+	ldw	a2, (a1, 12)
+	tstnbz	a2
+	bf	4f
+	stw	a2, (a3, 12)
+
+	ldw	a2, (a1, 16)
+	tstnbz	a2
+	bf	5f
+	stw	a2, (a3, 16)
+
+	ldw	a2, (a1, 20)
+	tstnbz	a2
+	bf	6f
+	stw	a2, (a3, 20)
+
+	ldw	a2, (a1, 24)
+	tstnbz	a2
+	bf	7f
+	stw	a2, (a3, 24)
+
+	ldw	a2, (a1, 28)
+	tstnbz	a2
+	bf	8f
+	stw	a2, (a3, 28)
+
+	addi	a3, 32
+	addi	a1, 32
+	br	1b
+
+2:
+	addi	a3, 4
+	br	9f
+
+3:
+	addi	a3, 8
+	br	9f
+
+4:
+	addi	a3, 12
+	br	9f
+
+5:
+	addi	a3, 16
+	br	9f
+
+6:
+	addi	a3, 20
+	br	9f
+
+7:
+	addi	a3, 24
+	br	9f
+
+8:
+	addi	a3, 28
+9:
+	xtrb3	t0, a2
+	st.b	t0, (a3)
+	bez	t0, 10f
+	xtrb2	t0, a2
+	st.b	t0, (a3, 1)
+	bez	t0, 10f
+	xtrb1	t0, a2
+	st.b	t0, (a3, 2)
+	bez	t0, 10f
+	stw	a2, (a3)
+10:
+	jmp	lr
+
+11:
+	subi	t0, 4
+12:
+	ld.b	a2, (a1)
+	st.b	a2, (a3)
+	bez	a2, 10b
+	addi	t0, 1
+	addi	a1, a1, 1
+	addi	a3, a3, 1
+	bnez	t0, 12b
+	br	1b
+
+END (strcpy)
+
+libc_hidden_def (strcpy)
+.weak strcpy
diff --git a/sysdeps/csky/abiv2/strlen.S b/sysdeps/csky/abiv2/strlen.S
new file mode 100644
index 0000000..96083c3
--- /dev/null
+++ b/sysdeps/csky/abiv2/strlen.S
@@ -0,0 +1,102 @@
+/* The assembly function for string length.  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 (strlen)
+	/* Check if the start addr is aligned.  */
+	mov	r3, r0
+	andi	r1, r0, 3
+	movi	r2, 4
+	movi	r0, 0
+	bnez	r1, .L_start_not_aligned
+
+	LABLE_ALIGN
+.L_start_addr_aligned:
+	/* Check if all the bytes in the word are not zero.  */
+	ldw	r1, (r3)
+	tstnbz	r1
+	bf	.L_string_tail
+
+	ldw	r1, (r3, 4)
+	addi	r0, 4
+	tstnbz	r1
+	bf	.L_string_tail
+
+	ldw	r1, (r3, 8)
+	addi	r0, 4
+	tstnbz	r1
+	bf	.L_string_tail
+
+	ldw	r1, (r3, 12)
+	addi	r0, 4
+	tstnbz	r1
+	bf	.L_string_tail
+
+	ldw	r1, (r3, 16)
+	addi	r0, 4
+	tstnbz	r1
+	bf	.L_string_tail
+
+	ldw	r1, (r3, 20)
+	addi	r0, 4
+	tstnbz	r1
+	bf	.L_string_tail
+
+	ldw	r1, (r3, 24)
+	addi	r0, 4
+	tstnbz	r1
+	bf	.L_string_tail
+
+	ldw	r1, (r3, 28)
+	addi	r0, 4
+	tstnbz	r1
+	bf	.L_string_tail
+
+	addi	r0, 4
+	addi	r3, 32
+	br	.L_start_addr_aligned
+
+.L_string_tail:
+	xtrb3	r3, r1
+	bez	r3, .L_return
+	addi	r0, 1
+	xtrb2	r3, r1
+	bez	r3, .L_return
+	addi	r0, 1
+	xtrb1	r3, r1
+	bez	r3, .L_return
+	addi	r0, 1
+
+.L_return:
+	rts
+
+.L_start_not_aligned:
+	sub	r2, r2, r1
+.L_start_not_aligned_loop:
+	ldb	r1, (r3)
+	PRE_BNEZAD (r2)
+	addi	r3, 1
+	bez	r1, .L_return
+	addi	r0, 1
+	BNEZAD (r2, .L_start_not_aligned_loop)
+	br	.L_start_addr_aligned
+END (strlen)
+
+libc_hidden_def (strlen)
+.weak strlen
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..51df38d
--- /dev/null
+++ b/sysdeps/csky/bits/endian.h
@@ -0,0 +1,9 @@
+#ifndef _ENDIAN_H
+# error "Never use <bits/endian.h> directly; include <endian.h> instead."
+#endif
+
+#ifdef __CSKYBE__
+# error "Big endian not supported for C-SKY."
+#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..13155ac
--- /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..6f0cace
--- /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..90b99cd
--- /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..d3b823c
--- /dev/null
+++ b/sysdeps/csky/bsd-setjmp.S
@@ -0,0 +1 @@
+/* setjmp is in setjmp.S.  */
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..526a7d3
--- /dev/null
+++ b/sysdeps/csky/sysdep.h
@@ -0,0 +1,84 @@
+/* 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>
+
+#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;		\
+	CALL_MCOUNT
+
+# undef  END
+# define END(name)		\
+	cfi_endproc;		\
+	ASM_SIZE_DIRECTIVE(name)
+
+/* If compiled for profiling, call `mcount' at the start of each function.  */
+# ifdef PROF
+#  ifdef __PIC__
+#   define CALL_MCOUNT				\
+	subi	sp, 4;				\
+	stw	lr, (sp, 0);			\
+	grs	t0, .Lgetpc;			\
+.Lgetpc:					\
+	lrw	gb, .Lgetpc@GOTPC;		\
+	addu	gb, t0;				\
+	lrw	t1, _mcount@PLT;		\
+	ldr.w	t0, (gb, t1 << 0);		\
+	jmp	t0;
+#  else
+#   define CALL_MCOUNT				\
+	subi	sp, 4;				\
+	stw	lr, (sp, 0);			\
+	jbsr	_mcount;
+#  endif
+# else
+#  define CALL_MCOUNT	/* Do nothing.  */
+# endif
+
+# if defined (__CK860__)
+/* Instruction fetch will be faster when the label is 16 bytes aligned.
+   Filling with nop instruction to avoid extra jump.  */
+#  define LABLE_ALIGN	\
+	.balignw 16, 0x6c03
+
+#  define PRE_BNEZAD(R)
+
+#  define BNEZAD(R, L)	\
+	bnezad	R, L
+# else
+#  define LABLE_ALIGN	\
+	.balignw 8, 0x6c03
+
+#  define PRE_BNEZAD(R)	\
+	subi	R, 1
+
+#  define BNEZAD(R, L)	\
+	bnez	R, L
+# endif
+
+#endif
