qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Helge Deller <deller@gmx.de>, qemu-devel@nongnu.org
Cc: "Laurent Vivier" <laurent@vivier.eu>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	qemu-arm@nongnu.org, "Daniel P . Berrangé" <berrange@redhat.com>
Subject: Re: [PATCH v2 2/3] linux-user: Emulate /proc/cpuinfo on aarch64 and arm
Date: Wed, 2 Aug 2023 11:15:14 -0700	[thread overview]
Message-ID: <52cb992d-90b5-e28c-8184-6f3637f2459e@linaro.org> (raw)
In-Reply-To: <20230801230842.414421-3-deller@gmx.de>

On 8/1/23 16:08, Helge Deller wrote:
> +#if defined(TARGET_AARCH64) || defined(TARGET_ARM)
> +static int open_cpuinfo(CPUArchState *cpu_env, int fd)
> +{
> +    const int is64 = TARGET_ABI_BITS == 64;
> +    ARMCPU *cpu = ARM_CPU(thread_cpu);
> +    uint64_t midr = cpu->midr;
> +    const int rev  = (midr & 0xf);
> +    const int arch = is64 ? 8 : 7;

The 32-bit arch is not automatically v7: -cpu max is v8 and -cpu ti925t is v4.

You need an if ladder for this:

     if (arm_feature(&cpu->env, ARM_FEATURE_V8)) {
         arch = 8;
     } else if (arm_feature(&cpu->env, ARM_FEATURE_V7)) {
         arch = 7;
     } else if (arm_feature(&cpu->env, ARM_FEATURE_V6)) {
         arch = 6;
     } else if (arm_feature(&cpu->env, ARM_FEATURE_V5)) {
         arch = 5;
     } else {
         arch = 4;
     }

Also,

     ref = FIELD_EX64(cpu->midr, MIDR_EL1, REVISION);

etc, instead of masking by hand.

> +        dprintf(fd, "model name\t: ARMv%d Processor rev %d (%s%c)\n",
> +            arch, rev, is64 ? "v8" : "armv7",

Will need adjustment.

> +#if TARGET_BIG_ENDIAN
> +            'b'
> +#else
> +            'l'
> +#endif

Don't need an ifdef: (TARGET_BIG_ENDIAN ? 'b' : 'l').

> +        dprintf(fd, "CPU implementer\t: %#02x\n", (int)(midr >> 24) & 0xff);
> +        dprintf(fd, "CPU architecture: %d\n",     arch);
> +        dprintf(fd, "CPU variant\t: %#x\n",       (int)(midr >> 20) & 0xf );
> +        dprintf(fd, "CPU part\t: %#03x\n",        (int)(midr >> 4) & 0xfff);
> +        dprintf(fd, "CPU revision\t: %d\n\n",     rev);
> +    }

FIELD_EX64(midr, MIDR_EL1, ...)

Though I have some memory of these fields changing across arch versions.
You might need to extract them earlier, within the if ladder.


r~


  reply	other threads:[~2023-08-02 18:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01 23:08 [PATCH v2 0/3] linux-user: /proc/cpuinfo fix and content emulation for arm Helge Deller
2023-08-01 23:08 ` [PATCH v2 1/3] linux-user: Fix openat() emulation to correctly detect accesses to /proc Helge Deller
2023-08-02  8:16   ` Daniel P. Berrangé
2023-08-01 23:08 ` [PATCH v2 2/3] linux-user: Emulate /proc/cpuinfo on aarch64 and arm Helge Deller
2023-08-02 18:15   ` Richard Henderson [this message]
2023-08-01 23:08 ` [PATCH v2 3/3] linux-user: Emulate /proc/cpuinfo for Alpha Helge Deller

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=52cb992d-90b5-e28c-8184-6f3637f2459e@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=berrange@redhat.com \
    --cc=deller@gmx.de \
    --cc=laurent@vivier.eu \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --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).