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

Re: [MiNT] [PATCH] FreeMiNT for ColdFire



Here is the ColdFire patch for inet4.xdd.

This one was tricky, because the checksums are calculated on 16-bit while the ColdFire can only manipulate 32-bit values.

I have successfully tested this ColdFire inet4.xdd on the FireBee thank's to m0n0's FEC driver :-)

Alan, please commit!

After that, one can build the ColdFire inet4.xdd with:
export M68K_ATARI_MINT_CROSS=yes
cd ~/sources/freemint.work/sys/sockets
(cd inet4 && make libinet4.a CPU=v4e) && make inet4.xdd CPU=v4e && m68k-atari-mint-strip inet4.xdd

--
Vincent Rivière
diff -x CVS -aurN freemint.orig/sys/sockets/inet4/ifload.c freemint.work/sys/sockets/inet4/ifload.c
--- freemint.orig/sys/sockets/inet4/ifload.c	2010-01-04 23:22:12.000000000 +0100
+++ freemint.work/sys/sockets/inet4/ifload.c	2011-06-16 23:25:22.328125000 +0200
@@ -69,13 +69,13 @@
 
 	__asm__ volatile
 	(
-		"moveml	d3-d7/a3-a6,sp@-;"
-		"movl	%3,sp@-;"
-		"movl	%2,sp@-;"
-		"movl	%1,a0;"
-		"jsr	a0@;"
-		"addqw	#8,sp;"
-		"moveml	sp@+,d3-d7/a3-a6;"
+		PUSH_SP("d3-d7/a3-a6", 36)
+		"movl	%3,sp@-\n\t"
+		"movl	%2,sp@-\n\t"
+		"movl	%1,a0\n\t"
+		"jsr	a0@\n\t"
+		"addql	#8,sp\n\t"
+		POP_SP("d3-d7/a3-a6", 36)
 		: "=r"(ret)				/* outputs */
 		: "g"(initfunc), "g"(k), "g"(n)		/* inputs  */
 		: __CLOBBER_RETURN("d0")
diff -x CVS -aurN freemint.orig/sys/sockets/inet4/inetutil.c freemint.work/sys/sockets/inet4/inetutil.c
--- freemint.orig/sys/sockets/inet4/inetutil.c	2001-05-26 02:30:58.000000000 +0200
+++ freemint.work/sys/sockets/inet4/inetutil.c	2011-06-21 20:54:40.953125000 +0200
@@ -278,26 +278,63 @@
 	__asm__
 	(
 		"clrl	d0		\n\t"
+#ifdef __mcoldfire__
+		"mvzw	%2, d1		\n\t"
+		"lsrl	#1, d1		\n\t"	/* # of longs in buf */
+#else
 		"movew	%2, d1		\n\t"
 		"lsrw	#1, d1		\n\t"	/* # of longs in buf */
+#endif
 		"bcc	l1		\n\t"	/* multiple of 4 ? */
+#ifdef __mcoldfire__
+		"mvz.w	%1@+, d2	\n\t"
+		"addl	d2, %0		\n\t"	/* no, add in extra word */
+		"addxl	d0, %0		\n"
+#else
 		"addw	%1@+, %0	\n\t"	/* no, add in extra word */
 		"addxw	d0, %0		\n"
+#endif
 		"l1:			\n\t"
+#ifdef __mcoldfire__
+		"subql	#1, d1		\n\t"	/* decrement for dbeq */
+#else
 		"subqw	#1, d1		\n\t"	/* decrement for dbeq */
+#endif
 		"bmi	l3		\n"
 		"l2:			\n\t"
 		"addl	%1@+, %0	\n\t"
 		"addxl	d0, %0		\n\t"
+#ifdef __mcoldfire__
+		"subql	#1, d1		\n\t"
+		"bpls	l2		\n"	/* loop over all longs */
+#else
 		"dbra	d1, l2		\n"	/* loop over all longs */
+#endif
 		"l3:			\n\t"
+#ifdef __mcoldfire__
+		"swap	%0		\n\t"	/* convert to short */
+		"mvzw	%0, d1		\n\t"
+		"clr.w	%0		\n\t"
+		"swap	%0		\n\t"
+		"addl	d1, %0		\n\t"
+		"swap	%0		\n\t"
+		"mvzw	%0, d1		\n\t"
+		"clr.w	%0		\n\t"
+		"swap	%0		\n\t"
+		"addl	d1, %0		\n\t"
+#else
 		"movel	%0, d1		\n\t"	/* convert to short */
 		"swap	d1		\n\t"
 		"addw	d1, %0		\n\t"
 		"addxw	d0, %0		\n\t"
+#endif
 		: "=d"(sum), "=a"(buf)
 		: "g"(nwords), "1"(buf), "0"(sum)
+#ifdef __mcoldfire__
+		: "d0", "d1", "d2"
+#else
 		: "d0", "d1"
+#endif
 	);
 	
 	return (short)(~sum & 0xffff);
diff -x CVS -aurN freemint.orig/sys/sockets/inet4/tcputil.c freemint.work/sys/sockets/inet4/tcputil.c
--- freemint.orig/sys/sockets/inet4/tcputil.c	2011-07-30 21:21:00.000000000 +0200
+++ freemint.work/sys/sockets/inet4/tcputil.c	2011-11-25 23:38:42.250000000 +0100
@@ -411,16 +411,26 @@
 	 */
 	__asm__
 	(
-		"clrw	d0		\n\t"
+		"moveq	#0, d0		\n\t"
 		"movel	%3, %0		\n\t"
 		"addl	%1, %0		\n\t"
 		"addxl	%2, %0		\n\t"
+#ifdef __mcoldfire__
+		"mvz.w	%4, d1		\n\t"   /* X not affected */
+		"addxl	d1, %0		\n\t"
+		"addxl	d0, %0		\n\t"
+#else
 		"addxw	%4, %0		\n\t"
 		"addxw	d0, %0		\n\t"
+#endif
 		: "=d"(sum)
 		: "g"(srcadr), "d"(dstadr), "i"(IPPROTO_TCP),
 		  "d"(len), "0"(sum)
+#ifdef __mcoldfire__
+		: "d0", "d1"
+#else
 		: "d0"
+#endif
 	);
 	
 	/*
@@ -429,29 +439,64 @@
 	__asm__
 	(
 		"clrl	d0		\n\t"
+#ifdef __mcoldfire__
+		"mvzw	%2, d1		\n\t"
+		"lsrl	#4, d1		\n\t"
+#else
 		"movew	%2, d1		\n\t"
 		"lsrw	#4, d1		\n\t"
+#endif
 		"beq	4f		\n\t"
+#ifdef __mcoldfire__
+		"subql	#1, d1		\n"	/* clears X bit */
+#else
 		"subqw	#1, d1		\n"	/* clears X bit */
+#endif
 		"1:			\n\t"
+#ifdef __mcoldfire__
+		"moveml	%4@, d0/d2-d4	\n\t"	/* 16 byte loop */
+		"lea	%4@(16), %4	\n\t"
+#else
 		"moveml	%4@+, d0/d2-d4	\n\t"	/* 16 byte loop */
+#endif
 		"addxl	d0, %0		\n\t"	/* ~5 clock ticks per byte */
 		"addxl	d2, %0		\n\t"
 		"addxl	d3, %0		\n\t"
 		"addxl	d4, %0		\n\t"
+#ifdef __mcoldfire__
+		"moveq	#0, d0		\n\t"   /* X not affected */
+		"addxl	d0, %0		\n\t"
+		"subql	#1, d1		\n\t"   /* X cloberred */
+		"bpls	1b		\n\t"   /* X not affected */
+#else
 		"dbra	d1, 1b		\n\t"
 		"clrl	d0		\n\t"
 		"addxl	d0, %0		\n"
+#endif
 		"4:			\n\t"
 		"movew	%2, d1		\n\t"
+#ifdef __mcoldfire__
+		"andil	#0xf, d1	\n\t"
+		"lsrl	#2, d1		\n\t"
+#else
 		"andiw	#0xf, d1	\n\t"
 		"lsrw	#2, d1		\n\t"
+#endif
 		"beq	2f		\n\t"
+#ifdef __mcoldfire__
+		"subql	#1, d1		\n"
+#else
 		"subqw	#1, d1		\n"
+#endif
 		"3:			\n\t"
 		"addl	%4@+, %0	\n\t"	/* 4 byte loop */
 		"addxl	d0, %0		\n\t"	/* ~10 clock ticks per byte */
+#ifdef __mcoldfire__
+		"subql	#1, d1		\n\t"
+		"bpls	3b		\n\t"
+#else
 		"dbra	d1, 3b		\n"
+#endif
 		"2:			\n\t"
 		: "=d"(sum), "=a"(dgram)
 		: "g"(len), "0"(sum), "1"(dgram)
@@ -467,23 +512,53 @@
 		"clrl	d0		\n\t"
 		"btst	#1, %2		\n\t"
 		"beq	5f		\n\t"
+#ifdef __mcoldfire__
+		"mvzw	%4@+, d2	\n\t"
+		"addl	d2, %0		\n\t"	/* no, add in extra word */
+		"addxl	d0, %0		\n"
+#else
 		"addw	%4@+, %0	\n\t"	/* extra word */
 		"addxw	d0, %0		\n"
+#endif
 		"5:			\n\t"
 		"btst	#0, %2		\n\t"
 		"beq	6f		\n\t"
+#ifdef __mcoldfire__
+		"mvzb	%4@+, d1	\n\t"	/* extra byte */
+		"lsll	#8, d1		\n\t"
+		"addl	d1, %0		\n\t"
+		"addxl	d0, %0		\n"
+#else
 		"moveb	%4@+, d1	\n\t"	/* extra byte */
 		"lslw	#8, d1		\n\t"
 		"addw	d1, %0		\n\t"
 		"addxw	d0, %0		\n"
+#endif
 		"6:			\n\t"
+#ifdef __mcoldfire__
+		"swap	%0		\n\t"	/* convert to short */
+		"mvzw	%0, d1		\n\t"
+		"clr.w	%0		\n\t"
+		"swap	%0		\n\t"
+		"addl	d1, %0		\n\t"
+		"swap	%0		\n\t"
+		"mvzw	%0, d1		\n\t"
+		"clr.w	%0		\n\t"
+		"swap	%0		\n\t"
+		"addl	d1, %0		\n\t"
+#else
 		"movel	%0, d1		\n\t"	/* convert to short */
 		"swap	d1		\n\t"
 		"addw	d1, %0		\n\t"
 		"addxw	d0, %0		\n\t"
+#endif
 		: "=d"(sum), "=a"(dgram)
 		: "d"(len), "0"(sum), "1"(dgram)
+#ifdef __mcoldfire__
+		: "d0", "d1", "d2"
+#else
 		: "d0", "d1"
+#endif
 	);
 	
 	return (short)(~sum & 0xffff);
