[PATCH v3 4/4] linux/riscv: Split out generic RISC-V code

Alistair Francis alistair.francis at wdc.com
Sat Mar 7 02:22:23 UTC 2020


Split out the generic RISC-V code in preperation for adding RV32
support.

Signed-off-by: Alistair Francis <alistair.francis at wdc.com>
---
 linux/riscv/arch_regs.c          | 11 +++++++++++
 linux/riscv/get_error.c          | 19 +++++++++++++++++++
 linux/riscv/get_scno.c           | 14 ++++++++++++++
 linux/riscv/get_syscall_args.c   | 19 +++++++++++++++++++
 linux/riscv/raw_syscall.h        | 29 +++++++++++++++++++++++++++++
 linux/riscv/set_error.c          | 20 ++++++++++++++++++++
 linux/riscv/set_scno.c           | 15 +++++++++++++++
 linux/riscv64/arch_regs.c        |  5 +----
 linux/riscv64/get_error.c        | 13 +------------
 linux/riscv64/get_scno.c         |  8 +-------
 linux/riscv64/get_syscall_args.c | 13 +------------
 linux/riscv64/raw_syscall.h      | 21 +--------------------
 linux/riscv64/set_error.c        | 14 +-------------
 linux/riscv64/set_scno.c         |  9 +--------
 14 files changed, 134 insertions(+), 76 deletions(-)
 create mode 100644 linux/riscv/arch_regs.c
 create mode 100644 linux/riscv/get_error.c
 create mode 100644 linux/riscv/get_scno.c
 create mode 100644 linux/riscv/get_syscall_args.c
 create mode 100644 linux/riscv/raw_syscall.h
 create mode 100644 linux/riscv/set_error.c
 create mode 100644 linux/riscv/set_scno.c

diff --git a/linux/riscv/arch_regs.c b/linux/riscv/arch_regs.c
new file mode 100644
index 00000000..5a2bab90
--- /dev/null
+++ b/linux/riscv/arch_regs.c
@@ -0,0 +1,11 @@
+/*
+ * Copyright (c) 2016-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+static struct user_regs_struct riscv_regs;
+#define ARCH_REGS_FOR_GETREGSET riscv_regs
+#define ARCH_PC_REG riscv_regs.pc
+#define ARCH_SP_REG riscv_regs.sp
diff --git a/linux/riscv/get_error.c b/linux/riscv/get_error.c
new file mode 100644
index 00000000..ac20c769
--- /dev/null
+++ b/linux/riscv/get_error.c
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2016-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(riscv_regs.a0)) {
+		tcp->u_rval = -1;
+		tcp->u_error = -riscv_regs.a0;
+	} else {
+		tcp->u_rval = riscv_regs.a0;
+	}
+}
diff --git a/linux/riscv/get_scno.c b/linux/riscv/get_scno.c
new file mode 100644
index 00000000..c77f4f55
--- /dev/null
+++ b/linux/riscv/get_scno.c
@@ -0,0 +1,14 @@
+/*
+ * 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)
+{
+	tcp->scno = riscv_regs.a7;
+	return 1;
+}
diff --git a/linux/riscv/get_syscall_args.c b/linux/riscv/get_syscall_args.c
new file mode 100644
index 00000000..0167fa52
--- /dev/null
+++ b/linux/riscv/get_syscall_args.c
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2016-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] = riscv_regs.a0;
+	tcp->u_arg[1] = riscv_regs.a1;
+	tcp->u_arg[2] = riscv_regs.a2;
+	tcp->u_arg[3] = riscv_regs.a3;
+	tcp->u_arg[4] = riscv_regs.a4;
+	tcp->u_arg[5] = riscv_regs.a5;
+	return 1;
+}
diff --git a/linux/riscv/raw_syscall.h b/linux/riscv/raw_syscall.h
new file mode 100644
index 00000000..932975cd
--- /dev/null
+++ b/linux/riscv/raw_syscall.h
@@ -0,0 +1,29 @@
+/*
+ * Raw syscalls.
+ *
+ * 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)
+{
+	*err = 0;
+	register kernel_ulong_t a7 __asm__("a7") = nr;
+	register kernel_ulong_t a0 __asm__("a0");
+	__asm__ __volatile__("scall"
+			     : "=r"(a0)
+			     : "r"(a7)
+			     : "memory");
+	return a0;
+}
+# define raw_syscall_0 raw_syscall_0
+
+#endif /* !STRACE_RAW_SYSCALL_H */
diff --git a/linux/riscv/set_error.c b/linux/riscv/set_error.c
new file mode 100644
index 00000000..b922e102
--- /dev/null
+++ b/linux/riscv/set_error.c
@@ -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)
+{
+	riscv_regs.a0 = -tcp->u_error;
+	return set_regs(tcp->pid);
+}
+
+static int
+arch_set_success(struct tcb *tcp)
+{
+	riscv_regs.a0 = tcp->u_rval;
+	return set_regs(tcp->pid);
+}
diff --git a/linux/riscv/set_scno.c b/linux/riscv/set_scno.c
new file mode 100644
index 00000000..f6d08d4c
--- /dev/null
+++ b/linux/riscv/set_scno.c
@@ -0,0 +1,15 @@
+/*
+ * 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 (ptrace_syscall_info_is_valid() && get_regs(tcp) < 0)
+		return -1;
+	riscv_regs.a7 = scno;
+	return set_regs(tcp->pid);
+}
diff --git a/linux/riscv64/arch_regs.c b/linux/riscv64/arch_regs.c
index 5a2bab90..dfbe1216 100644
--- a/linux/riscv64/arch_regs.c
+++ b/linux/riscv64/arch_regs.c
@@ -5,7 +5,4 @@
  * SPDX-License-Identifier: LGPL-2.1-or-later
  */
 
