1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
5 * Floating-point emulation code
6 * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
9 * linux/arch/math-emu/driver.c.c
11 * decodes and dispatches unimplemented FPU instructions
13 * Copyright (C) 1999, 2000 Philipp Rumpf <prumpf@tux.org>
14 * Copyright (C) 2001 Hewlett-Packard <bame@debian.org>
17 #include <linux/sched/signal.h>
25 #define extru(r,pos,len) (((r) >> (31-(pos))) & (( 1 << (len)) - 1))
29 /* Format of the floating-point exception registers. */
31 unsigned int exception
: 6;
35 /* Macros for grabbing bits of the instruction format from the 'ei'
37 /* Major opcode 0c and 0e */
38 #define FP0CE_UID(i) (((i) >> 6) & 3)
39 #define FP0CE_CLASS(i) (((i) >> 9) & 3)
40 #define FP0CE_SUBOP(i) (((i) >> 13) & 7)
41 #define FP0CE_SUBOP1(i) (((i) >> 15) & 7) /* Class 1 subopcode */
42 #define FP0C_FORMAT(i) (((i) >> 11) & 3)
43 #define FP0E_FORMAT(i) (((i) >> 11) & 1)
45 /* Major opcode 0c, uid 2 (performance monitoring) */
46 #define FPPM_SUBOP(i) (((i) >> 9) & 0x1f)
48 /* Major opcode 2e (fused operations). */
49 #define FP2E_SUBOP(i) (((i) >> 5) & 1)
50 #define FP2E_FORMAT(i) (((i) >> 11) & 1)
52 /* Major opcode 26 (FMPYSUB) */
53 /* Major opcode 06 (FMPYADD) */
54 #define FPx6_FORMAT(i) ((i) & 0x1f)
56 /* Flags and enable bits of the status word. */
57 #define FPSW_FLAGS(w) ((w) >> 27)
58 #define FPSW_ENABLE(w) ((w) & 0x1f)
65 /* Handle a floating point exception. Return zero if the faulting
66 instruction can be completed successfully. */
68 handle_fpe(struct pt_regs
*regs
)
70 extern void printbinary(unsigned long x
, int nbits
);
71 unsigned int orig_sw
, sw
;
73 /* need an intermediate copy of float regs because FPU emulation
74 * code expects an artificial last entry which contains zero
76 * also, the passed in fr registers contain one word that defines
77 * the fpu type. the fpu type information is constructed
78 * inside the emulation code
82 memcpy(frcopy
, regs
->fr
, sizeof regs
->fr
);
85 memcpy(&orig_sw
, frcopy
, sizeof(orig_sw
));
88 printk(KERN_DEBUG
"FP VZOUICxxxxCQCQCQCQCQCRMxxTDVZOUI ->\n ");
89 printbinary(orig_sw
, 32);
90 printk(KERN_DEBUG
"\n");
93 signalcode
= decode_fpu(frcopy
, 0x666);
95 /* Status word = FR0L. */
96 memcpy(&sw
, frcopy
, sizeof(sw
));
98 printk(KERN_DEBUG
"VZOUICxxxxCQCQCQCQCQCRMxxTDVZOUI decode_fpu returns %d|0x%x\n",
99 signalcode
>> 24, signalcode
& 0xffffff);
101 printk(KERN_DEBUG
"\n");
104 memcpy(regs
->fr
, frcopy
, sizeof regs
->fr
);
105 if (signalcode
!= 0) {
106 force_sig_fault(signalcode
>> 24, signalcode
& 0xffffff,
107 (void __user
*) regs
->iaoq
[0]);
111 return signalcode
? -1 : 0;