[PATCH] Add kvx architecture support
Clement Leger
cleger at kalray.eu
Wed Apr 22 13:08:16 UTC 2020
This commit implements strace support for kvx architecture.
* clone.c [KVX] (ARG_*): Define.
* configure.ac [$host_cpu == kvx*]: Define KVX.
* linux/kvx/arch_regs.c: New file.
* linux/kvx/get_error.c: Likewise.
* linux/kvx/get_scno.c: Likewise.
* linux/kvx/get_syscall_args.c: Likewise.
* linux/kvx/ioctls_arch0.h: Likewise.
* linux/kvx/ioctls_inc0.h: Likewise.
* linux/kvx/raw_syscall.h: Likewise.
* linux/kvx/set_error.c: Likewise.
* linux/kvx/set_scno.c: Likewise.
* linux/kvx/syscallent.h: Likewise.
* Makefile.am (EXTRA_DIST): Add them.
* NEWS: Mention this change.
Signed-off-by: Clement Leger <cleger at kalray.eu>
---
Makefile.am | 10 +++++++++
NEWS | 1 +
clone.c | 3 ++-
configure.ac | 4 ++++
linux/kvx/arch_regs.c | 11 ++++++++++
linux/kvx/get_error.c | 19 ++++++++++++++++
linux/kvx/get_scno.c | 14 ++++++++++++
linux/kvx/get_syscall_args.c | 20 +++++++++++++++++
linux/kvx/ioctls_arch0.h | 1 +
linux/kvx/ioctls_inc0.h | 1 +
linux/kvx/raw_syscall.h | 42 ++++++++++++++++++++++++++++++++++++
linux/kvx/set_error.c | 20 +++++++++++++++++
linux/kvx/set_scno.c | 15 +++++++++++++
linux/kvx/syscallent.h | 8 +++++++
14 files changed, 168 insertions(+), 1 deletion(-)
create mode 100644 linux/kvx/arch_regs.c
create mode 100644 linux/kvx/get_error.c
create mode 100644 linux/kvx/get_scno.c
create mode 100644 linux/kvx/get_syscall_args.c
create mode 100644 linux/kvx/ioctls_arch0.h
create mode 100644 linux/kvx/ioctls_inc0.h
create mode 100644 linux/kvx/raw_syscall.h
create mode 100644 linux/kvx/set_error.c
create mode 100644 linux/kvx/set_scno.c
create mode 100644 linux/kvx/syscallent.h
diff --git a/Makefile.am b/Makefile.am
index addbc223..7717f15a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -605,6 +605,16 @@ EXTRA_DIST = \
linux/ia64/syscallent_base_nr.h \
linux/ia64/userent.h \
linux/inet_diag.h \
+ linux/kvx/arch_regs.c \
+ linux/kvx/get_error.c \
+ linux/kvx/get_scno.c \
+ linux/kvx/get_syscall_args.c \
+ linux/kvx/ioctls_arch0.h \
+ linux/kvx/ioctls_inc0.h \
+ linux/kvx/raw_syscall.h \
+ linux/kvx/set_error.c \
+ linux/kvx/set_scno.c \
+ linux/kvx/syscallent.h \
linux/m68k/arch_defs_.h \
linux/m68k/arch_regs.c \
linux/m68k/arch_rt_sigframe.c \
diff --git a/NEWS b/NEWS
index 4da9c6d8..bf2fed8b 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ Noteworthy changes in release ?.? (????-??-??)
* Updated lists of BPF_* constants.
* Added -e trace=%clock option for tracing syscalls reading of modifying
system clocks.
+ * Added KVX architecture support.
Noteworthy changes in release 5.6 (2020-04-07)
==============================================
diff --git a/clone.c b/clone.c
index 3fad9565..9dc14052 100644
--- a/clone.c
+++ b/clone.c
@@ -45,7 +45,8 @@
# 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 || defined CSKY
+#elif defined ALPHA || defined TILE || defined OR1K || defined CSKY \
+ || defined KVX
# define ARG_FLAGS 0
# define ARG_STACK 1
# define ARG_PTID 2
diff --git a/configure.ac b/configure.ac
index 24a0f2ba..b1ceba75 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,6 +101,10 @@ ia64)
arch=ia64
AC_DEFINE([IA64], 1, [Define for the IA64 architecture.])
;;
+kvx*)
+ arch=kvx
+ AC_DEFINE([KVX], 1, [Define for the KVX architecture])
+ ;;
m68k)
arch=m68k
AC_DEFINE([M68K], 1, [Define for the m68k architecture.])
diff --git a/linux/kvx/arch_regs.c b/linux/kvx/arch_regs.c
new file mode 100644
index 00000000..2b3002a1
--- /dev/null
+++ b/linux/kvx/arch_regs.c
@@ -0,0 +1,11 @@
+/*
+ * Copyright (c) 2016-2020 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+static struct user_regs_struct kvx_regs;
+#define ARCH_REGS_FOR_GETREGSET kvx_regs
+#define ARCH_PC_REG kvx_regs.spc
+#define ARCH_SP_REG kvx_regs.gpr_regs[12]
diff --git a/linux/kvx/get_error.c b/linux/kvx/get_error.c
new file mode 100644
index 00000000..fb31f389
--- /dev/null
+++ b/linux/kvx/get_error.c
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2016-2020 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(kvx_regs.gpr_regs[0])) {
+ tcp->u_rval = -1;
+ tcp->u_error = -kvx_regs.gpr_regs[0];
+ } else {
+ tcp->u_rval = kvx_regs.gpr_regs[0];
+ }
+}
diff --git a/linux/kvx/get_scno.c b/linux/kvx/get_scno.c
new file mode 100644
index 00000000..b0a8c5c1
--- /dev/null
+++ b/linux/kvx/get_scno.c
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2016-2020 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)
+{
+ tcp->scno = kvx_regs.gpr_regs[6];
+ return 1;
+}
diff --git a/linux/kvx/get_syscall_args.c b/linux/kvx/get_syscall_args.c
new file mode 100644
index 00000000..45c10303
--- /dev/null
+++ b/linux/kvx/get_syscall_args.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2016-2020 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] = kvx_regs.gpr_regs[0];
+ tcp->u_arg[1] = kvx_regs.gpr_regs[1];
+ tcp->u_arg[2] = kvx_regs.gpr_regs[2];
+ tcp->u_arg[3] = kvx_regs.gpr_regs[3];
+ tcp->u_arg[4] = kvx_regs.gpr_regs[4];
+ tcp->u_arg[5] = kvx_regs.gpr_regs[5];
+
+ return 1;
+}
diff --git a/linux/kvx/ioctls_arch0.h b/linux/kvx/ioctls_arch0.h
new file mode 100644
index 00000000..d0c5dda2
--- /dev/null
+++ b/linux/kvx/ioctls_arch0.h
@@ -0,0 +1 @@
+/* Generated by ioctls_gen.sh from definitions found in $linux/arch/kvx/include/ tree. */
diff --git a/linux/kvx/ioctls_inc0.h b/linux/kvx/ioctls_inc0.h
new file mode 100644
index 00000000..f9939faa
--- /dev/null
+++ b/linux/kvx/ioctls_inc0.h
@@ -0,0 +1 @@
+#include "64/ioctls_inc.h"
diff --git a/linux/kvx/raw_syscall.h b/linux/kvx/raw_syscall.h
new file mode 100644
index 00000000..ac0ee56e
--- /dev/null
+++ b/linux/kvx/raw_syscall.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016-2020 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)
+{
+ *err = 0;
+ register kernel_ulong_t r6 __asm__("r6") = nr;
+ register kernel_ulong_t r0 __asm__("r0");
+ __asm__ __volatile__("scall %[rSys]"
+ : "=r"(r0), [rSys] "+r"(r6)
+ :
+ : "memory",
+ /* Restored by syscall in theory but better be safe
+ * than sorry */
+ "r1", "r2", "r3", "r4", "r5", "r7",
+ /* Unused arguments */
+ "r8", "r9", "r10", "r11",
+ /* Struct pointer */
+ "r15",
+ /* Veneer registers */
+ "r16", "r17",
+ /* 32 -> 63 are caller-saved */
+ "r32", "r33", "r34", "r35", "r36", "r37", "r38",
+ "r39", "r40", "r41", "r42", "r43", "r44", "r45",
+ "r46", "r47", "r48", "r49", "r50", "r51", "r52",
+ "r53", "r54", "r55", "r56", "r57", "r58", "r59",
+ "r60", "r61", "r62", "r63");
+ return r0;
+}
+# define raw_syscall_0 raw_syscall_0
+
+#endif /* !STRACE_RAW_SYSCALL_H */
diff --git a/linux/kvx/set_error.c b/linux/kvx/set_error.c
new file mode 100644
index 00000000..739f9624
--- /dev/null
+++ b/linux/kvx/set_error.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2016-2020 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+static int
+arch_set_error(struct tcb *tcp)
+{
+ kvx_regs.gpr_regs[0] = -tcp->u_error;
+ return set_regs(tcp->pid);
+}
+
+static int
+arch_set_success(struct tcb *tcp)
+{
+ kvx_regs.gpr_regs[0] = tcp->u_rval;
+ return set_regs(tcp->pid);
+}
diff --git a/linux/kvx/set_scno.c b/linux/kvx/set_scno.c
new file mode 100644
index 00000000..6174a0ee
--- /dev/null
+++ b/linux/kvx/set_scno.c
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2016-2020 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 (ptrace_syscall_info_is_valid() && get_regs(tcp) < 0)
+ return -1;
+ kvx_regs.gpr_regs[6] = scno;
+ return set_regs(tcp->pid);
+}
diff --git a/linux/kvx/syscallent.h b/linux/kvx/syscallent.h
new file mode 100644
index 00000000..24a9346d
--- /dev/null
+++ b/linux/kvx/syscallent.h
@@ -0,0 +1,8 @@
+/*
+ * Copyright (c) 2016-2020 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "64/syscallent.h"
--
2.17.1
More information about the Strace-devel
mailing list