2024-07-23 11:36 PM
Hello,
I have a code snippet where I initialize PSP (stack pointer) to its very first location, and then manually fill the stack with some values as follows:
pTask = (uint32_t *)TASK1_STACK_START; //Stack Start location for Task1
*pTask = (uint32_t) SET_XPSR_FOR_THUMB; //Store the xPSR value in address :TASK1_STACK_START
pTask--; //Decrement
In the above code when I execute the very first "pTask--;", I get an IMPRECISERR. However when I modify the sequence as below, the exception went away
pTask = (uint32_t *)TASK1_STACK_START; //Stack Start location for Task1
pTask--; //Decrement
*pTask = (uint32_t) SET_XPSR_FOR_THUMB; //Store the xPSR value in address :TASK1_STACK_START - 4
Although I am aware that the decrement needs to happen before setting a value in Arm Cortex, I was setting the xPSR value first in order to make use of the very first Stack location TASK1_STACK_START. (in the second case, the first stack location TASK1_STACK_START will go unused)
Could someone tell me why this is the case ? Is there any internal check in Arm processors whereby decrements are mandated before storing value to a stack location , and throw an exception otherwise ?
Thanks