All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [RFC PATCH 10/11] qemu: Introduce qemu_arch_name() helper
Date: Wed, 5 Mar 2025 08:59:07 +0000	[thread overview]
Message-ID: <Z8gSW9n0R8zWS7jM@redhat.com> (raw)
In-Reply-To: <20250305005225.95051-11-philmd@linaro.org>

On Wed, Mar 05, 2025 at 01:52:24AM +0100, Philippe Mathieu-Daudé wrote:
> Introduce a generic helper to get the target name of a QemuArchBit.
> (This will be used for single / heterogeneous binaries).
> Use it in target_name(), removing the last use of the TARGET_NAME
> definition.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  include/qemu/arch_info.h |  2 ++
>  arch_info-target.c       | 34 +++++++++++++++++++++++++++++++++-
>  2 files changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/include/qemu/arch_info.h b/include/qemu/arch_info.h
> index 613dc2037db..7e3192f590f 100644
> --- a/include/qemu/arch_info.h
> +++ b/include/qemu/arch_info.h
> @@ -46,6 +46,8 @@ typedef enum QemuArchBit {
>  #define QEMU_ARCH_LOONGARCH     BIT(QEMU_ARCH_BIT_LOONGARCH)
>  #define QEMU_ARCH_ALL           -1
>  
> +const char *qemu_arch_name(QemuArchBit qemu_arch_bit);
> +
>  const char *target_name(void);
>  
>  bool qemu_arch_available(unsigned qemu_arch_mask);
> diff --git a/arch_info-target.c b/arch_info-target.c
> index 61007415b30..9b19fe8d56d 100644
> --- a/arch_info-target.c
> +++ b/arch_info-target.c
> @@ -24,9 +24,41 @@
>  #include "qemu/osdep.h"
>  #include "qemu/arch_info.h"
>  
> +const char *qemu_arch_name(QemuArchBit qemu_arch_bit)
> +{
> +    static const char *legacy_target_names[] = {
> +        [QEMU_ARCH_ALPHA] = "alpha",

All the others you've used QEMU_ARCH_BIT except for this. Yes, it happens
to have the same value either way, but it still looks wrong.

> +        [QEMU_ARCH_BIT_ARM] = TARGET_LONG_BITS == 32 ? "arm" : "aarch64",
> +        [QEMU_ARCH_BIT_AVR] = "avr",
> +        [QEMU_ARCH_BIT_HEXAGON] = "hexagon",
> +        [QEMU_ARCH_BIT_HPPA] = "hppa",
> +        [QEMU_ARCH_BIT_I386] = TARGET_LONG_BITS == 32 ? "i386" : "x86_64",
> +        [QEMU_ARCH_BIT_LOONGARCH] = "loongarch64",
> +        [QEMU_ARCH_BIT_M68K] = "m68k",
> +        [QEMU_ARCH_BIT_MICROBLAZE] = TARGET_BIG_ENDIAN ? "microblaze"
> +                                                       : "microblazeel",
> +        [QEMU_ARCH_BIT_MIPS] = TARGET_BIG_ENDIAN
> +                             ? (TARGET_LONG_BITS == 32 ? "mips" : "mips64")
> +                             : (TARGET_LONG_BITS == 32 ? "mipsel" : "mips64el"),
> +        [QEMU_ARCH_BIT_OPENRISC] = "or1k",
> +        [QEMU_ARCH_BIT_PPC] = TARGET_LONG_BITS == 32 ? "ppc" : "ppc64",
> +        [QEMU_ARCH_BIT_RISCV] = TARGET_LONG_BITS == 32 ? "riscv32" : "riscv64",
> +        [QEMU_ARCH_BIT_RX] = "rx",
> +        [QEMU_ARCH_BIT_S390X] = "s390x",
> +        [QEMU_ARCH_BIT_SH4] = TARGET_BIG_ENDIAN ? "sh4eb" : "sh4",
> +        [QEMU_ARCH_BIT_SPARC] = TARGET_LONG_BITS == 32 ? "sparc" : "sparc64",
> +        [QEMU_ARCH_BIT_TRICORE] = "tricore",
> +        [QEMU_ARCH_BIT_XTENSA] = TARGET_BIG_ENDIAN ? "xtensaeb" : "xtensa",

Why do we need to give arches different names based on endian/bits, as
opposed to a fixed int -> name mapping. What's the intended  usage of
this ?

Since you're calling this a legacy_target_names, should the method also
be call qemu_legacy_arch_name() rather than qemu_arch_name - I would
have naively expected qemu_arch_name to be a plain mapping.

> +    };
> +
> +    assert(qemu_arch_bit < ARRAY_SIZE(legacy_target_names));
> +    assert(legacy_target_names[qemu_arch_bit]);
> +    return legacy_target_names[qemu_arch_bit];
> +}
> +
>  const char *target_name(void)
>  {
> -    return TARGET_NAME;
> +    return qemu_arch_name(QEMU_ARCH_BIT);
>  }
>  
>  bool qemu_arch_available(unsigned qemu_arch_mask)
> -- 
> 2.47.1
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  parent reply	other threads:[~2025-03-05  8:59 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-05  0:52 [RFC PATCH 00/11] qemu: Remove TARGET_NAME definition Philippe Mathieu-Daudé
2025-03-05  0:52 ` [RFC PATCH 01/11] system: Extract target-specific globals to their own compilation unit Philippe Mathieu-Daudé
2025-03-05  1:20   ` Pierrick Bouvier
2025-03-05  1:33     ` Philippe Mathieu-Daudé
2025-03-05  1:41       ` Pierrick Bouvier
2025-03-11 10:24   ` Alex Bennée
2025-03-05  0:52 ` [RFC PATCH 02/11] system: Open-code qemu_init_arch_modules() using target_name() Philippe Mathieu-Daudé
2025-03-05  2:27   ` Richard Henderson
2025-03-05  0:52 ` [RFC PATCH 03/11] system: Introduce QemuArchBit enum Philippe Mathieu-Daudé
2025-03-05  1:23   ` Pierrick Bouvier
2025-03-05  1:31     ` Philippe Mathieu-Daudé
2025-03-05  1:36       ` Pierrick Bouvier
2025-03-05  1:39         ` Philippe Mathieu-Daudé
2025-03-05  2:27   ` Richard Henderson
2025-03-05  8:55   ` Daniel P. Berrangé
2025-03-05  9:00     ` Daniel P. Berrangé
2025-03-05  0:52 ` [RFC PATCH 04/11] system: Replace arch_type global by qemu_arch_available() helper Philippe Mathieu-Daudé
2025-03-05  2:29   ` Richard Henderson
2025-03-05  0:52 ` [RFC PATCH 05/11] include: Expose QemuArchBit enum to user emulation Philippe Mathieu-Daudé
2025-03-05  2:43   ` Richard Henderson
2025-03-05  0:52 ` [RFC PATCH 06/11] include: Declare target_name() in common "qemu/arch_info.h" Philippe Mathieu-Daudé
2025-03-05  2:44   ` Richard Henderson
2025-03-05  0:52 ` [RFC PATCH 07/11] plugins/loader: populate target_name with target_name() Philippe Mathieu-Daudé
2025-03-05  0:52 ` [RFC PATCH 08/11] tests/qtest: Replace TARGET_NAME -> target_name() Philippe Mathieu-Daudé
2025-03-05  3:02   ` Richard Henderson
2025-03-05  0:52 ` [RFC PATCH 09/11] user: " Philippe Mathieu-Daudé
2025-03-05  0:52 ` [RFC PATCH 10/11] qemu: Introduce qemu_arch_name() helper Philippe Mathieu-Daudé
2025-03-05  1:32   ` BALATON Zoltan
2025-03-05  1:36     ` Philippe Mathieu-Daudé
2025-03-05  2:05       ` BALATON Zoltan
2025-03-05  2:23   ` Richard Henderson
2025-03-05  8:59   ` Daniel P. Berrangé [this message]
2025-03-05  0:52 ` [RFC PATCH 11/11] qemu: Remove C definitions of TARGET_NAME Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z8gSW9n0R8zWS7jM@redhat.com \
    --to=berrange@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.