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.

Coding > ARM and thumb rules

#101770 - gmiller - Thu Sep 07, 2006 11:57 pm

I was under the impression that interrupts must be in ARM mode and can be loaded in IWRAM or not (as long as the speed is OK). I have been trying to get my compile and link switches to work the way I though it should be. Using the base_rules and gba_rules files as part of devkitPRO to help make my makefile simpler I have run into an issue with -marm -mthumb-interwork". So I have a question:

Should I use -marm -mthumb-interwork" for my interrupt?
Should I not use -mthumb -mthumb-interwork for my main?

Based on what I am seeing their is a basic missunderstand of how these command line swiches work on my part. would someone care to enlighten me?

#101772 - tepples - Fri Sep 08, 2006 12:07 am

gmiller wrote:
Should I use -marm -mthumb-interwork" for my interrupt?
Should I not use -mthumb -mthumb-interwork for my main?

Your ISR's entry point MUST be -marm -mthumb-interwork, and most everything else SHOULD be -mthumb -mthumb-interwork.

Quote:
Based on what I am seeing their is a basic missunderstand of how these command line swiches work on my part. would someone care to enlighten me?

You need -mthumb-interwork on everything so that calls between source code files can use the interworking protocol. You need -marm or -mthumb to force an instruction set in a given source code file.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#101792 - gmiller - Fri Sep 08, 2006 2:04 am

That is what I though it should be so I had a separate souce file with my interrupt handler with -marm -mthumb-interword and the other files with -mthumb -mthumb-interwork. When I did that the link step would fail if I did not specify -marm -mthumb-interwork on the link (using gcc) stage. But the code would fail. If I use -marm -mthunb-interwork on all it works. This behavior does not seem to follow what I though would happen.

Last edited by gmiller on Fri Sep 08, 2006 5:21 pm; edited 1 time in total

#101795 - tepples - Fri Sep 08, 2006 2:11 am

You need to specify -mthumb-interwork and either -mthumb or -marm when linking so that GCC knows what libraries to bring in.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#101882 - gmiller - Fri Sep 08, 2006 5:20 pm

My link stage was -mthumb -mthumb-interwork and the code fails when it runs. Can the 'arm' interrupt handler call a thumb routine? I though it could so I never worried about it. Also do I need to do something in the prototypes to indicate that a piece of code is arm while compiling thumb and vice-versa. The default according to the man page is thumb mode but I am beginning to wonder.

#101888 - gmiller - Fri Sep 08, 2006 6:18 pm

I have solved the problem but I am not sure why it was a problem yet. If I used the base rules and had my interrupt handler as isr.iwram.c the code will complain about references to some routines. I created a rule for just forcing the code to be arm code and all seems to work. The link rules (that I don't understand yet) must be doing something to the code when it is .iwram.o that is messing up somehow. I will investigate further to see if I can understand the issue I am creating.

#101939 - wintermute - Sat Sep 09, 2006 2:10 am

If you're calling functions in ROM from your interrupt code then you'll need to build the iwram files with -mlong-calls as well. Branches from iwram to rom and vice versa are out of range.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#101947 - gmiller - Sat Sep 09, 2006 3:55 am

Ok ... I see how things were messed up ....

#101949 - gmiller - Sat Sep 09, 2006 4:27 am

Is there a document somewhere that points out the mixtures of these options and suggested use. I understood the arm / thumb modifiers because of the instrution sets and the thumb-interwork because the CPU state has to switch. I knew about the arm mode for interrupts but the long call thing (even though I understand it now) was not something I had though about. I am just trying to make sure I don't shoot myself in the foot too many times because I am running out of toes.