qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <huth@tuxfamily.org>
To: Laurent Vivier <laurent@vivier.eu>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] target/m68k: only change valid bits in CACR
Date: Sat, 14 Dec 2019 10:10:47 +0100	[thread overview]
Message-ID: <20191214101047.217a887a@thl530.multi.box> (raw)
In-Reply-To: <20191212194045.12882-1-laurent@vivier.eu>

Am Thu, 12 Dec 2019 20:40:45 +0100
schrieb Laurent Vivier <laurent@vivier.eu>:

> This is used by netBSD (and MacOS ROM) to detect the MMU type
> 
> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
> ---
>  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	other threads:[~2019-12-14  9:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-12 19:40 [PATCH] target/m68k: only change valid bits in CACR Laurent Vivier
2019-12-14  9:10 ` Thomas Huth [this message]

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=20191214101047.217a887a@thl530.multi.box \
    --to=huth@tuxfamily.org \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    /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).