Skip to content

Missing arm_rebuild_hflags call after writing to UC_ARM64_REG_PSTATE? #2333

Description

@yt6983138

Hello, currently I'm writing a hardware interrupt/cpu exception emulator by manually fiddling with VBAR_ELx/SPSR_ELx/ELR_ELx registers.

By default, Unicorn runs on EL1 and I tried to elevate the execution to EL2 by manipulating the bits of PSTATE, however after running instruction MRS X0, CurrentEL it reveals even if I set PSTATE manually to EL2, the CurrentEL is still EL1 then ERET would return to EL0 instead.

After some investigation, I found at unicorn_aarch64.c, line 383 (case UC_ARM64_REG_PSTATE) there is no call to arm_rebuild_hflags, causing Unicorn still uses old value of CurrentEL.

I believe it is missing because after writing to a dummy UC_ARM64_REG_CP_REG (which has call to arm_rebuild_hflags, line 406) both CurrentEL and ERET returned correct level.

According to issue #1843, the issue is marked as fixed in commit a24e53d in PR #1844, but it only adds the call for UC_ARM64_REG_CP_REG, and the description says "We need either doc this or save more information for a context", but I can't seem to find the documentation/information anywhere.

Related? #1884 (also, I found that reading CurrentEL fails assert in helper.c: raw_read function because ri->fieldoffset is 0. And writing to it seems may corrupt CPUARMState *env, as in write_cp_reg, CPREG_FIELD64(env, ri) writes to ((char *)env)[0] because of the null fieldoffset, please correct me if I'm wrong)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions