Hi
Want to know if there is a way to instruct the compiler to preserve more than the normal registers (R0-R3, R12, LR, PSR, and PC) during an interrupt.
Regards Viktor Bucher
Surely, the compiler has to preserve whatever registers it uses - and, if it doesn't use a register, there is no point in preserving it?!
Not exactly. I wrote an assembly function that is called from inside the interrupt. This function uses more registers than those that are preserved by the interrupt itself
but if YOU wrote the function in assembly, you must do the preserve and restore manually...
hence:
void __asm foo(void) { push... . . . pop... }
I know that and I did so. Those registers must only be preserved during an interrupt call and not when called from the main program. So this presents a difference. If I put that function in a library It would be a good idea not to preserve those registers and let the compiler do that when needed. That is why a asked the question.
But, surely, the function must always preserve whatever registers it modifies - however it gets called?!
Not all registers should be preserved during calls. At least with ARM tools.
A compiler always (at least if the processor allows it) defines a number of scratch registers that may be used without second thought.
But any function playing with other registers must take 100% responsibility for such use, and restore the expected state before returning or calling another function that hasn't been explicitly written to accept these exceptional register uses.
Those registers must only be preserved during an interrupt call and not when called from the main program.
Then write two versions of the function, one for calling from the ISR and one for calling from the main program. That avoids pesky reentrancy issues, too.