Switching to and from ARM/Thumb

Nick Clifton nickc@redhat.com
Tue Jan 18 09:55:00 GMT 2005


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




More information about the Binutils mailing list