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 <th...@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