We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I was wrong about the effect of the instruction, and for some exceptions the instruction will return to the instruction that caused the exception allowing it to be reexecuted.
LR (R14) will (normally?) point 8 bytes (2 ARM instructions) after the instruction that caused the exception. If you wish to debug the cause, you'll need to examine LR - 8, not move it to PC using SUBS.
SUBS PC,R14, #4 , this instruction is used for debugging. After the execution of this instruction , pc will point to the instruction which caused the exception. Hence one can debug the cause of exception.
Link register is used to store return address after a branch with link. As u said if it holds [address of current instruction + 8 bytes] , how will it return to the next instruction if the previous instruction was a branch with link. All the instructions are 4 bytes aligned.
Exactly. The value saved in LR seems to be inconsistent across exceptions. Which is the source of all my confusion!
The ARM reference manual specifies sometimes MOV PC,R14 and sometimes SUBS PC,R14, #4 for returning from exceptions. But they have not mentioned why. Can somebdy expain?
Also, when exactly does the PC get incremented? During the Fetch ?
And exactly when (Fetching / Decoding / Executing) does an exception get generated?
Does an undefined instruction get generated when the instruction is decoded or when it is executed?What about Data and Prefetch aborts?