Page 2 of 2

Re: Porting help, possible bug in AVR port

Posted: Thu Jan 17, 2013 4:11 pm
by Giovanni
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

Re: Porting help, possible bug in AVR port

Posted: Thu Jan 17, 2013 5:19 pm
by swinchen
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

Re: Porting help, possible bug in AVR port

Posted: Fri Jan 18, 2013 2:48 am
by swinchen
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)?

...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?

Re: Porting help, possible bug in AVR port

Posted: Fri Jan 18, 2013 9:13 am
by Giovanni
Good question :)

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

Posted: Fri Jan 18, 2013 3:29 pm
by swinchen
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

Re: Porting help, possible bug in AVR port

Posted: Fri Jan 18, 2013 3:45 pm
by Giovanni
You are welcome, ChibiOS is tricky at that level in order to achieve a good performance.

Giovanni