You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Unicorn to emulate an Arm binary, I noticed a behavior where the stack pointer in the emulator is being reset to 0 if the CPSR register is written after the SP register.
Here's a minimal example:
importunicornasUuc=U.Uc(U.UC_ARCH_ARM, U.UC_MODE_ARM)
uc.reg_write(U.arm_const.UC_ARM_REG_SP,100)
# This returns 100, as expectedprint(uc.reg_read(U.arm_const.UC_ARM_REG_SP))
# Now, write something to the CPSR registeruc.reg_write(U.arm_const.UC_ARM_REG_CPSR,0x30)
# Reading from stack pointer returns 0, instead of 100print(uc.reg_read(U.arm_const.UC_ARM_REG_SP))
Assuming this is not expected behavior in Arm, the SP register being reset may be a bug in the writing of the CPSR register. In my testing, other registers (PC or other general purpose registers) do not reset upon the CPSR being written - only the SP has this behavior.
The text was updated successfully, but these errors were encountered:
I think I have the root cause - I noticed that the default value of CPSR (when read immediately after initialization) is 0x400001d3. The bottom bits indicate supervisor mode. Arm has banked registers - SP being one of them - which means that each processor mode (supervisor, user, etc) has it's own distinct physical SP register. When you switch modes (say from supervisor to user), the SP is saved somewhere, and then restored upon your mode switching back to user mode.
Using Unicorn to emulate an Arm binary, I noticed a behavior where the stack pointer in the emulator is being reset to 0 if the
CPSR
register is written after theSP
register.Here's a minimal example:
Assuming this is not expected behavior in Arm, the SP register being reset may be a bug in the writing of the CPSR register. In my testing, other registers (PC or other general purpose registers) do not reset upon the CPSR being written - only the SP has this behavior.
The text was updated successfully, but these errors were encountered: