[PATCH v2 16/23] exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h'

Philippe Mathieu-Daudé posted 23 patches 1 year, 11 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Riku Voipio <riku.voipio@iki.fi>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Gerd Hoffmann <kraxel@redhat.com>, Manos Pitsidianakis <manos.pitsidianakis@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, Alistair Francis <alistair@alistair23.me>, BALATON Zoltan <balaton@eik.bme.hu>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Laurent Vivier <laurent@vivier.eu>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, Brian Cain <bcain@quicinc.com>, Song Gao <gaosong@loongson.cn>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Huacai Chen <chenhuacai@kernel.org>, Chris Wulff <crwulff@gmail.com>, Marek Vasut <marex@denx.de>, Stafford Horne <shorne@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, "Cédric Le Goater" <clg@kaod.org>, Palmer Dabbelt <palmer@dabbelt.com>, Bin Meng <bin.meng@windriver.com>, Weiwei Li <liwei1518@gmail.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, Ilya Leoshkevich <iii@linux.ibm.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Max Filippov <jcmvbkbc@gmail.com>
[PATCH v2 16/23] exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h'
Posted by Philippe Mathieu-Daudé 1 year, 11 months ago
tswapl() and bswaptls() are target-dependent and only used
by user emulation. Move their definitions to a new header:
"exec/user/tswap-target.h".

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 bsd-user/freebsd/target_os_elf.h   |  1 +
 bsd-user/freebsd/target_os_stack.h |  1 +
 bsd-user/netbsd/target_os_elf.h    |  1 +
 bsd-user/openbsd/target_os_elf.h   |  1 +
 include/exec/cpu-all.h             |  8 --------
 include/exec/user/abitypes.h       |  1 +
 include/exec/user/tswap-target.h   | 22 ++++++++++++++++++++++
 bsd-user/signal.c                  |  1 +
 bsd-user/strace.c                  |  1 +
 linux-user/elfload.c               |  1 +
 linux-user/i386/signal.c           |  1 +
 linux-user/ppc/signal.c            |  1 +
 12 files changed, 32 insertions(+), 8 deletions(-)
 create mode 100644 include/exec/user/tswap-target.h

diff --git a/bsd-user/freebsd/target_os_elf.h b/bsd-user/freebsd/target_os_elf.h
index 9df17d56d8..27d8ce036c 100644
--- a/bsd-user/freebsd/target_os_elf.h
+++ b/bsd-user/freebsd/target_os_elf.h
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "exec/user/tswap-target.h"
 
 #define bsd_get_ncpu() 1 /* until we pull in bsd-proc.[hc] */
 
diff --git a/bsd-user/freebsd/target_os_stack.h b/bsd-user/freebsd/target_os_stack.h
index d15fc3263f..6125208182 100644
--- a/bsd-user/freebsd/target_os_stack.h
+++ b/bsd-user/freebsd/target_os_stack.h
@@ -23,6 +23,7 @@
 #include <sys/param.h>
 #include "target_arch_sigtramp.h"
 #include "qemu/guest-random.h"
+#include "exec/user/tswap-target.h"
 
 /*
  * The initial FreeBSD stack is as follows:
diff --git a/bsd-user/netbsd/target_os_elf.h b/bsd-user/netbsd/target_os_elf.h
index 2f3cb20871..23b422bfce 100644
--- a/bsd-user/netbsd/target_os_elf.h
+++ b/bsd-user/netbsd/target_os_elf.h
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "exec/user/tswap-target.h"
 
 /* this flag is uneffective under linux too, should be deleted */
 #ifndef MAP_DENYWRITE
diff --git a/bsd-user/openbsd/target_os_elf.h b/bsd-user/openbsd/target_os_elf.h
index 6dca9c5a85..fc1dfa2e49 100644
--- a/bsd-user/openbsd/target_os_elf.h
+++ b/bsd-user/openbsd/target_os_elf.h
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "exec/user/tswap-target.h"
 
 /* this flag is uneffective under linux too, should be deleted */
 #ifndef MAP_DENYWRITE
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index b042d94892..95af418920 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -36,14 +36,6 @@
 #define BSWAP_NEEDED
 #endif
 
