Patchwork [RFC,V2,10/10] C-SKY: Linux ABI

login
register
mail settings
Submitter Han Mao
Date April 8, 2018, 7:02 a.m.
Message ID <0169426b30550679285be2936aed9bf366efedb9.1523169833.git.han_mao@c-sky.com>
Download mbox | patch
Permalink /patch/26652/
State New
Headers show

Comments

Han Mao - April 8, 2018, 7:02 a.m.
Linux-specific code that is required for maintaining ABI compatibility.
This doesn't contain the actual system call interface.

        * sysdeps/csky/nptl/pthread-offsets.h: New file
        * sysdeps/csky/nptl/pthreaddef.h: New file
        * sysdeps/unix/sysv/linux/csky/Versions: New file
        * sysdeps/unix/sysv/linux/csky/bits/fcntl.h: New file
        * sysdeps/unix/sysv/linux/csky/bits/mman.h: New file
        * sysdeps/unix/sysv/linux/csky/bits/shm.h: New file
        * sysdeps/unix/sysv/linux/csky/c++-types.data: New file
        * sysdeps/unix/sysv/linux/csky/csky_readtp.h: New file
        * sysdeps/unix/sysv/linux/csky/ipc_priv.h: New file
        * sysdeps/unix/sysv/linux/csky/jmp_buf-macros.h: New file
        * sysdeps/unix/sysv/linux/csky/kernel-features.h: New file
        * sysdeps/unix/sysv/linux/csky/makecontext.c: New file
        * sysdeps/unix/sysv/linux/csky/profil-counter.h: New file
        * sysdeps/unix/sysv/linux/csky/register-dump.h: New file
        * sysdeps/unix/sysv/linux/csky/setcontext.S: New file
        * sysdeps/unix/sysv/linux/csky/shlib-versions: New file
        * sysdeps/unix/sysv/linux/csky/sigcontextinfo.h: New file
        * sysdeps/unix/sysv/linux/csky/swapcontext.S: New file
        * sysdeps/unix/sysv/linux/csky/sys/cachectl.h: New file
        * sysdeps/unix/sysv/linux/csky/sys/procfs.h: New file
        * sysdeps/unix/sysv/linux/csky/sys/ucontext.h: New file
        * sysdeps/unix/sysv/linux/csky/sys/user.h: New file
        * sysdeps/unix/sysv/linux/csky/sysdep-cancel.h: New file
        * sysdeps/unix/sysv/linux/csky/sysdep.S: New file
        * sysdeps/unix/sysv/linux/csky/sysdep.h: New file
        * sysdeps/unix/sysv/linux/csky/ucontext_i.sym: New file
---
 sysdeps/csky/nptl/pthread-offsets.h            |   5 +
 sysdeps/csky/nptl/pthreaddef.h                 |  40 ++
 sysdeps/unix/sysv/linux/csky/Versions          |  34 ++
 sysdeps/unix/sysv/linux/csky/bits/fcntl.h      |  55 ++
 sysdeps/unix/sysv/linux/csky/bits/mman.h       |  42 ++
 sysdeps/unix/sysv/linux/csky/bits/shm.h        | 103 ++++
 sysdeps/unix/sysv/linux/csky/c++-types.data    |  67 +++
 sysdeps/unix/sysv/linux/csky/csky_readtp.h     |  24 +
 sysdeps/unix/sysv/linux/csky/ipc_priv.h        |  21 +
 sysdeps/unix/sysv/linux/csky/jmp_buf-macros.h  |   6 +
 sysdeps/unix/sysv/linux/csky/kernel-features.h |  29 +
 sysdeps/unix/sysv/linux/csky/makecontext.c     |  81 +++
 sysdeps/unix/sysv/linux/csky/profil-counter.h  |  34 ++
 sysdeps/unix/sysv/linux/csky/register-dump.h   | 218 +++++++
 sysdeps/unix/sysv/linux/csky/setcontext.S      | 128 +++++
 sysdeps/unix/sysv/linux/csky/shlib-versions    |   3 +
 sysdeps/unix/sysv/linux/csky/sigcontextinfo.h  |  37 ++
 sysdeps/unix/sysv/linux/csky/swapcontext.S     | 112 ++++
 sysdeps/unix/sysv/linux/csky/sys/cachectl.h    |  35 ++
 sysdeps/unix/sysv/linux/csky/sys/procfs.h      | 123 ++++
 sysdeps/unix/sysv/linux/csky/sys/ucontext.h    | 111 ++++
 sysdeps/unix/sysv/linux/csky/sys/user.h        |  65 +++
 sysdeps/unix/sysv/linux/csky/sysdep.S          | 110 ++++
 sysdeps/unix/sysv/linux/csky/sysdep.h          | 757 +++++++++++++++++++++++++
 sysdeps/unix/sysv/linux/csky/ucontext_i.sym    |  31 +
 25 files changed, 2271 insertions(+)
 create mode 100644 sysdeps/csky/nptl/pthread-offsets.h
 create mode 100644 sysdeps/csky/nptl/pthreaddef.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/Versions
 create mode 100644 sysdeps/unix/sysv/linux/csky/bits/fcntl.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/bits/mman.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/bits/shm.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/c++-types.data
 create mode 100644 sysdeps/unix/sysv/linux/csky/csky_readtp.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/ipc_priv.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/jmp_buf-macros.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/kernel-features.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/makecontext.c
 create mode 100644 sysdeps/unix/sysv/linux/csky/profil-counter.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/register-dump.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/setcontext.S
 create mode 100644 sysdeps/unix/sysv/linux/csky/shlib-versions
 create mode 100644 sysdeps/unix/sysv/linux/csky/sigcontextinfo.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/swapcontext.S
 create mode 100644 sysdeps/unix/sysv/linux/csky/sys/cachectl.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/sys/procfs.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/sys/ucontext.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/sys/user.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/sysdep.S
 create mode 100644 sysdeps/unix/sysv/linux/csky/sysdep.h
 create mode 100644 sysdeps/unix/sysv/linux/csky/ucontext_i.sym
Joseph Myers - April 17, 2018, 8:56 p.m.
On Sun, 8 Apr 2018, Mao Han wrote:

