No because if you call a function from your ISR the compiler would assume the registers to contain trash after the call and it would generate the required saves in the prologue.
The compiler cannot see through function calls unless those are inlined, port_switch() is never inlined by design, it is into another module to begin with.
Giovanni
Porting help, possible bug in AVR port
Moderator: tfAteba
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Porting help, possible bug in AVR port
Thank you for your patience.
That makes sense. I need to really start thinking more about what the compiler expects in terms of call-saved and call-used registers. I keep thinking that I have to do it all, while in reality the compiler will do most of it.
Sam
That makes sense. I need to really start thinking more about what the compiler expects in terms of call-saved and call-used registers. I keep thinking that I have to do it all, while in reality the compiler will do most of it.
Sam
Re: Porting help, possible bug in AVR port
Phew, I got my port up and working. It isn't really much more than extending the program counter and adding a few registers to extctx, but still it is working.
I hate to ask this but I have to: The ISR calls a function (port_switch) so why do we need to manually save the call-used registers (r18-r27,r30,r31 on AVR)?
From that line of reasoning it seems as though the compiler should save the call-used registers in the ISR prologue that it generates?
I hate to ask this but I have to: The ISR calls a function (port_switch) so why do we need to manually save the call-used registers (r18-r27,r30,r31 on AVR)?
...if you call a function from your ISR the compiler would assume the registers to contain trash after the call and it would generate the required saves in the prologue.
From that line of reasoning it seems as though the compiler should save the call-used registers in the ISR prologue that it generates?
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Porting help, possible bug in AVR port
Good question 
We don't save those registers, the macro...
...is probably redundant. Note that it does not save registers, it just makes sure that the compiler saves them even in case a function is not called from the ISR (and this is never the case because port_switch() is always called).
Giovanni
We don't save those registers, the macro...
Code: Select all
#define PORT_IRQ_PROLOGUE() { \
asm ("" : : : "r18", "r19", "r20", "r21", "r22", "r23", "r24", \
"r25", "r26", "r27", "r30", "r31"); \
}
...is probably redundant. Note that it does not save registers, it just makes sure that the compiler saves them even in case a function is not called from the ISR (and this is never the case because port_switch() is always called).
Giovanni
Re: Porting help, possible bug in AVR port
Muahaha! Thank goodness, I finally understand it. 
Just to verify I commented out the "touching" of the registers and recompiled. The compiler still added those registers to the prologue. Thank you so much for walking me through how this all works. I have a much better grasp on it now.
Sam
Just to verify I commented out the "touching" of the registers and recompiled. The compiler still added those registers to the prologue. Thank you so much for walking me through how this all works. I have a much better grasp on it now.
Sam
- Giovanni
- Site Admin
- Posts: 14891
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Porting help, possible bug in AVR port
You are welcome, ChibiOS is tricky at that level in order to achieve a good performance.
Giovanni
Giovanni