[PATCH 3/3] riscv: Add support for 32-bit RISC-V

Alistair Francis alistair.francis at wdc.com
Fri Feb 14 19:40:28 UTC 2020


Signed-off-by: Alistair Francis <alistair.francis at wdc.com>
---
 Makefile.am                                 | 20 ++++++++--------
 configure.ac                                |  6 ++++-
 dist/INSTALL                                |  2 +-
 linux/riscv/arch_defs_.h                    | 16 +++++++++++++
 linux/{riscv64 => riscv}/arch_regs.c        |  0
 linux/riscv/asm_stat.h                      | 26 +++++++++++++++++++++
 linux/{riscv64 => riscv}/get_error.c        |  0
 linux/{riscv64 => riscv}/get_scno.c         |  0
 linux/{riscv64 => riscv}/get_syscall_args.c |  0
 linux/{riscv64 => riscv}/ioctls_arch0.h     |  0
 linux/riscv/ioctls_inc0.h                   |  7 ++++++
 linux/{riscv64 => riscv}/raw_syscall.h      |  0
 linux/{riscv64 => riscv}/set_error.c        |  0
 linux/{riscv64 => riscv}/set_scno.c         |  0
 linux/{riscv64 => riscv}/syscallent.h       |  8 ++++++-
 linux/riscv64/ioctls_inc0.h                 |  1 -
 riscv.c                                     |  4 ++--
 17 files changed, 74 insertions(+), 16 deletions(-)
 create mode 100644 linux/riscv/arch_defs_.h
 rename linux/{riscv64 => riscv}/arch_regs.c (100%)
 create mode 100644 linux/riscv/asm_stat.h
 rename linux/{riscv64 => riscv}/get_error.c (100%)
 rename linux/{riscv64 => riscv}/get_scno.c (100%)
 rename linux/{riscv64 => riscv}/get_syscall_args.c (100%)
 rename linux/{riscv64 => riscv}/ioctls_arch0.h (100%)
 create mode 100644 linux/riscv/ioctls_inc0.h
 rename linux/{riscv64 => riscv}/raw_syscall.h (100%)
 rename linux/{riscv64 => riscv}/set_error.c (100%)
 rename linux/{riscv64 => riscv}/set_scno.c (100%)
 rename linux/{riscv64 => riscv}/syscallent.h (64%)
 delete mode 100644 linux/riscv64/ioctls_inc0.h

diff --git a/Makefile.am b/Makefile.am
index 9c62218f..4955654b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -746,16 +746,16 @@ EXTRA_DIST =				\
 	linux/powerpc64le/userent.h	\
 	linux/ptrace_pokeuser.c		\
 	linux/raw_syscall.h		\
-	linux/riscv64/arch_regs.c		\
-	linux/riscv64/get_error.c		\
-	linux/riscv64/get_scno.c		\
-	linux/riscv64/get_syscall_args.c	\
-	linux/riscv64/ioctls_arch0.h	\
-	linux/riscv64/ioctls_inc0.h	\
-	linux/riscv64/raw_syscall.h	\
-	linux/riscv64/set_error.c		\
-	linux/riscv64/set_scno.c		\
-	linux/riscv64/syscallent.h	\
+	linux/riscv/arch_regs.c		\
+	linux/riscv/get_error.c		\
+	linux/riscv/get_scno.c		\
+	linux/riscv/get_syscall_args.c	\
+	linux/riscv/ioctls_arch0.h	\
+	linux/riscv/ioctls_inc0.h	\
+	linux/riscv/raw_syscall.h	\
+	linux/riscv/set_error.c		\
+	linux/riscv/set_scno.c		\
+	linux/riscv/syscallent.h	\
 	linux/rt_sigframe.h		\
 	linux/s390/arch_defs_.h		\
 	linux/s390/arch_regs.c		\
diff --git a/configure.ac b/configure.ac
index dd4f13f4..4a53681c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -144,8 +144,12 @@ powerpc*)
 		esac
 	fi
 	;;
+riscv32*)
+	arch=riscv
+	AC_DEFINE([RISCV32], 1, [Define for the RISC-V 32-bit architecture])
+	;;
 riscv64*)
-	arch=riscv64
+	arch=riscv
 	AC_DEFINE([RISCV64], 1, [Define for the RISC-V 64-bit architecture])
 	;;
 s390)
diff --git a/dist/INSTALL b/dist/INSTALL
index 0d22512b..19e059cf 100644
--- a/dist/INSTALL
+++ b/dist/INSTALL
@@ -63,7 +63,7 @@ Taking the aforementioned into account, there are the following requirements:
 
  - gawk (at least version 3)
  - Ability to compile for m32 personality (on architectures where it is supported)
-  - On x86_64, x32, powerpc64, sparc64, riscv64, tile64: gcc -m32
+  - On x86_64, x32, powerpc64, sparc64, riscv32, riscv64, tile64: gcc -m32
   - s390x: gcc -m31
   - AArch64: a separate compiler for armv7 EABI
    - See information about configuration in "1.3.2. AArch64: AArch32 support"
