gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Compiling in ARM vs Thumb

#80482 - Obelix - Sat Apr 22, 2006 6:02 pm

Hi all !

I'm just using the latest version of devkitarm (R18 with GCC 4.1.0) to compile a small code for GBA, and I have some problems. Maybe someone could help me.

1 - When I use the -S option to output the assembly code generated by gcc, the extension is .o instead of .s. This is not a big problem, but do you know why ?

2 - More important : I want to compile C source code in ARM mode.
This was working fine in my previous projet with devkitadv. But with devkitarm r18, the assembly code generated is still thumb code.
I've tried many different syntax, using "__attribute__ ((section (".iwram"), long_call))", calling my source file "xxx.iwram.c", etc., but nothing work.

With "__attribute__ ((section (".iwram"), long_call))",
- the assembly code generated contains the line :
.section .iwram,"ax",%progbits
- the map file show the code is in iwram at 0x03000000 adress
but the code use the Thumb instruction set !!!

Do you know if there is another configuration to specifiy ?

Thanks in advance for your help.
--
Philippe
_________________
--
Philippe aka Obelix

#80484 - poslundc - Sat Apr 22, 2006 6:51 pm

Putting code in IWRAM does not make it ARM code instead of Thumb code. The type of code and the section of memory it resides in are two distinct and exclusive properties of the code.

I need to preface my responses with saying I've not worked with DevkitARM so they are just general info... if they don't work, someone with more precise knowledge will have to fill you in.

1. This is probably if you are using the -o flag to specify the output file name, and then giving that output file name a ".o" extension. At least, that would be my best guess.

2. You should be able to generate ARM code instead of Thumb code for the files you want to be ARM code by removing the "-mthumb" flag from the GCC command line.

Dan.

#80485 - wintermute - Sat Apr 22, 2006 6:53 pm

Obelix wrote:
Hi all !

1 - When I use the -S option to output the assembly code generated by gcc, the extension is .o instead of .s. This is not a big problem, but do you know why ?


It's because the output file is specified using -o. The -S switch is intended for single files afaik. If you want to see the assembly for all of your files you can use -save-temps in CFLAGS instead. With the standard makefiles all output files will be found in the $BUILD folder.

Quote:

2 - More important : I want to compile C source code in ARM mode.
This was working fine in my previous projet with devkitadv. But with devkitarm r18, the assembly code generated is still thumb code.
I've tried many different syntax, using "__attribute__ ((section (".iwram"), long_call))", calling my source file "xxx.iwram.c", etc., but nothing work.

With "__attribute__ ((section (".iwram"), long_call))",
- the assembly code generated contains the line :
.section .iwram,"ax",%progbits
- the map file show the code is in iwram at 0x03000000 adress
but the code use the Thumb instruction set !!!

Do you know if there is another configuration to specifiy ?



You need to specify -marm to use the arm instruction set. Either add a specific rule for the file you wish to compile as arm in your main makefile

Code:

#---------------------------------------------------------------------------------
<filename>.o: <filename>.cpp
   @echo $(notdir $<)
   $(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -marm -mlong-calls -c $< -o $@


or, what I should probably do, is add these lines to base_rules - found in the devkitARM folder

Code:

#---------------------------------------------------------------------------------
%.iwram.o: %.iwram.cpp
   @echo $(notdir $<)
   $(CXX) -MMD -MP -MF $(DEPSDIR)/$*.d $(CXXFLAGS) -marm -mlong-calls -c $< -o $@
#---------------------------------------------------------------------------------
%.iwram.o: %.iwram.c
   @echo $(notdir $<)
   $(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) -marm -c $< -o $@


adding -mlong-calls allows for the iwram routines to call functions in rom - you'll get relocation errors on linking if this is necessary.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog


Last edited by wintermute on Sun Apr 23, 2006 6:13 pm; edited 2 times in total

#80507 - Obelix - Sun Apr 23, 2006 1:12 am

Dave & Dan,

Many thanks for your ultra-quick answers !!!

All is fine now.
--
Philippe
_________________
--
Philippe aka Obelix