Switch between ARM instruction set <-> Thumb instruction set
Sep 04, 2003 6 Replies
M
Martin Maurer
Hello,
can someone explain me how to switch between ARM instruction set and Thumb insturction set. Can i do this on the fly, e.g. subroutine in thumb else in ARM ? Or is there a external pin used for this ? Or is there a processor version for each mode ?
Greetings,
Martin
Didn't find your answer? Ask the community — no account required.
M
Mark A. Odell
"Martin Maurer" wrote in news:bj83uc$asn$05$ snipped-for-privacy@news.t-online.com:
Look up the blx instruction.
- Mark ->
--
T
tim
You need to compile/assemble everything with the 'interwork' switch. The first instruction after an interrupt must be in ARM, few people would ever get any thumb code to work if it weren't simple
It jumps to a 'veneer' which does the 'conversion' for you. some debuggers hide this jump and some don't.
There's a processor mode (I think), is this what you mean?
Tim
V
Vadim Borshchev
The usual way to enter Thumb mode is 'bx rN' command with LSB of rN set to
There is also 'blx' command.
Yes. It is called interworking and is used widely.
No. Some ARM cores have Thumb mode in addition to ARM mode. Others do not.
Visit
formatting link
, buy "ARM System Architecture" by Steve Furber (ISBN 0-201-40352-8), subscribe to comp.sys.arm newsgroup, search for the document "ARM Architecture Reference Manual" (ARM DDI0100E). Have I missed something? :)
Vadim
T
Tauno Voipio
The key is the bx instruction. If the least significant bit of the target address is an one, the processor will switch to Thumb mode. Similarly, if the bit is a zero, the processor will switch to ARM mode.
The address saved in lr by the Thumb subroutine call (bl) has the least significant bit on, so a subroutine return with a bx returns to the proper mode.
In newer processors, there is also the blx instruction, which is a combination of the bl and bx instructions: it saves the return address into lr and then works just as the bx instruction.
If the processor does not support the blx instruction, it can be functionally replaced by a subroutine consisting of the bx instruction only: the subroutine call saves the return address and the bx instruction dispatches to the proper address and mode.
The ARM family compilers support an ARM/Thumb interworking mode which makes the inter-module transfers with bx instructions, so that a mode change is done when needed. The interworking mode has some inherent overhead, so it's not always recommended. With care it's possible to write code with both ARM and Thumb modes without selecting interworking in the compiler command.
The GNU tool set supports an assembler directive (thumb_proc) to tell the linker that a symbol is in Thumb code, so the linker is able to add the Thumb bit at link time.
HTH
Tauno Voipio tauno voipio @ iki fi
S
Schwob
// The cores that use a "T" such as ARM7 "T"DMI support the Thumb mode. //
J
Jonathan Larmour
Tauno Voipio enlightened us with:
.thumb_func not .thumb_proc. There is also .thumb (aka ".code 16")
Obviously you can just compile C code with the compiler option -mthumb and, since GNU also supports interworking, optionally -mthumb-interwork.
Jifl
--["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine
Join the Discussion
Have something to add? Share your thoughts — no account required.
Didn't find your answer?
Ask the community — no account required
Report Content
You are reporting this content to the moderators. They will look at it
ASAP.