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

Re: [MiNT] FreeMiNT for ColdFire



Here are the ColdFire patches for libkern.

Alan, please commit!

- libkern.patch
Added ColdFire support. Contributed by Vincent Riviere.

--
Vincent Rivière
diff -x CVS -aurN freemint.orig/sys/libkern/asm/Makefile.objs freemint/sys/libkern/asm/Makefile.objs
--- freemint.orig/sys/libkern/asm/Makefile.objs	2008-01-22 14:47:46.000000000 +0100
+++ freemint/sys/libkern/asm/Makefile.objs	2011-03-24 22:57:04.406250000 +0100
@@ -27,17 +27,6 @@
 #DEFINITIONS = -DM68030
 #endif
 
-NOCFLAGS-blockcopy.S = $(MODEL)
-CFLAGS-blockcopy.S = -m68000
-NOCFLAGS-memset.S = $(MODEL)
-CFLAGS-memset.S = -m68000
-NOCFLAGS-quickmove.S = $(MODEL)
-CFLAGS-quickmove.S = -m68000
-NOCFLAGS-quickswap.S = $(MODEL)
-CFLAGS-quickswap.S = -m68000
-NOCFLAGS-quickzero.S = $(MODEL)
-CFLAGS-quickzero.S = -m68000
-
 # default definitions
 OBJS = $(SOBJS:.S=.o)
 
diff -x CVS -aurN freemint.orig/sys/libkern/asm/blockcopy.S freemint/sys/libkern/asm/blockcopy.S
--- freemint.orig/sys/libkern/asm/blockcopy.S	2011-03-28 20:26:40.578125000 +0200
+++ freemint/sys/libkern/asm/blockcopy.S	2011-03-28 20:19:51.000000000 +0200
@@ -12,7 +12,7 @@
 __mint_blockcpy:
 	movem.l	4(sp),a0/a1		| dst & src
 	move.l	12(sp),d0		| blocks
-#ifndef M68000
+#if !(defined(M68000) || defined(__mcoldfire__))
 	move.l	_mcpu,d1
 	cmp.w	#40,d1
 	bcc.s	L_040			| for 68000-68030 do quickmove
@@ -54,8 +54,39 @@
 	rts
 #endif
 
-blkmv:	movem.l	d2-d7/a2-a6,-(sp)	| save regs
+blkmv:
+#ifdef __mcoldfire__
+	lea	-44(sp),sp
+	movem.l	d2-d7/a2-a6,(sp)	| save regs
+#else
+	movem.l	d2-d7/a2-a6,-(sp)	| save regs
+#endif
 L1:
+#ifdef __mcoldfire__
+	movem.l	(a1),d1-d7/a2-a6	| read 12*4 = 48 bytes
+	movem.l	d1-d7/a2-a6,(a0)	|
+	movem.l	48(a1),d1-d7/a2-a6	| 2nd read
+	movem.l	d1-d7/a2-a6,48(a0)	|
+	movem.l	96(a1),d1-d7/a2-a6	| 3rd read
+	movem.l	d1-d7/a2-a6,96(a0)	|
+	movem.l	144(a1),d1-d7/a2-a6	| 4th read
+	movem.l	d1-d7/a2-a6,144(a0)	|
+	movem.l	192(a1),d1-d7/a2-a6	| 5th
+	movem.l	d1-d7/a2-a6,192(a0)	|
+	movem.l	240(a1),d1-d7/a2-a6	| 6th
+	movem.l	d1-d7/a2-a6,240(a0)	|
+	movem.l	288(a1),d1-d7/a2-a6	| 7th
+	movem.l	d1-d7/a2-a6,288(a0)	|
+	movem.l	336(a1),d1-d7/a2-a6	| 8th
+	movem.l	d1-d7/a2-a6,336(a0)	|
+	movem.l	384(a1),d1-d7/a2-a6	| 9th
+	movem.l	d1-d7/a2-a6,384(a0)	|
+	movem.l	432(a1),d1-d7/a2-a6	| 10th
+	movem.l	d1-d7/a2-a6,432(a0)	| At this point, 480 bytes done
+	movem.l	480(a1),d1-d7/a2	| Only do 32 more bytes
+	movem.l	d1-d7/a2,480(a0)	| for a total of 512
+	lea	512(a1),a1
+#else
 	movem.l	(a1)+,d1-d7/a2-a6	| read 12*4 = 48 bytes
 	movem.l	d1-d7/a2-a6,(a0)	|
 	movem.l	(a1)+,d1-d7/a2-a6	| 2nd read
