Index: c/src/lib/libbsp/powerpc/support/new_exception_processing/ChangeLog
===================================================================
--- c/src/lib/libbsp/powerpc/support/new_exception_processing/ChangeLog	(revision 19131e97448c53a4cbb58448f33e52e2b92cacfd)
+++ c/src/lib/libbsp/powerpc/support/new_exception_processing/ChangeLog	(revision 830e5f74eab67787b9c30fe658a0160035f2a3f2)
@@ -1,2 +1,23 @@
+2001-05-14	Till Straumann <strauman@slac.stanford.edu>
+
+	* cpu.c: Per PR211 fix
+	saving/restoring floating point context.  The fpsave and fprestore
+	routines are only used in a executing context which _is_ fp and hence
+	has the FPU enabled. The current behavior required the FPU always to
+	be on which is very dangerous if lazy context switching is used.  
+	[Joel Note: Some ports explicitly enabled the FPU in the FP save and
+	restore routines to avoid this.]
+
+	The patch also makes sure (on powerpc only) that the FPU is disabled
+	for integer tasks. Note that this is crucial if deferred fp context
+	switching is used. Otherwise, fp context corruption may go undetected!
+	Also note that even tasks which merely push/pop FP registers to/from
+	the stack without modifying them still MUST be FP tasks - otherwise
+	(if lazy FP context switching is used), FP register corruption (of
+	other, FP, tasks may occur)!
+
+	Furthermore, (on PPC) by default, lazy FP context save/restore
+	is _disabled_.
+
 2002-04-18	Ralf Corsepius <corsepiu@faw.uni-ulm.de>
 
Index: c/src/lib/libbsp/powerpc/support/new_exception_processing/cpu.c
===================================================================
--- c/src/lib/libbsp/powerpc/support/new_exception_processing/cpu.c	(revision 19131e97448c53a4cbb58448f33e52e2b92cacfd)
+++ c/src/lib/libbsp/powerpc/support/new_exception_processing/cpu.c	(revision 830e5f74eab67787b9c30fe658a0160035f2a3f2)
@@ -94,6 +94,18 @@
    */
 
-  /*if ( is_fp ) */
+  /* Till Straumann: For deferred FPContext save/restore, make sure integer
+   *                 tasks have no FPU access in order to catch violations.
+   *                 Otherwise, the FP registers may be corrupted.
+   *				 Since we set the_contex->msr using our current MSR,
+   *				 we must make sure MSR_FP is off if (!is_fp)...
+   */
+#if defined(CPU_USE_DEFERRED_FP_SWITCH) && (CPU_USE_DEFERRED_FP_SWITCH==TRUE)
+  if ( is_fp )
+#endif
     the_context->msr |= PPC_MSR_FP;
+#if defined(CPU_USE_DEFERRED_FP_SWITCH) && (CPU_USE_DEFERRED_FP_SWITCH==TRUE)
+  else
+	the_context->msr &= ~PPC_MSR_FP;
+#endif
 
   the_context->pc = (unsigned32)entry_point;
Index: c/src/lib/libcpu/powerpc/new-exceptions/ChangeLog
===================================================================
--- c/src/lib/libcpu/powerpc/new-exceptions/ChangeLog	(revision 19131e97448c53a4cbb58448f33e52e2b92cacfd)
+++ c/src/lib/libcpu/powerpc/new-exceptions/ChangeLog	(revision 830e5f74eab67787b9c30fe658a0160035f2a3f2)
@@ -1,2 +1,23 @@
+2001-05-14	Till Straumann <strauman@slac.stanford.edu>
+
+	* cpu.c: Per PR211 fix
+	saving/restoring floating point context.  The fpsave and fprestore
+	routines are only used in a executing context which _is_ fp and hence
+	has the FPU enabled. The current behavior required the FPU always to
+	be on which is very dangerous if lazy context switching is used.  
+	[Joel Note: Some ports explicitly enabled the FPU in the FP save and
+	restore routines to avoid this.]
+
+	The patch also makes sure (on powerpc only) that the FPU is disabled
+	for integer tasks. Note that this is crucial if deferred fp context
+	switching is used. Otherwise, fp context corruption may go undetected!
+	Also note that even tasks which merely push/pop FP registers to/from
+	the stack without modifying them still MUST be FP tasks - otherwise
+	(if lazy FP context switching is used), FP register corruption (of
+	other, FP, tasks may occur)!
+
+	Furthermore, (on PPC) by default, lazy FP context save/restore
+	is _disabled_.
+
 2002-04-18	Ralf Corsepius <corsepiu@faw.uni-ulm.de>
 
Index: c/src/lib/libcpu/powerpc/new-exceptions/cpu.c
===================================================================
--- c/src/lib/libcpu/powerpc/new-exceptions/cpu.c	(revision 19131e97448c53a4cbb58448f33e52e2b92cacfd)
+++ c/src/lib/libcpu/powerpc/new-exceptions/cpu.c	(revision 830e5f74eab67787b9c30fe658a0160035f2a3f2)
@@ -94,6 +94,18 @@
    */
 
-  /*if ( is_fp ) */
+  /* Till Straumann: For deferred FPContext save/restore, make sure integer
+   *                 tasks have no FPU access in order to catch violations.
+   *                 Otherwise, the FP registers may be corrupted.
+   *				 Since we set the_contex->msr using our current MSR,
+   *				 we must make sure MSR_FP is off if (!is_fp)...
+   */
+#if defined(CPU_USE_DEFERRED_FP_SWITCH) && (CPU_USE_DEFERRED_FP_SWITCH==TRUE)
+  if ( is_fp )
+#endif
     the_context->msr |= PPC_MSR_FP;
+#if defined(CPU_USE_DEFERRED_FP_SWITCH) && (CPU_USE_DEFERRED_FP_SWITCH==TRUE)
+  else
+	the_context->msr &= ~PPC_MSR_FP;
+#endif
 
   the_context->pc = (unsigned32)entry_point;
