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)
Hello, currently I'm writing a hardware interrupt/cpu exception emulator by manually fiddling with
VBAR_ELx/SPSR_ELx/ELR_ELxregisters.By default, Unicorn runs on EL1 and I tried to elevate the execution to EL2 by manipulating the bits of
PSTATE, however after running instructionMRS X0, CurrentELit reveals even if I setPSTATEmanually to EL2, theCurrentELis still EL1 thenERETwould return to EL0 instead.After some investigation, I found at unicorn_aarch64.c, line 383 (
case UC_ARM64_REG_PSTATE) there is no call toarm_rebuild_hflags, causing Unicorn still uses old value ofCurrentEL.I believe it is missing because after writing to a dummy
UC_ARM64_REG_CP_REG(which has call toarm_rebuild_hflags, line 406) bothCurrentELandERETreturned 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
CurrentELfails assert in helper.c:raw_readfunction becauseri->fieldoffsetis 0. And writing to it seems may corruptCPUARMState *env, as inwrite_cp_reg,CPREG_FIELD64(env, ri)writes to((char *)env)[0]because of the nullfieldoffset, please correct me if I'm wrong)