Mangle functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux