thumb-2 and crt0.S init_hooks
Alexandre Pereira Nunes
alexandre.nunes@gmail.com
Fri Dec 19 20:48:00 GMT 2008
Hi,
It seems that there's a problem with the patch suggested on
http://sourceware.org/ml/newlib/2008/msg00500.html.
This sort of constructs:
+#if defined(__thumb__) || defined(__thumb2__)
+ blx r3
+#else
mov lr, pc
mov pc, r3
+#endif
Will probably fail on armv4t targets. The reason is that this
architecture lacks support for the blx instruction.
Also, on thumb1 targets, mov lr, pc will do right thing, because the
calling code is in arm mode, but the mov pc, r3 may fail to call a
thumb function.
The way I see it, this sequence will probably work fine:
+#if defined(__thumb2__)
+ blx r3
+#else
mov lr, pc
bx r3
+#endif
But there's still a catch on armv4t targets, if the code is compiled
with -mno-thumb-interwork (default for arm-elf targets, but not for
arm-*-eabi ones): some gcc versions tends to emit mov pc, lr or
similar sequences in order to return from thumb functions, and on this
case, a thunk has to be implemented to manually switch from thumb to
arm mode since the processor is unable to do this by itself.
I'm too lazy to write a patch right now, but I may work on that later.
More information about the Newlib
mailing list