This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Thumb->ARM->Thumb in inline-wrapped asm? [31740]


>>>>> "dhm" == dave madden <dhm@mersenne.com> writes:

    dhm> I'm hoping to put together an inline func wrapper for an
    dhm> asm() fragment that can, for the sake of argument, disable
    dhm> interrupts and return CPSR to a Thumb function.

Following up my own message, it turns out I'd wandered down Stupid
Lane after misinterpreting other error messages.  The way to do this
is the ADR pseudo-op, which reliably gets the necessary address into a
register.  One solution that appears to work is:

/*
 * Thumb-mode function to disable interrupts and return current
 * value of CPSR
 */
static inline int
portDISABLE_INTERRUPTS( void ) {
    int  retval, tmp;
    __asm__ __volatile__ ( "adr %0 , 1$\n"
                           "bx  %0\n"
                           ".arm\n"
                           "1$: mrs  %0 , CPSR\n"
                           "orr %1 , %0 , #0xc0\n"
                           "msr CPSR_c , %1\n"
                           "adr %1 , 2$ + 1\n"
                           "bx  %1\n"
                           ".thumb\n"
                           "2$:\n"
                           : "=r" (retval), "=r" (tmp) );
    return retval;
}

d.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]