From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hobo2.sui-inter.net (hobo2.sui-inter.net [80.74.150.112]) by sourceware.org (Postfix) with ESMTPS id 7D147388A401 for ; Mon, 12 Apr 2021 09:20:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7D147388A401 Received: from PSMacBook.local (localhost [127.0.0.1]) by hobo2.sui-inter.net (Postfix) with ESMTPSA id 2D4A817D06D7; Mon, 12 Apr 2021 11:20:46 +0200 (CEST) Received-SPF: pass (hobo.sui-inter.net: connection is authenticated) Subject: Re: static class member as interrupt handler works, but not if class is templated To: Klaus Rudolph Cc: "gcc-help@gcc.gnu.org" , avr-gcc-list@nongnu.org References: <5f39cb4e-a445-bf19-ae90-b76c934aa930@gmx.de> From: "Peter Sommerlad (C++)" Message-ID: <38829120-5ab7-d74e-0149-edf8ec6d4227@sommerlad.ch> Date: Mon, 12 Apr 2021 11:20:50 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 PostboxApp/7.0.47 MIME-Version: 1.0 In-Reply-To: <5f39cb4e-a445-bf19-ae90-b76c934aa930@gmx.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00, BODY_8BITS, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Apr 2021 09:20:50 -0000 Klaus, I do not have a solution, but I try to be helpful and give a list what I would try to understand the situation: - 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::Handler into the 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. - 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? - 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 what I have in the top of my head at the moment. In the end, you might need to either change the tools or their configuration to get what you want. Regards Peter. Klaus Rudolph wrote on 10.04.21 15:33: > Hi all, > > if I write a class with static member function I can use it as an > interrupt handler as follows: > > class Dummy > { >     static void Handler() __asm__("__vector_10") > __attribute__((__signal__, __used__, __externally_visible__)); > }; > > void Dummy::Handler() > { > > } > > I can see the vector is entered in the handler table: > > > >   1c:    0c 94 34 00     jmp    0x68    ; 0x68 <__bad_interrupt> >   20:    0c 94 34 00     jmp    0x68    ; 0x68 <__bad_interrupt> >   24:    0c 94 34 00     jmp    0x68    ; 0x68 <__bad_interrupt> >   28:    0c 94 36 00     jmp    0x6c    ; 0x6c <__vector_10> >   2c:    0c 94 34 00     jmp    0x68    ; 0x68 <__bad_interrupt> >   30:    0c 94 34 00     jmp    0x68    ; 0x68 <__bad_interrupt> > > ################### > > But if the class becomes a template, the function is not longer entered > in the handler. How can I fix it? > > template < int i > > class Dummy > { >     static void Handler() __asm__("__vector_10") > __attribute__((__signal__, __used__, __externally_visible__)); > }; > > template < int i> > void Dummy::Handler() > { > > } > > Dummy<1> d1; > >   20:    0c 94 3c 00     jmp    0x78    ; 0x78 <__bad_interrupt> >   24:    0c 94 3c 00     jmp    0x78    ; 0x78 <__bad_interrupt> >   28:    0c 94 3c 00     jmp    0x78    ; 0x78 <__bad_interrupt> >   2c:    0c 94 3c 00     jmp    0x78    ; 0x78 <__bad_interrupt> >   30:    0c 94 3c 00     jmp    0x78    ; 0x78 <__bad_interrupt> > > > I tried it with avr-g++ (Fedora 10.2.0-1.fc33) 10.2.0 > > Thanks! > > > -- Peter Sommerlad Better Software: Consulting, Training, Reviews Modern, Safe & Agile C++ peter.cpp@sommerlad.ch +41 79 432 23 32