Skip to contentSkip to conversation

pstate_read/write ignores nRW field that is kept in env->aarch64

DISCUSSION [email protected] 2 participants 2 messages Oct 6, 2020

lore
Share & tools
lore
#1 lore raw
In reply to [email protected]
Quoted 5 lines · On Tue, 6 Oct 2020 at 12:36, <[email protected]> wrote:

Could you please explain me why in pstate_read and pstate_write the nRW bit is ignored?
The comment in CPUState says that nRW (also known as M[4]) is kept, inverted, in env->aarch64,
but the value returned by pstate_read doesn't contain this bit.

That's because pstate_read() is in general only used from contexts where the CPU is known to be in AArch64 state and so that bit is always zero. AArch32 state code instead uses cpsr_read(). Similarly for pstate_write(), it is only used in cases where we're in (or switching to) AArch64 state, and the calling code generally handles the "flip the env->aarch64 flag" part itself -- see for instance the exception_return handling in helper-a64.c, which does

 if (!return_to_aa64) {
     env->aarch64 = 0;
     /* ... */
     cpsr_write(...);
     /* ... */
 } else {
     env->aarch64 = 1;
     /* ... */
     pstate_write(...);
     /* ... */

}

This is because switching between AArch32 and AArch64 is complicated (among other things you need to sync the state to or from the 32-bit and 64-bit views of the general purpose registers in env->regs[] and env->xregs[]). It never happens just as a side-effect of a pstate_write():
you always know you're making the switch and are doing a lot of other things at the same time.

thanks
-- PMM

#0 lore raw

Hello!
Could you please explain me why in pstate_read and pstate_write the nRW bit is ignored?
The comment in CPUState says that nRW (also known as M[4]) is kept, inverted, in env->aarch64,
but the value returned by pstate_read doesn't contain this bit.

static inline uint32_t pstate_read(CPUARMState *env)

{
    int ZF;
    ZF = (env->ZF == 0);
    return (env->NF & 0x80000000) | (ZF << 30)
        | (env->CF << 29) | ((env->VF & 0x80000000) >> 3)
        | env->pstate | env->daif | (env->btype << 10);
}

Best regards, Ivan.