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

Dmitry V. Levin ldv at altlinux.org
Wed Feb 26 02:44:54 UTC 2020


On Fri, Feb 14, 2020 at 11:40:28AM -0800, Alistair Francis wrote:
> 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

I'm not very happy about this approach of ifdefs in arch-specific
directories.  Couldn't we have linux/riscv32/ and linux/riscv64/
directories instead, maybe with common parts placed into linux/riscv/
directory and included from there?

> +#define HAVE_ARCH_OLD_TIME64_SYSCALLS 0

I'm afraid this would break build on riscv64.

> 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 */

This looks even more fragile than linux/asm_stat.h, could we have
a linux/riscv32/asm_stat.h without so many layered redefinitions?


-- 
ldv


More information about the Strace-devel mailing list