All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Richard Henderson <rth@twiddle.net>
Cc: qemu-arm <qemu-arm@nongnu.org>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Liviu Ionescu" <ilg@livius.net>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"patches@linaro.org" <patches@linaro.org>
Subject: Re: [Qemu-devel] [PATCH 05/10] armv7m: honour CCR.STACKALIGN on exception entry
Date: Tue, 24 Jan 2017 19:45:03 +0000	[thread overview]
Message-ID: <CAFEAcA8hZKk429b_sdtQb5bT7ymjBAqbcokpOL-oc2Vi8zUbyQ@mail.gmail.com> (raw)
In-Reply-To: <649a4b6e-2c7f-cf2c-5fb2-9213aaffd34a@twiddle.net>

On 24 January 2017 at 19:33, Richard Henderson <rth@twiddle.net> wrote:
> On 01/24/2017 11:16 AM, Peter Maydell wrote:
>> The CCR.STACKALIGN bit controls whether the CPU is supposed to force
>> 8-alignment of the stack pointer on entry to the exception handler.
>
> 8...
>
>> +    /* Align stack pointer if the guest wants that */
>> +    if ((env->regs[13] & 4) && (env->v7m.ccr & R_V7M_CCR_STKALIGN_MASK)) {
>
> 4...
>
>>          env->regs[13] -= 4;
>
> Not alignment.  "&= -4"?

We know SP is always at least a multiple of 4. If it's already
a multiple of 8 then (sp & 4) will be false and we leave sp alone.
Otherwise it's a multiple of 4 but not 8, and subtracting 4
makes it 8 aligned (and we set the saved-XPSR bit to indicate
that we need to undo that on exception exit).

You could maybe rephrase the code to look a bit closer to the
v7M ARM ARM pseudocode, but the way it's written now isn't wrong,
so since this patch is only trying to say "do this if STKALIGN
is set rather than all the time" just adjusting the if conditional
seemed the best thing to me.

(The pseudocode checks for "do we need to align" with
"SP<2> AND forcealign", and does the alignment by
ANDing with a mask constructed with "NOT(ZeroExtend(forcealign:'00',32))".
So we do the check the same way it does, but use a subtract
rather than an AND-NOT. (Since we know that bit 2 must be set
then subtracting 4 and masking that bit to 0 are the same thing.)

thanks
-- PMM

  reply	other threads:[~2017-01-24 19:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-24 19:16 [Qemu-devel] [PATCH 00/10] More M profile bugfixes Peter Maydell
2017-01-24 19:16 ` [Qemu-devel] [PATCH 01/10] target/arm: Drop IS_M() macro Peter Maydell
2017-01-27 12:33   ` Alex Bennée
2017-01-24 19:16 ` [Qemu-devel] [PATCH 02/10] armv7m_nvic: keep a pointer to the CPU Peter Maydell
2017-01-27 12:41   ` Alex Bennée
2017-01-27 13:16     ` Peter Maydell
2017-01-24 19:16 ` [Qemu-devel] [PATCH 03/10] armv7m: add state for v7M CCR, CFSR, HFSR, DFSR, MMFAR, BFAR Peter Maydell
2017-01-27 12:28   ` Alex Bennée
2017-01-27 13:14     ` Peter Maydell
2017-01-24 19:16 ` [Qemu-devel] [PATCH 04/10] armv7m: implement CCR, CFSR, HFSR, DFSR, BFAR, and MMFAR Peter Maydell
2017-01-27 13:43   ` Alex Bennée
2017-01-24 19:16 ` [Qemu-devel] [PATCH 05/10] armv7m: honour CCR.STACKALIGN on exception entry Peter Maydell
2017-01-24 19:33   ` Richard Henderson
2017-01-24 19:45     ` Peter Maydell [this message]
2017-01-24 19:16 ` [Qemu-devel] [PATCH 06/10] armv7m: set CFSR.UNDEFINSTR on undefined instructions Peter Maydell
2017-01-27 13:44   ` Alex Bennée
2017-01-24 19:16 ` [Qemu-devel] [PATCH 07/10] armv7m: Report no-coprocessor faults correctly Peter Maydell
2017-01-27 13:53   ` Alex Bennée
2017-01-24 19:16 ` [Qemu-devel] [PATCH 08/10] armv7m: Honour CCR.USERSETMPEND Peter Maydell
2017-01-27 13:55   ` Alex Bennée
2017-01-24 19:16 ` [Qemu-devel] [PATCH 09/10] armv7m: FAULTMASK should be 0 on reset Peter Maydell
2017-01-27 13:56   ` Alex Bennée
2017-01-24 19:16 ` [Qemu-devel] [PATCH 10/10] armv7m: R14 should reset to 0xffffffff Peter Maydell
2017-01-27 13:58   ` Alex Bennée

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=CAFEAcA8hZKk429b_sdtQb5bT7ymjBAqbcokpOL-oc2Vi8zUbyQ@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=ilg@livius.net \
    --cc=patches@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.