public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Mangle functions
@ 2008-01-28 10:22 Ron Kreymborg
  2008-01-28 17:22 ` Daniel Lohmann
  2008-01-28 18:12 ` Brian Dessent
  0 siblings, 2 replies; 7+ messages in thread
From: Ron Kreymborg @ 2008-01-28 10:22 UTC (permalink / raw)
  To: gcc-help

Is there a way the C++ pre-processor can access the mangled name of a class
method? This would greatly simplify implementing interrupt handlers as
private class methods in embedded systems where the processor uses an
interrupt vector table. Currently one must manually build the mangled name
and pass it to the gcc "alias" attribute. 

My idea is a macro like:

#define CLASS_ISR(theclassname, themethodname) \
 ISR(theclassname) ISR_ALIASOF(gcc_mangle(theclassname, themethodname)); \
 void theclassname::themethodname(void)

where the "gcc_mangle" function is what I am after.  If this existed it
would allow automating the creation of classes for embedded systems where
the interrupt handler is a private class method and its "friend" status
allows it access to the class data of the owning device manager class. The
abbreviated example class definitions below show the timer overflow
interrupt handler for the Timer0 peripheral of an Atmel AVR microprocessor:

//-------------------------------------------
class CTimer0Interrupt
{
public:
    CTimer0Interrupt();
    ~CTimer0Interrupt();
private:
    // Overflow interrupt handler.
    void TIMER0_OVF_vect(void) __attribute__ ((signal, __INTR_ATTRS));
};

//-------------------------------------------
class CTimer0
{
    friend class CTimer0Interrupt;
public:
    CTimer0();
    ~CTimer0();
    int GetTimer0Flag(void);     // true if overflow occurred
private:
    void SetOverflowFlag(void);  // called from int handler
private:
    volatile bool       mTimer0Flag;
    CTimer0Interrupt    mTimer0Interrupt;
};

And in the cpp class implementation file, the method is:

//---------------------------------------------------------------
// Timer0 overflow interrupt handler.
//
CLASS_ISR(CTimer0Interrupt, TIMER0_OVF_vect)
{
    TCNT0 = TIMER0_TIMEOUT;     // restart the timeout
    Timer0.SetOverflowFlag();   // tell our friend
}

Inserting the mangled name by hand in the macro above produces the vector
alias that allows gcc to link the external C vector name while the C++ code
remains unaware of its existence outside the owning class:

extern "C" void __vector_16 (void) __attribute__ ((signal,used,
externally_visible)) ; 
void __vector_16 (void)
__attribute__((alias("_ZN16CTimer0Interrupt11__vector_16Ev"))); 
void CTimer0Interrupt::__vector_16(void)
{
    (*(volatile uint8_t *)((0x32) + 0x20)) = 100;
    Timer0.SetOverflowFlag();
}

Ron Kreymborg




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-01-30  7:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-28 10:22 Mangle functions Ron Kreymborg
2008-01-28 17:22 ` Daniel Lohmann
2008-01-28 19:23   ` Andrew Haley
2008-01-28 19:25     ` Ron Kreymborg
2008-01-29  0:54       ` Daniel Lohmann
     [not found]         ` <000301c86303$3be6eae0$b3b4c0a0$@com.au>
2008-01-31 17:51           ` Daniel Lohmann
2008-01-28 18:12 ` Brian Dessent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).