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 2/3] target/i386/cpu: Allow to limit the 64-bit binary to 32-bit mode only
Date: Tue, 25 Apr 2023 15:38:50 +0200 [thread overview]
Message-ID: <20230425133851.489283-3-thuth@redhat.com> (raw)
In-Reply-To: <20230425133851.489283-1-thuth@redhat.com>
qemu-system-x86_64 is pretty much a proper superset of qemu-system-i386,
so in the long run, it does not make too much sense that we continuously
build two binaries here.
However, some people still might want to start QEMU in a mode that limits
the environment to 32-bit. Thus allow qemu-system-x86_64 to run in 32-bit
mode if the binary name ends in "-i386".
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
target/i386/cpu.h | 4 ++--
target/i386/cpu.c | 28 +++++++++++++---------------
target/i386/gdbstub.c | 8 +-------
3 files changed, 16 insertions(+), 24 deletions(-)
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index d243e290d3..5cb2eb3493 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -40,8 +40,8 @@
#define TARGET_HAS_PRECISE_SMC
#ifdef TARGET_X86_64
-#define I386_ELF_MACHINE EM_X86_64
-#define ELF_MACHINE_UNAME "x86_64"
+#define I386_ELF_MACHINE (qemu_target_only_32bits() ? EM_386 : EM_X86_64)
+#define ELF_MACHINE_UNAME (qemu_target_only_32bits() ? "i686" : "x86_64")
#else
#define I386_ELF_MACHINE EM_386
#define ELF_MACHINE_UNAME "i686"
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 2e30e348a1..f713005476 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5093,11 +5093,9 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,
} else {
return ~0;
}
-#ifndef TARGET_X86_64
- if (w == FEAT_8000_0001_EDX) {
+ if (qemu_target_only_32bits() && w == FEAT_8000_0001_EDX) {
r &= ~CPUID_EXT2_LM;
}
-#endif
if (migratable_only) {
r &= x86_cpu_get_migratable_flags(w);
}
@@ -5267,11 +5265,11 @@ static void x86_cpu_load_model(X86CPU *cpu, X86CPUModel *model)
static gchar *x86_gdb_arch_name(CPUState *cs)
{
-#ifdef TARGET_X86_64
- return g_strdup("i386:x86-64");
-#else
- return g_strdup("i386");
-#endif
+ if (qemu_target_only_32bits()) {
+ return g_strdup("i386");
+ } else {
+ return g_strdup("i386:x86-64");
+ }
}
static void x86_cpu_cpudef_class_init(ObjectClass *oc, void *data)
@@ -7295,13 +7293,13 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
#endif /* !CONFIG_USER_ONLY */
cc->gdb_arch_name = x86_gdb_arch_name;
-#ifdef TARGET_X86_64
- cc->gdb_core_xml_file = "i386-64bit.xml";
- cc->gdb_num_core_regs = 66;
-#else
- cc->gdb_core_xml_file = "i386-32bit.xml";
- cc->gdb_num_core_regs = 50;
-#endif
+ if (qemu_target_only_32bits()) {
+ cc->gdb_core_xml_file = "i386-32bit.xml";
+ cc->gdb_num_core_regs = 50;
+ } else {
+ cc->gdb_core_xml_file = "i386-64bit.xml";
+ cc->gdb_num_core_regs = 66;
+ }
cc->disas_set_info = x86_disas_set_info;
dc->user_creatable = true;
diff --git a/target/i386/gdbstub.c b/target/i386/gdbstub.c
index ebb000df6a..35a56b317c 100644
--- a/target/i386/gdbstub.c
+++ b/target/i386/gdbstub.c
@@ -72,15 +72,9 @@ static const int gpr_map32[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
#define IDX_CTL_CR8_REG (IDX_CTL_REGS + 4)
#define IDX_CTL_EFER_REG (IDX_CTL_REGS + 5)
-#ifdef TARGET_X86_64
-#define GDB_FORCE_64 1
-#else
-#define GDB_FORCE_64 0
-#endif
-
static int gdb_read_reg_cs64(uint32_t hflags, GByteArray *buf, target_ulong val)
{
- if ((hflags & HF_CS64_MASK) || GDB_FORCE_64) {
+ if ((hflags & HF_CS64_MASK) || !qemu_target_only_32bits()) {
return gdb_get_reg64(buf, val);
}
return gdb_get_reg32(buf, val);
--
2.31.1
next prev parent reply other threads:[~2023-04-25 13:40 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 ` [RFC PATCH 1/3] cpu: Add a way to detect 32-bit mode from argv0 Thomas Huth
2023-04-25 13:38 ` Thomas Huth [this message]
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-3-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).