[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MiNT] [PATCH] FreeMiNT SLB support for binutils >= 2.18-mint-20080209



Vincent Rivière wrote:
Is SLB support broken ? I suspect the answer is yes.

Years ago, Frank asked me to change the assembler jump at the start of
the MiNT header. Previous binutils versions clobbered d4, but starting
with binutils-2.18-mint-20080209 d0 is clobbered instead.

Yes, FreeMiNT SLB support was broken for libraries built with new binutils. Slbopen() returned ENOEXEC. Here is a patch to fix that.

Alan, please commit!

slb.patch
Fixed support for SLB libraries built with binutils-2.18-mint-20080209 and higher. Contributed by Vincent Riviere.

--
Vincent Rivière
diff -x CVS -aurN freemint.orig/sys/arch/user_things.S freemint/sys/arch/user_things.S
--- freemint.orig/sys/arch/user_things.S	2011-06-03 10:56:48.000000000 +0200
+++ freemint/sys/arch/user_things.S	2011-08-09 18:06:53.562500000 +0200
@@ -224,21 +224,42 @@
 
 	move.l	4(sp),a0		// basepage pointer
 	lea	256(a0),a0		// begin of the TEXT segment
+
+	// Test for original binutils
 #ifdef __mcoldfire__
 	move.l	#0x283a001a,d0
 	cmp.l	(a0),d0
 #else
 	cmp.l	#0x283a001a,(a0)
 #endif
-	bne.s	oldfmt
+	bne.s	binu2
 #ifdef __mcoldfire__
 	move.l	#0x4efb48fa,d0
 	cmp.l	4(a0),d0
 #else
 	cmp.l	#0x4efb48fa,4(a0)
 #endif
+	bne.s	binu2
+	bra.s	newfmt
+
+	// Test for binutils >= 2.18-mint-20080209
+binu2:
+#ifdef __mcoldfire__
+	move.l	#0x203a001a,d0
+	cmp.l	(a0),d0
+#else
+	cmp.l	#0x203a001a,(a0)
+#endif
+	bne.s	oldfmt
+#ifdef __mcoldfire__
+	move.l	#0x4efb08fa,d0
+	cmp.l	4(a0),d0
+#else
+	cmp.l	#0x4efb08fa,4(a0)
+#endif
 	bne.s	oldfmt
 
+newfmt:
 	lea	228.w(a0),a0		// the header is a bit bigger (new format)
 
 oldfmt:	move.l	a0,-(sp)		// 4 bytes go to the stack
diff -x CVS -aurN freemint.orig/sys/k_exec.c freemint/sys/k_exec.c
--- freemint.orig/sys/k_exec.c	2011-06-16 11:25:11.000000000 +0200
+++ freemint/sys/k_exec.c	2011-08-09 17:55:41.562500000 +0200
@@ -694,7 +694,12 @@
 		long *exec_longs = (long *)b->p_tbase;
 
 		/* Test for new program format */
-		if (exec_longs[0] == 0x283a001aL && exec_longs[1] == 0x4efb48faL)
+		if (
+		     /* Original binutils */
+		     (exec_longs[0] == 0x283a001aL && exec_longs[1] == 0x4efb48faL)
+		     /* binutils >= 2.18-mint-20080209 */
+		     || (exec_longs[0] == 0x203a001aL && exec_longs[1] == 0x4efb08faL)
+		   )
 			exec_longs += (228 / sizeof(long));
 
 		if (exec_longs[0] == SLB_HEADER_MAGIC)
diff -x CVS -aurN freemint.orig/sys/slb.c freemint/sys/slb.c
--- freemint.orig/sys/slb.c	2011-05-01 17:05:07.000000000 +0200
+++ freemint/sys/slb.c	2011-08-09 17:44:58.671875000 +0200
@@ -229,7 +229,12 @@
 
 	/* Test for the new program format */
 	exec_longs = (long *) b->p_tbase;
-	if (exec_longs[0] == 0x283a001aL && exec_longs[1] == 0x4efb48faL)
+	if (
+	     /* Original binutils */
+	     (exec_longs[0] == 0x283a001aL && exec_longs[1] == 0x4efb48faL)
+	     /* binutils >= 2.18-mint-20080209 */
+	     || (exec_longs[0] == 0x203a001aL && exec_longs[1] == 0x4efb08faL)
+	   )
 	{
 		(*sl)->slb_head = (SLB_HEAD *)(b->p_tbase + 228);
 	}