I've been going through ARM ISA related documentation since a while and so far I believe that I've got a good understanding for the basics of ARM/Thumb interworking. I'll quickly summarize that in the following:
- Instructions can be either 4 byte aligned (ARM) or 2 byte aligned (Thumb).
- Thumb and ARM instructions reside in separate regions i.e. they are not intermixed without explicit processor state change.
- State change can happen upon executing either of
bx
,blx
,ldm
,ldr
. Choosing between ARM or Thumb depends on the value of the least significant bit in the address which can be 0 or 1 respectively. - The current state of the processor can be either ARM or thumb. That depends on the state of bit 5 of
CPSR
.
Rules for state change can be summarized in the following figure taken from this paper:
However, Thumb-2 instructions have confused me a bit. For instance, let's inspect the encoding of instruction ADC
which can be found in section A8.8.2
of the ARMv7-A/R reference manual. Basically, the same instruction has 3 distinct encodings 16 bit (Thumb), 32 bit (Thumb2), and 32 bit (ARM).
Here are my questions:
Does the 32-bit Thumb-2 instructions execute in ARM or Thumb mode of the processor? (I'm assuming its the latter but not sure)
Some resources mention that ARM/Thumb instructions can be "freely" intermixed in thumb-2. Does that mean explicit state change using
bx
,blx
,ldm
orldr
doesn't need to happen?
Final note, this is the closest question to mine, however, I'm focusing on interworking.