Handle altivec assist exception properly
PATCH 1/1 Handle altivec assist exception properly
This is the PPC64 counterpart of the PPC32 Altivec assist exception handler that went in recently.
On PPC64 machines with Altivec (i.e. machines that use the PPC970 chip, such as the G5 powermac), 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.
Note that Altivec is Motorola's name for the PowerPC vector/SIMD instructions; IBM calls the same thing VMX, and currently only IBM makes 64-bit PowerPC CPU chips. Nevertheless, I have used the term Altivec in the PPC64 code for consistency with the PPC32 code.
arch/ppc64/kernel/Makefile +2 -0
@@ -56,4 +56,6 @@ obj-$(CONFIG_PPC_PMAC) += pmac_smp.o smp-tbsync.o endif +obj-$(CONFIG_ALTIVEC) += vecemu.o vector.o + CFLAGS_ioctl32.o += -Ifs/
arch/ppc64/kernel/traps.c +32 -2
@@ -544,9 +544,39 @@void AltivecAssistException (struct pt_regs *regs) { +int err; +siginfo_t info; + +if (!user_mode (regs)) { +printk (KERN_EMERG "VMX/Altivec assist exception in kernel mode" +" at %lx\n" , regs->nip); +die ("Kernel VMX/Altivec assist exception" , regs,SIGILL ); + } +flush_altivec_to_thread (current); -/* XXX quick hack for now: set the non-Java bit in the VSCR */ - current->thread.vscr.u[3 ] |=0x10000 ; + + err =emulate_altivec (regs); +if (err ==0 ) { + regs->nip +=4 ;/* skip emulated instruction */ +emulate_single_step (regs); +return ; + } + +if (err == -EFAULT ) { +/* got an error reading the instruction */ + info.si_signo =SIGSEGV ; + info.si_errno =0 ; + info.si_code =SEGV_MAPERR ; + info.si_addr = (void *) regs->nip; +force_sig_info (SIGSEGV , &info, current); + }else { +/* didn't recognize the instruction */ +/* XXX quick hack for now: set the non-Java bit in the VSCR */ +if (printk_ratelimit ()) +printk (KERN_ERR "Unrecognized altivec instruction " +"in %s at %lx\n" , current->comm, regs->nip); + current->thread.vscr.u[3 ] |=0x10000 ; + } }#endif /* CONFIG_ALTIVEC */
arch/ppc64/kernel/vecemu.c new file +346 -0
346 lines not on this page · raw message
arch/ppc64/kernel/vector.S new file +172 -0
172 lines not on this page · raw message
include/asm-ppc64/system.h +1 -0
@@ -116,6 +116,7 @@extern void giveup_altivec (struct task_struct *);extern void disable_kernel_altivec (void );extern void enable_kernel_altivec (void ); +extern int emulate_altivec (struct pt_regs *);extern void cvt_fd (float *from,double *to,unsigned long *fpscr);extern void cvt_df (double *from,float *to,unsigned long *fpscr);