Open OBarronCS opened 2 months ago
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.
Might this be configurable?
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.