This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Switching to and from ARM/Thumb
- From: Paul Brook <paul at codesourcery dot com>
- To: binutils at sources dot redhat dot com,Shaun Jackman <sjackman at gmail dot com>
- Date: Mon, 17 Jan 2005 22:55:25 +0000
- Subject: Re: Switching to and from ARM/Thumb
- Organization: CodeSourcery
- References: <7f45d9390501171142ffea371@mail.gmail.com>
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