driver.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  3. *
  4. * Floating-point emulation code
  5. * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /*
  22. * linux/arch/math-emu/driver.c.c
  23. *
  24. * decodes and dispatches unimplemented FPU instructions
  25. *
  26. * Copyright (C) 1999, 2000 Philipp Rumpf <prumpf@tux.org>
  27. * Copyright (C) 2001 Hewlett-Packard <bame@debian.org>
  28. */
  29. #include <linux/sched.h>
  30. #include "float.h"
  31. #include "math-emu.h"
  32. #define fptpos 31
  33. #define fpr1pos 10
  34. #define extru(r,pos,len) (((r) >> (31-(pos))) & (( 1 << (len)) - 1))
  35. #define FPUDEBUG 0
  36. /* Format of the floating-point exception registers. */
  37. struct exc_reg {
  38. unsigned int exception : 6;
  39. unsigned int ei : 26;
  40. };
  41. /* Macros for grabbing bits of the instruction format from the 'ei'
  42. field above. */
  43. /* Major opcode 0c and 0e */
  44. #define FP0CE_UID(i) (((i) >> 6) & 3)
  45. #define FP0CE_CLASS(i) (((i) >> 9) & 3)
  46. #define FP0CE_SUBOP(i) (((i) >> 13) & 7)
  47. #define FP0CE_SUBOP1(i) (((i) >> 15) & 7) /* Class 1 subopcode */
  48. #define FP0C_FORMAT(i) (((i) >> 11) & 3)
  49. #define FP0E_FORMAT(i) (((i) >> 11) & 1)
  50. /* Major opcode 0c, uid 2 (performance monitoring) */
  51. #define FPPM_SUBOP(i) (((i) >> 9) & 0x1f)
  52. /* Major opcode 2e (fused operations). */
  53. #define FP2E_SUBOP(i) (((i) >> 5) & 1)
  54. #define FP2E_FORMAT(i) (((i) >> 11) & 1)
  55. /* Major opcode 26 (FMPYSUB) */
  56. /* Major opcode 06 (FMPYADD) */
  57. #define FPx6_FORMAT(i) ((i) & 0x1f)
  58. /* Flags and enable bits of the status word. */
  59. #define FPSW_FLAGS(w) ((w) >> 27)
  60. #define FPSW_ENABLE(w) ((w) & 0x1f)
  61. #define FPSW_V (1<<4)
  62. #define FPSW_Z (1<<3)
  63. #define FPSW_O (1<<2)
  64. #define FPSW_U (1<<1)
  65. #define FPSW_I (1<<0)
  66. /* Handle a floating point exception. Return zero if the faulting
  67. instruction can be completed successfully. */
  68. int
  69. handle_fpe(struct pt_regs *regs)
  70. {
  71. extern void printbinary(unsigned long x, int nbits);
  72. struct siginfo si;
  73. unsigned int orig_sw, sw;
  74. int signalcode;
  75. /* need an intermediate copy of float regs because FPU emulation
  76. * code expects an artificial last entry which contains zero
  77. *
  78. * also, the passed in fr registers contain one word that defines
  79. * the fpu type. the fpu type information is constructed
  80. * inside the emulation code
  81. */
  82. __u64 frcopy[36];
  83. memcpy(frcopy, regs->fr, sizeof regs->fr);
  84. frcopy[32] = 0;
  85. memcpy(&orig_sw, frcopy, sizeof(orig_sw));
  86. if (FPUDEBUG) {
  87. printk(KERN_DEBUG "FP VZOUICxxxxCQCQCQCQCQCRMxxTDVZOUI ->\n ");
  88. printbinary(orig_sw, 32);
  89. printk(KERN_DEBUG "\n");
  90. }
  91. signalcode = decode_fpu(frcopy, 0x666);
  92. /* Status word = FR0L. */
  93. memcpy(&sw, frcopy, sizeof(sw));
  94. if (FPUDEBUG) {
  95. printk(KERN_DEBUG "VZOUICxxxxCQCQCQCQCQCRMxxTDVZOUI decode_fpu returns %d|0x%x\n",
  96. signalcode >> 24, signalcode & 0xffffff);
  97. printbinary(sw, 32);
  98. printk(KERN_DEBUG "\n");
  99. }
  100. memcpy(regs->fr, frcopy, sizeof regs->fr);
  101. if (signalcode != 0) {
  102. si.si_signo = signalcode >> 24;
  103. si.si_errno = 0;
  104. si.si_code = signalcode & 0xffffff;
  105. si.si_addr = (void __user *) regs->iaoq[0];
  106. force_sig_info(si.si_signo, &si, current);
  107. return -1;
  108. }
  109. return signalcode ? -1 : 0;
  110. }