-static struct user_regs_struct riscv_regs;
-#define ARCH_REGS_FOR_GETREGSET riscv_regs
-#define ARCH_PC_REG riscv_regs.pc
-#define ARCH_SP_REG riscv_regs.sp
+#include "riscv/arch_regs.c"
diff --git a/linux/riscv64/get_error.c b/linux/riscv64/get_error.c
index ac20c769..b9c15886 100644
--- a/linux/riscv64/get_error.c
+++ b/linux/riscv64/get_error.c
@@ -5,15 +5,4 @@
  * 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(riscv_regs.a0)) {
-		tcp->u_rval = -1;
-		tcp->u_error = -riscv_regs.a0;
-	} else {
-		tcp->u_rval = riscv_regs.a0;
-	}
-}
+#include "riscv/get_error.c"
diff --git a/linux/riscv64/get_scno.c b/linux/riscv64/get_scno.c
index c77f4f55..10e93bc8 100644
--- a/linux/riscv64/get_scno.c
+++ b/linux/riscv64/get_scno.c
@@ -5,10 +5,4 @@
  * 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 = riscv_regs.a7;
-	return 1;
-}
+#include "riscv/get_scno.c"
diff --git a/linux/riscv64/get_syscall_args.c b/linux/riscv64/get_syscall_args.c
index 0167fa52..f62c32f4 100644
--- a/linux/riscv64/get_syscall_args.c
+++ b/linux/riscv64/get_syscall_args.c
@@ -5,15 +5,4 @@
  * 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] = riscv_regs.a0;
-	tcp->u_arg[1] = riscv_regs.a1;
-	tcp->u_arg[2] = riscv_regs.a2;
-	tcp->u_arg[3] = riscv_regs.a3;
-	tcp->u_arg[4] = riscv_regs.a4;
-	tcp->u_arg[5] = riscv_regs.a5;
-	return 1;
-}
+#include "riscv/get_syscall_args.c"
diff --git a/linux/riscv64/raw_syscall.h b/linux/riscv64/raw_syscall.h
index 932975cd..6302ca2e 100644
--- a/linux/riscv64/raw_syscall.h
+++ b/linux/riscv64/raw_syscall.h
@@ -7,23 +7,4 @@
  * 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 a7 __asm__("a7") = nr;
-	register kernel_ulong_t a0 __asm__("a0");
-	__asm__ __volatile__("scall"
-			     : "=r"(a0)
-			     : "r"(a7)
-			     : "memory");
-	return a0;
-}
-# define raw_syscall_0 raw_syscall_0
-
-#endif /* !STRACE_RAW_SYSCALL_H */
+#include "riscv/raw_syscall.h"
diff --git a/linux/riscv64/set_error.c b/linux/riscv64/set_error.c
index b922e102..164ddcec 100644
--- a/linux/riscv64/set_error.c
+++ b/linux/riscv64/set_error.c
@@ -5,16 +5,4 @@
  * SPDX-License-Identifier: LGPL-2.1-or-later
  */
 
-static int
-arch_set_error(struct tcb *tcp)
-{
-	riscv_regs.a0 = -tcp->u_error;
-	return set_regs(tcp->pid);
-}
-
-static int
-arch_set_success(struct tcb *tcp)
-{
-	riscv_regs.a0 = tcp->u_rval;
-	return set_regs(tcp->pid);
-}
+#include "riscv/set_error.c"
diff --git a/linux/riscv64/set_scno.c b/linux/riscv64/set_scno.c
index f6d08d4c..45f441ed 100644
--- a/linux/riscv64/set_scno.c
+++ b/linux/riscv64/set_scno.c
@@ -5,11 +5,4 @@
  * 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;
-	riscv_regs.a7 = scno;
-	return set_regs(tcp->pid);
-}
+#include "riscv/set_scno.c"
\ No newline at end of file
-- 
2.25.1



More information about the Strace-devel mailing list