-finline and ISRs

Edwin Olson eolson@MIT.EDU
Sat Apr 21 20:14:00 GMT 2007


I'm working with a small embedded O/S on an ARM7TDMI.

A typical IRQ handler must save the state of a previous task, perform 
some processing, possibly invoke the scheduler, and then restore a new 
task. I'd like to do as much of this as possible from C, but 
automatically generated prologue/epilogue chunks interfere with my 
IRQ_TASK_SAVE/RESTORE macros (which are inline assembly). So I've been 
doing this:

static void emac_irq(void) __attribute__ ((naked));
static void emac_irq(void)
{
    IRQ_TASK_SAVE;
    emac_irq_real();
    IRQ_TASK_RESTORE;
}

Calling out to the actual ISR as a separate function call seems to 
isolate stack variable allocations to the section between the 
IRQ_TASK_SAVE/RESTORE.

This works pretty well, however, if I optimize at -O4, emac_irq_real is 
inlined, and the IRQ handler no longer runs correctly. (I've verified: 
the code works with -O4 -fno-inline, but doesn't work with just -O4).

I can attach a "noinline" attribute to emac_irq_real, which again causes 
things to work, but the whole thing is starting to feel clumsy.

Does anyone have an idea of how I can do this in a more elegant way, 
that doesn't require setting a bunch of attributes?

-Ed



More information about the Gcc-help mailing list