summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/csky/bits
diff options
context:
space:
mode:
authorGuo Ren <ren_guo@c-sky.com>2017-10-15 20:59:34 +0800
committerWaldemar Brodkorb <wbx@uclibc-ng.org>2017-11-19 09:20:11 +0100
commit2fcffe26e815b7125a357c83b59617ab93c16b41 (patch)
treefe5a973dc4bbf38bce8468a4497f5f656f082a9f /libc/sysdeps/linux/csky/bits
parent9e38e0aa45cca21d5023d0af94377f0e1e41d2f4 (diff)
csky: port to uclibc-ng
Follow the steps to build c-sky uclibc linux system: 1. git clone https://github.com/c-sky/buildroot.git 2. cd buildroot 3. make qemu_csky_ck810_uclibc_defconfig 4. make Follow the buildroot/board/qemu/csky/readme.txt to run. This buildroot toolchain is pre-build, But you can rebuild the c-sky uclibc-ng alone and install it to the buildroot sysroot manually. We'll try our best to improve the uclibc-ng continuously. Signed-off-by: Guo Ren <ren_guo@c-sky.com>
Diffstat (limited to 'libc/sysdeps/linux/csky/bits')
-rw-r--r--libc/sysdeps/linux/csky/bits/atomic.h93
-rw-r--r--libc/sysdeps/linux/csky/bits/endian.h10
-rw-r--r--libc/sysdeps/linux/csky/bits/fcntl.h193
-rw-r--r--libc/sysdeps/linux/csky/bits/fenv.h58
-rw-r--r--libc/sysdeps/linux/csky/bits/kernel_stat.h60
-rw-r--r--libc/sysdeps/linux/csky/bits/kernel_types.h47
-rw-r--r--libc/sysdeps/linux/csky/bits/mathinline.h445
-rw-r--r--libc/sysdeps/linux/csky/bits/setjmp.h19
-rw-r--r--libc/sysdeps/linux/csky/bits/shm.h85
-rw-r--r--libc/sysdeps/linux/csky/bits/sigcontextinfo.h26
-rw-r--r--libc/sysdeps/linux/csky/bits/stackinfo.h6
-rw-r--r--libc/sysdeps/linux/csky/bits/syscalls.h113
-rw-r--r--libc/sysdeps/linux/csky/bits/uClibc_arch_features.h46
-rw-r--r--libc/sysdeps/linux/csky/bits/wordsize.h1
14 files changed, 1202 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/csky/bits/atomic.h b/libc/sysdeps/linux/csky/bits/atomic.h
new file mode 100644
index 000000000..231d58f30
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/atomic.h
@@ -0,0 +1,93 @@
+#ifndef __CSKY_ATOMIC_H_
+#define __CSKY_ATOMIC_H_
+
+#include <stdint.h>
+#include <sysdep.h>
+
+typedef int8_t atomic8_t;
+typedef uint8_t uatomic8_t;
+typedef int_fast8_t atomic_fast8_t;
+typedef uint_fast8_t uatomic_fast8_t;
+
+typedef int16_t atomic16_t;
+typedef uint16_t uatomic16_t;
+typedef int_fast16_t atomic_fast16_t;
+typedef uint_fast16_t uatomic_fast16_t;
+
+typedef int32_t atomic32_t;
+typedef uint32_t uatomic32_t;
+typedef int_fast32_t atomic_fast32_t;
+typedef uint_fast32_t uatomic_fast32_t;
+
+typedef int64_t atomic64_t;
+typedef uint64_t uatomic64_t;
+typedef int_fast64_t atomic_fast64_t;
+typedef uint_fast64_t uatomic_fast64_t;
+
+typedef intptr_t atomicptr_t;
+typedef uintptr_t uatomicptr_t;
+typedef intmax_t atomic_max_t;
+typedef uintmax_t uatomic_max_t;
+
+# define __arch_compare_and_exchange_bool_8_int(mem, newval, oldval) \
+ (abort (), 0)
+
+# define __arch_compare_and_exchange_bool_16_int(mem, newval, oldval) \
+ (abort (), 0)
+
+# define __arch_compare_and_exchange_bool_32_int(mem, newval, oldval) \
+ ({ __typeof(mem) _mem = (mem); \
+ __typeof(oldval) _oldval = oldval; \
+ __typeof(newval) _newval = newval; \
+ register __typeof(oldval) _a0 __asm__ ("a0") = _oldval; \
+ register __typeof(newval) _a1 __asm__ ("a1") = _newval; \
+ register __typeof(mem) _a2 __asm__ ("a2") = _mem; \
+ __asm__ __volatile__ ("trap 2;" \
+ : "+r" (_a0) : "r" (_a1) , "r" (_a2) \
+ : "a3", "memory"); \
+ _a0; })
+
+# define __arch_compare_and_exchange_bool_64_int(mem, newval, oldval) \
+ (abort (), 0)
+
+#define __arch_compare_and_exchange_val_8_int(mem, newval, oldval) \
+ (abort (), 0)
+
+#define __arch_compare_and_exchange_val_16_int(mem, newval, oldval) \
+ (abort (), 0)
+
+#define __arch_compare_and_exchange_val_32_int(mem, newval, oldval) \
+ ({ __typeof (mem) _mem = (mem); \
+ __typeof (*mem) __gret = *_mem; \
+ unsigned int _tmp = 0; \
+ __typeof (oldval) _oldval = oldval; \
+ __typeof (newval) _newval = newval; \
+ register __typeof (oldval) _a0 __asm__ ("a0") = _oldval; \
+ register __typeof (newval) _a1 __asm__ ("a1") = _newval; \
+ register __typeof (mem) _a2 __asm__ ("a2") = _mem; \
+ __asm__ __volatile__ ("1:\n\t" \
+ "ldw %1, (%4, 0x0)\n\t" \
+ "cmpne %1, %0\n\t" \
+ "bt 2f\n\t" \
+ "mov %2, %0\n\t" \
+ "trap 2\n\t" \
+ "cmpnei %0, 0\n\t" \
+ "mov %0, %2\n\t" \
+ "bt 1b\n\t" \
+ "2: \n\t" \
+ :"+r" (_a0), "+r"(__gret), "+r" (_tmp) :"r" (_a1) , "r" (_a2) \
+ : "a3", "memory"); \
+ __gret; })
+
+# define __arch_compare_and_exchange_val_64_int(mem, newval, oldval) \
+ (abort (), 0)
+
+# define atomic_compare_and_exchange_bool_acq(mem, new, old) \
+ __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \
+ mem, new, old)
+
+# define atomic_compare_and_exchange_val_acq(mem, new, old) \
+ __atomic_val_bysize (__arch_compare_and_exchange_val, int, \
+ mem, new, old)
+
+#endif
diff --git a/libc/sysdeps/linux/csky/bits/endian.h b/libc/sysdeps/linux/csky/bits/endian.h
new file mode 100644
index 000000000..09af89cd7
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/endian.h
@@ -0,0 +1,10 @@
+#ifndef _ENDIAN_H
+# error "Never use <bits/endian.h> directly; include <endian.h> instead."
+#endif
+
+/* CSKY CPU can be either big or little endian. */
+#ifdef __cskyBE__
+# define __BYTE_ORDER __BIG_ENDIAN
+#else
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#endif
diff --git a/libc/sysdeps/linux/csky/bits/fcntl.h b/libc/sysdeps/linux/csky/bits/fcntl.h
new file mode 100644
index 000000000..feacdaded
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/fcntl.h
@@ -0,0 +1,193 @@
+#ifndef _FCNTL_H
+# error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
+#endif
+
+
+#include <sys/types.h>
+#ifdef __USE_GNU
+# include <bits/uio.h>
+#endif
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+ located on an ext2 file system */
+#define O_ACCMODE 0003
+#define O_RDONLY 00
+#define O_WRONLY 01
+#define O_RDWR 02
+#define O_CREAT 0100 /* not fcntl */
+#define O_EXCL 0200 /* not fcntl */
+#define O_NOCTTY 0400 /* not fcntl */
+#define O_TRUNC 01000 /* not fcntl */
+#define O_APPEND 02000
+#define O_NONBLOCK 04000
+#define O_NDELAY O_NONBLOCK
+#define O_SYNC 010000
+#define O_FSYNC O_SYNC
+#define O_ASYNC 020000
+
+#ifdef __USE_GNU
+# define O_DIRECTORY 040000 /* Must be a directory. */
+# define O_NOFOLLOW 0100000 /* Do not follow links. */
+# define O_DIRECT 0200000 /* Direct disk access. */
+# define O_STREAMING 04000000/* streaming access */
+# define O_CLOEXEC 02000000 /* set close_on_exec */
+#endif
+
+/* For now Linux has synchronisity options for data and read operations.
+ We define the symbols here but let them do the same as O_SYNC since
+ this is a superset. */
+#if defined __USE_POSIX199309 || defined __USE_UNIX98
+# define O_DSYNC O_SYNC /* Synchronize data. */
+# define O_RSYNC O_SYNC /* Synchronize read operations. */
+#endif
+
+#ifdef __USE_LARGEFILE64
+# define O_LARGEFILE 0400000
+#endif
+
+/* Values for the second argument to `fcntl'. */
+#define F_DUPFD 0 /* Duplicate file descriptor. */
+#define F_GETFD 1 /* Get file descriptor flags. */
+#define F_SETFD 2 /* Set file descriptor flags. */
+#define F_GETFL 3 /* Get file status flags. */
+#define F_SETFL 4 /* Set file status flags. */
+#ifndef __USE_FILE_OFFSET64
+# define F_GETLK 5 /* Get record locking info. */
+# define F_SETLK 6 /* Set record locking info (non-blocking). */
+# define F_SETLKW 7 /* Set record locking info (blocking). */
+#else
+# define F_GETLK F_GETLK64 /* Get record locking info. */
+# define F_SETLK F_SETLK64 /* Set record locking info (non-blocking).*/
+# define F_SETLKW F_SETLKW64 /* Set record locking info (blocking). */
+#endif
+#define F_GETLK64 12 /* Get record locking info. */
+#define F_SETLK64 13 /* Set record locking info (non-blocking). */
+#define F_SETLKW64 14 /* Set record locking info (blocking). */
+
+#if defined __USE_BSD || defined __USE_XOPEN2K
+# define F_SETOWN 8 /* Get owner of socket (receiver of SIGIO). */
+# define F_GETOWN 9 /* Set owner of socket (receiver of SIGIO). */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETSIG 10 /* Set number of signal to be sent. */
+# define F_GETSIG 11 /* Get number of signal to be sent. */
+#endif
+
+#ifdef __USE_GNU
+# define F_SETLEASE 1024 /* Set a lease. */
+# define F_GETLEASE 1025 /* Enquire what lease is active. */
+# define F_NOTIFY 1026 /* Request notfications on a directory. */
+#endif
+
+/* For F_[GET|SET]FL. */
+#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
+
+/* For posix fcntl() and `l_type' field of a `struct flock' for lockf(). */
+#define F_RDLCK 0 /* Read lock. */
+#define F_WRLCK 1 /* Write lock. */
+#define F_UNLCK 2 /* Remove lock. */
+
+/* For old implementation of bsd flock(). */
+#define F_EXLCK 4 /* or 3 */
+#define F_SHLCK 8 /* or 4 */
+
+#ifdef __USE_BSD
+/* Operations for bsd flock(), also used by the kernel implementation. */
+# define LOCK_SH 1 /* shared lock */
+# define LOCK_EX 2 /* exclusive lock */
+# define LOCK_NB 4 /* or'd with one of the above to prevent
+ blocking */
+# define LOCK_UN 8 /* remove lock */
+#endif
+
+#ifdef __USE_GNU
+# define LOCK_MAND 32 /* This is a mandatory flock: */
+# define LOCK_READ 64 /* ... which allows concurrent read operations. */
+# define LOCK_WRITE 128 /* ... which allows concurrent write operations. */
+# define LOCK_RW 192 /* ... Which allows concurrent read & write operations. */
+#endif
+
+#ifdef __USE_GNU
+/* Types of directory notifications that may be requested with F_NOTIFY. */
+# define DN_ACCESS 0x00000001 /* File accessed. */
+# define DN_MODIFY 0x00000002 /* File modified. */
+# define DN_CREATE 0x00000004 /* File created. */
+# define DN_DELETE 0x00000008 /* File removed. */
+# define DN_RENAME 0x00000010 /* File renamed. */
+# define DN_ATTRIB 0x00000020 /* File changed attibutes. */
+# define DN_MULTISHOT 0x80000000 /* Don't remove notifier. */
+#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
+
+/* Define some more compatibility macros to be backward compatible with
+ BSD systems which did not managed to hide these kernel macros. */
+#ifdef __USE_BSD
+# define FAPPEND O_APPEND
+# define FFSYNC O_FSYNC
+# define FASYNC O_ASYNC
+# define FNONBLOCK O_NONBLOCK
+# define FNDELAY O_NDELAY
+#endif /* Use BSD. */
+
+/* Advise to `posix_fadvise'. */
+#ifdef __USE_XOPEN2K
+# define POSIX_FADV_NORMAL 0 /* No further special treatment. */
+# define POSIX_FADV_RANDOM 1 /* Expect random page references. */
+# define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */
+# define POSIX_FADV_WILLNEED 3 /* Will need these pages. */
+# define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */
+# define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */
+#endif
+
+__BEGIN_DECLS
+
+#if defined __USE_GNU && defined __UCLIBC_LINUX_SPECIFIC__
+
+/* Provide kernel hint to read ahead. */
+extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
+ __THROW;
+
+
+/* Selective file content synch'ing. */
+extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
+ unsigned int __flags);
+
+/* Splice address range into a pipe. */
+extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
+ size_t __count, unsigned int __flags);
+
+/* Splice two files together. */
+extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
+ __off64_t *__offout, size_t __len,
+ unsigned int __flags);
+
+/* In-kernel implementation of tee for pipe buffers. */
+extern ssize_t tee (int __fdin, int __fdout, size_t __len,
+ unsigned int __flags);
+
+#endif
+__END_DECLS
diff --git a/libc/sysdeps/linux/csky/bits/fenv.h b/libc/sysdeps/linux/csky/bits/fenv.h
new file mode 100644
index 000000000..606fe793d
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/fenv.h
@@ -0,0 +1,58 @@
+#ifndef _FENV_H
+# error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
+#endif
+
+/* Define bits representing the exception. We use the bit positions of
+ the appropriate bits in the FPSR Accrued Exception Byte. */
+enum
+ {
+ FE_INEXACT = 1 << 3,
+#define FE_INEXACT FE_INEXACT
+ FE_DIVBYZERO = 1 << 4,
+#define FE_DIVBYZERO FE_DIVBYZERO
+ FE_UNDERFLOW = 1 << 5,
+#define FE_UNDERFLOW FE_UNDERFLOW
+ FE_OVERFLOW = 1 << 6,
+#define FE_OVERFLOW FE_OVERFLOW
+ FE_INVALID = 1 << 7
+#define FE_INVALID FE_INVALID
+ };
+
+#define FE_ALL_EXCEPT \
+ (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
+
+/* The csky FPU supports all of the four defined rounding modes. We use
+ the bit positions in the FPCR Mode Control Byte as the values for the
+ appropriate macros. */
+enum
+ {
+ FE_TONEAREST = 0,
+#define FE_TONEAREST FE_TONEAREST
+ FE_TOWARDZERO = 1 << 4,
+#define FE_TOWARDZERO FE_TOWARDZERO
+ FE_DOWNWARD = 2 << 4,
+#define FE_DOWNWARD FE_DOWNWARD
+ FE_UPWARD = 3 << 4
+#define FE_UPWARD FE_UPWARD
+ };
+
+/* Type representing exception flags. */
+typedef unsigned int fexcept_t;
+
+/* Type representing floating-point environment. This structure
+ corresponds to the layout of the block written by `fmovem'. */
+typedef struct
+ {
+ unsigned int __control_register;
+ unsigned int __status_register;
+ unsigned int __instruction_address;
+ }
+fenv_t;
+
+/* If the default argument is used we use this value. */
+#define FE_DFL_ENV ((__const fenv_t *) -1)
+
+#ifdef __USE_GNU
+/* Floating-point environment where none of the exceptions are masked. */
+# define FE_NOMASK_ENV ((__const fenv_t *) -2)
+#endif
diff --git a/libc/sysdeps/linux/csky/bits/kernel_stat.h b/libc/sysdeps/linux/csky/bits/kernel_stat.h
new file mode 100644
index 000000000..079a01ace
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/kernel_stat.h
@@ -0,0 +1,60 @@
+#ifndef _BITS_STAT_STRUCT_H
+#define _BITS_STAT_STRUCT_H
+
+#define STAT_HAVE_NSEC 1
+
+struct kernel_stat {
+#if defined(__cskyBE__)
+ unsigned short st_dev;
+ unsigned short __pad1;
+#else
+ unsigned long st_dev;
+#endif
+ unsigned long st_ino;
+ unsigned short st_mode;
+ unsigned short st_nlink;
+ unsigned short st_uid;
+ unsigned short st_gid;
+#if defined(__cskyBE__)
+ unsigned short st_rdev;
+ unsigned short __pad2;
+#else
+ unsigned long st_rdev;
+#endif
+ unsigned long st_size;
+ unsigned long st_blksize;
+ unsigned long st_blocks;
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ unsigned long __unused4;
+ unsigned long __unused5;
+};
+
+struct kernel_stat64 {
+ unsigned long long st_dev;
+ unsigned char __pad0[4];
+
+#define STAT64_HAS_BROKEN_ST_INO 1
+ unsigned long __st_ino;
+ unsigned int st_mode;
+ unsigned int st_nlink;
+
+ unsigned long st_uid;
+ unsigned long st_gid;
+
+ unsigned long long st_rdev;
+ unsigned char __pad3[4];
+
+ long long st_size;
+ unsigned long st_blksize;
+ unsigned long long st_blocks; /* Number 512-byte blocks allocated. */
+
+ struct timespec st_atim;
+ struct timespec st_mtim;
+ struct timespec st_ctim;
+ unsigned long long st_ino;
+};
+
+#endif /* _BITS_STAT_STRUCT_H */
+
diff --git a/libc/sysdeps/linux/csky/bits/kernel_types.h b/libc/sysdeps/linux/csky/bits/kernel_types.h
new file mode 100644
index 000000000..80c9d599e
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/kernel_types.h
@@ -0,0 +1,47 @@
+/* Note that we use the exact same include guard #define names
+ * as asm/posix_types.h. This will avoid gratuitous conflicts
+ * with the posix_types.h kernel header, and will ensure that
+ * our private content, and not the kernel header, will win.
+ * -Erik
+ */
+#if !defined(__ARCH_CSKY_POSIX_TYPES_H) || !defined(__ASM_GENERIC_POSIX_TYPES_H)
+#define __ARCH_CSKY_POSIX_TYPES_H
+#define __ASM_GENERIC_POSIX_TYPES_H
+
+typedef unsigned short __kernel_dev_t;
+typedef unsigned long __kernel_ino_t;
+typedef unsigned short __kernel_mode_t;
+typedef unsigned short __kernel_nlink_t;
+typedef long __kernel_off_t;
+typedef int __kernel_pid_t;
+typedef unsigned short __kernel_ipc_pid_t;
+typedef unsigned short __kernel_uid_t;
+typedef unsigned short __kernel_gid_t;
+typedef unsigned int __kernel_size_t;
+typedef int __kernel_ssize_t;
+typedef int __kernel_ptrdiff_t;
+typedef long __kernel_time_t;
+typedef long __kernel_suseconds_t;
+typedef long __kernel_clock_t;
+typedef int __kernel_daddr_t;
+typedef char * __kernel_caddr_t;
+typedef unsigned short __kernel_uid16_t;
+typedef unsigned short __kernel_gid16_t;
+typedef unsigned int __kernel_uid32_t;
+typedef unsigned int __kernel_gid32_t;
+typedef unsigned short __kernel_old_uid_t;
+typedef unsigned short __kernel_old_gid_t;
+typedef long long __kernel_loff_t;
+typedef __kernel_dev_t __kernel_old_dev_t;
+typedef long __kernel_long_t;
+typedef unsigned long __kernel_ulong_t;
+
+typedef struct {
+#ifdef __USE_ALL
+ int val[2];
+#else
+ int __val[2];
+#endif
+} __kernel_fsid_t;
+
+#endif /* __ARCH_CSKY_POSIX_TYPES_H */
diff --git a/libc/sysdeps/linux/csky/bits/mathinline.h b/libc/sysdeps/linux/csky/bits/mathinline.h
new file mode 100644
index 000000000..d6ab1a22c
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/mathinline.h
@@ -0,0 +1,445 @@
+#ifdef __GNUC__
+
+#ifdef __USE_ISOC99
+
+/* ISO C99 defines some macros to perform unordered comparisons. The
+ csky FPU supports this with special opcodes and we should use them.
+ These must not be inline functions since we have to be able to handle
+ all floating-point types. */
+# define isgreater(x, y) \
+ __extension__ \
+ ({ char __result; \
+ __asm__ ("fcmp%.x %2,%1; fsogt %0" \
+ : "=dm" (__result) : "f" (x), "f" (y)); \
+ __result != 0; })
+
+# define isgreaterequal(x, y) \
+ __extension__ \
+ ({ char __result; \
+ __asm__ ("fcmp%.x %2,%1; fsoge %0" \
+ : "=dm" (__result) : "f" (x), "f" (y)); \
+ __result != 0; })
+
+# define isless(x, y) \
+ __extension__ \
+ ({ char __result; \
+ __asm__ ("fcmp%.x %2,%1; fsolt %0" \
+ : "=dm" (__result) : "f" (x), "f" (y)); \
+ __result != 0; })
+
+# define islessequal(x, y) \
+ __extension__ \
+ ({ char __result; \
+ __asm__ ("fcmp%.x %2,%1; fsole %0" \
+ : "=dm" (__result) : "f" (x), "f" (y)); \
+ __result != 0; })
+
+# define islessgreater(x, y) \
+ __extension__ \
+ ({ char __result; \
+ __asm__ ("fcmp%.x %2,%1; fsogl %0" \
+ : "=dm" (__result) : "f" (x), "f" (y)); \
+ __result != 0; })
+
+# define isunordered(x, y) \
+ __extension__ \
+ ({ char __result; \
+ __asm__ ("fcmp%.x %2,%1; fsun %0" \
+ : "=dm" (__result) : "f" (x), "f" (y)); \
+ __result != 0; })
+#endif
+
+
+#if (!defined __NO_MATH_INLINES && defined __OPTIMIZE__) \
+ || defined __LIBC_INTERNAL_MATH_INLINES
+
+#ifdef __LIBC_INTERNAL_MATH_INLINES
+/* This is used when defining the functions themselves. Define them with
+ __ names, and with `static inline' instead of `extern inline' so the
+ bodies will always be used, never an external function call. */
+# define __m81_u(x) __CONCAT(__,x)
+# define __m81_inline static __inline
+#else
+# define __m81_u(x) x
+# ifdef __cplusplus
+# define __m81_inline __inline
+# else
+# define __m81_inline extern __inline
+# endif
+# define __M81_MATH_INLINES 1
+#endif
+
+/* Define a const math function. */
+#define __m81_defun(rettype, func, args) \
+ __m81_inline rettype __attribute__((__const__)) \
+ __m81_u(func) args
+
+/* Define the three variants of a math function that has a direct
+ implementation in the csky fpu. FUNC is the name for C (which will be
+ suffixed with f and l for the float and long double version, resp). OP
+ is the name of the fpu operation (without leading f). */
+
+#if defined __USE_MISC || defined __USE_ISOC99
+# define __inline_mathop(func, op) \
+ __inline_mathop1(double, func, op) \
+ __inline_mathop1(float, __CONCAT(func,f), op) \
+ __inline_mathop1(long double, __CONCAT(func,l), op)
+#else
+# define __inline_mathop(func, op) \
+ __inline_mathop1(double, func, op)
+#endif
+
+#define __inline_mathop1(float_type,func, op) \
+ __m81_defun (float_type, func, (float_type __mathop_x)) __THROW \
+ { \
+ float_type __result; \
+ __asm("f" __STRING(op) "%.x %1, %0" : "=f" (__result) : "f" (__mathop_x));\
+ return __result; \
+ }
+
+__inline_mathop(__atan, atan)
+__inline_mathop(__cos, cos)
+__inline_mathop(__sin, sin)
+__inline_mathop(__tan, tan)
+__inline_mathop(__tanh, tanh)
+__inline_mathop(__fabs, abs)
+
+#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
+__inline_mathop(__rint, int)
+__inline_mathop(__expm1, etoxm1)
+__inline_mathop(__log1p, lognp1)
+#endif
+
+#ifdef __USE_MISC
+__inline_mathop(__significand, getman)
+#endif
+
+#ifdef __USE_ISOC99
+__inline_mathop(__trunc, intrz)
+#endif
+
+#if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
+
+__inline_mathop(atan, atan)
+__inline_mathop(cos, cos)
+__inline_mathop(sin, sin)
+__inline_mathop(tan, tan)
+__inline_mathop(tanh, tanh)
+
+# if defined __USE_MISC || defined __USE_XOPEN_EXTENDED || defined __USE_ISOC99
+__inline_mathop(rint, int)
+__inline_mathop(expm1, etoxm1)
+__inline_mathop(log1p, lognp1)
+# endif
+
+# ifdef __USE_MISC
+__inline_mathop(significand, getman)
+# endif
+
+# ifdef __USE_ISOC99
+__inline_mathop(trunc, intrz)
+# endif
+
+#endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
+
+/* This macro contains the definition for the rest of the inline
+ functions, using FLOAT_TYPE as the domain type and S as the suffix
+ for the function names. */
+
+#define __inline_functions(float_type, s) \
+__m81_inline float_type \
+__m81_u(__CONCAT(__frexp,s))(float_type __value, int *__expptr) __THROW \
+{ \
+ float_type __mantissa, __exponent; \
+ int __iexponent; \
+ unsigned long __fpsr; \
+ __asm("ftst%.x %1\n" \
+ "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value)); \
+ if (__fpsr & (7 << 24)) \
+ { \
+ /* Not finite or zero. */ \
+ *__expptr = 0; \
+ return __value; \
+ } \
+ __asm("fgetexp%.x %1, %0" : "=f" (__exponent) : "f" (__value)); \
+ __iexponent = (int) __exponent + 1; \
+ *__expptr = __iexponent; \
+ __asm("fscale%.l %2, %0" : "=f" (__mantissa) \
+ : "0" (__value), "dmi" (-__iexponent)); \
+ return __mantissa; \
+} \
+ \
+__m81_defun (float_type, __CONCAT(__floor,s), (float_type __x)) __THROW \
+{ \
+ float_type __result; \
+ unsigned long int __ctrl_reg; \
+ __asm __volatile__ ("fmove%.l %!, %0" : "=dm" (__ctrl_reg)); \
+ /* Set rounding towards negative infinity. */ \
+ __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
+ : "dmi" ((__ctrl_reg & ~0x10) | 0x20)); \
+ /* Convert X to an integer, using -Inf rounding. */ \
+ __asm __volatile__ ("fint%.x %1, %0" : "=f" (__result) : "f" (__x)); \
+ /* Restore the previous rounding mode. */ \
+ __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
+ : "dmi" (__ctrl_reg)); \
+ return __result; \
+} \
+ \
+__m81_defun (float_type, __CONCAT(__ceil,s), (float_type __x)) __THROW \
+{ \
+ float_type __result; \
+ unsigned long int __ctrl_reg; \
+ __asm __volatile__ ("fmove%.l %!, %0" : "=dm" (__ctrl_reg)); \
+ /* Set rounding towards positive infinity. */ \
+ __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
+ : "dmi" (__ctrl_reg | 0x30)); \
+ /* Convert X to an integer, using +Inf rounding. */ \
+ __asm __volatile__ ("fint%.x %1, %0" : "=f" (__result) : "f" (__x)); \
+ /* Restore the previous rounding mode. */ \
+ __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
+ : "dmi" (__ctrl_reg)); \
+ return __result; \
+}
+
+__inline_functions(double,)
+#if defined __USE_MISC || defined __USE_ISOC99
+__inline_functions(float,f)
+__inline_functions(long double,l)
+#endif
+#undef __inline_functions
+
+#ifdef __USE_MISC
+
+# define __inline_functions(float_type, s) \
+__m81_defun (int, __CONCAT(__isinf,s), (float_type __value)) __THROW \
+{ \
+ /* There is no branch-condition for infinity, \
+ so we must extract and examine the condition codes manually. */ \
+ unsigned long int __fpsr; \
+ __asm("ftst%.x %1\n" \
+ "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value)); \
+ return (__fpsr & (2 << 24)) ? (__fpsr & (8 << 24) ? -1 : 1) : 0; \
+} \
+ \
+__m81_defun (int, __CONCAT(__finite,s), (float_type __value)) __THROW \
+{ \
+ /* There is no branch-condition for infinity, so we must extract and \
+ examine the condition codes manually. */ \
+ unsigned long int __fpsr; \
+ __asm ("ftst%.x %1\n" \
+ "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value)); \
+ return (__fpsr & (3 << 24)) == 0; \
+} \
+ \
+__m81_defun (float_type, __CONCAT(__scalbn,s), \
+ (float_type __x, int __n)) __THROW \
+{ \
+ float_type __result; \
+ __asm ("fscale%.l %1, %0" : "=f" (__result) : "dmi" (__n), "0" (__x)); \
+ return __result; \
+}
+
+__inline_functions(double,)
+__inline_functions(float,f)
+__inline_functions(long double,l)
+# undef __inline_functions
+
+#endif /* Use misc. */
+
+#if defined __USE_MISC || defined __USE_XOPEN
+
+# define __inline_functions(float_type, s) \
+__m81_defun (int, __CONCAT(__isnan,s), (float_type __value)) __THROW \
+{ \
+ char __result; \
+ __asm("ftst%.x %1\n" \
+ "fsun %0" : "=dm" (__result) : "f" (__value)); \
+ return __result; \
+}
+
+__inline_functions(double,)
+# ifdef __USE_MISC
+__inline_functions(float,f)
+__inline_functions(long double,l)
+# endif
+# undef __inline_functions
+
+#endif
+
+#ifdef __USE_ISOC99
+
+# define __inline_functions(float_type, s) \
+__m81_defun (int, __CONCAT(__signbit,s), (float_type __value)) __THROW \
+{ \
+ /* There is no branch-condition for the sign bit, so we must extract \
+ and examine the condition codes manually. */ \
+ unsigned long int __fpsr; \
+ __asm ("ftst%.x %1\n" \
+ "fmove%.l %/fpsr, %0" : "=dm" (__fpsr) : "f" (__value)); \
+ return (__fpsr >> 27) & 1; \
+} \
+ \
+__m81_defun (float_type, __CONCAT(__scalbln,s), \
+ (float_type __x, long int __n)) __THROW \
+{ \
+ return __CONCAT(__scalbn,s) (__x, __n); \
+} \
+ \
+__m81_defun (float_type, __CONCAT(__nearbyint,s), (float_type __x)) __THROW \
+{ \
+ float_type __result; \
+ unsigned long int __ctrl_reg; \
+ __asm __volatile__ ("fmove%.l %!, %0" : "=dm" (__ctrl_reg)); \
+ /* Temporarily disable the inexact exception. */ \
+ __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
+ : "dmi" (__ctrl_reg & ~0x200)); \
+ __asm __volatile__ ("fint%.x %1, %0" : "=f" (__result) : "f" (__x)); \
+ __asm __volatile__ ("fmove%.l %0, %!" : /* No outputs. */ \
+ : "dmi" (__ctrl_reg)); \
+ return __result; \
+} \
+ \
+__m81_defun (long int, __CONCAT(__lrint,s), (float_type __x)) __THROW \
+{ \
+ long int __result; \
+ __asm ("fmove%.l %1, %0" : "=dm" (__result) : "f" (__x)); \
+ return __result; \
+} \
+ \
+__m81_inline float_type \
+__m81_u(__CONCAT(__fma,s))(float_type __x, float_type __y, \
+ float_type __z) __THROW \
+{ \
+ return (__x * __y) + __z; \
+}
+
+__inline_functions (double,)
+__inline_functions (float,f)
+__inline_functions (long double,l)
+# undef __inline_functions
+
+#endif /* Use ISO C9x */
+
+#ifdef __USE_GNU
+
+# define __inline_functions(float_type, s) \
+__m81_inline void \
+__m81_u(__CONCAT(__sincos,s))(float_type __x, float_type *__sinx, \
+ float_type *__cosx) __THROW \
+{ \
+ __asm ("fsincos%.x %2,%1:%0" \
+ : "=f" (*__sinx), "=f" (*__cosx) : "f" (__x)); \
+}
+
+__inline_functions (double,)
+__inline_functions (float,f)
+__inline_functions (long double,l)
+# undef __inline_functions
+
+#endif
+
+#if !defined __NO_MATH_INLINES && defined __OPTIMIZE__
+
+/* Define inline versions of the user visible functions. */
+
+/* Note that there must be no whitespace before the argument passed for
+ NAME, to make token pasting work correctly with -traditional. */
+# define __inline_forward_c(rettype, name, args1, args2) \
+extern __inline rettype __attribute__((__const__)) \
+name args1 __THROW \
+{ \
+ return __CONCAT(__,name) args2; \
+}
+
+# define __inline_forward(rettype, name, args1, args2) \
+extern __inline rettype name args1 __THROW \
+{ \
+ return __CONCAT(__,name) args2; \
+}
+
+__inline_forward(double,frexp, (double __value, int *__expptr),
+ (__value, __expptr))
+__inline_forward_c(double,floor, (double __x), (__x))
+__inline_forward_c(double,ceil, (double __x), (__x))
+# ifdef __USE_MISC
+# ifndef __USE_ISOC99 /* Conflict with macro of same name. */
+__inline_forward_c(int,isinf, (double __value), (__value))
+# endif
+__inline_forward_c(int,finite, (double __value), (__value))
+__inline_forward_c(double,scalbn, (double __x, int __n), (__x, __n))
+# endif
+# if defined __USE_MISC || defined __USE_XOPEN
+# ifndef __USE_ISOC99 /* Conflict with macro of same name. */
+__inline_forward_c(int,isnan, (double __value), (__value))
+# endif
+# endif
+# ifdef __USE_ISOC99
+__inline_forward_c(double,scalbln, (double __x, long int __n), (__x, __n))
+__inline_forward_c(double,nearbyint, (double __value), (__value))
+__inline_forward_c(long int,lrint, (double __value), (__value))
+__inline_forward_c(double,fma, (double __x, double __y, double __z),
+ (__x, __y, __z))
+# endif
+# ifdef __USE_GNU
+__inline_forward(void,sincos, (double __x, double *__sinx, double *__cosx),
+ (__x, __sinx, __cosx))
+# endif
+
+# if defined __USE_MISC || defined __USE_ISOC99
+
+__inline_forward(float,frexpf, (float __value, int *__expptr),
+ (__value, __expptr))
+__inline_forward_c(float,floorf, (float __x), (__x))
+__inline_forward_c(float,ceilf, (float __x), (__x))
+# ifdef __USE_MISC
+__inline_forward_c(int,isinff, (float __value), (__value))
+__inline_forward_c(int,finitef, (float __value), (__value))
+__inline_forward_c(float,scalbnf, (float __x, int __n), (__x, __n))
+__inline_forward_c(int,isnanf, (float __value), (__value))
+# endif
+# ifdef __USE_ISOC99
+__inline_forward_c(float,scalblnf, (float __x, long int __n), (__x, __n))
+__inline_forward_c(float,nearbyintf, (float __value), (__value))
+__inline_forward_c(long int,lrintf, (float __value), (__value))
+__inline_forward_c(float,fmaf, (float __x, float __y, float __z),
+ (__x, __y, __z))
+# endif
+# ifdef __USE_GNU
+__inline_forward(void,sincosf, (float __x, float *__sinx, float *__cosx),
+ (__x, __sinx, __cosx))
+# endif
+
+__inline_forward(long double,frexpl, (long double __value, int *__expptr),
+ (__value, __expptr))
+__inline_forward_c(long double,floorl, (long double __x), (__x))
+__inline_forward_c(long double,ceill, (long double __x), (__x))
+# ifdef __USE_MISC
+__inline_forward_c(int,isinfl, (long double __value), (__value))
+__inline_forward_c(int,finitel, (long double __value), (__value))
+__inline_forward_c(long double,scalbnl, (long double __x, int __n), (__x, __n))
+__inline_forward_c(int,isnanl, (long double __value), (__value))
+# endif
+# ifdef __USE_ISOC99
+__inline_forward_c(long double,scalblnl, (long double __x, long int __n),
+ (__x, __n))
+__inline_forward_c(long double,nearbyintl, (long double __value), (__value))
+__inline_forward_c(long int,lrintl, (long double __value), (__value))
+__inline_forward_c(long double,fmal,
+ (long double __x, long double __y, long double __z),
+ (__x, __y, __z))
+# endif
+# ifdef __USE_GNU
+__inline_forward(void,sincosl,
+ (long double __x, long double *__sinx, long double *__cosx),
+ (__x, __sinx, __cosx))
+# endif
+
+#endif /* Use misc or ISO C99 */
+
+#undef __inline_forward
+#undef __inline_forward_c
+
+#endif /* !__NO_MATH_INLINES && __OPTIMIZE__ */
+
+#endif
+#endif
diff --git a/libc/sysdeps/linux/csky/bits/setjmp.h b/libc/sysdeps/linux/csky/bits/setjmp.h
new file mode 100644
index 000000000..c818ec9dc
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/setjmp.h
@@ -0,0 +1,19 @@
+#ifndef _BITS_SETJMP_H
+#define _BITS_SETJMP_H 1
+
+#if !defined _SETJMP_H && !defined _PTHREAD_H
+# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead."
+#endif
+
+typedef struct
+{
+ unsigned long __sp; /* the return stack address */
+ unsigned long __pc; /* pc: r15, return address */
+ /*
+ * ABIV1 is r8~r14
+ * ABIV2 is r4~r11, r16~r17, r26~r31
+ */
+ unsigned long __regs[16];
+} __jmp_buf[1];
+
+#endif /* _BITS_SETJMP_H */
diff --git a/libc/sysdeps/linux/csky/bits/shm.h b/libc/sysdeps/linux/csky/bits/shm.h
new file mode 100644
index 000000000..bfb44bb4c
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/shm.h
@@ -0,0 +1,85 @@
+#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 */
+
+/* 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 set of semaphores. */
+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 __unused1;
+ __time_t shm_dtime; /* time of last shmdt() */
+ unsigned long int __unused2;
+ __time_t shm_ctime; /* time of last change by shmctl() */
+ unsigned long int __unused3;
+ __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 __unused4;
+ unsigned long int __unused5;
+ };
+
+#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 __unused1;
+ unsigned long int __unused2;
+ unsigned long int __unused3;
+ unsigned long int __unused4;
+ };
+
+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/libc/sysdeps/linux/csky/bits/sigcontextinfo.h b/libc/sysdeps/linux/csky/bits/sigcontextinfo.h
new file mode 100644
index 000000000..b7e08cfc9
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/sigcontextinfo.h
@@ -0,0 +1,26 @@
+/* Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>, 1998.
+
+ 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, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#define SIGCONTEXT int _code, struct sigcontext *
+#define SIGCONTEXT_EXTRA_ARGS _code,
+#define GET_PC(ctx) ((void *) (ctx)->sc_pc)
+#define GET_FRAME(ctx) ((void *) __builtin_frame_address (1))
+#define GET_STACK(ctx) ((void *) (ctx)->sc_usp)
+#define CALL_SIGHANDLER(handler, signo, ctx) \
+ (handler)((signo), SIGCONTEXT_EXTRA_ARGS (ctx))
diff --git a/libc/sysdeps/linux/csky/bits/stackinfo.h b/libc/sysdeps/linux/csky/bits/stackinfo.h
new file mode 100644
index 000000000..aaf980752
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/stackinfo.h
@@ -0,0 +1,6 @@
+#ifndef _STACKINFO_H
+#define _STACKINFO_H 1
+
+#define _STACK_GROWS_DOWN 1
+
+#endif
diff --git a/libc/sysdeps/linux/csky/bits/syscalls.h b/libc/sysdeps/linux/csky/bits/syscalls.h
new file mode 100644
index 000000000..04d01f4ca
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/syscalls.h
@@ -0,0 +1,113 @@
+#ifndef _BITS_SYSCALLS_H
+#define _BITS_SYSCALLS_H
+#ifndef _SYSCALL_H
+# error "Never use <bits/syscalls.h> directly; include <sys/syscall.h> instead."
+#endif
+
+#undef __NR_iopl
+#undef __NR_vm86
+
+/*
+ Some of the sneaky macros in the code were taken from
+ glibc-2.3.2/sysdeps/unix/sysv/linux/arm/sysdep.h
+*/
+
+//#include <errno.h>
+
+#define INLINE_SYSCALL_NCS(name, nr, args...) \
+(__extension__ \
+ ({ \
+ unsigned int _inline_sys_result = INTERNAL_SYSCALL_NCS (name, , nr, args);\
+ if (unlikely (INTERNAL_SYSCALL_ERROR_P (_inline_sys_result, ))) \
+ { \
+ __set_errno (INTERNAL_SYSCALL_ERRNO (_inline_sys_result, )); \
+ _inline_sys_result = (unsigned int) -1; \
+ } \
+ (int) _inline_sys_result; \
+ }) \
+)
+
+#undef INTERNAL_SYSCALL_NCS
+#ifndef __cskyabiv2__
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({unsigned int __sys_result; \
+ { \
+ register int _a1 __asm__ ("a0"), _nr __asm__ ("r1"); \
+ LOAD_ARGS_##nr (args) \
+ _nr = (name); \
+ __asm__ __volatile__ ("trap 0 \n\t" \
+ : "=r" (_a1) \
+ : "r" (_nr) ASM_ARGS_##nr \
+ : "memory"); \
+ __sys_result = _a1; \
+ } \
+ (int) __sys_result; })
+
+#else /* __cskyabiv2__ */
+#define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+ ({unsigned int __sys_result; \
+ { \
+ register int _a1 __asm__ ("a0"), _nr __asm__ ("r7"); \
+ LOAD_ARGS_##nr (args) \
+ _nr = (name); \
+ __asm__ __volatile__ ("trap 0 \n\t" \
+ : "=r" (_a1) \
+ : "r" (_nr) ASM_ARGS_##nr \
+ : "memory"); \
+ __sys_result = _a1; \
+ } \
+ (int) __sys_result; })
+#endif /* __ABI_CSKY_V2__ */
+
+#define INTERNAL_SYSCALL_ERROR_P(val, err) \
+ ((unsigned int) (val) >= 0xfffff001u)
+
+#define LOAD_ARGS_0()
+#define ASM_ARGS_0
+#define LOAD_ARGS_1(a1) \
+ _a1 = (int) (a1); \
+ LOAD_ARGS_0 ()
+#define ASM_ARGS_1 ASM_ARGS_0, "r" (_a1)
+#define LOAD_ARGS_2(a1, a2) \
+ register int _a2 __asm__ ("a1") = (int) (a2); \
+ LOAD_ARGS_1 (a1)
+#define ASM_ARGS_2 ASM_ARGS_1, "r" (_a2)
+#define LOAD_ARGS_3(a1, a2, a3) \
+ register int _a3 __asm__ ("a2") = (int) (a3); \
+ LOAD_ARGS_2 (a1, a2)
+#define ASM_ARGS_3 ASM_ARGS_2, "r" (_a3)
+#define LOAD_ARGS_4(a1, a2, a3, a4) \
+ register int _a4 __asm__ ("a3") = (int) (a4); \
+ LOAD_ARGS_3 (a1, a2, a3)
+#define ASM_ARGS_4 ASM_ARGS_3, "r" (_a4)
+
+#ifndef __cskyabiv2__
+#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
+ register int _v1 __asm__ ("a4") = (int) (a5); \
+ LOAD_ARGS_4 (a1, a2, a3, a4)
+#define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
+#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
+ register int _v2 __asm__ ("a5") = (int) (a6); \
+ LOAD_ARGS_5 (a1, a2, a3, a4, a5)
+#define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
+#define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
+ register int _v3 __asm__ ("r8") = (int) (a7); \
+ LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
+#define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
+#else /* __cskyabiv2__ */
+#define LOAD_ARGS_5(a1, a2, a3, a4, a5) \
+ register int _v1 __asm__ ("l0") = (int) (a5); \
+ LOAD_ARGS_4 (a1, a2, a3, a4)
+#define ASM_ARGS_5 ASM_ARGS_4, "r" (_v1)
+#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6) \
+ register int _v2 __asm__ ("l1") = (int) (a6); \
+ LOAD_ARGS_5 (a1, a2, a3, a4, a5)
+#define ASM_ARGS_6 ASM_ARGS_5, "r" (_v2)
+#define LOAD_ARGS_7(a1, a2, a3, a4, a5, a6, a7) \
+ register int _v3 __asm__ ("l2") = (int) (a7); \
+ LOAD_ARGS_6 (a1, a2, a3, a4, a5, a6)
+#define ASM_ARGS_7 ASM_ARGS_6, "r" (_v3)
+#endif /* __ABI_CSKY_V2__ */
+
+
+#endif /* _BITS_SYSCALLS_H */
diff --git a/libc/sysdeps/linux/csky/bits/uClibc_arch_features.h b/libc/sysdeps/linux/csky/bits/uClibc_arch_features.h
new file mode 100644
index 000000000..ca898ee18
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/uClibc_arch_features.h
@@ -0,0 +1,46 @@
+/*
+ * Track misc arch-specific features that aren't config options
+ */
+
+#ifndef _BITS_UCLIBC_ARCH_FEATURES_H
+#define _BITS_UCLIBC_ARCH_FEATURES_H
+
+# define __UCLIBC_ABORT_INSTRUCTION__ ".long 0xffffffff"
+
+/* can your target use syscall6() for mmap ? */
+#undef __UCLIBC_MMAP_HAS_6_ARGS__
+
+#ifdef __CSKYABIV2__
+#undef __UCLIBC_SYSCALL_ALIGN_64BIT__
+#else
+#define __UCLIBC_SYSCALL_ALIGN_64BIT__
+#endif
+
+/* does your target have a broken create_module() ? */
+#define __UCLIBC_BROKEN_CREATE_MODULE__
+
+/* does your target have to worry about older [gs]etrlimit() ? */
+#define __UCLIBC_HANDLE_OLDER_RLIMIT__
+
+/* does your target have an asm .set ? */
+#define __UCLIBC_HAVE_ASM_SET_DIRECTIVE__
+
+/* define if target doesn't like .global */
+#undef __UCLIBC_ASM_GLOBAL_DIRECTIVE__
+
+/* define if target supports .weak */
+#define __UCLIBC_HAVE_ASM_WEAK_DIRECTIVE__
+
+/* define if target supports .weakext */
+#undef __UCLIBC_HAVE_ASM_WEAKEXT_DIRECTIVE__
+
+/* needed probably only for ppc64 */
+#undef __UCLIBC_HAVE_ASM_GLOBAL_DOT_NAME__
+
+/* define if target supports IEEE signed zero floats */
+#define __UCLIBC_HAVE_SIGNED_ZERO__
+
+/* define if target supports CFI pseudo ops */
+#define __UCLIBC_HAVE_ASM_CFI_DIRECTIVES__
+
+#endif /* _BITS_UCLIBC_ARCH_FEATURES_H */
diff --git a/libc/sysdeps/linux/csky/bits/wordsize.h b/libc/sysdeps/linux/csky/bits/wordsize.h
new file mode 100644
index 000000000..1b5842adb
--- /dev/null
+++ b/libc/sysdeps/linux/csky/bits/wordsize.h
@@ -0,0 +1 @@
+#define __WORDSIZE 32