http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53689

             Bug #: 53689
           Summary: [SH] GCC emits an invalid slot instruction for RTE
                    (Return from Exception)
    Classification: Unclassified
           Product: gcc
           Version: 4.5.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: mrko...@gmail.com


Under target (sh-elf) big-endian SuperH-2 (SH7604) (options -m2 -mb
-fno-omit-frame-pointer).

When defining an interrupt handler:
static void __attribute__ ((interrupt_handler))
foo(void)
{
}

GCC 4.5.3 emits the following:

00000000 <_foo>:
   0:    2f e6           mov.l    r14,@-r15
   2:    6e f3           mov    r15,r14
   4:    6f e3           mov    r14,r15
   6:    00 2b           rte    
   8:    6e f6           mov.l    @r15+,r14



How to generate the interrupt:
int
main(int argc, char *argv[])
{
        __asm__ __volatile__ ("trapa #32\n"
                "tst #0, r0");

        return 0;
}

the TRAPA instruction pushes both the SR and PC register values onto the stack
before jumping the interrupt handler foo().

Upon exiting foo(), with RTE, the delay slot is NOT executed first. Instead,
RTE pops both the SR and PC register off the stack, then the slot instruction
is executed.

The (hack) solution is:


static void __attribute__ ((interrupt_handler))
foo(void)
{
        __asm__ __volatile__ ("mov.l @r15+, r14\n"
                "rte\n"
                "nop");
}

Reply via email to