]> granicus.if.org Git - strace/commitdiff
Add C-SKY architecture support
authorGuo Ren <ren_guo@c-sky.com>
Sat, 23 Mar 2019 00:56:14 +0000 (08:56 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 24 Mar 2019 12:12:58 +0000 (12:12 +0000)
This is port of C-SKY architecture for strace.  There is a little
difference between abiv1 and abiv2, we use __CSKYABIV2__ from GCC-csky
to distinguish.

Signed-off-by: Guo Ren <ren_guo@c-sky.com>
Reviewed-By: Dmitry V. Levin <ldv@altlinux.org>
* cacheflush.c [CSKY] (cacheflush_flags, SYS_FUNC(cacheflush)): Define.
* clone.c [CSKY] (ARG_*): Define.
* configure.ac [$host_cpu == csky*]: Define CSKY.
* linux/csky/arch_regs.c: New file.
* linux/csky/get_error.c: Likewise.
* linux/csky/get_scno.c: Likewise.
* linux/csky/get_syscall_args.c: Likewise.
* linux/csky/ioctls_arch0.h: Likewise.
* linux/csky/ioctls_inc0.h: Likewise.
* linux/csky/raw_syscall.h: Likewise.
* linux/csky/set_error.c: Likewise.
* linux/csky/set_scno.c: Likewise.
* linux/csky/syscallent.h: Likewise.
* Makefile.am (EXTRA_DIST): Add them.
* NEWS: Mention this change.

15 files changed:
Makefile.am
NEWS
cacheflush.c
clone.c
configure.ac
linux/csky/arch_regs.c [new file with mode: 0644]
linux/csky/get_error.c [new file with mode: 0644]
linux/csky/get_scno.c [new file with mode: 0644]
linux/csky/get_syscall_args.c [new file with mode: 0644]
linux/csky/ioctls_arch0.h [new file with mode: 0644]
linux/csky/ioctls_inc0.h [new file with mode: 0644]
linux/csky/raw_syscall.h [new file with mode: 0644]
linux/csky/set_error.c [new file with mode: 0644]
linux/csky/set_scno.c [new file with mode: 0644]
linux/csky/syscallent.h [new file with mode: 0644]

index 56987ae05a93e19e91c3e777e1330b1669b4d7a4..b5946914a4f64b2a376b154da192441dc8fd2fdd 100644 (file)
@@ -510,6 +510,16 @@ EXTRA_DIST =                               \
        linux/bfin/set_error.c          \
        linux/bfin/set_scno.c           \
        linux/bfin/syscallent.h         \
+       linux/csky/arch_regs.c          \
+       linux/csky/get_error.c          \
+       linux/csky/get_scno.c           \
+       linux/csky/get_syscall_args.c   \
+       linux/csky/ioctls_arch0.h       \
+       linux/csky/ioctls_inc0.h        \
+       linux/csky/raw_syscall.h        \
+       linux/csky/set_error.c          \
+       linux/csky/set_scno.c           \
+       linux/csky/syscallent.h         \
        linux/bfin/userent.h            \
        linux/check_scno.c              \
        linux/dummy.h                   \
diff --git a/NEWS b/NEWS
index cf63deaef46b996712ff4a620214cba5e17253bf..50212c14411de46f3d11629c5a978a10e994ef0f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ Noteworthy changes in release ?.? (????-??-??)
 * Bug fixes
   * Fixed decoding of last two arguments of clone syscall on riscv.
 
+* Improvements
+  * Added C-SKY architecture support.
+
 Noteworthy changes in release 5.0 (2019-03-19)
 ==============================================
 
index f38a3f916e93e887b6bcbc83ff657a10c12e3361..401aa8f9b8136e0f597d6a05c57cf5fe7cad7acc 100644 (file)
@@ -49,7 +49,7 @@ SYS_FUNC(cacheflush)
 }
 #endif /* M68K */
 
-#ifdef BFIN
+#if defined(BFIN) || defined(CSKY)
 static const struct xlat cacheflush_flags[] = {
        XLAT(ICACHE),
        XLAT(DCACHE),
@@ -68,7 +68,7 @@ SYS_FUNC(cacheflush)
 
        return RVAL_DECODED;
 }
-#endif /* BFIN */
+#endif /* BFIN || CSKY */
 
 #ifdef SH
 static const struct xlat cacheflush_flags[] = {
diff --git a/clone.c b/clone.c
index 64c7e950f3b623e11185e48cfa9ff99cfbd910a9..da05f1d3c4576b5c81800fdb9428bd901caf99e5 100644 (file)
--- a/clone.c
+++ b/clone.c
@@ -42,7 +42,7 @@
 # define ARG_PTID      2
 # define ARG_CTID      ((current_personality != 1) ? 3 : 4)
 # define ARG_TLS       ((current_personality != 1) ? 4 : 3)
-#elif defined ALPHA || defined TILE || defined OR1K
+#elif defined ALPHA || defined TILE || defined OR1K || defined CSKY
 # define ARG_FLAGS     0
 # define ARG_STACK     1
 # define ARG_PTID      2
index c95fd229b833ddedbabccb9c2eeee38b32a1df1d..86d3626b218e1d9323ae8d1f1317ccaf9f3f7721 100644 (file)
@@ -79,6 +79,10 @@ bfin)
        arch=bfin
        AC_DEFINE([BFIN], 1, [Define for the Blackfin architecture.])
        ;;
