This is the mail archive of the gcc@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]

Fwd: QUERY : ARM inline code in Thumb file?


2008/8/27 Aaron P. D'Souza <adsouzp@netscape.net>
>
> hello:
>
> one small question regarding use of ARM inline assembly code in a
> C file that has been compiled for Thumb mode.
>
> is it possible to use ARM assembly code from within a C file that
> has been compiled for Thumb and Thumb interworking?

The easiest way would be to just write an assembler file with:

.global function_f
.arm
function_f:
mrs r0, cpsr
msr cpsr_c, r0
bx lr

... if you provide the correct cpu and interwork flags during the
assemble/link phases, this will get interworking veeners and thus will
be called correctly from both arm and thumb code.

If that's not an option, then you probably would need to do something like this:

void function_f(void)
{
 register int x;
#ifdef __thumb__
 register int y;
#endif
 asm volatile (
#ifdef __thumb__
      ".align 2\n"
      "bx pc\n"
      "nop\n"
      ".arm\n"
#endif
   "mrs     %0,     cpsr  \n\t"
   "msr     cpsr_c, %0    \n\t"
#ifdef __thumb__
  "add %1, pc, #1\n"
 "bx %1\n"
#endif
  : "=r" (x)
#ifdef __thumb__
  , "=r" (y)
#endif
 );
}


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