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

Re: [MiNT] [PATCH] FreeMiNT for ColdFire: FPU



Hello.

I didn't care about the FPU on ColdFire until now. As a result, running for example 2 POV-Ray simultaneously resulted in visual bugs inside the generated images. The attached patch adds proper FPU handing in context switch with EmuTOS on ColdFire. FireTOS fixes will follow tomorrow.

Please commit!

fpu1.patch
Added ColdFire FPU support in context switch for EmuTOS. Contributed by Vincent Riviere.

--
Vincent Rivière
--- freemint-1.18.orig/sys/arch/context.S	2013-02-08 00:18:12.734375000 +0100
+++ freemint-1.18/sys/arch/context.S	2013-02-26 22:32:45.406250000 +0100
@@ -108,7 +108,10 @@
 	addq.l	#2,a1			// assume 2-byte filler after the exception frame
 build_stack_fixed:
 
-	// TODO FPU
+	// ColdFire FPU
+	fsave	C_FSTATE(a0)		// save internal state frame (including fpcr and fpsr)
+	fmovem.d fp0-fp7,C_FREGS(a0)	// save data registers
+	fmove.l	fpiar,C_FCTRL+8(a0)	// and control registers
 
 	bra.s	short1
 build_68k:
@@ -237,6 +240,19 @@
 noprot2:
 #endif
 
+#ifdef __mcoldfire__
+	tst.w	_coldfire_68k_emulation
+	bne.s	savefpu_68k
+
+	// ColdFire FPU
+	fsave	C_FSTATE(a0)		// save internal state frame (including fpcr and fpsr)
+	fmovem.d fp0-fp7,C_FREGS(a0)	// save data registers
+	fmove.l	fpiar,C_FCTRL+8(a0)	// and control registers
+
+	bra.s	nofpu2
+savefpu_68k:
+#endif
+
 // if running with a true coprocessor we need to save the FPU state
 
 	tst.w	_fpu			// is there a true FPU in the system
@@ -344,7 +360,10 @@
 	tst.w	_coldfire_68k_emulation
 	bne.s	restore_68k
 
-	// TODO FPU
+	// ColdFire FPU
+	fmove.l	C_FCTRL+8(a0),fpiar	// restore control registers
+	fmovem.d C_FREGS(a0),fp0-fp7	// and data registers
+	frestore C_FSTATE(a0)		// finally the internal state (including fpcr and fpsr)
 
 	move.l	C_PC(a0),-(sp)		// push the PC
 	move.w	C_SR(a0),-(sp)		// push the status register
@@ -496,7 +515,10 @@
 	tst.w	_coldfire_68k_emulation
 	bne.s	change_68k
 
-	// TODO FPU
+	// ColdFire FPU
+	fmove.l	C_FCTRL+8(a0),fpiar	// restore control registers
+	fmovem.d C_FREGS(a0),fp0-fp7	// and data registers
+	frestore C_FSTATE(a0)		// finally the internal state (including fpcr and fpsr)
 
 	move.l	C_PC(a0),-(sp)		// push the PC
 	move.w	C_SR(a0),-(sp)		// push the status register