EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

[Q] avr-gcc and calling convention

Started by 42Bastian Schick January 24, 2005
Hi

I am starting to port our RTOS to AVR using avr-gcc ( later surely
IAR, ImageCraft).

Currently I am confused about the calling convention. The AVR-lib
document says:

r2-r17 are callee saved
r18-27 are caller saved
r25-r8 are the parameters left to right

Does this mean, I must preserve the parameter values in r17-r8 ?

TIA
-- 
42Bastian
Do not email to bastian42@yahoo.com, it's a spam-only account :-)
Use <same-name>@epost.de instead !
"42Bastian Schick" <bastian42@yahoo.com> skrev i meddelandet
news:41f48fca.3864156@news.individual.de...
> Hi > > I am starting to port our RTOS to AVR using avr-gcc ( later surely > IAR, ImageCraft). > > Currently I am confused about the calling convention. The AVR-lib > document says: > > r2-r17 are callee saved > r18-27 are caller saved > r25-r8 are the parameters left to right > > Does this mean, I must preserve the parameter values in r17-r8 ? >
One range is free to use by the subroutine without saving. The other needs to be pushed/popped by the subroutine to allow usage "callee" is the subroutine, and "caller" is the code calling the subroutine. I think it works like this: if A calls B, and A wants to make sure that R18 is not changed by the call, A, needs to push R18 on the stack to make sure it is not modif&#4294967295;ed. R18-R27 is thus free to be used by the subroutine. R2-R17 will not be modified by the subroutine. I am not sure, since I only use IAR and occasionally Imagecraft,so if I were you I would compile a small example to find out which range is which. It may be the other way around. It would be better if the documentation said which registers can be used freely by a subroutine and which registers needs to be saved. -- Best Regards Ulf at atmel dot com These comments are intended to be my own opinion and they may, or may not be shared by my employer, Atmel Sweden.
On Mon, 24 Jan 2005 09:19:31 +0100, "Ulf Samuelsson"
<ulf@NOSPAMatmel.com> wrote:

>> Currently I am confused about the calling convention. The AVR-lib >> document says: >> >> r2-r17 are callee saved >> r18-27 are caller saved >> r25-r8 are the parameters left to right >> >> Does this mean, I must preserve the parameter values in r17-r8 ? >> > > >One range is free to use by the subroutine without saving. >The other needs to be pushed/popped by the subroutine to allow usage >"callee" is the subroutine, and "caller" is the code calling the subroutine. > >I think it works like this: >if A calls B, and A wants to make sure that R18 is not changed >by the call, A, needs to push R18 on the stack to make sure it is not >modif&#4294967295;ed. >R18-R27 is thus free to be used by the subroutine. >R2-R17 will not be modified by the subroutine.
So far, it has been clear to me. What confuses me is the overlapping set of registers r8..r17 which should be preservered in an function but may also serve as parameters. But I guess I have to build some test functions that need a lot of registers and has a lot of parameters. -- 42Bastian Do not email to bastian42@yahoo.com, it's a spam-only account :-) Use <same-name>@monlynx.de instead !
42Bastian Schick wrote:
> So far, it has been clear to me. What confuses me is the overlapping > set of registers r8..r17 which should be preservered in an function > but may also serve as parameters.
If the registers are needed as parameters, the caller knows it and so does the callee. I'd assume that the rules for parameters apply in the case where one of these registers is assigned as a parameter. Other parameters don't need to be preserved, so these probably don't either.

The 2024 Embedded Online Conference