> diff --git a/sysdeps/unix/sysv/linux/csky/Versions b/sysdeps/unix/sysv/linux/csky/Versions
> new file mode 100644
> index 0000000..bcb77fd
> --- /dev/null
> +++ b/sysdeps/unix/sysv/linux/csky/Versions
> @@ -0,0 +1,34 @@
> +libc {
> +  GLIBC_2.27 {

None of this should be needed, beyond maybe the cacheflush entry; the 
generic Versions entries should suffice.

> +    # Exception handling support functions from libgcc
> +    __register_frame; __register_frame_table; __deregister_frame;
> +    __frame_state_for; __register_frame_info_table;

These should only be in extremely old glibc ports, not anything from the 
past decade.

Patch

diff --git a/sysdeps/csky/nptl/pthread-offsets.h b/sysdeps/csky/nptl/pthread-offsets.h
new file mode 100644
index 0000000..9617354
--- /dev/null
+++ b/sysdeps/csky/nptl/pthread-offsets.h
@@ -0,0 +1,5 @@ 
+#define __PTHREAD_MUTEX_NUSERS_OFFSET   16
+#define __PTHREAD_MUTEX_KIND_OFFSET     12
+#define __PTHREAD_MUTEX_SPINS_OFFSET    20
+#define __PTHREAD_MUTEX_ELISION_OFFSET  22
+#define __PTHREAD_MUTEX_LIST_OFFSET     20
diff --git a/sysdeps/csky/nptl/pthreaddef.h b/sysdeps/csky/nptl/pthreaddef.h
new file mode 100644
index 0000000..f6e3b65
--- /dev/null
+++ b/sysdeps/csky/nptl/pthreaddef.h
@@ -0,0 +1,40 @@ 
+/* 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/>.  */
+
+/* Default stack size.  */
+#define ARCH_STACK_DEFAULT_SIZE	(2 * 1024 * 1024)
+
+/* Required stack pointer alignment at beginning.  */
+#define STACK_ALIGN		8
+
+/* Minimal stack size after allocating thread descriptor and guard size.  */
+#define MINIMAL_REST_STACK	2048
+
+/* Alignment requirement for TCB.  */
+#define TCB_ALIGNMENT		8
+
+
+/* Location of current stack frame.
+
+   __builtin_frame_address (0) returns the value of the hard frame
+   pointer, which will point at the location of the saved PC on the
+   stack.  Below this in memory is the remainder of the linkage info,
+   occupying 12 bytes.  Therefore in order to address from
+   CURRENT_STACK_FRAME using "struct layout", we need to have the macro
+   return the hard FP minus 12.  Of course, this makes no sense
+   without the obsolete APCS stack layout...  */
+#define CURRENT_STACK_FRAME	(__builtin_frame_address (0) - 12)
diff --git a/sysdeps/unix/sysv/linux/csky/Versions b/sysdeps/unix/sysv/linux/csky/Versions
new file mode 100644
index 0000000..bcb77fd
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/Versions
@@ -0,0 +1,34 @@ 
+libc {
+  GLIBC_2.27 {
+    #errlist-compat     134
+    _sys_errlist; sys_errlist; _sys_nerr; sys_nerr;
+
+    # Exception handling support functions from libgcc
+    __register_frame; __register_frame_table; __deregister_frame;
+    __frame_state_for; __register_frame_info_table;
+
+    # c*
+    cacheflush;
+
+    # functions used in other libraries
+    __xstat64; __fxstat64; __lxstat64;
+
+    # a*
+    alphasort64;
+
+    # g*
+    glob64;
+
+    # New rlimit interface
+    getrlimit; setrlimit; getrlimit64;
+
+    # r*
+    readdir64; readdir64_r;
+
+    # s*
+    scandir64;
+
+
+    fallocate64;
+  }
+}
diff --git a/sysdeps/unix/sysv/linux/csky/bits/fcntl.h b/sysdeps/unix/sysv/linux/csky/bits/fcntl.h
new file mode 100644
index 0000000..0f609c5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/bits/fcntl.h
@@ -0,0 +1,55 @@ 
+/* O_*, F_*, FD_* bit values for Linux.
+   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	_FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+#include <bits/wordsize.h>
+
+#if __WORDSIZE == 64
+# define __O_LARGEFILE  0
+#endif
+
+struct flock
+  {
+    short int l_type;   /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
+    short int l_whence; /* Where `l_start' is relative to (like `lseek').  */
+#ifndef __USE_FILE_OFFSET64
+    __off_t l_start;    /* Offset where the lock begins.  */
+    __off_t l_len;      /* Size of the locked area; zero means until EOF.  */
+#else
+    __off64_t l_start;  /* Offset where the lock begins.  */
+    __off64_t l_len;    /* Size of the locked area; zero means until EOF.  */
+#endif
+    __pid_t l_pid;      /* Process holding the lock.  */
+  };
+
+#ifdef __USE_LARGEFILE64
+struct flock64
+  {
+    short int l_type;   /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
+    short int l_whence; /* Where `l_start' is relative to (like `lseek').  */
+    __off64_t l_start;  /* Offset where the lock begins.  */
+    __off64_t l_len;    /* Size of the locked area; zero means until EOF.  */
+    __pid_t l_pid;      /* Process holding the lock.  */
+  };
+#endif
+
+/* Include generic Linux declarations.  */
+#include <bits/fcntl-linux.h>
diff --git a/sysdeps/unix/sysv/linux/csky/bits/mman.h b/sysdeps/unix/sysv/linux/csky/bits/mman.h
new file mode 100644
index 0000000..6ced845
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/bits/mman.h
@@ -0,0 +1,42 @@ 
+/* Definitions for POSIX memory map interface.  Linux/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 _SYS_MMAN_H
+# error "Never use <bits/mman.h> directly; include <sys/mman.h> instead."
+#endif
+
+/* The following definitions basically come from the kernel headers.
+   But the kernel header is not namespace clean.  */
+
+/* These are Linux-specific.  */
+#ifdef __USE_MISC
+# define MAP_GROWSDOWN	0x00100		/* Stack-like segment.  */
+# define MAP_DENYWRITE	0x00800		/* ETXTBSY */
+# define MAP_EXECUTABLE	0x01000		/* Mark it as an executable.  */
+# define MAP_LOCKED	0x02000		/* Lock the mapping.  */
+# define MAP_NORESERVE	0x04000		/* Don't check for reservations.  */
+# define MAP_POPULATE	0x08000		/* Populate (prefault) pagetables.  */
+# define MAP_NONBLOCK	0x10000		/* Do not block on IO.  */
+# define MAP_STACK	0x20000		/* Allocation is for a stack.  */
+# define MAP_HUGETLB	0x40000		/* Create huge page mapping.  */
+# define MAP_SYNC	0x80000		/* Perform synchronous page
+					   faults for the mapping.  */
+#endif
+
+/* Include generic Linux declarations.  */
+#include <bits/mman-linux.h>
diff --git a/sysdeps/unix/sysv/linux/csky/bits/shm.h b/sysdeps/unix/sysv/linux/csky/bits/shm.h
new file mode 100644
index 0000000..d745233
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/bits/shm.h
@@ -0,0 +1,103 @@ 
+/* 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 _SYS_SHM_H
+# error "Never include <bits/shm.h> directly; use <sys/shm.h> instead."
+#endif
+
+#include <bits/types.h>
+
+/* Permission flag for shmget.  */
+#define SHM_R		0400		/* or S_IRUGO from <linux/stat.h> */
+#define SHM_W		0200		/* or S_IWUGO from <linux/stat.h> */
+
+/* Flags for `shmat'.  */
+#define SHM_RDONLY	010000		/* attach read-only else read-write */
+#define SHM_RND		020000		/* round attach address to SHMLBA */
+#define SHM_REMAP	040000		/* take-over region on attach */
+#define SHM_EXEC	0100000		/* execution access */
+
+/* Commands for `shmctl'.  */
+#define SHM_LOCK	11		/* lock segment (root only) */
+#define SHM_UNLOCK	12		/* unlock segment (root only) */
+
+__BEGIN_DECLS
+
+/* Segment low boundary address multiple.  */
+#define SHMLBA		(__getpagesize () << 2)
+extern int __getpagesize (void) __THROW __attribute__ ((__const__));
+
+
+/* Type to count number of attaches.  */
+typedef unsigned long int shmatt_t;
+
+/* Data structure describing a shared memory segment.  */
+struct shmid_ds
+  {
+    struct ipc_perm shm_perm;		/* operation permission struct */
+    size_t shm_segsz;			/* size of segment in bytes */
+    __time_t shm_atime;			/* time of last shmat() */
+    unsigned long int __glibc_reserved1;
+    __time_t shm_dtime;			/* time of last shmdt() */
+    unsigned long int __glibc_reserved2;
+    __time_t shm_ctime;			/* time of last change by shmctl() */
+    unsigned long int __glibc_reserved3;
+    __pid_t shm_cpid;			/* pid of creator */
+    __pid_t shm_lpid;			/* pid of last shmop */
+    shmatt_t shm_nattch;		/* number of current attaches */
+    unsigned long int __glibc_reserved4;
+    unsigned long int __glibc_reserved5;
+  };
+
+#ifdef __USE_MISC
+
+/* ipcs ctl commands */
+# define SHM_STAT 	13
+# define SHM_INFO 	14
+
+/* shm_mode upper byte flags */
+# define SHM_DEST	01000	/* segment will be destroyed on last detach */
+# define SHM_LOCKED	02000   /* segment will not be swapped */
+# define SHM_HUGETLB	04000	/* segment is mapped via hugetlb */
+# define SHM_NORESERVE	010000	/* don't check for reservations */
+
+struct	shminfo
+  {
+    unsigned long int shmmax;
+    unsigned long int shmmin;
+    unsigned long int shmmni;
+    unsigned long int shmseg;
+    unsigned long int shmall;
+    unsigned long int __glibc_reserved1;
+    unsigned long int __glibc_reserved2;
+    unsigned long int __glibc_reserved3;
+    unsigned long int __glibc_reserved4;
+  };
+
+struct shm_info
+  {
+    int used_ids;
+    unsigned long int shm_tot;	/* total allocated shm */
+    unsigned long int shm_rss;	/* total resident shm */
+    unsigned long int shm_swp;	/* total swapped shm */
+    unsigned long int swap_attempts;
+    unsigned long int swap_successes;
+  };
+
+#endif /* __USE_MISC */
+
+__END_DECLS
diff --git a/sysdeps/unix/sysv/linux/csky/c++-types.data b/sysdeps/unix/sysv/linux/csky/c++-types.data
new file mode 100644
index 0000000..303f457
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/c++-types.data
@@ -0,0 +1,67 @@ 
+blkcnt64_t:x
+blkcnt_t:l
+blksize_t:i
+caddr_t:Pc
+clockid_t:i
+clock_t:l
+daddr_t:i
+dev_t:y
+fd_mask:l
+fsblkcnt64_t:y
+fsblkcnt_t:m
+fsfilcnt64_t:y
+fsfilcnt_t:m
+fsid_t:8__fsid_t
+gid_t:j
+id_t:j
+ino64_t:y
+ino_t:m
+int16_t:s
+int32_t:i
+int64_t:x
+int8_t:a
+intptr_t:i
+key_t:i
+loff_t:x
+mode_t:j
+nlink_t:j
+off64_t:x
+off_t:l
+pid_t:i
+pthread_attr_t:14pthread_attr_t
+pthread_barrier_t:17pthread_barrier_t
+pthread_barrierattr_t:21pthread_barrierattr_t
+pthread_cond_t:14pthread_cond_t
+pthread_condattr_t:18pthread_condattr_t
+pthread_key_t:j
+pthread_mutex_t:15pthread_mutex_t
+pthread_mutexattr_t:19pthread_mutexattr_t
+pthread_once_t:i
+pthread_rwlock_t:16pthread_rwlock_t
+pthread_rwlockattr_t:20pthread_rwlockattr_t
+pthread_spinlock_t:i
+pthread_t:m
+quad_t:x
+register_t:i
+rlim64_t:y
+rlim_t:m
+sigset_t:10__sigset_t
+size_t:j
+socklen_t:j
+ssize_t:i
+suseconds_t:l
+time_t:l
+u_char:h
+uid_t:j
+uint:j
+u_int:j
+u_int16_t:t
+u_int32_t:j
+u_int64_t:y
+u_int8_t:h
+ulong:m
+u_long:m
+u_quad_t:y
+useconds_t:j
+ushort:t
+u_short:t
diff --git a/sysdeps/unix/sysv/linux/csky/csky_readtp.h b/sysdeps/unix/sysv/linux/csky/csky_readtp.h
new file mode 100644
index 0000000..fffd52c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/csky_readtp.h
@@ -0,0 +1,24 @@ 
+/* 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/>.  */
+
+#ifdef	__CSKYABIV2__
+# define csky_read_tp	\
+	mov	a0, r31
+#else
+# define csky_read_tp	\
+	trap	3
+#endif
diff --git a/sysdeps/unix/sysv/linux/csky/ipc_priv.h b/sysdeps/unix/sysv/linux/csky/ipc_priv.h
new file mode 100644
index 0000000..38d86fd
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/ipc_priv.h
@@ -0,0 +1,21 @@ 
+/* Old SysV permission definition for Linux.  CSKY version.
+   Copyright (C) 2017-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/ipc.h>  /* For __key_t  */
+
+#define __IPC_64	0x0
diff --git a/sysdeps/unix/sysv/linux/csky/jmp_buf-macros.h b/sysdeps/unix/sysv/linux/csky/jmp_buf-macros.h
new file mode 100644
index 0000000..5a390c7
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/jmp_buf-macros.h
@@ -0,0 +1,6 @@ 
+#define JMP_BUF_SIZE 268
+#define SIGJMP_BUF_SIZE 268
+#define JMP_BUF_ALIGN 4
+#define SIGJMP_BUF_ALIGN 4
+#define MASK_WAS_SAVED_OFFSET 136
+#define SAVED_MASK_OFFSET 140
diff --git a/sysdeps/unix/sysv/linux/csky/kernel-features.h b/sysdeps/unix/sysv/linux/csky/kernel-features.h
new file mode 100644
index 0000000..f1fbc71
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/kernel-features.h
@@ -0,0 +1,29 @@ 
+/* Set flags signalling availability of kernel features based on given
+   kernel version number.
+   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_next <kernel-features.h>
+
+/* fadvise64_64 reorganize the syscall arguments.  */
+#define __ASSUME_FADVISE64_64_6ARG	1
+
+/* Define this if your 32-bit syscall API requires 64-bit register
+   pairs to start with an even-number register.  */
+#ifdef __CSKYABIV1__
+# define __ASSUME_ALIGNED_REGISTER_PAIRS	1
+#endif
diff --git a/sysdeps/unix/sysv/linux/csky/makecontext.c b/sysdeps/unix/sysv/linux/csky/makecontext.c
new file mode 100644
index 0000000..8585c5e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/makecontext.c
@@ -0,0 +1,81 @@ 
+/* 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 <stdarg.h>
+#include <ucontext.h>
+
+/* Number of arguments that go in registers.  */
+#ifdef __CSKYABIV2__
+# define NREG_ARGS  4
+#else
+# define NREG_ARGS  6
+#endif
+
+/* Take a context previously prepared via getcontext() and set to
+   call func() with the given int only args.  */
+void
+__makecontext (ucontext_t *ucp, void (*func) (void), int argc, ...)
+{
+  extern void __startcontext (void);
+  unsigned long *funcstack;
+  va_list vl;
+  unsigned long *regptr;
+  unsigned int reg;
+  int misaligned;
+
+  /* Start at the top of stack.  */
+  funcstack = (unsigned long *) (ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
+
+  /* Ensure the stack stays eight byte aligned.  */
+  misaligned = ((unsigned long) funcstack & 4) != 0;
+
+  if ((argc > NREG_ARGS) && (argc & 1) != 0)
+    misaligned = !misaligned;
+
+  if (misaligned)
+    funcstack -= 1;
+
+  va_start (vl, argc);
+
+  /* Reserve space for the on-stack arguments.  */
+  if (argc > NREG_ARGS)
+    funcstack -= (argc - NREG_ARGS);
+
+  ucp->uc_mcontext.sc_usp = (unsigned long) funcstack;
+  ucp->uc_mcontext.sc_pc = (unsigned long) func;
+
+  /* Exit to startcontext() with the next context in R9 */
+#ifdef __CSKYABIV2__
+  ucp->uc_mcontext.sc_regs[5] = (unsigned long) ucp->uc_link;
+#else
+  ucp->uc_mcontext.sc_regs[3] = (unsigned long) ucp->uc_link;
+#endif
+  ucp->uc_mcontext.sc_r15 = (unsigned long) __startcontext;
+
+  /* The first four arguments go into registers.  */
+  regptr = &(ucp->uc_mcontext.sc_a0);
+
+  for (reg = 0; (reg < argc) && (reg < NREG_ARGS); reg++)
+    *regptr++ = va_arg (vl, unsigned long);
+
+  /* And the remainder on the stack.  */
+  for (; reg < argc; reg++)
+    *funcstack++ = va_arg (vl, unsigned long);
+
+  va_end (vl);
+}
+weak_alias (__makecontext, makecontext)
diff --git a/sysdeps/unix/sysv/linux/csky/profil-counter.h b/sysdeps/unix/sysv/linux/csky/profil-counter.h
new file mode 100644
index 0000000..5d5ac34
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/profil-counter.h
@@ -0,0 +1,34 @@ 
+/* Low-level statistical profiling support function.  Linux/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 <signal.h>
+#include <sigcontextinfo.h>
+
+void
+__profil_counter (int signo, const SIGCONTEXT scp)
+{
+  profil_count ((void *) GET_PC (scp));
+
+  /* This is a hack to prevent the compiler from implementing the
+     above function call as a sibcall.  The sibcall would overwrite
+     the signal context.  */
+  asm volatile ("");
+}
+#ifndef __profil_counter
+weak_alias (__profil_counter, profil_counter)
+#endif
diff --git a/sysdeps/unix/sysv/linux/csky/register-dump.h b/sysdeps/unix/sysv/linux/csky/register-dump.h
new file mode 100644
index 0000000..2154544
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/register-dump.h
@@ -0,0 +1,218 @@ 
+/* Dump registers.
+   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 <sys/uio.h>
+#include <_itoa.h>
+#include <bits/sigcontext.h>
+#include <sys/ucontext.h>
+
+/* We will print the register dump in this format:
+
+ PSR: XXXXXXXX  PC: XXXXXXXX   SP: XXXXXXXX   LR: XXXXXXXX
+ MASK: XXXXXXXX
+
+ A0: XXXXXXXX   A1: XXXXXXXX   A2: XXXXXXXX   A3: XXXXXXXX
+ R6: XXXXXXXX   R7: XXXXXXXX   R8: XXXXXXXX   R9: XXXXXXXX
+ R10: XXXXXXXX  R11: XXXXXXXX  R12: XXXXXXXX  R13: XXXXXXXX
+ R14: XXXXXXXX  R1: XXXXXXXX
+
+************************ I am cutter! *********************
+
+ PSR: XXXXXXXX  PC: XXXXXXXX   SP: XXXXXXXX   LR: XXXXXXXX
+ MASK: XXXXXXXX
+
+ A0: XXXXXXXX   A1: XXXXXXXX   A2: XXXXXXXX   A3: XXXXXXXX
+ R4: XXXXXXXX   R5: XXXXXXXX   R6: XXXXXXXX   R7: XXXXXXXX
+ R8: XXXXXXXX   R9: XXXXXXXX   R10: XXXXXXXX  R11: XXXXXXXX
+ R12: XXXXXXXX  R13: XXXXXXXX  R14: XXXXXXXX  R15: XXXXXXXX
+ R16: XXXXXXXX  R17: XXXXXXXX  R18: XXXXXXXX  R19: XXXXXXXX
+ R20: XXXXXXXX  R21: XXXXXXXX  R22: XXXXXXXX  R23: XXXXXXXX
+ R24: XXXXXXXX  R25: XXXXXXXX  R26: XXXXXXXX  R27: XXXXXXXX
+ R28: XXXXXXXX  R29: XXXXXXXX  R30: XXXXXXXX  R31: XXXXXXXX
+
+ */
+
+static void
+hexvalue (unsigned long int value, char *buf, size_t len)
+{
+  char *cp = _itoa_word (value, buf + len, 16, 0);
+  while (cp > buf)
+    *--cp = '0';
+}
+
+static void
+register_dump (int fd, const struct ucontext *ctx)
+{
+  char regs[35][8];
+  struct iovec iov[97];
+  size_t nr = 0;
+
+#define ADD_STRING(str) \
+  iov[nr].iov_base = (char *) str;					      \
+  iov[nr].iov_len = strlen (str);					      \
+  ++nr
+#define ADD_MEM(str, len) \
+  iov[nr].iov_base = str;						      \
+  iov[nr].iov_len = len;						      \
+  ++nr
+
+  /* Generate strings of register contents.  */
+  hexvalue (ctx->uc_mcontext.sc_sr, regs[0], 8);
+  hexvalue (ctx->uc_mcontext.sc_pc, regs[1], 8);
+  hexvalue (ctx->uc_mcontext.sc_usp, regs[2], 8);
+  hexvalue (ctx->uc_mcontext.sc_r15, regs[3], 8);
+  hexvalue (ctx->uc_mcontext.sc_mask, regs[4], 8);
+  hexvalue (ctx->uc_mcontext.sc_a0, regs[5], 8);
+  hexvalue (ctx->uc_mcontext.sc_a1, regs[6], 8);
+  hexvalue (ctx->uc_mcontext.sc_a2, regs[7], 8);
+  hexvalue (ctx->uc_mcontext.sc_a3, regs[8], 8);
+  hexvalue (ctx->uc_mcontext.sc_regs[0], regs[9], 8);
+  hexvalue (ctx->uc_mcontext.sc_regs[1], regs[10], 8);
+  hexvalue (ctx->uc_mcontext.sc_regs[2], regs[11], 8);
+  hexvalue (ctx->uc_mcontext.sc_regs[3], regs[12], 8);
+  hexvalue (ctx->uc_mcontext.sc_regs[4], regs[13], 8);
+  hexvalue (ctx->uc_mcontext.sc_regs[5], regs[14], 8);
+  hexvalue (ctx->uc_mcontext.sc_regs[6], regs[15], 8);
+  hexvalue (ctx->uc_mcontext.sc_regs[7], regs[16], 8);
+  hexvalue (ctx->uc_mcontext.sc_regs[8], regs[17], 8);
+  hexvalue (ctx->uc_mcontext.sc_regs[9], regs[18], 8);
+#ifdef	__CSKYABIV2__
+  hexvalue (ctx->uc_mcontext.sc_exregs[0], regs[19], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[1], regs[20], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[2], regs[21], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[3], regs[22], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[4], regs[23], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[5], regs[24], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[6], regs[25], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[7], regs[26], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[8], regs[27], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[9], regs[28], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[10], regs[29], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[11], regs[30], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[12], regs[31], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[13], regs[32], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[14], regs[33], 8);
+  hexvalue (ctx->uc_mcontext.sc_exregs[15], regs[34], 8);
+#endif
+
+  /* Generate the output.  */
+  ADD_STRING ("Register dump:\n\n PSR: ");
+  ADD_MEM (regs[0], 8);
+  ADD_STRING ("  PC: ");
+  ADD_MEM (regs[1], 8);
+  ADD_STRING ("   SP: ");
+  ADD_MEM (regs[2], 8);
+  ADD_STRING ("   LR: ");
+  ADD_MEM (regs[3], 8);
+  ADD_STRING ("\n MASK: ");
+  ADD_MEM (regs[4], 8);
+  ADD_STRING ("\n\n A0: ");
+  ADD_MEM (regs[5], 8);
+  ADD_STRING ("   A1: ");
+  ADD_MEM (regs[6], 8);
+  ADD_STRING ("   A2: ");
+  ADD_MEM (regs[7], 8);
+  ADD_STRING ("   A3: ");
+  ADD_MEM (regs[8], 8);
+#ifdef __CSKYABIV2__
+  ADD_STRING ("\n R4: ");
+  ADD_MEM (regs[9], 8);
+  ADD_STRING ("   r5: ");
+  ADD_MEM (regs[10], 8);
+  ADD_STRING ("   r6: ");
+  ADD_MEM (regs[11], 8);
+  ADD_STRING ("   r7: ");
+  ADD_MEM (regs[12], 8);
+  ADD_STRING ("\n R8: ");
+  ADD_MEM (regs[13], 8);
+  ADD_STRING ("   R9: ");
+  ADD_MEM (regs[14], 8);
+  ADD_STRING ("   R10: ");
+  ADD_MEM (regs[15], 8);
+  ADD_STRING ("  R11: ");
+  ADD_MEM (regs[16], 8);
+  ADD_STRING ("\n R12: ");
+  ADD_MEM (regs[17], 8);
+  ADD_STRING ("  R13: ");
+  ADD_MEM (regs[18], 8);
+  ADD_STRING ("  R14: ");
+  ADD_MEM (regs[19], 8);
+  ADD_STRING ("  R15: ");
+  ADD_MEM (regs[20], 8);
+  ADD_STRING ("\n R16: ");
+  ADD_MEM (regs[21], 8);
+  ADD_STRING ("  R17: ");
+  ADD_MEM (regs[22], 8);
+  ADD_STRING ("  R18: ");
+  ADD_MEM (regs[23], 8);
+  ADD_STRING ("  R19: ");
+  ADD_MEM (regs[24], 8);
+  ADD_STRING ("\n R20: ");
+  ADD_MEM (regs[25], 8);
+  ADD_STRING ("  R21: ");
+  ADD_MEM (regs[26], 8);
+  ADD_STRING ("  R22: ");
+  ADD_MEM (regs[27], 8);
+  ADD_STRING ("  R23: ");
+  ADD_MEM (regs[28], 8);
+  ADD_STRING ("\n R24: ");
+  ADD_MEM (regs[29], 8);
+  ADD_STRING ("  R25: ");
+  ADD_MEM (regs[30], 8);
+  ADD_STRING ("  R26: ");
+  ADD_MEM (regs[31], 8);
+  ADD_STRING ("  R27: ");
+  ADD_MEM (regs[32], 8);
+  ADD_STRING ("\n R28: ");
+  ADD_MEM (regs[33], 8);
+  ADD_STRING ("  R29: ");
+  ADD_MEM (regs[34], 8);
+  ADD_STRING ("  R30: ");
+  ADD_MEM (regs[33], 8);
+  ADD_STRING ("  R31: ");
+  ADD_MEM (regs[34], 8);
+#else
+  ADD_STRING ("   R6: ");
+  ADD_MEM (regs[9], 8);
+  ADD_STRING ("   R7: ");
+  ADD_MEM (regs[10], 8);
+  ADD_STRING ("   R8: ");
+  ADD_MEM (regs[11], 8);
+  ADD_STRING ("   R9: ");
+  ADD_MEM (regs[12], 8);
+  ADD_STRING ("\n R10: ");
+  ADD_MEM (regs[13], 8);
+  ADD_STRING ("  R11: ");
+  ADD_MEM (regs[14], 8);
+  ADD_STRING ("  R12: ");
+  ADD_MEM (regs[15], 8);
+  ADD_STRING ("  R13: ");
+  ADD_MEM (regs[16], 8);
+  ADD_STRING ("\n R14: ");
+  ADD_MEM (regs[17], 8);
+  ADD_STRING ("  R1: ");
+  ADD_MEM (regs[18], 8);
+#endif
+
+  ADD_STRING ("\n");
+
+  /* Write the stuff out.  */
+  writev (fd, iov, nr);
+}
+
+#define REGISTER_DUMP register_dump (fd, ctx)
diff --git a/sysdeps/unix/sysv/linux/csky/setcontext.S b/sysdeps/unix/sysv/linux/csky/setcontext.S
new file mode 100644
index 0000000..199a07f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/setcontext.S
@@ -0,0 +1,128 @@ 
+/* 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/>.  */
+
+#ifdef __CSKYABIV2__
+# include "abiv2_setcontext.S"
+#else
+
+# include <sysdep.h>
+
+# include "ucontext_i.h"
+
+/* int setcontext (const ucontext_t *ucp) */
+
+ENTRY(__setcontext)
+	mov	r7, r2
+
+	/* set sigmask */
+	movi	r2, SIG_SETMASK
+	lrw	r3, UCONTEXT_SIGMASK
+	add	r3, r7
+	movi	r4, 0
+
+	subi	sp, 8
+	stw	r7, (sp, 0)	/* save r7(ucp) */
+
+        /* do sigprocmask syscall */
+# ifdef __PIC__
+	subi	sp, 8
+	stw	gb, (sp, 0)
+	stw	lr, (sp, 4)
+	bsr	.Lgetpc1
+.Lgetpc1:
+	lrw	gb, .Lgetpc1@GOTPC
+	addu	gb, r15
+	lrw	r7, __sigprocmask@PLT
+	addu	r7, gb
+	ldw	r7, (r7)
+	jsr	r7
+	ldw	gb, (sp, 0)
+	ldw	lr, (sp, 4)
+	addi	sp, 8
+# else
+	jsri	__sigprocmask
+# endif /* __PIC__ */
+
+	ldw	r1, (sp, 0)	/* restore r7(ucp) */
+	addi	sp, 8
+
+	lrw	r2, MCONTEXT_CSKY_A0
+	add	r2, r1
+
+	/* set r2-r14. Load r2-r7, for makecontext requires */
+	ldw	r3, (r2, 4)
+	ldw	r4, (r2, 8)
+	ldw	r5, (r2, 12)
+	ldw	r6, (r2, 16)
+	ldw	r7, (r2, 20)
+	ldw	r8, (r2, 24)
+	ldw	r9, (r2, 28)
+	ldw	r10, (r2, 32)
+	ldw	r11, (r2, 36)
+	ldw	r12, (r2, 40)
+	ldw	r13, (r2, 44)
+	ldw	r14, (r2, 48)
+
+	ldw	r15, (r2, 56)			/* load lr */
+
+	lrw	r2, MCONTEXT_CSKY_SP
+	add	r2, r1
+	ldw	sp, (r2)			/* load sp */
+
+	lrw	r2, MCONTEXT_CSKY_PC
+	add	r2, r1
+	ldw	r2, (r2)			/* load start addr */
+
+	subi	sp, 8				/* for getcontext success */
+	stw	r2, (sp, 0)
+	lrw	r2, MCONTEXT_CSKY_A0
+	add	r2, r1
+	ldw	r2, (r2)			/* load a0 */
+	ldw	r1, (sp, 0)
+	addi	sp, 8
+
+	jmp	r1
+END(setcontext)
+weak_alias(__setcontext, setcontext)
+
+ENTRY(__startcontext)
+	mov	a0, r9
+	cmpnei	r9, 0		/* r9 was set in makecontext */
+	bf	1f		/* null, then exit */
+
+	/* call setcontext */
+# ifdef __PIC__
+	mov	r5, r15		/* save r15 */
+	bsr	.Lgetpc2
+.Lgetpc2:
+	lrw	r6, .Lgetpc2@GOTPC
+	addu	r6, r15
+	lrw	r7, __setcontext@GOT
+	addu	r7, r6
+	ldw	r7, (r7)
+	mov	r15, r5		/* restore r15 */
+# else
+	lrw	r7, __setcontext
+# endif
+	jsr	r7
+
+1:
+	lrw	r1, __NR_exit
+	trap	0
+END(__startcontext)
+
+#endif	/* __CSKYAVBI2__*/
diff --git a/sysdeps/unix/sysv/linux/csky/shlib-versions b/sysdeps/unix/sysv/linux/csky/shlib-versions
new file mode 100644
index 0000000..6c1ca16
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/shlib-versions
@@ -0,0 +1,3 @@ 
+DEFAULT			GLIBC_2.27
+
+ld=ld.so.1
diff --git a/sysdeps/unix/sysv/linux/csky/sigcontextinfo.h b/sysdeps/unix/sysv/linux/csky/sigcontextinfo.h
new file mode 100644
index 0000000..ba69f36
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/sigcontextinfo.h
@@ -0,0 +1,37 @@ 
+/* 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 SIGCONTEXT siginfo_t *_si, struct ucontext *
+#define SIGCONTEXT_EXTRA_ARGS _si,
+#define GET_PC(ctx)	((void *) (ctx)->uc_mcontext.sc_pc)
+/* r8 is fp, make sure it is in the same area in sigcontext.  */
+#define GET_FRAME(ctx)	((void *) (ctx)->uc_mcontext.sc_regs[2])
+#define GET_STACK(ctx)	((void *) (ctx)->uc_mcontext.sc_usp)
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+  (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
+
+/* There is no reliable way to get the sigcontext unless we use a
+   three-argument signal handler.  */
+#define __sigaction(sig, act, oact) ({ \
+  (act)->sa_flags |= SA_SIGINFO; \
+  (__sigaction) (sig, act, oact); \
+})
+
+#define sigaction(sig, act, oact) ({ \
+  (act)->sa_flags |= SA_SIGINFO; \
+  (sigaction) (sig, act, oact); \
+})
diff --git a/sysdeps/unix/sysv/linux/csky/swapcontext.S b/sysdeps/unix/sysv/linux/csky/swapcontext.S
new file mode 100644
index 0000000..db3c2f8
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/swapcontext.S
@@ -0,0 +1,112 @@ 
+/* 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>
+
+#include "ucontext_i.h"
+
+/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */
+
+ENTRY(swapcontext)
+	/* save params and lr */
+	subi	sp, 16
+	stw	a0, (sp, 0)
+	stw	a1, (sp, 4)
+	stw	r15, (sp, 8)
+
+	/* call getcontext */
+#ifdef __PIC__
+# ifdef __CSKYABIV2__
+	grs	t1, .Lgetpc1
+.Lgetpc1:
+	lrw	t0, .Lgetpc1@GOTPC
+	addu	t1, t1, t0
+	lrw	t0, __getcontext@GOT
+	ldr.w	t0, (t1, t0 << 0)
+	jsr	t0
+# else /* __CSKYABIV1 */
+	mov	r7, lr
+	bsr	.Lgetpc1
+.Lgetpc1:	/* do not use gb here, and restore lr before call getcontext*/
+	lrw	r6, .Lgetpc1@GOTPC
+	addu	r6, r15
+	mov	lr, r7	/* restore r15 */
+	lrw	r5, __getcontext@GOT
+	addu	r5, r6
+	ldw	r5, (r5)
+	jsr	r5
+# endif
+#else /* no pic */
+	jsri	 __getcontext
+#endif
+
+	mov	a3, a0	/* save return value */
+
+	/* restore params and lr */
+	ldw	a0, (sp, 0)
+	ldw	a1, (sp, 4)
+	ldw	r15, (sp, 8)
+	addi	sp, 16
+
+	cmpnei	a3, 0
+	bt	error_exit
+
+	/* Fix up LR and the PC */
+#ifdef	__CSKYABIV2__
+	stw	sp, (a0, MCONTEXT_CSKY_SP)
+	stw	r15, (a0, MCONTEXT_CSKY_LR)
+	stw	r15, (a0, MCONTEXT_CSKY_PC)
+#else
+	lrw	r4, MCONTEXT_CSKY_SP
+	add	r4, a0
+	stw	sp, (r4)
+	lrw	r4, MCONTEXT_CSKY_LR
+	add	r4, a0
+	stw	r15, (r4)
+	stw	r15, (r4, 8)	/* MCONTEXT_CSKY_PC */
+#endif
+
+	/* set setcontext's arg */
+	mov	a0, a1
+
+#ifdef __PIC__
+# ifdef __CSKYABIV2__
+	grs	t1, .Lgetpc2
+.Lgetpc2:
+	lrw	a3, .Lgetpc2@GOTPC
+	addu	t1, t1, a3
+	lrw	a3, __setcontext@GOT
+	ldr.w	a3, (t1, a3 << 0)
+# else
+	mov	r7, r15		/* save r15 */
+	bsr	.Lgetpc2
+.Lgetpc2:
+	lrw	r6, .Lgetpc2@GOTPC
+	addu	r6, r15
+	lrw	r5, __setcontext@GOT
+	addu	r5, r6
+	ldw	r5, (r5)
+	mov	r15, r7		/* restore r15 */
+# endif /* __CSKYABIV2__ */
+#else /* __PIC__ */
+	lrw	a3, __setcontext
+#endif /* __PIC__ */
+	jmp	a3
+
+error_exit:
+	jmp	r15
+END(swapcontext)
diff --git a/sysdeps/unix/sysv/linux/csky/sys/cachectl.h b/sysdeps/unix/sysv/linux/csky/sys/cachectl.h
new file mode 100644
index 0000000..1aeacde
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/sys/cachectl.h
@@ -0,0 +1,35 @@ 
+/* 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 _SYS_CACHECTL_H
+#define _SYS_CACHECTL_H 1
+
+#include <features.h>
+
+/* Get the kernel definition for the op bits.  */
+#include <asm/cachectl.h>
+
+__BEGIN_DECLS
+
+#ifdef __USE_MISC
+extern int cacheflush (void *__addr, const int __nbytes, const int __op) __THROW;
+#endif
+extern int _flush_cache (char *__addr, const int __nbytes, const int __op) __THROW;
+
+__END_DECLS
+
+#endif /* sys/cachectl.h */
diff --git a/sysdeps/unix/sysv/linux/csky/sys/procfs.h b/sysdeps/unix/sysv/linux/csky/sys/procfs.h
new file mode 100644
index 0000000..4c9721b
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/sys/procfs.h
@@ -0,0 +1,123 @@ 
+/* Core image file related 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 _SYS_PROCFS_H
+#define _SYS_PROCFS_H	1
+
+/* This is somewhat modelled after the file of the same name on SVR4
+   systems.  It provides a definition of the core file format for ELF
+   used on Linux.  It doesn't have anything to do with the /proc file
+   system, even though Linux has one.
+
+   Anyway, the whole purpose of this file is for GDB and GDB only.
+   Don't read too much into it.  Don't use it for anything other than
+   GDB unless you know what you are doing.  */
+
+#include <features.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/user.h>
+
+__BEGIN_DECLS
+
+/* Type for a general-purpose register.  */
+typedef unsigned long elf_greg_t;
+
+/* And the whole bunch of them.  We could have used `struct
+   user_regs' directly in the typedef, but tradition says that
+   the register set is an array, which does have some peculiar
+   semantics, so leave it that way.  */
+#define ELF_NGREG (sizeof (struct user_regs) / sizeof(elf_greg_t))
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+/* Register set for the floating-point registers.  */
+typedef struct user_fpregs elf_fpregset_t;
+
+/* Signal info.  */
+struct elf_siginfo
+  {
+    int si_signo;			/* Signal number.  */
+    int si_code;			/* Extra code.  */
+    int si_errno;			/* Errno.  */
+  };
+
+/* Definitions to generate Intel SVR4-like core files.  These mostly
+   have the same names as the SVR4 types with "elf_" tacked on the
+   front to prevent clashes with Linux definitions, and the typedef
+   forms have been avoided.  This is mostly like the SVR4 structure,
+   but more Linuxy, with things that Linux does not support and which
+   GDB doesn't really use excluded.  */
+
+struct elf_prstatus
+  {
+    struct elf_siginfo pr_info;		/* Info associated with signal.  */
+    short int pr_cursig;		/* Current signal.  */
+    unsigned long int pr_sigpend;	/* Set of pending signals.  */
+    unsigned long int pr_sighold;	/* Set of held signals.  */
+    __pid_t pr_pid;
+    __pid_t pr_ppid;
+    __pid_t pr_pgrp;
+    __pid_t pr_sid;
+    struct timeval pr_utime;		/* User time.  */
+    struct timeval pr_stime;		/* System time.  */
+    struct timeval pr_cutime;		/* Cumulative user time.  */
+    struct timeval pr_cstime;		/* Cumulative system time.  */
+    elf_gregset_t pr_reg;		/* GP registers.  */
+    int pr_fpvalid;			/* True if math copro being used.  */
+  };
+
+
+#define ELF_PRARGSZ     (80)    /* Number of chars for args.  */
+
+struct elf_prpsinfo
+  {
+    char pr_state;			/* Numeric process state.  */
+    char pr_sname;			/* Char for pr_state.  */
+    char pr_zomb;			/* Zombie.  */
+    char pr_nice;			/* Nice val.  */
+    unsigned long int pr_flag;		/* Flags.  */
+    unsigned short int pr_uid;
+    unsigned short int pr_gid;
+    int pr_pid, pr_ppid, pr_pgrp, pr_sid;
+    /* Lots missing */
+    char pr_fname[16];			/* Filename of executable.  */
+    char pr_psargs[ELF_PRARGSZ];	/* Initial part of arg list.  */
+  };
+
+/* The rest of this file provides the types for emulation of the
+   Solaris <proc_service.h> interfaces that should be implemented by
+   users of libthread_db.  */
+
+/* Addresses.  */
+typedef void *psaddr_t;
+
+/* Register sets.  Linux has different names.  */
+typedef elf_gregset_t prgregset_t;
+typedef elf_fpregset_t prfpregset_t;
+
+/* We don't have any differences between processes and threads,
+   therefore have only one PID type.  */
+typedef __pid_t lwpid_t;
+
+/* Process status and info.  In the end we do provide typedefs for them.  */
+typedef struct elf_prstatus prstatus_t;
+typedef struct elf_prpsinfo prpsinfo_t;
+
+__END_DECLS
+
+#endif	/* sys/procfs.h */
diff --git a/sysdeps/unix/sysv/linux/csky/sys/ucontext.h b/sysdeps/unix/sysv/linux/csky/sys/ucontext.h
new file mode 100644
index 0000000..a9c856e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/sys/ucontext.h
@@ -0,0 +1,111 @@ 
+/* System V/C-SKY ABI compliant context switching support.
+   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 _SYS_UCONTEXT_H
+#define _SYS_UCONTEXT_H	1
+
+#include <features.h>
+#include <signal.h>
+
+#include <bits/sigcontext.h>
+#include <bits/types/sigset_t.h>
+#include <bits/types/stack_t.h>
+
+/* Type for general register.  */
+typedef int greg_t;
+
+/* Number of general registers.  */
+#if (__CSKY__ == 2)
+#define NGREG   34
+#else
+#define NGREG   18
+#endif
+/* Container for all general registers.  */
+typedef greg_t gregset_t[NGREG];
+
+/* Number of each register is the `gregset_t' array.  */
+enum
+{
+  R_R0 = 0,
+#define R_R0    R_R0
+  R_R1 = 1,
+#define R_R1    R_R1
+  R_R2 = 2,
+#define R_R2    R_R2
+  R_R3 = 3,
+#define R_R3    R_R3
+  R_R4 = 4,
+#define R_R4    R_R4
+  R_R5 = 5,
+#define R_R5    R_R5
+  R_R6 = 6,
+#define R_R6    R_R6
+  R_R7 = 7,
+#define R8R7    R_R7
+  R_R8 = 8,
+#define R_R8    R_R8
+  R_R9 = 9,
+#define R_R9    R_R9
+  R_R10 = 10,
+#define R_R10   R_R10
+  R_R11 = 11,
+#define R_R11   R_R11
+  R_R12 = 12,
+#define R_R12   R_R12
+  R_R13 = 13,
+#define R_R13   R_R13
+  R_R14 = 14,
+#define R_R14   R_R14
+  R_R15 = 15,
+#define R_R15   R_R15
+#if (__CSKY__ == 2)
+  R_SR = 32,
+#define R_SR    R_SR
+  R_PC = 33,
+#define R_PC    R_PC
+#else
+  R_SR = 16,
+#define R_SR    R_SR
+  R_PC = 17,
+#define R_PC    R_PC
+#endif
+};
+
+/* Structure to describe FPU registers.  */
+typedef struct fpregset
+{
+  unsigned long  fesr;        /* fpu exception status reg */
+  unsigned long  fsr;         /* fpu status reg, nothing in CPU_CSKYV2 */
+  unsigned long  fp[32];      /* fpu general regs */
+} fpregset_t;
+
+/* store common registers and fp registers etc. */
+typedef struct sigcontext mcontext_t;
+
+/* Userlevel context.  */
+typedef struct ucontext
+{
+  unsigned long uc_flags;
+  struct ucontext *uc_link;
+  stack_t uc_stack;
+  mcontext_t uc_mcontext;	/* struct sigcontext */
+  __sigset_t uc_sigmask;
+  unsigned long uc_filler[80];
+} ucontext_t;
+
+#endif /* sys/ucontext.h */
diff --git a/sysdeps/unix/sysv/linux/csky/sys/user.h b/sysdeps/unix/sysv/linux/csky/sys/user.h
new file mode 100644
index 0000000..e969d60
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/sys/user.h
@@ -0,0 +1,65 @@ 
+/* 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 _SYS_USER_H
+#define _SYS_USER_H  1
+
+struct user_fpregs {
+  unsigned long fsr;		/* fpu status reg */
+  unsigned long fesr;		/* fpu exception status reg */
+  unsigned long fp[32];		/* fpu general regs */
+};
+
+struct user_regs {
+#if defined(__ck807__) || defined(__ck810__) || defined(__ck860__)
+  unsigned long int uregs[34];	/* CSKY V2 has 32 general rgister */
+#else
+  unsigned long int uregs[18];	/* CSKY V1 has 16 general rgister */
+#endif
+};
+
+/*
+ * When the kernel dumps core, it starts by dumping the user struct -
+ * this will be used by gdb to figure out where the data and stack segments
+ * are within the file, and what virtual addresses to use.
+ */
+struct user{
+/* We start with the registers, to mimic the way that "memory" is returned
+   from the ptrace(3,...) function.  */
+  struct user_regs    regs;	   /* The registers are actually stored */
+  int                 u_fpvalid;   /* True if math co-processor being used. */
+
+/* The rest of this junk is to help gdb figure out what goes where */
+  unsigned long int   u_tsize;	   /* Text segment size (pages). */
+  unsigned long int   u_dsize;	   /* Data segment size (pages). */
+  unsigned long int   u_ssize;	   /* Stack segment size (pages). */
+  unsigned long       start_code;  /* Starting virtual address of text. */
+  unsigned long       start_stack; /* Starting virtual address of stack area.
+				      This is actually the bottom of the stack
+				      the top of the stack is always found in
+				      the esp register.  */
+  long int            signal;	   /* Signal that caused the core dump. */
+  int                 reserved;	   /* No longer used */
+  struct user_regs *  u_ar0;	   /* Used by gdb to help find the values
+				      for the registers. */
+  unsigned long       magic;	   /* To uniquely identify a core file */
+  char                u_comm[32];  /* User command that was responsible */
+  struct user_fpregs  u_fp;
+  struct user_fpregs* u_fpstate;   /* Math Co-processor pointer. */
+};
+
+#endif /* _SYS_USER_H */
diff --git a/sysdeps/unix/sysv/linux/csky/sysdep.S b/sysdeps/unix/sysv/linux/csky/sysdep.S
new file mode 100644
index 0000000..44496d5
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/sysdep.S
@@ -0,0 +1,110 @@ 
+/* 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>
+#include <csky_readtp.h>
+
+/* The syscall stubs jump here when they detect an error.
+   The code for Linux is almost identical to the canonical Unix
+   code, except that the error number in R0 is negated.  */
+
+#undef CALL_MCOUNT
+#define CALL_MCOUNT /* Don't insert the profiling call, it clobbers R0.  */
+
+	.text
+ENTRY(__syscall_error)
+	movi	a1, 0
+	rsub	a0, a0, a1
+
+#ifdef __CSKYABIV2__
+1:
+# if !IS_IN (rtld)
+	mov	a1, a0
+        csky_read_tp
+
+        grs     t1, .Lgetpc1
+.Lgetpc1:
+        lrw     t0, errno@gottpoff
+        add     t1, t1, t0
+        ldw     t1, (t1)
+        add     t1, a0
+        stw     a1, (t1)
+        bmaski  a0, 0
+        rts
+# elif RTLD_PRIVATE_ERRNO /* !IS_IN (rtld) */
+#  ifdef  __PIC__
+        grs     t1, .Lgetpc2
+.Lgetpc2:
+        lrw     t0, .Lgetpc2@GOTPC
+        addu    t1, t1, t0
+        lrw     t0, rtld_errno@PLT
+        ldr.w   t0, (t1, t0 << 0)
+#  else
+        lrw     t0, rtld_errno
+#  endif /* __PIC__ */
+        stw     a0, (t0)
+        bmaski  a0, 0
+        rts
+# else
+#  error "Unsupported non-TLS case"
+# endif /* RTLD_PRIVATE_ERRNO */
+
+# undef  __syscall_error
+END (__syscall_error)
+
+#else /* __CSKYABIV2__ */
+
+1:
+# if !IS_IN (rtld)
+        mov     r7, r15
+	mov	r1, r2
+        csky_read_tp
+
+        bsr     .Lgetpc1
+.Lgetpc1:
+        lrw     r5, errno@gottpoff
+        add     r5, r15
+        ldw     r5, (r5)
+        add     r5, r2
+        stw     r1, (r5)
+        bmaski  r2, 0
+	mov	r15, r7
+        rts
+# elif RTLD_PRIVATE_ERRNO /* !IS_IN (rtld) */
+#  ifdef __PIC__
+        mov     r7, r15
+        bsr     .Lgetpc2
+.Lgetpc2:
+        lrw     r6, .Lgetpc2@GOTPC
+        addu    r6, r15
+        lrw     r5, rtld_errno@PLT
+        addu    r5, r6
+        ldw     r5, (r5)
+	mov	r15, r7
+#  else /* __PIC__ */
+        lrw     r5, rtld_errno
+#  endif /* __PIC__ */
+        stw     r2, (r5)
+        bmaski  r2, 0
+        rts
+# else
+#  error "Unsupported non-TLS case"
+# endif /* RTLD_PRIVATE_ERRNO */
+
+END (__syscall_error)
+
+#endif /* __CSKYABIV2__ */
diff --git a/sysdeps/unix/sysv/linux/csky/sysdep.h b/sysdeps/unix/sysv/linux/csky/sysdep.h
new file mode 100644
index 0000000..05013db
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/sysdep.h
@@ -0,0 +1,757 @@ 
+/* 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 _LINUX_CSKY_SYSDEP_H
+#define _LINUX_CSKY_SYSDEP_H 1
+
+/* There is some commonality.  */
+#include <sysdeps/unix/sysv/linux/generic/sysdep.h>
+#include <sysdeps/unix/sysv/linux/sysdep.h>
+#include <sysdeps/unix/csky/sysdep.h>
+
+/* Defines RTLD_PRIVATE_ERRNO and USE_DL_SYSINFO.  */
+#include <dl-sysdep.h>
+
+#include <tls.h>
+
+/* In order to get __set_errno() definition in INLINE_SYSCALL.  */
+#ifndef __ASSEMBLER__
+# include <errno.h>
+#endif
+
+#undef SYS_ify
+#define SYS_ify(syscall_name)  (__NR_##syscall_name)
+
+#ifdef __ASSEMBLER__
+/* Linux uses a negative return value to indicate syscall errors,
+   unlike most Unices, which use the condition codes' carry flag.
+
+   Since version 2.1 the return value of a system call might be
+   negative even if the call succeeded.  E.g., the `lseek' system call
+   might return a large offset.  Therefore we must not anymore test
+   for < 0, but test for a real error by making sure the value in R0
+   is a real error number.  Linus said he will make sure the no syscall
+   returns a value in -1 .. -4095 as a valid result so we can safely
+   test with -4095.  */
+
+# undef	PSEUDO
+# define	PSEUDO(name, syscall_name, args)	\
+  .text;						\
+  ENTRY (name);						\
+    DO_CALL (syscall_name, args);
+
+
+# if defined (__PIC__)
+#  define __GET_GB1  \
+	bsr getgb; getgb: lrw gb, getgb@GOTPC; addu gb, lr;
+# else
+#  define __GET_GB1
+# endif /* !__PIC__ */
+
+# undef  PSEUDO_RET
+# ifdef __PIC__
+#  if !IS_IN (libc)
+#   define PSEUDO_RET	\
+	btsti  a0, 31;					\
+	bf	   1f;					\
+	subi sp, 8; st.w lr, (sp); st.w gb, (sp, 4);	\
+	__GET_GB1					\
+	bsr    SYSCALL_ERROR;				\
+	ld.w lr, (sp); ld.w gb, (sp, 4); addi sp, 8;	\
+1:							\
+    rts
+#  else
+#   define PSEUDO_RET	\
+	btsti  a0, 31;					\
+	bf    2f;					\
+	subi sp, 8; st.w lr, (sp); st.w gb, (sp, 4);	\
+	__GET_GB1;					\
+	lrw   a2, SYSCALL_ERROR@PLT;			\
+	add   a2, gb;					\
+	ld.w  a2, (a2);					\
+	jsr   a2;					\
+	ld.w lr, (sp); ld.w gb, (sp, 4); addi sp, 8;	\
+2:							\
+	rts
+#  endif /* IS_IN (libc) */
+# else
+#  if !IS_IN (libc)
+#   define PSEUDO_RET		\
+	btsti  a0, 31;		\
+	bt     SYSCALL_ERROR;	\
+	rts
+#  else
+#   define PSEUDO_RET				\
+	btsti  a0, 31;				\
+	bf     3f;				\
+	jmpi   SYSCALL_ERROR;			\
+3:						\
+	rts
+#  endif /* !IS_IN (libc) */
+# endif /* __PIC__ */
+
+
+# undef ret
+# define ret PSEUDO_RET
+
+# undef	PSEUDO_END
+# define PSEUDO_END(name)	\
+  .align 4;			\
+  SYSCALL_ERROR_HANDLER;	\
+  END (name)
+
+# undef	PSEUDO_NOERRNO
+# define PSEUDO_NOERRNO(name, syscall_name, args)	\
+  .text;				\
+  ENTRY (name);				\
+    DO_CALL (syscall_name, args)
+
+# define PSEUDO_RET_NOERRNO \
+	jmp     r15;
+
+# undef ret_NOERRNO
+# define ret_NOERRNO PSEUDO_RET_NOERRNO
+
+# undef	PSEUDO_END_NOERRNO
+# define PSEUDO_END_NOERRNO(name)	\
+	END (name)
+
+/* The function has to return the error code.  */
+# undef	PSEUDO_ERRVAL
+# define PSEUDO_ERRVAL(name, syscall_name, args)	\
+  .text;				\
+  ENTRY (name)				\
+    DO_CALL (syscall_name, args);	\
+    not  a0;				\
+    addi a0, 1
+
+# undef	PSEUDO_END_ERRVAL
+# define PSEUDO_END_ERRVAL(name) \
+  END (name)
+
+# define ret_ERRVAL rts
+
+# if !IS_IN (libc)
+#  define SYSCALL_ERROR __local_syscall_error
+#  if RTLD_PRIVATE_ERRNO
+#   ifdef __PIC__
+#    define SYSCALL_ERROR_HANDLER	\
+__local_syscall_error:			\
+        lrw     a1, rtld_errno@PLT; 	\
+        addu	a1, gb;			\
+        ldw     a1, (a1);		\
+        rsubi   a0, 0;			\
+        stw     a0, (a1);		\
+        bmaski  a0, 0;			\
+        rts
+#   else /* __PIC__ */
+#    define SYSCALL_ERROR_HANDLER	\
+__local_syscall_error:			\
+        lrw     a1, rtld_errno;		\
+        rsubi   a0, 0;			\
+        stw     a0, (a1);		\
+        bmaski  a0, 0;			\
+        rts
+#   endif /* __PIC__ */
+#  else /* !RTLD_PRIVATE_ERRNO */
+#    ifdef __PIC__
+#     define SYSCALL_ERROR_HANDLER	\
+__local_syscall_error:				\
+        subi    sp, 8;				\
+        stw     a0, (sp, 0);			\
+        stw     r15, (sp, 4);			\
+        lrw     a1, __errno_location@PLT;	\
+	add	a1, gb;				\
+        ldw     a1, (a1);			\
+        jsr     a1;				\
+        ldw     a1, (sp, 0); /* load errno*/	\
+        ldw     r15, (sp, 4);			\
+        addi    sp, 8;				\
+        movi    a2, 0;				\
+        rsub    a1, a1, a2;			\
+        stw     a1, (a0);			\
+        bmaski  a0, 0;				\
+        rts
+#    else
+#     define SYSCALL_ERROR_HANDLER 	\
+__local_syscall_error:                                          \
+        subi    sp, 8;                                          \
+        stw     a0, (sp, 0);                                    \
+        stw     r15, (sp, 4);                                   \
+        lrw     a1, __errno_location;                           \
+        jsr     a1;                                             \
+        ldw     a1, (sp, 0);  /* load errno */                  \
+        ldw     r15, (sp, 4);                                   \
+        addi    sp, 8;                                          \
+        movi    a2, 0;                                          \
+        rsub    a1, a1, a2;                                     \
+        stw     a1, (a0);                                       \
+        bmaski  a0, 0;                                          \
+        rts
+#   endif /* __PIC__ */
+#  endif/* RTLD_PRIVATE_ERROR */
+# else
+#  define SYSCALL_ERROR_HANDLER  /* Nothing here; code in sysdep.S is used.  */
+#  define SYSCALL_ERROR __syscall_error
+# endif/* IS_IN (libc) */
+
+/* define DO_CALL */
+#ifdef __CSKYABIV2__
+#undef	DO_CALL
+#define DO_CALL(syscall_name, args)		\
+    DOARGS_##args;				\
+    lrw  r7, SYS_ify(syscall_name);		\
+    trap 0;					\
+    UNDOARGS_##args
+
+#undef  DOARGS_0
+#define DOARGS_0    \
+  subi sp, 8;       \
+  cfi_adjust_cfa_offset (8); \
+  stw  r7, (sp, 0);  \
+  cfi_rel_offset (r7, 0);
+
+#undef  DOARGS_1
+#define DOARGS_1 DOARGS_0
+#undef  DOARGS_2
+#define DOARGS_2 DOARGS_0
+#undef  DOARGS_3
+#define DOARGS_3 DOARGS_0
+#undef  DOARGS_4
+#define DOARGS_4 DOARGS_0
+#undef  DOARGS_5
+#define DOARGS_5    \
+  subi sp, 8;       \
+  cfi_adjust_cfa_offset (8); \
+  stw  r7, (sp, 0); \
+  cfi_rel_offset (7, 0); \
+  stw  r4, (sp, 4); \
+  cfi_rel_offset (4, 4); \
+  ldw  r4, (sp, 8)
+#undef  DOARGS_6
+#define DOARGS_6    \
+  subi sp, 16;      \
+  cfi_adjust_cfa_offset (16); \
+  stw  r7, (sp, 0); \
+  cfi_rel_offset (7, 0); \
+  stw  r4, (sp, 4); \
+  cfi_rel_offset (4, 4); \
+  stw  r5, (sp, 8); \
+  cfi_rel_offset (5, 8); \
+  ldw  r4, (sp, 16); \
+  ldw  r5, (sp, 20)
+
+#undef  UNDOARGS_0
+#define UNDOARGS_0 \
+  ldw  r7, (sp, 0); \
+  cfi_restore (r7); \
+  addi sp, 8;   \
+  cfi_adjust_cfa_offset (-8);
+
+#undef  UNDOARGS_1
+#define UNDOARGS_1 UNDOARGS_0
+#undef  UNDOARGS_2
+#define UNDOARGS_2 UNDOARGS_0
+#undef  UNDOARGS_3
+#define UNDOARGS_3 UNDOARGS_0
+#undef  UNDOARGS_4
+#define UNDOARGS_4 UNDOARGS_0
+#undef  UNDOARGS_5
+#define UNDOARGS_5  \
+  ldw  r7, (sp, 0); \
+  cfi_restore (r4); \
+  ldw  r4, (sp, 4); \
+  cfi_restore (r4); \
+  addi sp, 8;  \
+  cfi_adjust_cfa_offset (-8);
+
+#undef  UNDOARGS_6
+#define UNDOARGS_6 \
+  ldw  r7, (sp, 0); \
+  cfi_restore (r7); \
+  ldw  r4, (sp, 4); \
+  cfi_restore (r4); \
+  ldw  r5, (sp, 8); \
+  cfi_restore (r5); \
+  addi sp, 16;    \
+  cfi_adjust_cfa_offset (-16);
+
+#else	/* __CSKYABIV1__ */
+
+#undef  DO_CALL
+#define DO_CALL(syscall_name, args)             \
+    lrw  r1, SYS_ify(syscall_name);            \
+    trap 0
+//#endif	/* DO_CALL */
+#endif	/* __CSKYABIV2__ */
+
+/* define DO_CALL_2, only ABIV2 need DO_CALL_2 */
+#ifdef __CSKYABIV2__
+
+#undef	DO_CALL_2
+#define DO_CALL_2(syscall_name, args)		\
+    DOARGS2_##args;				\
+    lrw  r7, SYS_ify(syscall_name);		\
+    trap 0;					\
+    UNDOARGS2_##args
+
+/*
+ * to be quite different with DO_CALL, DO_CALL_2 need not save r7.
+ */
+#undef  DOARGS2_0
+#define DOARGS2_0
+
+#undef  DOARGS2_1
+#define DOARGS2_1 DOARGS2_0
+#undef  DOARGS2_2
+#define DOARGS2_2 DOARGS2_0
+#undef  DOARGS2_3
+#define DOARGS2_3 DOARGS2_0
+#undef  DOARGS2_4
+#define DOARGS2_4 DOARGS2_0
+#undef  DOARGS2_5
+#define DOARGS2_5   \
+  subi sp, 8;       \
+  cfi_adjust_cfa_offset (8); \
+  stw  r4, (sp, 0); \
+  cfi_rel_offset (4, 0); \
+  ldw  r4, (sp, 20)
+#undef  DOARGS2_6
+#define DOARGS2_6    \
+  subi sp, 8;       \
+  cfi_adjust_cfa_offset (8); \
+  stw  r4, (sp, 0); \
+  cfi_rel_offset (4, 0); \
+  stw  r5, (sp, 4); \
+  cfi_rel_offset (5, 0); \
+  ldw  r4, (sp, 20); \
+  ldw  r5, (sp, 24)
+
+#undef  UNDOARGS2_0
+#define UNDOARGS2_0
+
+#undef  UNDOARGS2_1
+#define UNDOARGS2_1 UNDOARGS2_0
+#undef  UNDOARGS2_2
+#define UNDOARGS2_2 UNDOARGS2_0
+#undef  UNDOARGS2_3
+#define UNDOARGS2_3 UNDOARGS2_0
+#undef  UNDOARGS2_4
+#define UNDOARGS2_4 UNDOARGS2_0
+#undef  UNDOARGS2_5
+#define UNDOARGS2_5  \
+  ldw  r4, (sp, 0); \
+  addi sp, 8
+
+#undef  UNDOARGS2_6
+#define UNDOARGS2_6 \
+  ldw  r4, (sp, 0); \
+  ldw  r5, (sp, 4); \
+  addi sp, 8
+
+#endif  /* DO_CALL_2 */
+
+#else /* not __ASSEMBLER__ */
+
+
+/* Define a macro which expands into the inline wrapper code for a system
+   call.  */
+#undef INLINE_SYSCALL
+#define INLINE_SYSCALL(name, nr, args...)                               \
+  ({ unsigned int _inline_sys_result = INTERNAL_SYSCALL (name, , nr, args);     \
+     if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (_inline_sys_result, ), 0)) \
+       {                                                                \
+         __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, ));           \
+         _inline_sys_result = (unsigned int) -1;                                \
+       }                                                                \
+     (int) _inline_sys_result; })
+
+#undef INTERNAL_SYSCALL_DECL
+#define INTERNAL_SYSCALL_DECL(err) do { } while (0)
+
+#undef INTERNAL_SYSCALL_ERROR_P
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+  ((unsigned int) (val) >= 0xffffff01u)
+
+#undef INTERNAL_SYSCALL_ERRNO
+#define INTERNAL_SYSCALL_ERRNO(val, err)        (-(val))
+
+
+#undef INTERNAL_SYSCALL_RAW
+#ifndef __CSKYABIV2__
+#define INTERNAL_SYSCALL_RAW0(name, err, dummy...)                      \
+  ({unsigned int __sys_result;                                          \
+     {                                                                  \
+       register int _a1 __asm__ ("a0"), _nr __asm__ ("r1");             \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr)                                \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW1(name, err, arg1)                          \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1);                               \
+     {                                                                  \
+       register int _a1 __asm__ ("a0"), _nr __asm__ ("r1");             \
+       _a1 = _tmp_arg1;                                                 \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1)                     \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW2(name, err, arg1, arg2)                    \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+     {                                                                  \
+       register int _nr __asm__ ("r1");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       _a1 = _tmp_arg1, _a2 = _tmp_arg2;                                \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2)          \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW3(name, err, arg1, arg2, arg3)              \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+    register int _tmp_arg3 = (int)(arg3);                               \
+     {                                                                  \
+       register int _nr __asm__ ("r1");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       register int _a3 __asm__ ("a2");                                 \
+       _a1 = _tmp_arg1;                                                 \
+       _a2 = _tmp_arg2;                                                 \
+       _a3 = _tmp_arg3;                                                 \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2),         \
+                               "r" (_a3)                                \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW4(name, err, arg1, arg2, arg3, arg4)        \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+    register int _tmp_arg3 = (int)(arg3), _tmp_arg4 = (int)(arg4);      \
+     {                                                                  \
+       register int _nr __asm__ ("r1");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       register int _a3 __asm__ ("a2"), _a4 __asm__ ("a3");             \
+       _a1 = _tmp_arg1, _a2 = _tmp_arg2, _a3 = _tmp_arg3;               \
+       _a4 = _tmp_arg4;                                                 \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2),         \
+                               "r" (_a3), "r" (_a4)                     \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW5(name, err, arg1, arg2, arg3, arg4,        \
+                              arg5)                                     \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+    register int _tmp_arg3 = (int)(arg3), _tmp_arg4 = (int)(arg4);      \
+    register int _tmp_arg5 = (int)(arg5);                               \
+     {                                                                  \
+       register int _nr __asm__ ("r1");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       register int _a3 __asm__ ("a2"), _a4 __asm__ ("a3");             \
+       register int _a5 __asm__ ("a4");                                 \
+       _a1 = _tmp_arg1, _a2 = _tmp_arg2, _a3 = _tmp_arg3;               \
+       _a4 = _tmp_arg4, _a5 = _tmp_arg5;                                \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2),         \
+                               "r" (_a3), "r" (_a4), "r" (_a5)          \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW6(name, err, arg1, arg2, arg3, arg4,        \
+                              arg5, arg6)                               \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+    register int _tmp_arg3 = (int)(arg3), _tmp_arg4 = (int)(arg4);      \
+    register int _tmp_arg5 = (int)(arg5), _tmp_arg6 = (int)(arg6);      \
+     {                                                                  \
+       register int _nr __asm__ ("r1");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       register int _a3 __asm__ ("a2"), _a4 __asm__ ("a3");             \
+       register int _a5 __asm__ ("a4"), _a6 __asm__ ("a5");             \
+       _a1 = _tmp_arg1, _a2 = _tmp_arg2, _a3 = _tmp_arg3;               \
+       _a4 = _tmp_arg4, _a5 = _tmp_arg5, _a6 = _tmp_arg6;               \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2),         \
+                               "r" (_a3), "r" (_a4), "r" (_a5),         \
+                               "r" (_a6)                                \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW7(name, err, arg1, arg2, arg3, arg4,        \
+                              arg5, arg6, arg7)                         \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+    register int _tmp_arg3 = (int)(arg3), _tmp_arg4 = (int)(arg4);      \
+    register int _tmp_arg5 = (int)(arg5), _tmp_arg6 = (int)(arg6);      \
+    register int _tmp_arg7 = (int)(arg7);                               \
+     {                                                                  \
+       register int _nr __asm__ ("r1");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       register int _a3 __asm__ ("a2"), _a4 __asm__ ("a3");             \
+       register int _a5 __asm__ ("a4"), _a6 __asm__ ("a5");             \
+       register int _a7 __asm__ ("r8");                                 \
+       _a1 = _tmp_arg1, _a2 = _tmp_arg2, _a3 = _tmp_arg3;               \
+       _a4 = _tmp_arg4, _a5 = _tmp_arg5, _a6 = _tmp_arg6;               \
+       _a7 = _tmp_arg7;                                                 \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2),         \
+                               "r" (_a3), "r" (_a4), "r" (_a5),         \
+                               "r" (_a6), "r" (_a7)                     \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#else
+#define INTERNAL_SYSCALL_RAW0(name, err, dummy...)                      \
+  ({unsigned int __sys_result;                                          \
+     {                                                                  \
+       register int _a1 __asm__ ("a0"), _nr __asm__ ("r7");             \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr)                                \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW1(name, err, arg1)                          \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1);                               \
+     {                                                                  \
+       register int _a1 __asm__ ("a0"), _nr __asm__ ("r7");             \
+       _a1 = _tmp_arg1;                                                 \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1)                     \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW2(name, err, arg1, arg2)                    \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+     {                                                                  \
+       register int _nr __asm__ ("r7");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       _a1 = _tmp_arg1, _a2 = _tmp_arg2;                                \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2)          \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW3(name, err, arg1, arg2, arg3)              \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+    register int _tmp_arg3 = (int)(arg3);                               \
+     {                                                                  \
+       register int _nr __asm__ ("r7");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       register int _a3 __asm__ ("a2");                                 \
+       _a1 = _tmp_arg1;                                                 \
+       _a2 = _tmp_arg2;                                                 \
+       _a3 = _tmp_arg3;                                                 \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2),         \
+                               "r" (_a3)                                \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW4(name, err, arg1, arg2, arg3, arg4)        \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+    register int _tmp_arg3 = (int)(arg3), _tmp_arg4 = (int)(arg4);      \
+     {                                                                  \
+       register int _nr __asm__ ("r7");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       register int _a3 __asm__ ("a2"), _a4 __asm__ ("a3");             \
+       _a1 = _tmp_arg1, _a2 = _tmp_arg2, _a3 = _tmp_arg3;               \
+       _a4 = _tmp_arg4;                                                 \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2),         \
+                               "r" (_a3), "r" (_a4)                     \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW5(name, err, arg1, arg2, arg3, arg4,        \
+                              arg5)                                     \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+    register int _tmp_arg3 = (int)(arg3), _tmp_arg4 = (int)(arg4);      \
+    register int _tmp_arg5 = (int)(arg5);                               \
+     {                                                                  \
+       register int _nr __asm__ ("r7");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       register int _a3 __asm__ ("a2"), _a4 __asm__ ("a3");             \
+       register int _a5 __asm__ ("r4");                                 \
+       _a1 = _tmp_arg1, _a2 = _tmp_arg2, _a3 = _tmp_arg3;               \
+       _a4 = _tmp_arg4, _a5 = _tmp_arg5;                                \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2),         \
+                               "r" (_a3), "r" (_a4), "r" (_a5)          \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW6(name, err, arg1, arg2, arg3, arg4,        \
+                              arg5, arg6)                               \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+    register int _tmp_arg3 = (int)(arg3), _tmp_arg4 = (int)(arg4);      \
+    register int _tmp_arg5 = (int)(arg5), _tmp_arg6 = (int)(arg6);      \
+     {                                                                  \
+       register int _nr __asm__ ("r7");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       register int _a3 __asm__ ("a2"), _a4 __asm__ ("a3");             \
+       register int _a5 __asm__ ("r4"), _a6 __asm__ ("r5");             \
+       _a1 = _tmp_arg1, _a2 = _tmp_arg2, _a3 = _tmp_arg3;               \
+       _a4 = _tmp_arg4, _a5 = _tmp_arg5, _a6 = _tmp_arg6;               \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2),         \
+                               "r" (_a3), "r" (_a4), "r" (_a5),         \
+                               "r" (_a6)                                \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#define INTERNAL_SYSCALL_RAW7(name, err, arg1, arg2, arg3, arg4,        \
+                              arg5, arg6, arg7)                         \
+  ({unsigned int __sys_result;                                          \
+    register int _tmp_arg1 = (int)(arg1), _tmp_arg2 = (int)(arg2);      \
+    register int _tmp_arg3 = (int)(arg3), _tmp_arg4 = (int)(arg4);      \
+    register int _tmp_arg5 = (int)(arg5), _tmp_arg6 = (int)(arg6);      \
+    register int _tmp_arg7 = (int)(arg7);                               \
+     {                                                                  \
+       register int _nr __asm__ ("r7");                                 \
+       register int _a1 __asm__ ("a0"), _a2 __asm__ ("a1");             \
+       register int _a3 __asm__ ("a2"), _a4 __asm__ ("a3");             \
+       register int _a5 __asm__ ("r4"), _a6 __asm__ ("r5");             \
+       register int _a7 __asm__ ("r6");                                 \
+       _a1 = _tmp_arg1, _a2 = _tmp_arg2, _a3 = _tmp_arg3;               \
+       _a4 = _tmp_arg4, _a5 = _tmp_arg5, _a6 = _tmp_arg6;               \
+       _a7 = _tmp_arg7;                                                 \
+       _nr = name;                                                      \
+       __asm__ __volatile__ ("trap  0 \n\t"                             \
+                             : "=r" (_a1)                               \
+                             : "r" (_nr), "r" (_a1), "r" (_a2),         \
+                               "r" (_a3), "r" (_a4), "r" (_a5),         \
+                               "r" (_a6), "r" (_a7)                     \
+                             : "memory");                               \
+               __sys_result = _a1;                                      \
+     }                                                                  \
+     (int) __sys_result; })
+
+#endif /* __ABI_CSKY_V2__ */
+
+#undef INTERNAL_SYSCALL
+#define INTERNAL_SYSCALL(name, err, nr, args...)                \
+        INTERNAL_SYSCALL_RAW##nr(SYS_ify(name), err, args)
+
+#undef INTERNAL_SYSCALL_NCS
+#define INTERNAL_SYSCALL_NCS(number, err, nr, args...)          \
+  INTERNAL_SYSCALL_RAW##nr (number, err, args)
+
+#endif	/* __ASSEMBLER__ */
+
+/* Pointer mangling support.  */
+#if IS_IN (rtld)
+#else
+# ifdef __ASSEMBLER__
+#  ifdef __CSKYABIV2__
+#   define PTR_MANGLE(dst, src, guard)	\
+  mov	t0, a0;				\
+  READ_THREAD_POINTER()			\
+  ldw	guard, (a0, POINTER_GUARD); 	\
+  mov	a0, t0;				\
+  xor	dst, src, guard;
+#  else
+#   define PTR_MANGLE(dst, src, guard)	\
+  mov   r7, a0;				\
+  READ_THREAD_POINTER();		\
+  ldw   guard, (a0, POINTER_GUARD);	\
+  mov   a0, r7;\
+  xor   dst, src, guard;
+#  endif
+#  define PTR_DEMANGLE(dst, src, guard) PTR_MANGLE (dst, src, guard)
+#  define PTR_MANGLE2(dst, src, guard) \
+  xor	dst, src, guard
+#  define PTR_DEMANGLE2(dst, src, guard) PTR_MANGLE2 (dst, src, guard)
+# else
+#  define PTR_MANGLE(var) \
+  (var) = (__typeof (var)) ((uintptr_t) (var) ^ THREAD_GET_POINTER_GUARD ())
+#  define PTR_DEMANGLE(var)     PTR_MANGLE (var)
+# endif
+#endif
+
+#endif /* linux/csky/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/csky/ucontext_i.sym b/sysdeps/unix/sysv/linux/csky/ucontext_i.sym
new file mode 100644
index 0000000..05fcf9d
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/csky/ucontext_i.sym
@@ -0,0 +1,31 @@ 
+#include <inttypes.h>
+#include <stddef.h>
+#include <sys/ucontext.h>
+
+SIG_BLOCK
+SIG_SETMASK
+
+-- Offsets of the fields in the ucontext_t structure.
+#define ucontext(member)	offsetof (ucontext_t, member)
+#define mcontext(member)	ucontext (uc_mcontext.member)
+
+UCONTEXT_FLAGS			ucontext(uc_flags)
+UCONTEXT_LINK			ucontext(uc_link)
+UCONTEXT_STACK			ucontext(uc_stack)
+UCONTEXT_MCONTEXT		ucontext(uc_mcontext)
+UCONTEXT_SIGMASK		ucontext(uc_sigmask)
+
+MCONTEXT_CSKY_A0		mcontext(sc_a0)
+MCONTEXT_CSKY_R4		mcontext(sc_regs[0])
+MCONTEXT_CSKY_R8		mcontext(sc_regs[2])
+MCONTEXT_CSKY_SP		mcontext(sc_usp)
+MCONTEXT_CSKY_LR		mcontext(sc_r15)
+#ifdef __CSKYABIV2__
+MCONTEXT_CSKY_R16		mcontext(sc_exregs[0])
+MCONTEXT_CSKY_HI		mcontext(sc_rhi)
+MCONTEXT_CSKY_LO		mcontext(sc_rlo)
+#endif
+MCONTEXT_CSKY_PC		mcontext(sc_pc)
+MCONTEXT_CSKY_FESR		mcontext(sc_fesr)
+MCONTEXT_CSKY_FSR		mcontext(sc_fsr)
+MCONTEXT_CSKY_FR0		mcontext(sc_fpregs[0])