This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
thumb-2 and crt0.S init_hooks
- From: Bill Tompkins <bill+newlib at key-square dot com>
- To: nickc at redhat dot com
- Cc: newlib at sources dot redhat dot com
- Date: Wed, 1 Oct 2008 14:27:32 +0100
- Subject: thumb-2 and crt0.S init_hooks
Hi Nick,
I get a fault on a Cortex-M3 when I implement either a
hardware_init_hook() or software_init_hook() function. The problem,
as I understand it, is that the calls in crt0.S are of the form
ldr r3, .Lhwinit
...
mov lr, pc
mov pc, r3
The LR then contains a word-aligned address, rather than having bit 0
set to indicate thumb mode.
My hardware_init_hook() gets compiled (by GCC 3.4.2) to something
ending with:
bx lr
Since the LR doesn't have the 0 bit set, that implies that it should
transition out of thumb mode, and on the M3 that faults.
I haven't tested the following on anything other than the M3, but it
seems like it should do the trick:
--- libgloss/arm/crt0.S 25 Apr 2008 09:02:40 -0000 1.7
+++ libgloss/arm/crt0.S 1 Oct 2008 12:54:56 -0000
@@ -167,14 +167,23 @@
ldr r3, .Lhwinit
cmp r3, #0
beq .LC24
+#if defined(__thumb__) || defined(__thumb2__)
+ blx r3
+#else
mov lr, pc
mov pc, r3
+#endif
.LC24:
ldr r3, .Lswinit
cmp r3, #0
beq .LC25
+#if defined(__thumb__) || defined(__thumb2__)
+ blx r3
+#else
mov lr, pc
mov pc, r3
+#endif
+
.LC25:
mov r0, #0 /* no arguments */
mov r1, #0 /* no argv either */
-Bill