driver.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  4. *
  5. * Floating-point emulation code
  6. * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
  7. */
  8. /*
  9. * linux/arch/math-emu/driver.c.c
  10. *
  11. * decodes and dispatches unimplemented FPU instructions
  12. *
  13. * Copyright (C) 1999, 2000 Philipp Rumpf <prumpf@tux.org>
  14. * Copyright (C) 2001 Hewlett-Packard <bame@debian.org>
  15. */
  16. #include <linux/sched/signal.h>
  17. #include "float.h"
  18. #include "math-emu.h"
  19. #define fptpos 31
  20. #define fpr1pos 10
  21. #define extru(r,pos,len) (((r) >> (31-(pos))) & (( 1 << (len)) - 1))
  22. #define FPUDEBUG 0
  23. /* Macros for grabbing bits of the instruction format from the 'ei'
  24. field above. */
  25. /* Major opcode 0c and 0e */
  26. #define FP0CE_UID(i) (((i) >> 6) & 3)
  27. #define FP0CE_CLASS(i) (((i) >> 9) & 3)
  28. #define FP0CE_SUBOP(i) (((i) >> 13) & 7)
  29. #define FP0CE_SUBOP1(i) (((i) >> 15) & 7) /* Class 1 subopcode */
  30. #define FP0C_FORMAT(i) (((i) >> 11) & 3)
  31. #define FP0E_FORMAT(i) (((i) >> 11) & 1)
  32. /* Major opcode 0c, uid 2 (performance monitoring) */
  33. #define FPPM_SUBOP(i) (((i) >> 9) & 0x1f)
  34. /* Major opcode 2e (fused operations). */
  35. #define FP2E_SUBOP(i) (((i) >> 5) & 1)
  36. #define FP2E_FORMAT(i) (((i) >> 11) & 1)
  37. /* Major opcode 26 (FMPYSUB) */
  38. /* Major opcode 06 (FMPYADD) */
  39. #define FPx6_FORMAT(i) ((i) & 0x1f)
  40. /* Flags and enable bits of the status word. */
  41. #define FPSW_FLAGS(w) ((w) >> 27)
  42. #define FPSW_ENABLE(w) ((w) & 0x1f)
  43. #define FPSW_V (1<<4)
  44. #define FPSW_Z (1<<3)
  45. #define FPSW_O (1<<2)
  46. #define FPSW_U (1<<1)
  47. #define FPSW_I (1<<0)
  48. /* Handle a floating point exception. Return zero if the faulting
  49. instruction can be completed successfully. */
  50. int
  51. handle_fpe(struct pt_regs *regs)
  52. {
  53. extern void printbinary(unsigned long x, int nbits);
  54. unsigned int orig_sw, sw;
  55. int signalcode;
  56. /* need an intermediate copy of float regs because FPU emulation
  57. * code expects an artificial last entry which contains zero
  58. *
  59. * also, the passed in fr registers contain one word that defines
  60. * the fpu type. the fpu type information is constructed
  61. * inside the emulation code
  62. */
  63. __u64 frcopy[36];
  64. memcpy(frcopy, regs->fr, sizeof regs->fr);
  65. frcopy[32] = 0;
  66. memcpy(&orig_sw, frcopy, sizeof(orig_sw));
  67. if (FPUDEBUG) {
  68. printk(KERN_DEBUG "FP VZOUICxxxxCQCQCQCQCQCRMxxTDVZOUI ->\n ");
  69. printbinary(orig_sw, 32);
  70. printk(KERN_DEBUG "\n");
  71. }
  72. signalcode = decode_fpu(frcopy, 0x666);
  73. /* Status word = FR0L. */
  74. memcpy(&sw, frcopy, sizeof(sw));
  75. if (FPUDEBUG) {
  76. printk(KERN_DEBUG "VZOUICxxxxCQCQCQCQCQCRMxxTDVZOUI decode_fpu returns %d|0x%x\n",
  77. signalcode >> 24, signalcode & 0xffffff);
  78. printbinary(sw, 32);
  79. printk(KERN_DEBUG "\n");
  80. }
  81. memcpy(regs->fr, frcopy, sizeof regs->fr);
  82. if (signalcode != 0) {
  83. int sig = signalcode >> 24;
  84. if (sig == SIGFPE) {
  85. /*
  86. * Clear floating point trap bit to avoid trapping
  87. * again on the first floating-point instruction in
  88. * the userspace signal handler.
  89. */
  90. regs->fr[0] &= ~(1ULL << 38);
  91. }
  92. force_sig_fault(sig, signalcode & 0xffffff,
  93. (void __user *) regs->iaoq[0]);
  94. return -1;
  95. }
  96. return signalcode ? -1 : 0;
  97. }