-#if TARGET_LONG_SIZE == 4
-#define tswapl(s) tswap32(s)
-#define bswaptls(s) bswap32s(s)
-#else
-#define tswapl(s) tswap64(s)
-#define bswaptls(s) bswap64s(s)
-#endif
-
 /* Target-endianness CPU memory access functions. These fit into the
  * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
  */
diff --git a/include/exec/user/abitypes.h b/include/exec/user/abitypes.h
index 6178453d94..ed10d5fe7e 100644
--- a/include/exec/user/abitypes.h
+++ b/include/exec/user/abitypes.h
@@ -2,6 +2,7 @@
 #define EXEC_USER_ABITYPES_H
 
 #include "cpu.h"
+#include "exec/user/tswap-target.h"
 
 #ifdef TARGET_ABI32
 #define TARGET_ABI_BITS 32
diff --git a/include/exec/user/tswap-target.h b/include/exec/user/tswap-target.h
new file mode 100644
index 0000000000..ff302436fe
--- /dev/null
+++ b/include/exec/user/tswap-target.h
@@ -0,0 +1,22 @@
+/*
+ * target-specific swap() definitions
+ *
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+#ifndef EXEC_USER_TSWAP_H
+#define EXEC_USER_TSWAP_H
+
+#include "exec/cpu-defs.h"
+#include "exec/tswap.h"
+
+#if TARGET_LONG_SIZE == 4
+#define tswapl(s) tswap32(s)
+#define bswaptls(s) bswap32s(s)
+#else
+#define tswapl(s) tswap64(s)
+#define bswaptls(s) bswap64s(s)
+#endif
+
+#endif
diff --git a/bsd-user/signal.c b/bsd-user/signal.c
index ca31470772..7b2d25230a 100644
--- a/bsd-user/signal.c
+++ b/bsd-user/signal.c
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "qemu/log.h"
 #include "qemu.h"
+#include "exec/user/tswap-target.h"
 #include "gdbstub/user.h"
 #include "signal-common.h"
 #include "trace.h"
diff --git a/bsd-user/strace.c b/bsd-user/strace.c
index 96499751eb..a1b738e63c 100644
--- a/bsd-user/strace.c
+++ b/bsd-user/strace.c
@@ -22,6 +22,7 @@
 #include <sys/ioccom.h>
 
 #include "qemu.h"
+#include "exec/user/tswap-target.h"
 
 #include "os-strace.h"  /* OS dependent strace print functions */
 
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index cf9e74468b..debea5c355 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -6,6 +6,7 @@
 #include <sys/shm.h>
 
 #include "qemu.h"
+#include "exec/user/tswap-target.h"
 #include "user-internals.h"
 #include "signal-common.h"
 #include "loader.h"
diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c
index bc5d45302e..eea1fa68c9 100644
--- a/linux-user/i386/signal.c
+++ b/linux-user/i386/signal.c
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "exec/user/tswap-target.h"
 
 /* from the Linux kernel - /arch/x86/include/uapi/asm/sigcontext.h */
 
diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c
index 7e7302823b..988b59a916 100644
--- a/linux-user/ppc/signal.c
+++ b/linux-user/ppc/signal.c
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "exec/user/tswap-target.h"
 #include "vdso-asmoffset.h"
 
 /* See arch/powerpc/include/asm/ucontext.h.  Only used for 32-bit PPC;
-- 
2.41.0


Re: [PATCH v2 16/23] exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h'
Posted by Anton Johansson via 1 year, 11 months ago
On 12/12/23, Philippe Mathieu-Daudé wrote:
> tswapl() and bswaptls() are target-dependent and only used
> by user emulation. Move their definitions to a new header:
> "exec/user/tswap-target.h".
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  bsd-user/freebsd/target_os_elf.h   |  1 +
>  bsd-user/freebsd/target_os_stack.h |  1 +
>  bsd-user/netbsd/target_os_elf.h    |  1 +
>  bsd-user/openbsd/target_os_elf.h   |  1 +
>  include/exec/cpu-all.h             |  8 --------
>  include/exec/user/abitypes.h       |  1 +
>  include/exec/user/tswap-target.h   | 22 ++++++++++++++++++++++
>  bsd-user/signal.c                  |  1 +
>  bsd-user/strace.c                  |  1 +
>  linux-user/elfload.c               |  1 +
>  linux-user/i386/signal.c           |  1 +
>  linux-user/ppc/signal.c            |  1 +
>  12 files changed, 32 insertions(+), 8 deletions(-)
>  create mode 100644 include/exec/user/tswap-target.h
> 
> diff --git a/bsd-user/freebsd/target_os_elf.h b/bsd-user/freebsd/target_os_elf.h
> index 9df17d56d8..27d8ce036c 100644
> --- a/bsd-user/freebsd/target_os_elf.h
> +++ b/bsd-user/freebsd/target_os_elf.h
> @@ -22,6 +22,7 @@
>  
>  #include "target_arch_elf.h"
>  #include "elf.h"
> +#include "exec/user/tswap-target.h"
>  
>  #define bsd_get_ncpu() 1 /* until we pull in bsd-proc.[hc] */
>  
> diff --git a/bsd-user/freebsd/target_os_stack.h b/bsd-user/freebsd/target_os_stack.h
> index d15fc3263f..6125208182 100644
> --- a/bsd-user/freebsd/target_os_stack.h
> +++ b/bsd-user/freebsd/target_os_stack.h
> @@ -23,6 +23,7 @@
>  #include <sys/param.h>
>  #include "target_arch_sigtramp.h"
>  #include "qemu/guest-random.h"
> +#include "exec/user/tswap-target.h"
>  
>  /*
>   * The initial FreeBSD stack is as follows:
> diff --git a/bsd-user/netbsd/target_os_elf.h b/bsd-user/netbsd/target_os_elf.h
> index 2f3cb20871..23b422bfce 100644
> --- a/bsd-user/netbsd/target_os_elf.h
> +++ b/bsd-user/netbsd/target_os_elf.h
> @@ -22,6 +22,7 @@
>  
>  #include "target_arch_elf.h"
>  #include "elf.h"
> +#include "exec/user/tswap-target.h"
>  
>  /* this flag is uneffective under linux too, should be deleted */
>  #ifndef MAP_DENYWRITE
> diff --git a/bsd-user/openbsd/target_os_elf.h b/bsd-user/openbsd/target_os_elf.h
> index 6dca9c5a85..fc1dfa2e49 100644
> --- a/bsd-user/openbsd/target_os_elf.h
> +++ b/bsd-user/openbsd/target_os_elf.h
> @@ -22,6 +22,7 @@
>  
>  #include "target_arch_elf.h"
>  #include "elf.h"
> +#include "exec/user/tswap-target.h"
>  
>  /* this flag is uneffective under linux too, should be deleted */
>  #ifndef MAP_DENYWRITE
> diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
> index b042d94892..95af418920 100644
> --- a/include/exec/cpu-all.h
> +++ b/include/exec/cpu-all.h
> @@ -36,14 +36,6 @@
>  #define BSWAP_NEEDED
>  #endif
>  
> -#if TARGET_LONG_SIZE == 4
> -#define tswapl(s) tswap32(s)
> -#define bswaptls(s) bswap32s(s)
> -#else
> -#define tswapl(s) tswap64(s)
> -#define bswaptls(s) bswap64s(s)
> -#endif
> -
>  /* Target-endianness CPU memory access functions. These fit into the
>   * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
>   */
> diff --git a/include/exec/user/abitypes.h b/include/exec/user/abitypes.h
> index 6178453d94..ed10d5fe7e 100644
> --- a/include/exec/user/abitypes.h
> +++ b/include/exec/user/abitypes.h
> @@ -2,6 +2,7 @@
>  #define EXEC_USER_ABITYPES_H
>  
>  #include "cpu.h"
> +#include "exec/user/tswap-target.h"
>  
>  #ifdef TARGET_ABI32
>  #define TARGET_ABI_BITS 32
> diff --git a/include/exec/user/tswap-target.h b/include/exec/user/tswap-target.h
> new file mode 100644
> index 0000000000..ff302436fe
> --- /dev/null
> +++ b/include/exec/user/tswap-target.h
> @@ -0,0 +1,22 @@
> +/*
> + * target-specific swap() definitions
> + *
> + *  Copyright (c) 2003 Fabrice Bellard
> + *
> + * SPDX-License-Identifier: LGPL-2.1-or-later
> + */
> +#ifndef EXEC_USER_TSWAP_H
> +#define EXEC_USER_TSWAP_H
> +
> +#include "exec/cpu-defs.h"
> +#include "exec/tswap.h"
> +
> +#if TARGET_LONG_SIZE == 4
> +#define tswapl(s) tswap32(s)
> +#define bswaptls(s) bswap32s(s)
> +#else
> +#define tswapl(s) tswap64(s)
> +#define bswaptls(s) bswap64s(s)
> +#endif
> +
> +#endif
> diff --git a/bsd-user/signal.c b/bsd-user/signal.c
> index ca31470772..7b2d25230a 100644
> --- a/bsd-user/signal.c
> +++ b/bsd-user/signal.c
> @@ -21,6 +21,7 @@
>  #include "qemu/osdep.h"
>  #include "qemu/log.h"
>  #include "qemu.h"
> +#include "exec/user/tswap-target.h"
>  #include "gdbstub/user.h"
>  #include "signal-common.h"
>  #include "trace.h"
> diff --git a/bsd-user/strace.c b/bsd-user/strace.c
> index 96499751eb..a1b738e63c 100644
> --- a/bsd-user/strace.c
> +++ b/bsd-user/strace.c
> @@ -22,6 +22,7 @@
>  #include <sys/ioccom.h>
>  
>  #include "qemu.h"
> +#include "exec/user/tswap-target.h"
>  
>  #include "os-strace.h"  /* OS dependent strace print functions */
>  
> diff --git a/linux-user/elfload.c b/linux-user/elfload.c
> index cf9e74468b..debea5c355 100644
> --- a/linux-user/elfload.c
> +++ b/linux-user/elfload.c
> @@ -6,6 +6,7 @@
>  #include <sys/shm.h>
>  
>  #include "qemu.h"
> +#include "exec/user/tswap-target.h"
>  #include "user-internals.h"
>  #include "signal-common.h"
>  #include "loader.h"
> diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c
> index bc5d45302e..eea1fa68c9 100644
> --- a/linux-user/i386/signal.c
> +++ b/linux-user/i386/signal.c
> @@ -21,6 +21,7 @@
>  #include "user-internals.h"
>  #include "signal-common.h"
>  #include "linux-user/trace.h"
> +#include "exec/user/tswap-target.h"
>  
>  /* from the Linux kernel - /arch/x86/include/uapi/asm/sigcontext.h */
>  
> diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c
> index 7e7302823b..988b59a916 100644
> --- a/linux-user/ppc/signal.c
> +++ b/linux-user/ppc/signal.c
> @@ -21,6 +21,7 @@
>  #include "user-internals.h"
>  #include "signal-common.h"
>  #include "linux-user/trace.h"
> +#include "exec/user/tswap-target.h"
>  #include "vdso-asmoffset.h"
>  
>  /* See arch/powerpc/include/asm/ucontext.h.  Only used for 32-bit PPC;
> -- 
> 2.41.0
> 
Reviewed-by: Anton Johansson <anjo@rev.ng>