diff -x CVS -aurN freemint.orig/sys/sockets/inet4/udp.c freemint.work/sys/sockets/inet4/udp.c
--- freemint.orig/sys/sockets/inet4/udp.c	2008-11-23 22:57:48.000000000 +0100
+++ freemint.work/sys/sockets/inet4/udp.c	2011-11-25 22:18:46.437500000 +0100
@@ -495,16 +495,26 @@
 	 */
 	__asm__
 	(
-		"clrw	d0		\n\t"
+		"moveq	#0, d0		\n\t"
 		"movel	%3, %0		\n\t"
 		"addl	%1, %0		\n\t"
 		"addxl	%2, %0		\n\t"
+#ifdef __mcoldfire__
+		"mvzw	%4, d1		\n\t"
+		"addxl	d1, %0		\n\t"
+		"addxl	d0, %0		\n\t"
+#else
 		"addxw	%4, %0		\n\t"
 		"addxw	d0, %0		\n\t"
+#endif
 		: "=d"(sum)
 		: "g"(srcadr), "d"(dstadr), "i"(IPPROTO_UDP),
 		  "d"(len), "0"(sum)
+#ifdef __mcoldfire__
+		: "d0", "d1"
+#else
 		: "d0"
+#endif
 	);
 	
 	/*
@@ -513,29 +523,64 @@
 	__asm__
 	(
 		"clrl	d0		\n\t"
+#ifdef __mcoldfire__
+		"mvzw	%2, d1		\n\t"
+		"lsrl	#4, d1		\n\t"
+#else
 		"movew	%2, d1		\n\t"
 		"lsrw	#4, d1		\n\t"
+#endif
 		"beq	4f		\n\t"
+#ifdef __mcoldfire__
+		"subql	#1, d1		\n"	/* clears X bit */
+#else
 		"subqw	#1, d1		\n"	/* clears X bit */
