Is it safe to save just part of registers in interrupt/exception handler?

Andrew Haley aph@redhat.com
Fri Jun 13 13:47:00 GMT 2008


PRC wrote:

> The MIPS ABI document says:
> For non-leaf function,$31 must be saved.  If any of
> $16..$23 or$29..$31 is changed within the called function, it must be saved
> in the stack frame before use and restored from the stack frame before re-
> turn from the function. 
> 
> My interrupt/exception handler contains two parts: one written in assembly
> and the other written in C. The ASM handler does some simple work like
> saving status, epc and gerneral registers and then jumps/calls to the C handler
> to do more complex work. Since MIPS ABI guarantees $16~$23 and $29~$31 are saved
> in C functions if they are used, is it safe to save only those registers except $16~$23 and $29~$31 in ASM handler?

In theory, yes: the ABI makes that guarantee.  As long as
all called code conforms to the ABI you'll be fine.

Andrew.



More information about the Gcc-help mailing list