[PATCH] Add C-SKY architecture support

Dmitry V. Levin ldv at altlinux.org
Fri Mar 22 12:47:23 UTC 2019


On Fri, Mar 22, 2019 at 07:43:46PM +0800, guoren at kernel.org wrote:
> From: Guo Ren <ren_guo at c-sky.com>
> 
> 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.

Thanks, see my comments below.

> TODO:
>  - personality, mpers (multi personality support)

This would only worth doing if the kernel gets the support for it.

> Signed-off-by: Guo Ren <ren_guo at c-sky.com>
> Cc: Dmitry V. Levin <ldv at altlinux.org>
> ---
>  Makefile.am                   | 11 +++++++++++
>  cacheflush.c                  |  4 ++--
>  clone.c                       |  2 +-
>  configure.ac                  |  4 ++++
>  linux/csky/arch_defs_.h       |  6 ++++++
>  linux/csky/arch_regs.c        | 11 +++++++++++
>  linux/csky/get_error.c        | 18 ++++++++++++++++++
>  linux/csky/get_scno.c         | 18 ++++++++++++++++++
>  linux/csky/get_syscall_args.c | 19 +++++++++++++++++++
>  linux/csky/ioctls_arch0.h     |  1 +
>  linux/csky/ioctls_inc0.h      |  1 +
>  linux/csky/raw_syscall.h      | 33 +++++++++++++++++++++++++++++++++
>  linux/csky/set_error.c        | 20 ++++++++++++++++++++
>  linux/csky/set_scno.c         | 17 +++++++++++++++++
>  linux/csky/syscallent.h       |  4 ++++
>  15 files changed, 166 insertions(+), 3 deletions(-)
>  create mode 100644 linux/csky/arch_defs_.h
>  create mode 100644 linux/csky/arch_regs.c
>  create mode 100644 linux/csky/get_error.c
>  create mode 100644 linux/csky/get_scno.c
>  create mode 100644 linux/csky/get_syscall_args.c
>  create mode 100644 linux/csky/ioctls_arch0.h
>  create mode 100644 linux/csky/ioctls_inc0.h
>  create mode 100644 linux/csky/raw_syscall.h
>  create mode 100644 linux/csky/set_error.c
>  create mode 100644 linux/csky/set_scno.c
>  create mode 100644 linux/csky/syscallent.h
> 
> diff --git a/Makefile.am b/Makefile.am
> index 56987ae..f61978c 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -510,6 +510,17 @@ EXTRA_DIST =				\
>  	linux/bfin/set_error.c		\
>  	linux/bfin/set_scno.c		\
>  	linux/bfin/syscallent.h		\
> +	linux/csky/arch_defs_.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			\

OK, but most likely you don't need linux/csky/arch_defs_.h

> diff --git a/cacheflush.c b/cacheflush.c
> index f38a3f9..401aa8f 100644
> --- a/cacheflush.c
> +++ b/cacheflush.c
> @@ -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[] = {

OK

> diff --git a/clone.c b/clone.c
> index 64c7e95..da05f1d 100644
> --- 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

OK

> diff --git a/configure.ac b/configure.ac
> index c95fd22..31edbde 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -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 RISC-V architecture])
> +	;;
>  hppa*|parisc*)
>  	arch=hppa
>  	AC_DEFINE([HPPA], 1, [Define for the HPPA architecture.])

Is it really RISC-V?

> diff --git a/linux/csky/arch_defs_.h b/linux/csky/arch_defs_.h
> new file mode 100644
> index 0000000..188aaaa
> --- /dev/null
> +++ b/linux/csky/arch_defs_.h
> @@ -0,0 +1,6 @@
> +/*
> + * Copyright (c) 2018 The strace developers.
> + * All rights reserved.
> + *
> + * SPDX-License-Identifier: LGPL-2.1-or-later
> + */

There is no need to create an empty arch-specific arch_defs_.h file.

> diff --git a/linux/csky/arch_regs.c b/linux/csky/arch_regs.c
> new file mode 100644
> index 0000000..70f5beb
> --- /dev/null
> +++ b/linux/csky/arch_regs.c
> @@ -0,0 +1,11 @@
> +/*
> + * Copyright (c) 2015-2018 The strace developers.

Are you sure it is correct and ends in 2018?

> + * All rights reserved.
> + *
> + * SPDX-License-Identifier: LGPL-2.1-or-later
> + */
> +
> +static struct pt_regs csky_regs;
> +unsigned long *const csky_sp_ptr = &csky_regs.usp;
> +# define ARCH_REGS_FOR_GETREGSET csky_regs
> +#define ARCH_PC_REG csky_regs.pc

Please indent two consequent defines in the same way.

> diff --git a/linux/csky/get_error.c b/linux/csky/get_error.c
> new file mode 100644
> index 0000000..b3bf595
> --- /dev/null
> +++ b/linux/csky/get_error.c
> @@ -0,0 +1,18 @@
> +/*
> + * Copyright (c) 2015-2018 The strace developers.

Are you sure it is correct and ends in 2018?

> + * 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;
> +	}
> +}

OK

> diff --git a/linux/csky/get_scno.c b/linux/csky/get_scno.c
> new file mode 100644
> index 0000000..bde4305
> --- /dev/null
> +++ b/linux/csky/get_scno.c
> @@ -0,0 +1,18 @@
> +/*
> + * Copyright (c) 2015-2018 The strace developers.

Are you sure it is correct and ends in 2018?

> + * 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;
> +}

OK

> diff --git a/linux/csky/get_syscall_args.c b/linux/csky/get_syscall_args.c
> new file mode 100644
> index 0000000..a083a7f
> --- /dev/null
> +++ b/linux/csky/get_syscall_args.c
> @@ -0,0 +1,19 @@
> +/*
> + * Copyright (c) 2015-2018 The strace developers.

Are you sure it is correct and ends in 2018?

> + * 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.a0;

This does not match syscall_get_arguments() from
arch/csky/include/asm/syscall.h where orig_a0 is used instead.

If this passes strace tests, then syscall_get_arguments() is most likely wrong.

> +	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;
> +}

OK

> diff --git a/linux/csky/ioctls_arch0.h b/linux/csky/ioctls_arch0.h
> new file mode 100644
> index 0000000..8b7ac89
> --- /dev/null
> +++ b/linux/csky/ioctls_arch0.h
> @@ -0,0 +1 @@
> +/* Generated by ioctls_gen.sh from definitions found in $linux/arch/csky/include/ tree. */

OK

> diff --git a/linux/csky/ioctls_inc0.h b/linux/csky/ioctls_inc0.h
> new file mode 100644
> index 0000000..4aecf98
> --- /dev/null
> +++ b/linux/csky/ioctls_inc0.h
> @@ -0,0 +1 @@
> +#include "32/ioctls_inc.h"

Shouldn't this conditionalize on __CSKYABIV2__?

> diff --git a/linux/csky/raw_syscall.h b/linux/csky/raw_syscall.h
> new file mode 100644
> index 0000000..3b4d4c5
> --- /dev/null
> +++ b/linux/csky/raw_syscall.h
> @@ -0,0 +1,33 @@
> +/*
> + * Raw syscalls.
> + *
> + * Copyright (c) 2018 The strace developers.

Are you sure it is correct and ends in 2018?

> + * 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;
> +#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"
> +			     : "+r"(scno), "=r"(a0)
> +			     :
> +			     : "memory");
> +	return a0;
> +}
> +# define raw_syscall_0 raw_syscall_0
> +
> +#endif /* !STRACE_RAW_SYSCALL_H */

Please indent preprocessor directives consistently.

> diff --git a/linux/csky/set_error.c b/linux/csky/set_error.c
> new file mode 100644
> index 0000000..16a3421
> --- /dev/null
> +++ b/linux/csky/set_error.c
> @@ -0,0 +1,20 @@
> +/*
> + * Copyright (c) 2016-2018 The strace developers.

Are you sure it is correct and ends in 2018?

> + * 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);
> +}

OK

> diff --git a/linux/csky/set_scno.c b/linux/csky/set_scno.c
> new file mode 100644
> index 0000000..70c690d
> --- /dev/null
> +++ b/linux/csky/set_scno.c
> @@ -0,0 +1,17 @@
> +/*
> + * Copyright (c) 2016-2018 The strace developers.

Are you sure it is correct and ends in 2018?

> + * 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);
> +}

OK

> diff --git a/linux/csky/syscallent.h b/linux/csky/syscallent.h
> new file mode 100644
> index 0000000..33e3e73
> --- /dev/null
> +++ b/linux/csky/syscallent.h
> @@ -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"},

OK


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20190322/3df191c2/attachment.bin>


More information about the Strace-devel mailing list