fpa11.c 3.1 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. #include <asm/system.h>
  25. /* Reset the FPA11 chip. Called to initialize and reset the emulator. */
  26. static void resetFPA11(void)
  27. {
  28. int i;
  29. FPA11 *fpa11 = GET_FPA11();
  30. /* initialize the register type array */
  31. for (i = 0; i <= 7; i++) {
  32. fpa11->fType[i] = typeNone;
  33. }
  34. /* FPSR: set system id to FP_EMULATOR, set AC, clear all other bits */
  35. fpa11->fpsr = FP_EMULATOR | BIT_AC;
  36. }
  37. int8 SetRoundingMode(const unsigned int opcode)
  38. {
  39. switch (opcode & MASK_ROUNDING_MODE) {
  40. default:
  41. case ROUND_TO_NEAREST:
  42. return float_round_nearest_even;
  43. case ROUND_TO_PLUS_INFINITY:
  44. return float_round_up;
  45. case ROUND_TO_MINUS_INFINITY:
  46. return float_round_down;
  47. case ROUND_TO_ZERO:
  48. return float_round_to_zero;
  49. }
  50. }
  51. int8 SetRoundingPrecision(const unsigned int opcode)
  52. {
  53. #ifdef CONFIG_FPE_NWFPE_XP
  54. switch (opcode & MASK_ROUNDING_PRECISION) {
  55. case ROUND_SINGLE:
  56. return 32;
  57. case ROUND_DOUBLE:
  58. return 64;
  59. case ROUND_EXTENDED:
  60. return 80;
  61. default:
  62. return 80;
  63. }
  64. #endif
  65. return 80;
  66. }
  67. void nwfpe_init_fpa(union fp_state *fp)
  68. {
  69. FPA11 *fpa11 = (FPA11 *)fp;
  70. #ifdef NWFPE_DEBUG
  71. printk("NWFPE: setting up state.\n");
  72. #endif
  73. memset(fpa11, 0, sizeof(FPA11));
  74. resetFPA11();
  75. fpa11->initflag = 1;
  76. }
  77. /* Emulate the instruction in the opcode. */
  78. unsigned int EmulateAll(unsigned int opcode)
  79. {
  80. unsigned int code;
  81. #ifdef NWFPE_DEBUG
  82. printk("NWFPE: emulating opcode %08x\n", opcode);
  83. #endif
  84. code = opcode & 0x00000f00;
  85. if (code == 0x00000100 || code == 0x00000200) {
  86. /* For coprocessor 1 or 2 (FPA11) */
  87. code = opcode & 0x0e000000;
  88. if (code == 0x0e000000) {
  89. if (opcode & 0x00000010) {
  90. /* Emulate conversion opcodes. */
  91. /* Emulate register transfer opcodes. */
  92. /* Emulate comparison opcodes. */
  93. return EmulateCPRT(opcode);
  94. } else {
  95. /* Emulate monadic arithmetic opcodes. */
  96. /* Emulate dyadic arithmetic opcodes. */
  97. return EmulateCPDO(opcode);
  98. }
  99. } else if (code == 0x0c000000) {
  100. /* Emulate load/store opcodes. */
  101. /* Emulate load/store multiple opcodes. */
  102. return EmulateCPDT(opcode);
  103. }
  104. }
  105. /* Invalid instruction detected. Return FALSE. */
  106. return 0;
  107. }