fpa11.c 3.1 KB

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