+csky*)
+       arch=csky
+       AC_DEFINE([CSKY], 1, [Define for the C-SKY architecture])
+       ;;
 hppa*|parisc*)
        arch=hppa
        AC_DEFINE([HPPA], 1, [Define for the HPPA architecture.])
diff --git a/linux/csky/arch_regs.c b/linux/csky/arch_regs.c
new file mode 100644 (file)
index 0000000..3caed7b
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2015-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+static struct pt_regs csky_regs;
+
+#define ARCH_REGS_FOR_GETREGSET        csky_regs
+#define ARCH_PC_REG            csky_regs.pc
+#define ARCH_SP_REG            csky_regs.usp
diff --git a/linux/csky/get_error.c b/linux/csky/get_error.c
new file mode 100644 (file)
index 0000000..c21a924
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+#include "negated_errno.h"
+
+static void
+arch_get_error(struct tcb *tcp, const bool check_errno)
+{
+       if (check_errno && is_negated_errno(csky_regs.a0)) {
+               tcp->u_rval = -1;
+               tcp->u_error = -csky_regs.a0;
+       } else {
+               tcp->u_rval = csky_regs.a0;
+       }
+}
diff --git a/linux/csky/get_scno.c b/linux/csky/get_scno.c
new file mode 100644 (file)
index 0000000..9efb202
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2015-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+/* Return codes: 1 - ok, 0 - ignore, other - error. */
+static int
+arch_get_scno(struct tcb *tcp)
+{
+#if defined(__CSKYABIV2__)
+       tcp->scno = csky_regs.regs[3];
+#else
+       tcp->scno = csky_regs.r1;
+#endif
+       return 1;
+}
diff --git a/linux/csky/get_syscall_args.c b/linux/csky/get_syscall_args.c
new file mode 100644 (file)
index 0000000..05dbfb4
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2015-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+/* Return -1 on error or 1 on success (never 0!). */
+static int
+arch_get_syscall_args(struct tcb *tcp)
+{
+       tcp->u_arg[0] = csky_regs.orig_a0;
+       tcp->u_arg[1] = csky_regs.a1;
+       tcp->u_arg[2] = csky_regs.a2;
+       tcp->u_arg[3] = csky_regs.a3;
+       tcp->u_arg[4] = csky_regs.regs[0];
+       tcp->u_arg[5] = csky_regs.regs[1];
+       return 1;
+}
diff --git a/linux/csky/ioctls_arch0.h b/linux/csky/ioctls_arch0.h
new file mode 100644 (file)
index 0000000..8b7ac89
--- /dev/null
@@ -0,0 +1 @@
+/* Generated by ioctls_gen.sh from definitions found in $linux/arch/csky/include/ tree. */
diff --git a/linux/csky/ioctls_inc0.h b/linux/csky/ioctls_inc0.h
new file mode 100644 (file)
index 0000000..4aecf98
--- /dev/null
@@ -0,0 +1 @@
+#include "32/ioctls_inc.h"
diff --git a/linux/csky/raw_syscall.h b/linux/csky/raw_syscall.h
new file mode 100644 (file)
index 0000000..aad0abd
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2018-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef STRACE_RAW_SYSCALL_H
+#define STRACE_RAW_SYSCALL_H
+
+# include "kernel_types.h"
+
+static inline kernel_ulong_t
+raw_syscall_0(const kernel_ulong_t nr, kernel_ulong_t *err)
+{
+#if defined(__CSKYABIV2__)
+       register kernel_ulong_t scno __asm__("r7") = nr;
+#else
+       register kernel_ulong_t scno __asm__("r1") = nr;
+#endif
+       register kernel_ulong_t a0 __asm__("a0");
+       asm volatile("trap 0"
+               : "+r"(scno), "=r"(a0)
+               :
+               : "memory");
+
+       *err = 0;
+       return a0;
+}
+# define raw_syscall_0 raw_syscall_0
+
+#endif /* !STRACE_RAW_SYSCALL_H */
diff --git a/linux/csky/set_error.c b/linux/csky/set_error.c
new file mode 100644 (file)
index 0000000..f8cb633
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2016-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+static int
+arch_set_error(struct tcb *tcp)
+{
+       csky_regs.a0 = -tcp->u_error;
+       return set_regs(tcp->pid);
+}
+
+static int
+arch_set_success(struct tcb *tcp)
+{
+       csky_regs.a0 = tcp->u_rval;
+       return set_regs(tcp->pid);
+}
diff --git a/linux/csky/set_scno.c b/linux/csky/set_scno.c
new file mode 100644 (file)
index 0000000..1f043ca
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2016-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+static int
+arch_set_scno(struct tcb *tcp, kernel_ulong_t scno)
+{
+#if defined(__CSKYABIV2__)
+       csky_regs.regs[3] = scno;
+#else
+       csky_regs.r1 = scno;
+#endif
+       return set_regs(tcp->pid);
+}
diff --git a/linux/csky/syscallent.h b/linux/csky/syscallent.h
new file mode 100644 (file)
index 0000000..33e3e73
--- /dev/null
@@ -0,0 +1,4 @@
+#include "32/syscallent.h"
+/* [244 ... 259] are arch specific */
+[244] = {1,    0,      SEN(set_thread_area), "set_thread_area"},
+[245] = {3,    0,      SEN(cacheflush), "cacheflush"},