@@ -78,11 +109,21 @@
 	movem.l	d1-d7/a2-a6,432(a0)	| At this point, 480 bytes done
 	movem.l	(a1)+,d1-d7/a2		| Only do 32 more bytes
 	movem.l	d1-d7/a2,480(a0)	| for a total of 512
+#endif
 
 	lea	512(a0),a0
 	subq.l	#1,d0
+#ifdef __mcoldfire__
+	bne	L1
+#else
 	bne.s	L1
+#endif
 
+#ifdef __mcoldfire__
+	movem.l	(sp),d2-d7/a2-a6	| pop registers
+	lea	44(sp),sp
+#else
 	movem.l	(sp)+,d2-d7/a2-a6	| pop registers
+#endif
 
 	rts				| return
diff -x CVS -aurN freemint.orig/sys/libkern/asm/memset.S freemint/sys/libkern/asm/memset.S
--- freemint.orig/sys/libkern/asm/memset.S	2007-09-18 16:57:23.000000000 +0200
+++ freemint/sys/libkern/asm/memset.S	2011-03-24 22:52:42.843750000 +0100
@@ -23,7 +23,11 @@
 	move.w	8+4(sp),d1
 #ifndef M68000
 	move.b	d1,d0		| expand d1 to longword
+#ifdef __mcoldfire__
+	lsl.l	#0x8,d1
+#else
 	lsl.w	#0x8,d1
+#endif
 	move.b	d0,d1
 	move.w	d1,d0
 	swap	d1
@@ -37,7 +41,11 @@
 	subq.l	#0x1,d0
 	bne.s	L_long
 	move.l	d2,d0
+#ifdef __mcoldfire__
+	and.l	#0xfffffffc,d0
+#else
 	and.w	#0xfffc,d0
+#endif
 	sub.l	d0,d2
 
 L_nolong:
diff -x CVS -aurN freemint.orig/sys/libkern/asm/quickmove.S freemint/sys/libkern/asm/quickmove.S
--- freemint.orig/sys/libkern/asm/quickmove.S	2007-07-13 23:32:52.000000000 +0200
+++ freemint/sys/libkern/asm/quickmove.S	2011-03-26 23:06:25.562500000 +0100
@@ -16,19 +16,34 @@
 	.globl	_memcpy
 
 __mint_bcopy:
+#ifdef __mcoldfire__
+	move.l	4(sp),a1
+	move.l	8(sp),a0
+#else
 	movem.l	4(sp),a0/a1
 	exg	a0,a1
+#endif
 	bra.s	_quickmovb1
 _memcpy:
 	movem.l	4(sp),a0/a1		| get dst & src
 _quickmovb1:
 	move.l 12(sp),d0
 	beq.s	done
+#ifdef __mcoldfire__
+	move.w	6(sp),d1
+	andi.l	#1,d1
+#else
 	moveq	#1,d1
 	and.w	6(sp),d1
+#endif
 	bne.s	sodd
+#ifdef __mcoldfire__
+	move.w	10(sp),d1
+	andi.l	#1,d1
+#else
 	moveq	#1,d1
 	and.w	10(sp),d1
+#endif
 	beq.s	quickmov1
 
 #ifdef mc68000
@@ -41,7 +56,13 @@
 	bra.s	quickmov1
 #endif
 
-sodd:	and.w	10(sp),d1
+sodd:
+#ifdef __mcoldfire__
+	move.w	10(sp),d1
+	andi.l	#1,d1
+#else
+	and.w	10(sp),d1
+#endif
 #ifdef mc68000
 	beq.s	bytecopy
 #else
@@ -57,15 +78,54 @@
 	move.l	12(sp),d0		| get nbytes
 	beq.s	done
 quickmov1:
+#ifdef __mcoldfire__
+	move.l	#0x1ff,d1
+	and.l	d0,d1			| d1 = nbytes % 512
+#else
 	move.w	#0x1ff,d1
 	and.w	d0,d1			| d1 = nbytes % 512
+#endif
 	lsr.l	#8,d0			| 
 	lsr.l	#1,d0			| d0 = nbytes / 512
+#ifdef __mcoldfire__
+	ble	Leftover		| if <= 0, skip
+#else
 	ble.s	Leftover		| if <= 0, skip
+#endif
 
 blkmv:
