All of lore.kernel.org
 help / color / mirror / Atom feed
* [ping][PATCH] Handle COP3 Unusable exception as COP1X for FP emulation
@ 2012-03-06 20:28 ` Maciej W. Rozycki
  0 siblings, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2012-03-06 20:28 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: Maciej W. Rozycki, linux-mips


 Our FP emulator is hardcoded for the MIPS IV FP instruction set and does 
not match the FP ISA with the general ISA.  However for the few MIPS IV FP 
instructions that use the COP1X major opcode it relies on the Coprocessor 
Unusable exception to be delivered as a COP1 rather than COP3 exception.  
This includes indexed transfer (LDXC1, etc.) and FP multiply-accumulate 
(MADD.D, etc.) instructions.

 All the MIPS I and MIPS II processors and some newer chips that do not 
implement the FPU use the COP3 exception however.  Therefore I believe the 
kernel should follow and redirect any COP3 Unusable traps to the emulator 
unless an actual FPU part or core is present.

 This is a change that implements it.  Any minor opcode encodings that are 
not recognised as valid FP instructions are rejected by the emulator and 
will result in a SIGILL signal being delivered as they currently do.  We 
do not support vendor-specific coprocessor 3 implementations supported 
with MIPS I and MIPS II ISA processors; we never set CP0.Status.CU3.

 If matching between the CPU and the FPU ISA is considered required one 
day, this can still be done in the emulator itself.  I think the CpU 
exception dispatcher is not the right place to do this anyway, as there 
are further differences between MIPS I, MIPS II, MIPS III, MIPS IV and 
MIPS32 FP ISAs.

 Corresponding explanation of this implementation is included within the 
change itself.

Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
---
Ralf,

 Any progress with this change?

  Maciej

patch-3.2.0-rc4-do-cpu-cop3-1
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index c6fc6a0..b86eb3d 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -1066,6 +1066,24 @@ asmlinkage void do_cpu(struct pt_regs *regs)
 
 		return;
 
+	case 3:
+		/*
+		 * Old (MIPS I and MIPS II) processors will set this code
+		 * for COP1X opcode instructions that replaced the original
+		 * COP3 space.  We don't limit COP1 space instructions in
+		 * the emulator according to the CPU ISA, so we want to
+		 * treat COP1X instructions consistently regardless of which
+		 * code the CPU chose.  Therefore we redirect this trap to
+		 * the FP emulator too.
+		 *
+		 * Then some newer FPU-less processors use this code
+		 * erroneously too, so they are covered by this choice
+		 * as well.
+		 */
+		if (raw_cpu_has_fpu)
+			break;
+		/* Fall through.  */
+
 	case 1:
 		if (used_math())	/* Using the FPU again.  */
 			own_fpu(1);
@@ -1089,9 +1107,6 @@ asmlinkage void do_cpu(struct pt_regs *regs)
 	case 2:
 		raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
 		return;
-
-	case 3:
-		break;
 	}
 
 	force_sig(SIGILL, current);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [ping][PATCH] Handle COP3 Unusable exception as COP1X for FP emulation
@ 2012-03-06 20:28 ` Maciej W. Rozycki
  0 siblings, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2012-03-06 20:28 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: Maciej W. Rozycki, linux-mips


 Our FP emulator is hardcoded for the MIPS IV FP instruction set and does 
not match the FP ISA with the general ISA.  However for the few MIPS IV FP 
instructions that use the COP1X major opcode it relies on the Coprocessor 
Unusable exception to be delivered as a COP1 rather than COP3 exception.  
This includes indexed transfer (LDXC1, etc.) and FP multiply-accumulate 
(MADD.D, etc.) instructions.

 All the MIPS I and MIPS II processors and some newer chips that do not 
implement the FPU use the COP3 exception however.  Therefore I believe the 
kernel should follow and redirect any COP3 Unusable traps to the emulator 
unless an actual FPU part or core is present.

 This is a change that implements it.  Any minor opcode encodings that are 
