From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Eduardo Habkost <eduardo@habkost.net>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
"Yanan Wang" <wangyanan55@huawei.com>,
"Daniel P . Berrangé" <berrange@redhat.com>
Subject: [RFC PATCH 1/3] cpu: Add a way to detect 32-bit mode from argv0
Date: Tue, 25 Apr 2023 15:38:49 +0200 [thread overview]
Message-ID: <20230425133851.489283-2-thuth@redhat.com> (raw)
In-Reply-To: <20230425133851.489283-1-thuth@redhat.com>
In the future, we might want to avoid compiling certain targets separately
for 32-bit mode (i.e. -i386, -arm and -ppc) where the 64-bit variant is a
superset of the 32-bit variant. But it would be good to provide a way to
mimic the 32-bit behavior via the program name in case the users need this
compatibility for some scenarios. Thus add a function that checks
for the old 32-bit program names and sets a flag accordingly.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
include/hw/core/cpu.h | 10 ++++++++++
cpu.c | 13 +++++++++++++
softmmu/vl.c | 1 +
3 files changed, 24 insertions(+)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 397fd3ac68..8fc15b7797 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -470,6 +470,15 @@ extern __thread CPUState *current_cpu;
extern bool mttcg_enabled;
#define qemu_tcg_mttcg_enabled() (mttcg_enabled)
+/**
+ * qemu_target_only_32bits:
+ * Check whether the target is 32 bits only (like i386 in contrast to x86_64).
+ *
+ * Returns: %true if we are running with a 32-bit only target
+ */
+extern bool target_only_32bits;
+#define qemu_target_only_32bits() (target_only_32bits)
+
/**
* cpu_paging_enabled:
* @cpu: The CPU whose state is to be inspected.
@@ -1009,6 +1018,7 @@ void cpu_exec_unrealizefn(CPUState *cpu);
*/
bool target_words_bigendian(void);
+void cpu_init_target_only_32bits(const char *argv0);
void page_size_init(void);
#ifdef NEED_CPU_H
diff --git a/cpu.c b/cpu.c
index 9105c85404..0b498f3a53 100644
--- a/cpu.c
+++ b/cpu.c
@@ -47,6 +47,8 @@
uintptr_t qemu_host_page_size;
intptr_t qemu_host_page_mask;
+bool target_only_32bits = (TARGET_LONG_BITS == 32);
+
#ifndef CONFIG_USER_ONLY
static int cpu_common_post_load(void *opaque, int version_id)
{
@@ -427,6 +429,17 @@ bool target_words_bigendian(void)
#endif
}
+/*
+ * This is used for 64-bit targets that can also run in restricted 32-bit
+ * mode, e.g. if running as qemu-system-i386 instead of qemu-system-x86_64
+ */
+void cpu_init_target_only_32bits(const char *argv0)
+{
+ target_only_32bits |= g_str_has_suffix(argv0, "-i386") ||
+ g_str_has_suffix(argv0, "-arm") ||
+ g_str_has_suffix(argv0, "-ppc");
+}
+
void page_size_init(void)
{
/* NOTE: we can always suppose that qemu_host_page_size >=
diff --git a/softmmu/vl.c b/softmmu/vl.c
index fb6c221e8e..51b35a6f0b 100644
--- a/softmmu/vl.c
+++ b/softmmu/vl.c
@@ -2677,6 +2677,7 @@ void qemu_init(int argc, char **argv)
error_init(argv[0]);
qemu_init_exec_dir(argv[0]);
+ cpu_init_target_only_32bits(argv[0]);
qemu_init_arch_modules();
--
2.31.1
next prev parent reply other threads:[~2023-04-25 13:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-25 13:38 [RFC PATCH 0/3] Deprecate the qemu-system-i386 binary Thomas Huth
2023-04-25 13:38 ` Thomas Huth [this message]
2023-04-25 13:38 ` [RFC PATCH 2/3] target/i386/cpu: Allow to limit the 64-bit binary to 32-bit mode only Thomas Huth
2023-04-25 13:38 ` [RFC PATCH 3/3] docs/about/deprecated: Deprecate the qemu-system-i386 binary Thomas Huth
2023-10-06 9:38 ` Philippe Mathieu-Daudé
2023-04-26 10:59 ` [RFC PATCH 0/3] " Paolo Bonzini
2023-04-27 8:13 ` Thomas Huth
2023-04-27 8:25 ` Paolo Bonzini
2023-04-27 8:28 ` Daniel P. Berrangé
2023-04-27 8:31 ` Paolo Bonzini
2023-04-27 8:33 ` Daniel P. Berrangé
2023-04-27 9:06 ` Paolo Bonzini
2023-04-27 12:12 ` Thomas Huth
2023-04-27 12:22 ` Daniel P. Berrangé
2024-06-19 10:09 ` 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=20230425133851.489283-2-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=berrange@redhat.com \
--cc=eduardo@habkost.net \
--cc=marcel.apfelbaum@gmail.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=wangyanan55@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).