+#ifdef __mcoldfire__
+	lea     -48(sp),sp
+	movem.l	d1-d7/a2-a6,(sp)	| save regs
+#else
 	movem.l	d1-d7/a2-a6,-(sp)	| save regs
+#endif
 L1:
+#ifdef __mcoldfire__
+	movem.l	(a1),d1-d7/a2-a6	| read 12*4 = 48 bytes
+	movem.l	d1-d7/a2-a6,(a0)	|
+	movem.l	48(a1),d1-d7/a2-a6	| 2nd read
+	movem.l	d1-d7/a2-a6,48(a0)	|
+	movem.l	96(a1),d1-d7/a2-a6	| 3rd read
+	movem.l	d1-d7/a2-a6,96(a0)	|
+	movem.l	144(a1),d1-d7/a2-a6	| 4th read
+	movem.l	d1-d7/a2-a6,144(a0)	|
+	movem.l	192(a1),d1-d7/a2-a6	| 5th
+	movem.l	d1-d7/a2-a6,192(a0)	|
+	movem.l	240(a1),d1-d7/a2-a6	| 6th
+	movem.l	d1-d7/a2-a6,240(a0)	|
+	movem.l	288(a1),d1-d7/a2-a6	| 7th
+	movem.l	d1-d7/a2-a6,288(a0)	|
+	movem.l	336(a1),d1-d7/a2-a6	| 8th
+	movem.l	d1-d7/a2-a6,336(a0)	|
+	movem.l	384(a1),d1-d7/a2-a6	| 9th
+	movem.l	d1-d7/a2-a6,384(a0)	|
+	movem.l	432(a1),d1-d7/a2-a6	| 10th
+	movem.l	d1-d7/a2-a6,432(a0)	| At this point, 480 bytes done
+	movem.l	480(a1),d1-d7/a2	| Only do 32 more bytes
+	movem.l	d1-d7/a2,480(a0)	| for a total of 512
+	lea	512(a1),a1
+#else
 	movem.l	(a1)+,d1-d7/a2-a6	| read 12*4 = 48 bytes
 	movem.l	d1-d7/a2-a6,(a0)	|
 	movem.l	(a1)+,d1-d7/a2-a6	| 2nd read
@@ -88,31 +148,63 @@
 	movem.l	d1-d7/a2-a6,432(a0)	| At this point, 480 bytes done
 	movem.l	(a1)+,d1-d7/a2		| Only do 32 more bytes
 	movem.l	d1-d7/a2,480(a0)	| for a total of 512
+#endif
 
 	lea	512(a0),a0
 	subq.l	#1,d0
+#ifdef __mcoldfire__
+	bgt	L1
+#else
 	bgt.s	L1
+#endif
 
+#ifdef __mcoldfire__
+	movem.l	(sp),d1-d7/a2-a6	| pop registers
+	lea	48(sp),sp
+#else
 	movem.l	(sp)+,d1-d7/a2-a6	| pop registers
+#endif
 
 Leftover:				| do the remaining bytes
 	moveq.l	#3,d0
+#ifdef __mcoldfire__
+	and.l	d1,d0
+	lsr.l	#2,d1
+	subq.l	#1,d1			| prepare for dbra loop
+	bmi.s	L4done
+	lsr.l	#1,d1
+#else
 	and.w	d1,d0
 	lsr.w	#2,d1
 	subq.w	#1,d1			| prepare for dbra loop
 	bmi.s	L4done
 	lsr.w	#1,d1
+#endif
 	bcc.s	L23
 L2l:
 	move.l	(a1)+,(a0)+
 L23:
 	move.l	(a1)+,(a0)+
+#ifdef __mcoldfire__
+	subq.l	#1,d1
+	bpl.s	L2l
+#else
 	dbra	d1,L2l
+#endif
 L4done:
+#ifdef __mcoldfire__
+	subq.l	#1,d0			| prepare for dbra loop
+#else
 	subq.w	#1,d0			| prepare for dbra loop
+#endif
 	bmi.s	Ldone
 L2:
 	move.b	(a1)+,(a0)+
+#ifdef __mcoldfire__
+	subq.l	#1,d0
+	bpl.s	L2
+#else
 	dbra	d0,L2
+#endif
 Ldone:
 	rts				| return
