Skip to contentSkip to conversation

Handle altivec assist exception properly

PATCH New Paul Mackerras 1 participant 1 message May 15, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Handle altivec assist exception properly

On machines with Altivec (i.e. G4 and G5 processors), the altivec floating-point instructions can operate in two modes: one where denormalized inputs or outputs are truncated to zero, and one where they aren't. In the latter mode the processor can take an exception when it encounters denormalized floating-point inputs or outputs rather than dealing with them in hardware.

This patch adds code to deal properly with the exception, by emulating the instruction that caused the exception. Previously the kernel just switched the altivec unit into the truncate-to-zero mode, which works but is a bit gross. Fortunately there are only a limited set of altivec instructions which can generate the assist exception, so we don't have to emulate the whole altivec instruction set.

This patch also makes sure that we always have a handler for the altivec unavailable exception. Without this, if you run a kernel that is not configured for altivec support on a machine with altivec, it works fine until a user process tries to execute an altivec instruction. At that point the kernel thinks it has taken an unknown exception and panics. With this patch it sends a SIGILL to the process instead.

Please apply. I'll send a similar patch for ppc64 soon.

Thanks,
Paul.

arch/ppc/kernel/Makefile +1 -0
diff -urN linux-2.5/arch/ppc/kernel/Makefile ppc-2.5/arch/ppc/kernel/Makefile
@@ -29,6 +29,7 @@
 obj-$(CONFIG_KGDB)		+= ppc-stub.o
 obj-$(CONFIG_SMP)		+= smp.o smp-tbsync.o
 obj-$(CONFIG_TAU)		+= temp.o
+obj-$(CONFIG_ALTIVEC)		+= vecemu.o vector.o
 
 ifdef CONFIG_MATH_EMULATION
 obj-$(CONFIG_8xx)		+= softemu8xx.o
arch/ppc/kernel/head.S +8 -5
diff -urN linux-2.5/arch/ppc/kernel/head.S ppc-2.5/arch/ppc/kernel/head.S
@@ -491,14 +491,16 @@
 /*
  * The Altivec unavailable trap is at 0x0f20.  Foo.
  * We effectively remap it to 0x3000.
+ * We include an altivec unavailable exception vector even if
+ * not configured for Altivec, so that you can't panic a
+ * non-altivec kernel running on a machine with altivec just
+ * by executing an altivec instruction.
  */
 	. = 0xf00
 	b	Trap_0f
 
 	. = 0xf20
-#ifdef CONFIG_ALTIVEC
 	b	AltiVecUnavailable
-#endif
 
 Trap_0f:
 	EXCEPTION_PROLOG
@@ -705,6 +707,7 @@
 #ifndef CONFIG_ALTIVEC
 #define AltivecAssistException	UnknownException
 #endif
+
 	EXCEPTION(0x1300, Trap_13, InstructionBreakpoint, EXC_XFER_EE)
 	EXCEPTION(0x1400, SMI, SMIException, EXC_XFER_EE)
 	EXCEPTION(0x1500, Trap_15, UnknownException, EXC_XFER_EE)
@@ -746,12 +749,12 @@
 
 	. = 0x3000
 
-#ifdef CONFIG_ALTIVEC
 AltiVecUnavailable:
 	EXCEPTION_PROLOG
+#ifdef CONFIG_ALTIVEC
 	bne	load_up_altivec		/* if from user, just load it up */
-	EXC_XFER_EE_LITE(0xf20, KernelAltiVec)
 #endif /* CONFIG_ALTIVEC */
+	EXC_XFER_EE_LITE(0xf20, AltivecUnavailException)
 
 #ifdef CONFIG_PPC64BRIDGE
 DataAccess:
@@ -1633,7 +1636,7 @@
 	blr
 
 #endif /* CONFIG_POWER4 */
-	
+
 #ifdef CONFIG_8260
 /* Jump into the system reset for the rom.
  * We first disable the MMU, and then jump to the ROM reset address.
arch/ppc/kernel/traps.c +39 -2

56 lines not on this page · raw message

arch/ppc/kernel/vecemu.c +346 -0

346 lines not on this page · raw message

arch/ppc/kernel/vector.S +217 -0

217 lines not on this page · raw message