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: Nick Clifton <nickc at redhat dot com>
- To: Shaun Jackman <sjackman at gmail dot com>
- Cc: binutils at sources dot redhat dot com
- Date: Tue, 18 Jan 2005 10:03:12 +0000
- Subject: Re: Switching to and from ARM/Thumb
- References: <7f45d9390501171142ffea371@mail.gmail.com>
Hi Shaun,
This mail is somewhat off-topic for binutils. If you know of a better
mailing list, please point me in the right direction.
The gcc mailing list would probably be your best bet for this kind of
question.
/** Switch to Arm mode. */
#define arm(x) \
".balignw 4, 0x46c0 @ nop\n" \
" bx pc\n" \
" nop\n" \
".code 32\n" \
L(x) "_arm:\n"
/** Switch to Thumb mode. */
#define thumb(x,r) "\n" \
" add " #r ", pc, #1\n" \
" bx " #r "\n" \
".code 16\n" \
".thumb_func\n" \
L(x) "_thumb:"
Sadly, they simply don't work. I don't, currently, have a low-level
enough debugger to find out where it's going wrong.
Have you tried using the ARM simulator that comes with GDB ? It can be
run in stand-alone mode and since you have the source available you can
annotate it to show you exactly what is happening. (In fact if you
look in the file sim/arm/armemu.c you will find some code commented out
with #if 0...#endif that will make it report each instruction before it
is executed. I use this technique all the time).
While I'm on the topic, to which address does the following branch jump?
.code 16
0: nop
2: bx pc
4: nop
6: nop
.code 32
8: nop
It is UNPREDICTABLE. The ARM Architecture Reference Manual states that,
for the Thumb BX instruction:
"If Rm[1:0] == 0b10, the result is UNPREDICTABLE, as branches
to non word-aligned addresses are impossible in ARM state."
Cheers
Nick