EmbDev.net

Forum: ARM programming with GCC/GNU tools gcc bug with -mthumb-interwork


von Alexey (Guest)


Rate this post
useful
not useful
Hi,

I am trying to write mixed ARM/Thumb code and compile it with WinARM.
Unfortunately if I use -mthumb-interwork option, my program don't work,
because gcc generates wrong code for some interrupt functions
(_attribute_ ((interrupt ("IRQ")))).

GCC inserts 'sub' instruction in enter/exit code twice:

sub     lr, lr, #4
stmfd   sp!, {r.., lr}
.
.
.
ldmfd   sp!, {r.., lr}
subs    pc, lr, #4

This bug is not new and it is not fixed (bug #16634 and #25428 on gcc
bugzilla).
But if I compile ARM code without -mthumb-interwork option my interrupt
function work correctly. I changed my make file for compile ARM code
without -mthumb-interwork, and compile Thumb code and linking all with
-mthumb-interwork option.
I excluded $(THUMB_IW) option from ALL_CFLAGS and ALL_ASFLAGS, and
inserted it into thumb compile command (...$(THUMB) $(THUMB_IW)...). So,
my programm is working.

For Martin Thomas:
May be you will change standard WinARM make file, and other people will
not have this problem?

von Martin Thomas (Guest)


Rate this post
useful
not useful
Alexey wrote:
> ...
> This bug is not new and it is not fixed (bug #16634 and #25428 on gcc
> bugzilla).
> But if I compile ARM code without -mthumb-interwork option my interrupt
> function work correctly. I changed my make file for compile ARM code
> without -mthumb-interwork, and compile Thumb code and linking all with
> -mthumb-interwork option.
> I excluded $(THUMB_IW) option from ALL_CFLAGS and ALL_ASFLAGS, and
> inserted it into thumb compile command (...$(THUMB) $(THUMB_IW)...). So,
> my programm is working.
>
> For Martin Thomas:
> May be you will change standard WinARM make file, and other people will
> not have this problem?

Thanks for your report. I know that there are problems with the binary
code created for ISRs with the interwork-option. You have already found
the bugzilla entries. This is why various examples include
entry/exit-macros or assembler-wrappers for interrupt-service-routines.
The settings in my current makefile-template have been created based on
the settings in the FreeRTOS-examples and the LPC2000-uart example from
Bill Knight/R O Software.

Did I get this correctly from your description?:
- code for ARM gets compiled without -mthumb-interwork (and of cause
without -mthumb)
- code for thumb gets compiled with -mthumb and -mthumb-interwork
- linking is done with -mthumb and -mthumb-interwork

Of cause I can change the makefile-template according to your
suggestions but I'd like to avoid any new problems/side-effects which
may be caused by changes. So please test with your makefile-settings:
- if a function in ARM-code (not an ISR) can be called from thumb-code
(which means a correct interface-code gets created by the compiler
without -mthumb-interwork given)
- if functions in thumb-code can be called from ARM-code (also to check
if the internal interface-code gets created)

Martin Thomas

von Alexey (Guest)


Rate this post
useful
not useful
Martin Thomas wrote:
>
> Of cause I can change the makefile-template according to your
> suggestions but I'd like to avoid any new problems/side-effects which
> may be caused by changes. So please test with your makefile-settings:
> - if a function in ARM-code (not an ISR) can be called from thumb-code
> (which means a correct interface-code gets created by the compiler
> without -mthumb-interwork given)
> - if functions in thumb-code can be called from ARM-code (also to check
> if the internal interface-code gets created)
>

Thanks for answer.

You understand clearly:
 - ARM-code compile without -mthumb and -mthumb-interwork
 - Thumb-code compile with -mthumb and -mthumb-interwork
 - Linking with -mthumb and -mthumb-interwork

I tested my make file and got result:
 - if I call thumb-function from ARM-code - it works
 - if I call arm-function from thumb-code - it doesn't work :-(

I was not right.
But if interrupt functions ARM-code gets picked out to single file and
compiled without -mthumb and -mthumb-interwork option, programm will be
working (of course other ARM-code gets compiled with -mthumb-interwork).

Of course it wouldn't be decision of this problem, but it would be
helpful to anybody.

Best regards, Alexey

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.