[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 2/3] target/i386/cpu: Allow to limit the 64-bit binary to 32-
From: |
Thomas Huth |
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 |
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
- [RFC PATCH 0/3] Deprecate the qemu-system-i386 binary, Thomas Huth, 2023/04/25
- [RFC PATCH 3/3] docs/about/deprecated: Deprecate the qemu-system-i386 binary, Thomas Huth, 2023/04/25
- [RFC PATCH 1/3] cpu: Add a way to detect 32-bit mode from argv0, Thomas Huth, 2023/04/25
- [RFC PATCH 2/3] target/i386/cpu: Allow to limit the 64-bit binary to 32-bit mode only,
Thomas Huth <=
- Re: [RFC PATCH 0/3] Deprecate the qemu-system-i386 binary, Paolo Bonzini, 2023/04/26
- Re: [RFC PATCH 0/3] Deprecate the qemu-system-i386 binary, Thomas Huth, 2023/04/27
- Re: [RFC PATCH 0/3] Deprecate the qemu-system-i386 binary, Daniel P . Berrangé, 2023/04/27
- Re: [RFC PATCH 0/3] Deprecate the qemu-system-i386 binary, Paolo Bonzini, 2023/04/27
- Re: [RFC PATCH 0/3] Deprecate the qemu-system-i386 binary, Daniel P . Berrangé, 2023/04/27
- Re: [RFC PATCH 0/3] Deprecate the qemu-system-i386 binary, Paolo Bonzini, 2023/04/27
- Re: [RFC PATCH 0/3] Deprecate the qemu-system-i386 binary, Thomas Huth, 2023/04/27
- Re: [RFC PATCH 0/3] Deprecate the qemu-system-i386 binary, Daniel P . Berrangé, 2023/04/27