diff --git a/linux/riscv/arch_defs_.h b/linux/riscv/arch_defs_.h
new file mode 100644
index 00000000..5b8263d0
--- /dev/null
+++ b/linux/riscv/arch_defs_.h
@@ -0,0 +1,16 @@
+/*
+ * Fallback file for arch-specific definitions.
+ *
+ * Copyright (c) 2020 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#define ARCH_TIMESIZE 64
+
+#if defined(RISCV32)
+# define HAVE_ARCH_TIME32_SYSCALLS 0
+#endif
+
+#define HAVE_ARCH_OLD_TIME64_SYSCALLS 0
diff --git a/linux/riscv64/arch_regs.c b/linux/riscv/arch_regs.c
similarity index 100%
rename from linux/riscv64/arch_regs.c
rename to linux/riscv/arch_regs.c
diff --git a/linux/riscv/asm_stat.h b/linux/riscv/asm_stat.h
new file mode 100644
index 00000000..73341454
--- /dev/null
+++ b/linux/riscv/asm_stat.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2020 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef STRACE_RISCV_ASM_STAT_H
+# define STRACE_RISCV_ASM_STAT_H
+
+# include "linux/asm_stat.h"
+
+# if defined(RISCV32)
+#  undef dev_t
+#  undef ino_t
+#  undef off64_t
+#  undef off_t
+#  undef time_t
+
+#  define dev_t		__kernel_loff_t
+#  define ino_t		__kernel_loff_t
+#  define off64_t	__kernel_off64_t
+#  define off_t		__kernel_off64_t
+#  define time_t	__kernel_time64_t
+# endif /* defined(RISCV32) */
+#endif /* !STRACE_RISCV_ASM_STAT_H */
diff --git a/linux/riscv64/get_error.c b/linux/riscv/get_error.c
similarity index 100%
rename from linux/riscv64/get_error.c
rename to linux/riscv/get_error.c
diff --git a/linux/riscv64/get_scno.c b/linux/riscv/get_scno.c
similarity index 100%
rename from linux/riscv64/get_scno.c
rename to linux/riscv/get_scno.c
diff --git a/linux/riscv64/get_syscall_args.c b/linux/riscv/get_syscall_args.c
similarity index 100%
rename from linux/riscv64/get_syscall_args.c
rename to linux/riscv/get_syscall_args.c
diff --git a/linux/riscv64/ioctls_arch0.h b/linux/riscv/ioctls_arch0.h
similarity index 100%
rename from linux/riscv64/ioctls_arch0.h
rename to linux/riscv/ioctls_arch0.h
diff --git a/linux/riscv/ioctls_inc0.h b/linux/riscv/ioctls_inc0.h
new file mode 100644
index 00000000..cc39332f
--- /dev/null
+++ b/linux/riscv/ioctls_inc0.h
@@ -0,0 +1,7 @@
+#if defined(RISCV64)
+# include "64/ioctls_inc.h"
+#elif defined(RISCV32)
+# include "32/ioctls_inc.h"
+#else
+# error "Unsupported RISC-V xlen"
+#endif
diff --git a/linux/riscv64/raw_syscall.h b/linux/riscv/raw_syscall.h
similarity index 100%
rename from linux/riscv64/raw_syscall.h
rename to linux/riscv/raw_syscall.h
diff --git a/linux/riscv64/set_error.c b/linux/riscv/set_error.c
similarity index 100%
rename from linux/riscv64/set_error.c
rename to linux/riscv/set_error.c
diff --git a/linux/riscv64/set_scno.c b/linux/riscv/set_scno.c
similarity index 100%
rename from linux/riscv64/set_scno.c
rename to linux/riscv/set_scno.c
diff --git a/linux/riscv64/syscallent.h b/linux/riscv/syscallent.h
similarity index 64%
rename from linux/riscv64/syscallent.h
rename to linux/riscv/syscallent.h
index 60c6ce58..c8fb3b8f 100644
--- a/linux/riscv64/syscallent.h
+++ b/linux/riscv/syscallent.h
@@ -5,7 +5,13 @@
  * SPDX-License-Identifier: LGPL-2.1-or-later
  */
 
-#include "64/syscallent.h"
+#if defined(RISCV64)
+# include "64/syscallent.h"
+#elif defined(RISCV32)
+# include "32/syscallent.h"
+#else
+# error "Unsupported RISC-V xlen"
+#endif
 
 /* #define __NR_riscv_flush_icache (__NR_arch_specific_syscall + 15) */
 [259] = { 3,	TM,		SEN(riscv_flush_icache),	"riscv_flush_icache"	},
diff --git a/linux/riscv64/ioctls_inc0.h b/linux/riscv64/ioctls_inc0.h
deleted file mode 100644
index f9939faa..00000000
--- a/linux/riscv64/ioctls_inc0.h
+++ /dev/null
@@ -1 +0,0 @@
-#include "64/ioctls_inc.h"
diff --git a/riscv.c b/riscv.c
index 825eb293..20094ba5 100644
--- a/riscv.c
+++ b/riscv.c
@@ -9,7 +9,7 @@
 
 #include "defs.h"
 
-#ifdef RISCV64
+#if defined(RISCV64) || defined(RISCV32)
 
 # include "xlat/riscv_flush_icache_flags.h"
 
@@ -30,4 +30,4 @@ SYS_FUNC(riscv_flush_icache)
 	return RVAL_DECODED;
 }
 
-#endif /* RISCV64 */
+#endif /* defined(RISCV64) || defined(RISCV32) */
-- 
2.25.0



More information about the Strace-devel mailing list