+#endif
 		"1:			\n\t"
+#ifdef __mcoldfire__
+		"moveml	%4@, d0/d2-d4	\n\t"	/* 16 byte loop */
+		"lea	%4@(16), %4	\n\t"
+#else
 		"moveml	%4@+, d0/d2-d4	\n\t"	/* 16 byte loop */
+#endif
 		"addxl	d0, %0		\n\t"	/* ~5 clock ticks per byte */
 		"addxl	d2, %0		\n\t"
 		"addxl	d3, %0		\n\t"
 		"addxl	d4, %0		\n\t"
+#ifdef __mcoldfire__
+		"moveq	#0, d0		\n\t"   /* X not affected */
+		"addxl	d0, %0		\n\t"
+		"subql	#1, d1		\n\t"   /* X cloberred */
+		"bpls	1b		\n\t"   /* X not affected */
+#else
 		"dbra	d1, 1b		\n\t"
 		"clrl	d0		\n\t"
 		"addxl	d0, %0		\n"
+#endif
 		"4:			\n\t"
 		"movew	%2, d1		\n\t"
+#ifdef __mcoldfire__
+		"andil	#0xf, d1	\n\t"
+		"lsrl	#2, d1		\n\t"
+#else
 		"andiw	#0xf, d1	\n\t"
 		"lsrw	#2, d1		\n\t"
