fpa11.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. NetWinder Floating Point Emulator
  4. (c) Rebel.COM, 1998,1999
  5. (c) Philip Blundell, 2001
  6. Direct questions, comments to Scott Bambrough <[email protected]>
  7. */
  8. #include "fpa11.h"
  9. #include "fpopcode.h"
  10. #include "fpmodule.h"
  11. #include "fpmodule.inl"
  12. #include <linux/compiler.h>
  13. #include <linux/string.h>
  14. /* Reset the FPA11 chip. Called to initialize and reset the emulator. */
  15. static void resetFPA11(void)
  16. {
  17. int i;
  18. FPA11 *fpa11 = GET_FPA11();
  19. /* initialize the register type array */
  20. for (i = 0; i <= 7; i++) {
  21. fpa11->fType[i] = typeNone;
  22. }
  23. /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
  24. fpa11->fpsr = FP_EMULATOR | BIT_AC;
  25. }
  26. int8 SetRoundingMode(const unsigned int opcode)
  27. {
  28. switch (opcode & MASK_ROUNDING_MODE) {
  29. default:
  30. case ROUND_TO_NEAREST:
  31. return float_round_nearest_even;
  32. case ROUND_TO_PLUS_INFINITY:
  33. return float_round_up;
  34. case ROUND_TO_MINUS_INFINITY:
  35. return float_round_down;
  36. case ROUND_TO_ZERO:
  37. return float_round_to_zero;
  38. }
  39. }
  40. int8 SetRoundingPrecision(const unsigned int opcode)
  41. {
  42. #ifdef CONFIG_FPE_NWFPE_XP
  43. switch (opcode & MASK_ROUNDING_PRECISION) {
  44. case ROUND_SINGLE:
  45. return 32;
  46. case ROUND_DOUBLE:
  47. return 64;
  48. case ROUND_EXTENDED:
  49. return 80;
  50. default:
  51. return 80;
  52. }
  53. #endif
  54. return 80;
  55. }
  56. void nwfpe_init_fpa(union fp_state *fp)
  57. {
  58. FPA11 *fpa11 = (FPA11 *)fp;
  59. #ifdef NWFPE_DEBUG
  60. printk("NWFPE: setting up state.\n");
  61. #endif
  62. memset(fpa11, 0, sizeof(FPA11));
  63. resetFPA11();
  64. fpa11->initflag = 1;
  65. }
  66. /* Emulate the instruction in the opcode. */
  67. unsigned int EmulateAll(unsigned int opcode)
  68. {
  69. unsigned int code;
  70. #ifdef NWFPE_DEBUG
  71. printk("NWFPE: emulating opcode %08x\n", opcode);
  72. #endif
  73. code = opcode & 0x00000f00;
  74. if (code == 0x00000100 || code == 0x00000200) {
  75. /* For coprocessor 1 or 2 (FPA11) */
  76. code = opcode & 0x0e000000;
  77. if (code == 0x0e000000) {
  78. if (opcode & 0x00000010) {
  79. /* Emulate conversion opcodes. */
  80. /* Emulate register transfer opcodes. */
  81. /* Emulate comparison opcodes. */
  82. return EmulateCPRT(opcode);
  83. } else {
  84. /* Emulate monadic arithmetic opcodes. */
  85. /* Emulate dyadic arithmetic opcodes. */
  86. return EmulateCPDO(opcode);
  87. }
  88. } else if (code == 0x0c000000) {
  89. /* Emulate load/store opcodes. */
  90. /* Emulate load/store multiple opcodes. */
  91. return EmulateCPDT(opcode);
  92. }
  93. }
  94. /* Invalid instruction detected. Return FALSE. */
  95. return 0;
  96. }