This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils 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: Switching to and from ARM/Thumb


On Monday 17 January 2005 19:42, Shaun Jackman wrote:
> This mail is somewhat off-topic for binutils. If you know of a better
> mailing list, please point me in the right direction.
>
> I'm writing a pair of macros that generate inline ARM assembler to
> switch to ARM mode from Thumb mode, preform some operation, and then
> switch back to Thumb mode. Their use looks something like this:
>
> #define cli()       \
>  do {       \
>    unsigned long temp;     \
>    __asm__ __volatile__(     \
> arm(cli) \
> " mrs %0, cpsr  @ cli\n"  \
> " orr %0, %0, #128\n"     \
> " msr cpsr, %0"     \
> thumb(cli,%0) \
>
>    : "=r" (temp)      \
>    :       \
>    : "memory");      \
>
>  } while(0)
>
> The arm macro switches to ARM mode, the thumb macro switches to Thumb
> mode using the temporary register %0.

You should not modify the thumb bit in the psr directly. The correct way to 
switch modes is using the bx instruction, ie:

.code 16
thumb_to_arm:
 .align 2
 bx pc
 nop
.code32
arm_to_thumb:
#ifdef __ARMv4T__
 add ip, pc, #1
 bx ip
#else
 sub pc, pc, #1
#endif
thumb_code:

Paul


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