stack unwinding during exception
Hi,
I am trying to test my fault exceptions. In the event of an exception, I would like to get more information about the problem. In the event of an exception, I am finding the stack pointer and trying to get PC by unwinding the stack. I think the PC would tell me the address where the problem occurred.
I have a test code in main() as given below to test my code.


Exception happens at PC 0x8042326.

Please note that the active stack pointer is SP_main, and the PC is 0x8042322.
I get an usage fault exception once the divide by zero is executed. The LR is 0xFFFFFFE9 in the exception handler which is correct. I expect to see the PC as 0x08042322 when I unwind the stack but this is different.
void UsageFault_Handler(void)
{
uint32_t StackPointer = 0UL;
__ASM volatile
(
" tst lr, #4 \n"
" ite eq \n"
" mrseq %0, msp \n"
" mrsne %0, psp \n"
: "=r"( StackPointer )
);I read the stack pointer as 0x2001'f070, but from the memory map 0x2001'f080 seems to be correct.

IAR says 0xC2500000 as PC which can be seen in the above memory map. Why is there an offset ?

