qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] target/m68k: only change valid bits in CACR


From: Thomas Huth
Subject: Re: [PATCH] target/m68k: only change valid bits in CACR
Date: Sat, 14 Dec 2019 10:10:47 +0100

Am Thu, 12 Dec 2019 20:40:45 +0100
schrieb Laurent Vivier <address@hidden>:

> This is used by netBSD (and MacOS ROM) to detect the MMU type
> 
> Signed-off-by: Laurent Vivier <address@hidden>
> ---
>  target/m68k/cpu.c    | 28 ++++++++++++++++++++++------
>  target/m68k/cpu.h    |  4 ++++
>  target/m68k/helper.c | 16 ++++++++++++++--
>  3 files changed, 40 insertions(+), 8 deletions(-)
> 
> diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
> index e6596de29c..1d202cec49 100644
> --- a/target/m68k/cpu.c
> +++ b/target/m68k/cpu.c
> @@ -114,11 +114,8 @@ static void m68000_cpu_initfn(Object *obj)
>      m68k_set_feature(env, M68K_FEATURE_MOVEP);
>  }
>  
> -static void m68020_cpu_initfn(Object *obj)
> +static void m680x0_cpu_common(CPUM68KState *env)
>  {
> -    M68kCPU *cpu = M68K_CPU(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);
> @@ -136,14 +133,32 @@ static void m68020_cpu_initfn(Object *obj)
>      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(Object *obj)
> +{
> +    M68kCPU *cpu = M68K_CPU(obj);
> +    CPUM68KState *env = &cpu->env;
> +
> +    m680x0_cpu_common(env);
> +    m68k_set_feature(env, M68K_FEATURE_MMU68851);
> +}
> +
> +static void m68030_cpu_initfn(Object *obj)
> +{
> +    M68kCPU *cpu = M68K_CPU(obj);
> +    CPUM68KState *env = &cpu->env;
> +
> +    m680x0_cpu_common(env);
> +    m68k_set_feature(env, M68K_FEATURE_MMU68030);
> +}
>  
>  static void m68040_cpu_initfn(Object *obj)
>  {
>      M68kCPU *cpu = M68K_CPU(obj);
>      CPUM68KState *env = &cpu->env;
>  
> -    m68020_cpu_initfn(obj);
> +    m680x0_cpu_common(env);
> +    m68k_set_feature(env, M68K_FEATURE_MMU68040);
>      m68k_set_feature(env, M68K_FEATURE_M68040);
>  }
>  
> @@ -166,6 +181,7 @@ static void m68060_cpu_initfn(Object *obj)
>      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_MMU68060);
>  }
>  
>  static void m5208_cpu_initfn(Object *obj)
> diff --git a/target/m68k/cpu.h b/target/m68k/cpu.h
> index 20de3c379a..36e4353b44 100644
> --- a/target/m68k/cpu.h
> +++ b/target/m68k/cpu.h
> @@ -483,6 +483,10 @@ enum m68k_features {
>      M68K_FEATURE_CHK2,
>      M68K_FEATURE_M68040, /* instructions specific to MC68040 */
>      M68K_FEATURE_MOVEP,
> +    M68K_FEATURE_MMU68851,
> +    M68K_FEATURE_MMU68030,
> +    M68K_FEATURE_MMU68040,
> +    M68K_FEATURE_MMU68060,
>  };
>  
>  static inline int m68k_feature(CPUM68KState *env, int feature)
> diff --git a/target/m68k/helper.c b/target/m68k/helper.c
> index ae766a6cb0..b5758bbd7d 100644
> --- a/target/m68k/helper.c
> +++ b/target/m68k/helper.c
> @@ -205,7 +205,13 @@ 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_MMU68040)) {

Why is the *Cache* control register tied to an MMU feature?
Maybe use M68K_FEATURE_M68040 instead? Or call the new flag
M68K_FEATURE_CACHE040 instead?

> +            env->cacr = val & 0x80008000;
> +        } else if (m68k_feature(env, M68K_FEATURE_MMU68030)) {
> +            env->cacr = val & 0x00003fff;

That seems to be too much, according to my MC68030 UM, there are some
bits tied to zero inbetween. The correct mask should be 0x3f1f, I think.

> +        } else if (m68k_feature(env, M68K_FEATURE_MMU68851)) {
> +            env->cacr = val & 0x0000000f;
> +        }

What about the 68060? It has yet another set of bits in the CACR...

>          m68k_switch_sp(env);
>          return;
>      /* MC680[34]0 */
> @@ -261,7 +267,13 @@ uint32_t HELPER(m68k_movec_from)(CPUM68KState
> *env, uint32_t reg) return env->vbr;
>      /* MC680[234]0 */
>      case M68K_CR_CACR:
> -        return env->cacr;
> +        if (m68k_feature(env, M68K_FEATURE_MMU68040)) {
> +            return env->cacr & 0x80008000;
> +        } else if (m68k_feature(env, M68K_FEATURE_MMU68030)) {
> +            return env->cacr & 0x00003fff;
> +        } else if (m68k_feature(env, M68K_FEATURE_MMU68851)) {
> +            return env->cacr & 0x0000000f;
> +        }

Wouldn't it be enough to do the masking either only during the "from"
or during the "to" move? If you want to do it for both, I'd suggest to
declare a little helper function for the masking instead, so that you
don't have to repeat the code.

 Thomas



reply via email to

[Prev in Thread] Current Thread [Next in Thread]