diff -x CVS -aurN freemint.orig/sys/libkern/asm/quickswap.S freemint/sys/libkern/asm/quickswap.S
--- freemint.orig/sys/libkern/asm/quickswap.S	2000-09-08 10:15:52.000000000 +0200
+++ freemint/sys/libkern/asm/quickswap.S	2011-03-24 22:52:39.562500000 +0100
@@ -18,12 +18,22 @@
 	move.l	4(sp),a0		| get dst
 	move.l	8(sp),a1		| get src
 	move.l	12(sp),d0		| get nbytes
+#ifdef __mcoldfire__
+	move.l	#0xff,d1
+	and.l	d0,d1			| d1 = nbytes % 256
+#else
 	move.w	#0xff,d1
 	and.w	d0,d1			| d1 = nbytes % 256
+#endif
 	lsr.l	#8,d0			| d0 = nbytes / 256
 	ble	Leftover		| if <= 0, skip
  
+#ifdef __mcoldfire__
+	lea	-48(sp),sp
+	movem.l	d1-d7/a2-a6,(sp)	| save regs
+#else
 	movem.l	d1-d7/a2-a6,-(sp)	| save regs
+#endif
 L1:
 	movem.l	(a1),d1-d6		| swap 6*4 = 24 bytes
 	movem.l (a0),d7/a2-a6		|
@@ -75,16 +85,32 @@
 	subq.l	#1,d0
 	bgt	L1
 
+#ifdef __mcoldfire__
+	movem.l	(sp),d1-d7/a2-a6	| pop registers
+	lea	48(sp),sp
+#else
 	movem.l	(sp)+,d1-d7/a2-a6	| pop registers
+#endif
 
 Leftover:				| do the remaining bytes
 	moveq.l	#3,d0
+#ifdef __mcoldfire__
+	and.l	d1,d0
+	lsr.l	#2,d1
+	subq.l	#1,d1			| prepare for dbra loop
+#else
 	and.w	d1,d0
 	lsr.w	#2,d1
 	subq.w	#1,d1			| prepare for dbra loop
+#endif
 	bmi.s	L4done
+#ifdef __mcoldfire__
+	move.l	d0,-(sp)		| save register
+	lsr.l	#1,d1
+#else
 	move.w	d0,-(sp)		| save register
 	lsr.w	#1,d1
+#endif
 	bcc.s	L23
 L2l:
 	move.l	(a1),d0
@@ -94,15 +120,30 @@
 	move.l	(a1),d0
 	move.l  (a0),(a1)+
 	move.l	d0,(a0)+
+#ifdef __mcoldfire__
+	subq.l	#1,d1
+	bpl.s	L2l
+	move.l	(sp)+,d0		| restore register
+#else
 	dbra	d1,L2l
 	move.w	(sp)+,d0		| restore register
+#endif
 L4done:
+#ifdef __mcoldfire__
+	subq.l	#1,d0			| prepare for dbra loop
+#else
 	subq.w	#1,d0			| prepare for dbra loop
+#endif
 	bmi.s	Ldone
 L2:
 	move.b	(a1),d1
 	move.b  (a0),(a1)+
 	move.b	d1,(a0)+
+#ifdef __mcoldfire__
+	subq.l	#1,d0
+	bpl.s	L2
+#else
 	dbra	d0,L2
+#endif
 Ldone:
 	rts				| return
diff -x CVS -aurN freemint.orig/sys/libkern/asm/quickzero.S freemint/sys/libkern/asm/quickzero.S
--- freemint.orig/sys/libkern/asm/quickzero.S	2011-03-28 20:26:40.578125000 +0200
+++ freemint/sys/libkern/asm/quickzero.S	2011-03-28 20:19:46.906250000 +0200
@@ -12,7 +12,12 @@
 __mint_quickzero:
 	move.l	4(sp),a0		| place to zero at
 	move.l	8(sp),d0		| number of blocks
+#ifdef __mcoldfire__
+	lea	-32(sp),sp
+	movem.l	d1-d7/a1,(sp)		| save registers
+#else
 	movem.l	d1-d7/a1,-(sp)		| save registers
+#endif
 	moveq.l	#0,d1			| zero them out
 	moveq.l	#0,d2
 	moveq.l	#0,d3
@@ -33,5 +38,10 @@
 	lea	256(a0),a0
 	subq.l	#1,d0
 	bne.s	loop
+#ifdef __mcoldfire__
+	movem.l	(sp),d1-d7/a1		| restore regs
+	lea	32(sp),sp
+#else
 	movem.l	(sp)+,d1-d7/a1		| restore regs
+#endif
 	rts				| and leave