not recognised as valid FP instructions are rejected by the emulator and 
will result in a SIGILL signal being delivered as they currently do.  We 
do not support vendor-specific coprocessor 3 implementations supported 
with MIPS I and MIPS II ISA processors; we never set CP0.Status.CU3.

 If matching between the CPU and the FPU ISA is considered required one 
day, this can still be done in the emulator itself.  I think the CpU 
exception dispatcher is not the right place to do this anyway, as there 
are further differences between MIPS I, MIPS II, MIPS III, MIPS IV and 
MIPS32 FP ISAs.

 Corresponding explanation of this implementation is included within the 
change itself.

Signed-off-by: Maciej W. Rozycki <macro@codesourcery.com>
---
Ralf,

 Any progress with this change?

  Maciej

patch-3.2.0-rc4-do-cpu-cop3-1
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index c6fc6a0..b86eb3d 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -1066,6 +1066,24 @@ asmlinkage void do_cpu(struct pt_regs *regs)
 
 		return;
 
+	case 3:
+		/*
+		 * Old (MIPS I and MIPS II) processors will set this code
+		 * for COP1X opcode instructions that replaced the original
+		 * COP3 space.  We don't limit COP1 space instructions in
+		 * the emulator according to the CPU ISA, so we want to
+		 * treat COP1X instructions consistently regardless of which
+		 * code the CPU chose.  Therefore we redirect this trap to
+		 * the FP emulator too.
+		 *
+		 * Then some newer FPU-less processors use this code
+		 * erroneously too, so they are covered by this choice
+		 * as well.
+		 */
+		if (raw_cpu_has_fpu)
+			break;
+		/* Fall through.  */
+
 	case 1:
 		if (used_math())	/* Using the FPU again.  */
 			own_fpu(1);
@@ -1089,9 +1107,6 @@ asmlinkage void do_cpu(struct pt_regs *regs)
 	case 2:
 		raw_notifier_call_chain(&cu2_chain, CU2_EXCEPTION, regs);
 		return;
-
-	case 3:
-		break;
 	}
 
 	force_sig(SIGILL, current);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [ping][PATCH] Handle COP3 Unusable exception as COP1X for FP emulation
  2012-03-06 20:28 ` Maciej W. Rozycki
  (?)
@ 2012-03-07 16:44 ` Ralf Baechle
  2012-03-07 19:39     ` Maciej W. Rozycki
  -1 siblings, 1 reply; 5+ messages in thread
From: Ralf Baechle @ 2012-03-07 16:44 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: Maciej W. Rozycki, linux-mips

On Tue, Mar 06, 2012 at 08:28:54PM +0000, Maciej W. Rozycki wrote:

> Subject: [ping][PATCH] Handle COP3 Unusable exception as COP1X for FP

The list's spam filter ate both this and your your original posting and
thus the patch also didn't make it to patchwork, whoops...  I've modified
the offending test to avoid this from repeating and would like to
encourageusers who experience problems posting to contact me off the
list.

The patch itself looks good and I've applied it.

Thanks!

  Ralf

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ping][PATCH] Handle COP3 Unusable exception as COP1X for FP emulation
@ 2012-03-07 19:39     ` Maciej W. Rozycki
  0 siblings, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2012-03-07 19:39 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: Maciej W. Rozycki, linux-mips

On Wed, 7 Mar 2012, Ralf Baechle wrote:

> The patch itself looks good and I've applied it.

 Thanks for your review.

  Maciej

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [ping][PATCH] Handle COP3 Unusable exception as COP1X for FP emulation
@ 2012-03-07 19:39     ` Maciej W. Rozycki
  0 siblings, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2012-03-07 19:39 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: Maciej W. Rozycki, linux-mips

On Wed, 7 Mar 2012, Ralf Baechle wrote:

> The patch itself looks good and I've applied it.

 Thanks for your review.

  Maciej

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-03-07 19:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-06 20:28 [ping][PATCH] Handle COP3 Unusable exception as COP1X for FP emulation Maciej W. Rozycki
2012-03-06 20:28 ` Maciej W. Rozycki
2012-03-07 16:44 ` Ralf Baechle
2012-03-07 19:39   ` Maciej W. Rozycki
2012-03-07 19:39     ` Maciej W. Rozycki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.