1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
5 * Floating-point emulation code
9 * linux/arch/math-emu/driver.c.c
11 * decodes and dispatches unimplemented FPU instructions
17 #include <linux/sched/signal.h>
25 #define extru(r,pos,len) (((r) >> (31-(pos))) & (( 1 << (len)) - 1))
29 /* Macros for grabbing bits of the instruction format from the 'ei'
31 /* Major opcode 0c and 0e */
32 #define FP0CE_UID(i) (((i) >> 6) & 3)
33 #define FP0CE_CLASS(i) (((i) >> 9) & 3)
34 #define FP0CE_SUBOP(i) (((i) >> 13) & 7)
35 #define FP0CE_SUBOP1(i) (((i) >> 15) & 7) /* Class 1 subopcode */
36 #define FP0C_FORMAT(i) (((i) >> 11) & 3)
37 #define FP0E_FORMAT(i) (((i) >> 11) & 1)
39 /* Major opcode 0c, uid 2 (performance monitoring) */
40 #define FPPM_SUBOP(i) (((i) >> 9) & 0x1f)
42 /* Major opcode 2e (fused operations). */
43 #define FP2E_SUBOP(i) (((i) >> 5) & 1)
44 #define FP2E_FORMAT(i) (((i) >> 11) & 1)
46 /* Major opcode 26 (FMPYSUB) */
47 /* Major opcode 06 (FMPYADD) */
48 #define FPx6_FORMAT(i) ((i) & 0x1f)
50 /* Flags and enable bits of the status word. */
51 #define FPSW_FLAGS(w) ((w) >> 27)
52 #define FPSW_ENABLE(w) ((w) & 0x1f)
59 /* Handle a floating point exception. Return zero if the faulting
60 instruction can be completed successfully. */
62 handle_fpe(struct pt_regs *regs)
64 extern void printbinary(unsigned long x, int nbits);
65 unsigned int orig_sw, sw;
67 /* need an intermediate copy of float regs because FPU emulation
68 * code expects an artificial last entry which contains zero
70 * also, the passed in fr registers contain one word that defines
71 * the fpu type. the fpu type information is constructed
72 * inside the emulation code
76 memcpy(frcopy, regs->fr, sizeof regs->fr);
79 memcpy(&orig_sw, frcopy, sizeof(orig_sw));
82 printk(KERN_DEBUG "FP VZOUICxxxxCQCQCQCQCQCRMxxTDVZOUI ->\n ");
83 printbinary(orig_sw, 32);
84 printk(KERN_DEBUG "\n");
87 signalcode = decode_fpu(frcopy, 0x666);
89 /* Status word = FR0L. */
90 memcpy(&sw, frcopy, sizeof(sw));
92 printk(KERN_DEBUG "VZOUICxxxxCQCQCQCQCQCRMxxTDVZOUI decode_fpu returns %d|0x%x\n",
93 signalcode >> 24, signalcode & 0xffffff);
95 printk(KERN_DEBUG "\n");
98 memcpy(regs->fr, frcopy, sizeof regs->fr);
99 if (signalcode != 0) {
100 force_sig_fault(signalcode >> 24, signalcode & 0xffffff,
101 (void __user *) regs->iaoq[0]);
105 return signalcode ? -1 : 0;