From: "Alex Bennée" <alex.bennee@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, patches@linaro.org,
Michael Davidsaver <mdavidsaver@gmail.com>
Subject: Re: [PATCH 4/4] arm: Fix APSR writes via M profile MSR
Date: Mon, 20 Mar 2017 11:01:54 +0000 [thread overview]
Message-ID: <87mvcgnrdp.fsf@linaro.org> (raw)
In-Reply-To: <1487616072-9226-5-git-send-email-peter.maydell@linaro.org>
Peter Maydell <peter.maydell@linaro.org> writes:
> Our implementation of writes to the APSR for M-profile via the MSR
> instruction was badly broken.
>
> First and worst, we had the sense wrong on the test of bit 2 of the
> SYSm field -- this is supposed to request an APSR write if bit 2 is 0
> but we were doing it if bit 2 was 1. This bug was introduced in
> commit 58117c9bb429cd, so hasn't been in a QEMU release.
>
> Secondly, the choice of exactly which parts of APSR should be written
> is defined by bits in the 'mask' field. We were not passing these
> through from instruction decode, making it impossible to check them
> in the helper.
>
> Pass the mask bits through from the instruction decode to the helper
> function and process them appropriately; fix the wrong sense of the
> SYSm bit 2 check.
>
> Invalid mask values and invalid combinations of mask and register
> number are UNPREDICTABLE; we choose to treat them as if the mask
> values were valid.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
> target/arm/helper.c | 26 ++++++++++++++++++++++----
> target/arm/translate.c | 3 ++-
> 2 files changed, 24 insertions(+), 5 deletions(-)
>
> diff --git a/target/arm/helper.c b/target/arm/helper.c
> index 948aba2..8349e1f 100644
> --- a/target/arm/helper.c
> +++ b/target/arm/helper.c
> @@ -8478,8 +8478,18 @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg)
> }
> }
>
> -void HELPER(v7m_msr)(CPUARMState *env, uint32_t reg, uint32_t val)
> -{
> +void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val)
> +{
> + /* We're passed bits [11..0] of the instruction; extract
> + * SYSm and the mask bits.
> + * Invalid combinations of SYSm and mask are UNPREDICTABLE;
> + * we choose to treat them as if the mask bits were valid.
> + * NB that the pseudocode 'mask' variable is bits [11..10],
> + * whereas ours is [11..8].
> + */
> + uint32_t mask = extract32(maskreg, 8, 4);
> + uint32_t reg = extract32(maskreg, 0, 8);
> +
> if (arm_current_el(env) == 0 && reg > 7) {
> /* only xPSR sub-fields may be written by unprivileged */
> return;
> @@ -8488,8 +8498,16 @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t reg, uint32_t val)
> switch (reg) {
> case 0 ... 7: /* xPSR sub-fields */
> /* only APSR is actually writable */
> - if (reg & 4) {
> - xpsr_write(env, val, 0xf8000000); /* APSR */
> + if (!(reg & 4)) {
> + uint32_t apsrmask = 0;
> +
> + if (mask & 8) {
> + apsrmask |= 0xf8000000; /* APSR NZCVQ */
> + }
> + if ((mask & 4) && arm_feature(env, ARM_FEATURE_THUMB_DSP)) {
> + apsrmask |= 0x000f0000; /* APSR GE[3:0] */
> + }
> + xpsr_write(env, val, apsrmask);
> }
> break;
> case 8: /* MSP */
> diff --git a/target/arm/translate.c b/target/arm/translate.c
> index 9090356..ce7f19f 100644
> --- a/target/arm/translate.c
> +++ b/target/arm/translate.c
> @@ -10391,7 +10391,8 @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw
> case 0: /* msr cpsr. */
> if (arm_dc_feature(s, ARM_FEATURE_M)) {
> tmp = load_reg(s, rn);
> - addr = tcg_const_i32(insn & 0xff);
> + /* the constant is the mask and SYSm fields */
> + addr = tcg_const_i32(insn & 0xfff);
> gen_helper_v7m_msr(cpu_env, addr, tmp);
> tcg_temp_free_i32(addr);
> tcg_temp_free_i32(tmp);
--
Alex Bennée
next prev parent reply other threads:[~2017-03-20 11:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-20 18:41 [PATCH 0/4] arm: Fix M profile MSR/MRS Peter Maydell
2017-02-20 18:41 ` [PATCH 1/4] arm: HVC and SMC encodings don't exist for M profile Peter Maydell
2017-03-20 10:48 ` Alex Bennée
2017-02-20 18:41 ` [PATCH 2/4] arm: Don't decode MRS(banked) or MSR(banked) " Peter Maydell
2017-03-20 10:57 ` Alex Bennée
2017-03-20 11:05 ` Peter Maydell
2017-02-20 18:41 ` [PATCH 3/4] arm: Enforce should-be-1 bits in MRS decoding Peter Maydell
2017-03-20 10:59 ` Alex Bennée
2017-02-20 18:41 ` [PATCH 4/4] arm: Fix APSR writes via M profile MSR Peter Maydell
2017-03-20 11:01 ` Alex Bennée [this message]
2017-03-14 11:52 ` [Qemu-arm] [PATCH 0/4] arm: Fix M profile MSR/MRS Peter Maydell
2017-03-18 17:36 ` Peter Maydell
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=87mvcgnrdp.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=mdavidsaver@gmail.com \
--cc=patches@linaro.org \
--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).