Re: [arm-gnu] Thumb instruction set generation...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [arm-gnu] Thumb instruction set generation...



On Thursday 09 September 2004 12:50, Patrick Bellasi wrote:
> Hi,
>  I'm compiling a toy .c source with:
> arm-none-elf-gcc (GCC) 3.4.0 20040409 (CodeSourcery ARM Q1A 2004)
> using those switch:
>  -mcpu=arm7tdmi -mthumb-interwork
>
> In the genarated code I expect to get sometimes a switching between ARM and
> Thumb instruction set, i.e following a BX instr.
>
> It seem to me that the generated code isn't conform to the THUMB
> instruction set specifications...

No, you misunderstand the purpose of that  option and the BX instruction.

The BX instruction only switches to thumb state if the bottom bit of the 
address is set. In the example you give the "bx lr" is the instruction used 
to return from the "main" procedure. if "main" was called from arm mode lr 
will have the bottom bit clear and this is equivalent to mov pc, lr. If 
"main" was called from thumb mode lr will have the bottom bit set, and the bx 
instruction will jump to the address and switch to thumb mode.

-mthumb-interwork Tells gcc to generate code that is thumb interworking safe. 
Ie. you can mix arm and thumb code and everything should work transparently. 
On armv4t chips this means use "bx lr" instead of "mov pc, lr" to return from 
procedures, and a few other details.

To generate thumb code you need to pass -mthumb to the compiler.

Paul