Re: static class member as interrupt handler works, but not if class is templated

Klaus Rudolph via Gcc-help <[email protected]> Mon, 12 Apr 2021 13:16:32 +0200
Newsgroups gmane.comp.gcc.help,gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
Hi,


Am 12.04.21 um 11:20 schrieb Peter Sommerlad (C++):

> - why is the special name __vector_10 used to get the function address
> into the interrupt table? Is there another way, or is the environment
> insisting on such a name? Can you change the linker (i.e. with a
> dedicated map file) to get the Dummy<i>::Handler into the table.

Currently the library (avr-libc) has a interrupt vector table which
simple uses the names __vector_xx. The linker collects all functions
with this naming conventions and replace the function address in that
table.

>
> - Is the static Handler() function dependent on the template parameter?
> If not, you can put it into a base class of the class template.

Yes, if not, it can be omitted, quite clear.

>
> - what is the means that a function is considered to be an interrupt
> handler? What does the tooling do between the compiler generating object
> code and the binary that ends up in flash? How does it work?

The attribute for an interrupt handler added to a function adds the
following to the code of the function:

Save all registers
.. normal function content ...
restore all registers
use "reti" instead of "ret" for returning to the "calling context".


>
> - figure out, where the special handling of the __vector_10 seems to
> happen, and why it is not happening in the class template case. This
> might help diagnose if and where to fix it within the compiler.

That is compiler internals... yes, if it is a compiler bug, it is the
way to have a solution. But in that case, it seems to be a generic
problem for gcc as attributes are not assigned to any templated class
member functions. No idea if this is related to the target ( avr ) or
generic for all platforms. But I never did any change inside the
compiler. Any help is welcome!


> In the end, you might need to either change the tools or their
> configuration to get what you want.

I was in hope, that I did something wrong or a workaround is known to
this problem. If that is not the case, I can fix the compiler, change
the linker, modify the avr-libc... yes. But in all this cases, I will
still use C style handlers for this purpose. It is uggly, but C++ on AVR
is always ugly ( v-table in RAM, jump for switch case in RAM, no STL
support ).

If someone can point me to the "problem" inside the compiler, I can give
it a try, but it seems to be the long way :-) But maybe a funny one and
helpful for others.

In general: Why assigning attributes to member functions in templated
class context fails? For me it looks like a bug.

Klaus