unicorn-engine / unicorn

Unicorn CPU emulator framework (ARM, AArch64, M68K, Mips, Sparc, PowerPC, RiscV, S390x, TriCore, X86)
http://www.unicorn-engine.org
GNU General Public License v2.0
7.53k stars 1.33k forks source link

aarch64: Fix PSTATE write. Expose CPSR register like on aarch32 #1844

Closed smx-smx closed 1 year ago

smx-smx commented 1 year ago

This makes it possible to change the Exception Level correctly (from the default EL1 to EL2 or EL3), and allows to change the processor execution mode (user, monitor, hypervisor, etc..)

Fixes #1843

wtdcode commented 1 year ago

AFAIK, you can do this by writing to cp regs.


From: smx @.> Sent: Sunday, June 25, 2023 8:16:48 AM To: unicorn-engine/unicorn @.> Cc: Subscribed @.***> Subject: [unicorn-engine/unicorn] aarch64: Fix PSTATE write. Expose CPSR register like on aarch32 (PR #1844)

This makes it possible to change Exception Level correctly (from the default EL1 to EL2 or EL3), and allows to change the processor execution mode (user, monitor, hypervisor, etc..)

Fixes #1843https://github.com/unicorn-engine/unicorn/issues/1843


You can view, comment on, or merge this pull request online at:

https://github.com/unicorn-engine/unicorn/pull/1844

Commit Summary

File Changes

(2 fileshttps://github.com/unicorn-engine/unicorn/pull/1844/files)

Patch Links:

― Reply to this email directly, view it on GitHubhttps://github.com/unicorn-engine/unicorn/pull/1844, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AHJULO45RJT2XFMUYZOKE53XM57PBANCNFSM6AAAAAAZSZODXY. You are receiving this because you are subscribed to this thread.Message ID: @.***>

smx-smx commented 1 year ago

I tried to, using uc_arm64_cp_reg, but it didn't work. I have a program that checks CurrentEL and jumps to an endless loop (halt and catch fire) if not EL3.

Writing uc_arm64_cp_reg doesn't trigger arm_rebuild_hflags, therefore the program will still see the old value

wtdcode commented 1 year ago

Writing uc_arm64_cp_reg doesn't trigger arm_rebuild_hflags, therefore the program will still see the old value

That bug has been fixed here: a24e53d7944110f8a3010436dc0b5bc79cc9776c

wtdcode commented 1 year ago

Also a fix for aarch32: 75676eb0cd2d7815500dd392d5050e38332c14b9

wtdcode commented 1 year ago

Closing due to no response and fixed pushed.