From: Guo Ren Date: Sat, 23 Mar 2019 00:56:14 +0000 (+0800) Subject: Add C-SKY architecture support X-Git-Tag: v5.1~99 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2dd0718508f7551d5c31bfe442eadda63c1a4b35;p=strace Add C-SKY architecture support 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. Signed-off-by: Guo Ren Reviewed-By: Dmitry V. Levin * cacheflush.c [CSKY] (cacheflush_flags, SYS_FUNC(cacheflush)): Define. * clone.c [CSKY] (ARG_*): Define. * configure.ac [$host_cpu == csky*]: Define CSKY. * linux/csky/arch_regs.c: New file. * linux/csky/get_error.c: Likewise. * linux/csky/get_scno.c: Likewise. * linux/csky/get_syscall_args.c: Likewise. * linux/csky/ioctls_arch0.h: Likewise. * linux/csky/ioctls_inc0.h: Likewise. * linux/csky/raw_syscall.h: Likewise. * linux/csky/set_error.c: Likewise. * linux/csky/set_scno.c: Likewise. * linux/csky/syscallent.h: Likewise. * Makefile.am (EXTRA_DIST): Add them. * NEWS: Mention this change. --- diff --git a/Makefile.am b/Makefile.am index 56987ae0..b5946914 100644 --- a/Makefile.am +++ b/Makefile.am @@ -510,6 +510,16 @@ EXTRA_DIST = \ linux/bfin/set_error.c \ linux/bfin/set_scno.c \ linux/bfin/syscallent.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 \ diff --git a/NEWS b/NEWS index cf63deae..50212c14 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,9 @@ Noteworthy changes in release ?.? (????-??-??) * Bug fixes * Fixed decoding of last two arguments of clone syscall on riscv. +* Improvements + * Added C-SKY architecture support. + Noteworthy changes in release 5.0 (2019-03-19) ============================================== diff --git a/cacheflush.c b/cacheflush.c index f38a3f91..401aa8f9 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[] = { diff --git a/clone.c b/clone.c index 64c7e950..da05f1d3 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 diff --git a/configure.ac b/configure.ac index c95fd229..86d3626b 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 C-SKY architecture]) + ;; hppa*|parisc*) arch=hppa AC_DEFINE([HPPA], 1, [Define for the HPPA architecture.]) diff --git a/linux/csky/arch_regs.c b/linux/csky/arch_regs.c new file mode 100644 index 00000000..3caed7b1 --- /dev/null +++ b/linux/csky/arch_regs.c @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2015-2019 The strace developers. + * All rights reserved. + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +static struct pt_regs csky_regs; + +#define ARCH_REGS_FOR_GETREGSET csky_regs +#define ARCH_PC_REG csky_regs.pc +#define ARCH_SP_REG csky_regs.usp diff --git a/linux/csky/get_error.c b/linux/csky/get_error.c new file mode 100644 index 00000000..c21a9248 --- /dev/null +++ b/linux/csky/get_error.c @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2015-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(csky_regs.a0)) { + tcp->u_rval = -1; + tcp->u_error = -csky_regs.a0; + } else { + tcp->u_rval = csky_regs.a0; + } +} diff --git a/linux/csky/get_scno.c b/linux/csky/get_scno.c new file mode 100644 index 00000000..9efb2020 --- /dev/null +++ b/linux/csky/get_scno.c @@ -0,0 +1,18 @@ +/* + * 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) +{ +#if defined(__CSKYABIV2__) + tcp->scno = csky_regs.regs[3]; +#else + tcp->scno = csky_regs.r1; +#endif + return 1; +} diff --git a/linux/csky/get_syscall_args.c b/linux/csky/get_syscall_args.c new file mode 100644 index 00000000..05dbfb4f --- /dev/null +++ b/linux/csky/get_syscall_args.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2015-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] = csky_regs.orig_a0; + 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; +} diff --git a/linux/csky/ioctls_arch0.h b/linux/csky/ioctls_arch0.h new file mode 100644 index 00000000..8b7ac89b --- /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. */ diff --git a/linux/csky/ioctls_inc0.h b/linux/csky/ioctls_inc0.h new file mode 100644 index 00000000..4aecf983 --- /dev/null +++ b/linux/csky/ioctls_inc0.h @@ -0,0 +1 @@ +#include "32/ioctls_inc.h" diff --git a/linux/csky/raw_syscall.h b/linux/csky/raw_syscall.h new file mode 100644 index 00000000..aad0abdc --- /dev/null +++ b/linux/csky/raw_syscall.h @@ -0,0 +1,32 @@ +/* + * 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) +{ +#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 0" + : "+r"(scno), "=r"(a0) + : + : "memory"); + + *err = 0; + return a0; +} +# define raw_syscall_0 raw_syscall_0 + +#endif /* !STRACE_RAW_SYSCALL_H */ diff --git a/linux/csky/set_error.c b/linux/csky/set_error.c new file mode 100644 index 00000000..f8cb6333 --- /dev/null +++ b/linux/csky/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) +{ + 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); +} diff --git a/linux/csky/set_scno.c b/linux/csky/set_scno.c new file mode 100644 index 00000000..1f043caf --- /dev/null +++ b/linux/csky/set_scno.c @@ -0,0 +1,17 @@ +/* + * 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 defined(__CSKYABIV2__) + csky_regs.regs[3] = scno; +#else + csky_regs.r1 = scno; +#endif + return set_regs(tcp->pid); +} diff --git a/linux/csky/syscallent.h b/linux/csky/syscallent.h new file mode 100644 index 00000000..33e3e73f --- /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"},