+#endif
 		"beq	2f		\n\t"
+#ifdef __mcoldfire__
+		"subql	#1, d1		\n"
+#else
 		"subqw	#1, d1		\n"
+#endif
 		"3:			\n\t"
 		"addl	%4@+, %0	\n\t"	/* 4 byte loop */
 		"addxl	d0, %0		\n\t"	/* ~10 clock ticks per byte */
+#ifdef __mcoldfire__
+		"subql	#1, d1		\n\t"
+		"bpls	3b		\n\t"
+#else
 		"dbra	d1, 3b		\n"
+#endif
 		"2:			\n\t"
 		: "=d"(sum), "=a"(dgram)
 		: "g"(len), "0"(sum), "1"(dgram)
@@ -551,23 +596,53 @@
 		"clrl	d0		\n\t"
 		"btst	#1, %2		\n\t"
 		"beq	5f		\n\t"
+#ifdef __mcoldfire__
+		"mvz.w	%4@+, d2	\n\t"
+		"addl	d2, %0		\n\t"	/* no, add in extra word */
+		"addxl	d0, %0		\n"
+#else
 		"addw	%4@+, %0	\n\t"	/* extra word */
 		"addxw	d0, %0		\n"
+#endif
 		"5:			\n\t"
 		"btst	#0, %2		\n\t"
 		"beq	6f		\n\t"
+#ifdef __mcoldfire__
+		"mvzb	%4@+, d1	\n\t"	/* extra byte */
+		"lsll	#8, d1		\n\t"
+		"addl	d1, %0		\n\t"
+		"addxl	d0, %0		\n"
+#else
 		"moveb	%4@+, d1	\n\t"	/* extra byte */
 		"lslw	#8, d1		\n\t"
 		"addw	d1, %0		\n\t"
 		"addxw	d0, %0		\n"
+#endif
 		"6:			\n\t"
+#ifdef __mcoldfire__
+		"swap	%0		\n\t"	/* convert to short */
+		"mvzw	%0, d1		\n\t"
+		"clr.w	%0		\n\t"
+		"swap	%0		\n\t"
+		"addl	d1, %0		\n\t"
+		"swap	%0		\n\t"
+		"mvzw	%0, d1		\n\t"
+		"clr.w	%0		\n\t"
+		"swap	%0		\n\t"
+		"addl	d1, %0		\n\t"
+#else
 		"movel	%0, d1		\n\t"	/* convert to short */
 		"swap	d1		\n\t"
 		"addw	d1, %0		\n\t"
 		"addxw	d0, %0		\n\t"
+#endif
 		: "=d"(sum), "=a"(dgram)
 		: "d"(len), "0"(sum), "1"(dgram)
+#ifdef __mcoldfire__
+		: "d0", "d1", "d2"
+#else
 		: "d0", "d1"
+#endif
 	);
 	
 	return (short)(~sum & 0xffff);