Compile thumb1 only
Asked Answered
A

1

6

How do I tell gcc to compile into Thumb1-only instructions?

Everyone knows helloworld.c:

#include <stdio.h>  
main() {  
 printf("Hello world");  
}  

And this is my command line:

user@debian-armel:~$gcc -mcpu=cortex-m3 -mthumb helloworld.c && objdump -d a.out

And voilá: most instructions are 32bit wide, as opposed to the 16bit I expected.

So, what am I doing wrong?

Aragon answered 20/11, 2012 at 13:31 Comment(0)
B
4

Cortex-M3 supports Thumb-2 so the compiler is free to generate 32-bit versions. One of the following should achieve what you need:

-march=ARMv5 -mthumb
-march=ARMv4T -mthumb
-march=ARMv6-M
-mcpu=Cortex-M0
Braxy answered 20/11, 2012 at 13:56 Comment(5)
Nope, Cortex-M0 and Cortex-M0+ don't support Thumb-2 with exception of BL and a couple of system instructions (MSR, MRS, DSB, DMB, ISB). See ARMv6-M Architecture Reference Manual.Braxy
yeah I know it supports a subset, but it still supports it kind of, which means that gcc could still emit those Thumb-2 instructionsSlaughter
if you do not specify the -march and only -mthumb you will get thumb instructions without thumb2 extensions. github.com/dwelch67/thumbulator if need be specify ARMv5 or ARMv4T which do not have thumb2 extensionsDiarrhoea
gcc -mthumb -c myprog.c -o myprog.oDiarrhoea
Whether -mthumb will generate Thumb-1 or Thumb-2 insns depends on how the compiler is built, for example in my ARM compilers the default ISA is ARMv7-A, so -mthumb alone generates 32-bit thumb mode insns. On the other hand, -march=armv4t -mthumb will pretty reliably do the right thing.Breechloader

© 2022 - 2024 — McMap. All rights reserved.