From fe60494b7722ecedbf96cea507b0d37e2abe994e Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Tue, 14 Jan 2020 08:17:06 -0500 Subject: [PATCH] target/m68k: only change valid bits in CACR This is used by netBSD (and MacOS ROM) to detect the MMU type Backports commit 18b6102e51bb317d25ee61b49b7b56702b79560c from qemu --- qemu/target/m68k/cpu.c | 28 ++++++++++++++++++++++------ qemu/target/m68k/cpu.h | 5 ++++- qemu/target/m68k/helper.c | 10 +++++++++- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/qemu/target/m68k/cpu.c b/qemu/target/m68k/cpu.c index 34794cd8..6993cb5a 100644 --- a/qemu/target/m68k/cpu.c +++ b/qemu/target/m68k/cpu.c @@ -110,11 +110,9 @@ static void m68000_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque) m68k_set_feature(env, M68K_FEATURE_MOVEP); } -static void m68020_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque) +/* common features for 68020, 68030 and 68040 */ +static void m680x0_cpu_common(CPUM68KState *env) { - M68kCPU *cpu = M68K_CPU(uc, obj); - CPUM68KState *env = &cpu->env; - m68k_set_feature(env, M68K_FEATURE_M68000); m68k_set_feature(env, M68K_FEATURE_USP); m68k_set_feature(env, M68K_FEATURE_WORD_INDEX); @@ -132,14 +130,31 @@ static void m68020_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque) m68k_set_feature(env, M68K_FEATURE_CHK2); m68k_set_feature(env, M68K_FEATURE_MOVEP); } -#define m68030_cpu_initfn m68020_cpu_initfn + +static void m68020_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque) +{ + M68kCPU *cpu = M68K_CPU(uc, obj); + CPUM68KState *env = &cpu->env; + + m680x0_cpu_common(env); + m68k_set_feature(env, M68K_FEATURE_M68020); +} + +static void m68030_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque) +{ + M68kCPU *cpu = M68K_CPU(uc, obj); + CPUM68KState *env = &cpu->env; + + m680x0_cpu_common(env); + m68k_set_feature(env, M68K_FEATURE_M68030); +} static void m68040_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque) { M68kCPU *cpu = M68K_CPU(uc, obj); CPUM68KState *env = &cpu->env; - m68020_cpu_initfn(uc, obj, opaque); + m680x0_cpu_common(env); m68k_set_feature(env, M68K_FEATURE_M68040); } @@ -162,6 +177,7 @@ static void m68060_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque) m68k_set_feature(env, M68K_FEATURE_BKPT); m68k_set_feature(env, M68K_FEATURE_RTD); m68k_set_feature(env, M68K_FEATURE_CHK2); + m68k_set_feature(env, M68K_FEATURE_M68060); } static void m5208_cpu_initfn(struct uc_struct *uc, Object *obj, void *opaque) diff --git a/qemu/target/m68k/cpu.h b/qemu/target/m68k/cpu.h index 29d9fbe0..19e67fc4 100644 --- a/qemu/target/m68k/cpu.h +++ b/qemu/target/m68k/cpu.h @@ -456,6 +456,10 @@ void do_m68k_semihosting(CPUM68KState *env, int nr); enum m68k_features { M68K_FEATURE_M68000, + M68K_FEATURE_M68020, + M68K_FEATURE_M68030, + M68K_FEATURE_M68040, + M68K_FEATURE_M68060, M68K_FEATURE_CF_ISA_A, M68K_FEATURE_CF_ISA_B, /* (ISA B or C). */ M68K_FEATURE_CF_ISA_APLUSC, /* BIT/BITREV, FF1, STRLDSR (ISA A+ or C). */ @@ -477,7 +481,6 @@ enum m68k_features { M68K_FEATURE_BKPT, M68K_FEATURE_RTD, M68K_FEATURE_CHK2, - M68K_FEATURE_M68040, /* instructions specific to MC68040 */ M68K_FEATURE_MOVEP, }; diff --git a/qemu/target/m68k/helper.c b/qemu/target/m68k/helper.c index a6a398b9..301fba89 100644 --- a/qemu/target/m68k/helper.c +++ b/qemu/target/m68k/helper.c @@ -68,7 +68,15 @@ void HELPER(m68k_movec_to)(CPUM68KState *env, uint32_t reg, uint32_t val) return; /* MC680[234]0 */ case M68K_CR_CACR: - env->cacr = val; + if (m68k_feature(env, M68K_FEATURE_M68020)) { + env->cacr = val & 0x0000000f; + } else if (m68k_feature(env, M68K_FEATURE_M68030)) { + env->cacr = val & 0x00003f1f; + } else if (m68k_feature(env, M68K_FEATURE_M68040)) { + env->cacr = val & 0x80008000; + } else if (m68k_feature(env, M68K_FEATURE_M68060)) { + env->cacr = val & 0xf8e0e000; + } m68k_switch_sp(env); return; /* MC680[34]0 */