fpa11.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. NetWinder Floating Point Emulator
  3. (c) Rebel.COM, 1998,1999
  4. (c) Philip Blundell, 2001
  5. Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include "fpa11.h"
  19. #include "fpopcode.h"
  20. #include "fpmodule.h"
  21. #include "fpmodule.inl"
  22. #include <linux/compiler.h>
  23. #include <linux/string.h>
  24. /* Reset the FPA11 chip. Called to initialize and reset the emulator. */
  25. static void resetFPA11(void)
  26. {
  27. int i;
  28. FPA11 *fpa11 = GET_FPA11();
  29. /* initialize the register type array */
  30. for (i = 0; i <= 7; i++) {
  31. fpa11->fType[i] = typeNone;
  32. }
  33. /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
  34. fpa11->fpsr = FP_EMULATOR | BIT_AC;
  35. }
  36. int8 SetRoundingMode(const unsigned int opcode)
  37. {
  38. switch (opcode & MASK_ROUNDING_MODE) {
  39. default:
  40. case ROUND_TO_NEAREST:
  41. return float_round_nearest_even;
  42. case ROUND_TO_PLUS_INFINITY:
  43. return float_round_up;
  44. case ROUND_TO_MINUS_INFINITY:
  45. return float_round_down;
  46. case ROUND_TO_ZERO:
  47. return float_round_to_zero;
  48. }
  49. }
  50. int8 SetRoundingPrecision(const unsigned int opcode)
  51. {
  52. #ifdef CONFIG_FPE_NWFPE_XP
  53. switch (opcode & MASK_ROUNDING_PRECISION) {
  54. case ROUND_SINGLE:
  55. return 32;
  56. case ROUND_DOUBLE:
  57. return 64;
  58. case ROUND_EXTENDED:
  59. return 80;
  60. default:
  61. return 80;
  62. }
  63. #endif
  64. return 80;
  65. }
  66. void nwfpe_init_fpa(union fp_state *fp)
  67. {
  68. FPA11 *fpa11 = (FPA11 *)fp;
  69. #ifdef NWFPE_DEBUG
  70. printk("NWFPE: setting up state.\n");
  71. #endif
  72. memset(fpa11, 0, sizeof(FPA11));
  73. resetFPA11();
  74. fpa11->initflag = 1;
  75. }
  76. /* Emulate the instruction in the opcode. */
  77. unsigned int EmulateAll(unsigned int opcode)
  78. {
  79. unsigned int code;
  80. #ifdef NWFPE_DEBUG
  81. printk("NWFPE: emulating opcode %08x\n", opcode);
  82. #endif
  83. code = opcode & 0x00000f00;
  84. if (code == 0x00000100 || code == 0x00000200) {
  85. /* For coprocessor 1 or 2 (FPA11) */
  86. code = opcode & 0x0e000000;
  87. if (code == 0x0e000000) {
  88. if (opcode & 0x00000010) {
  89. /* Emulate conversion opcodes. */
  90. /* Emulate register transfer opcodes. */
  91. /* Emulate comparison opcodes. */
  92. return EmulateCPRT(opcode);
  93. } else {
  94. /* Emulate monadic arithmetic opcodes. */
  95. /* Emulate dyadic arithmetic opcodes. */
  96. return EmulateCPDO(opcode);
  97. }
  98. } else if (code == 0x0c000000) {
  99. /* Emulate load/store opcodes. */
  100. /* Emulate load/store multiple opcodes. */
  101. return EmulateCPDT(opcode);
  102. }
  103. }
  104. /* Invalid instruction detected. Return FALSE. */
  105. return 0;
  106. }