fpu_control.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* FPU control word definitions. ARM version.
  2. Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _FPU_CONTROL_H
  16. #define _FPU_CONTROL_H
  17. #ifdef __VFP_FP__
  18. /* masking of interrupts */
  19. #define _FPU_MASK_IM 0x00000100 /* invalid operation */
  20. #define _FPU_MASK_ZM 0x00000200 /* divide by zero */
  21. #define _FPU_MASK_OM 0x00000400 /* overflow */
  22. #define _FPU_MASK_UM 0x00000800 /* underflow */
  23. #define _FPU_MASK_PM 0x00001000 /* inexact */
  24. /* Some bits in the FPSCR are not yet defined. They must be preserved when
  25. modifying the contents. */
  26. #define _FPU_RESERVED 0x0e08e0e0
  27. #define _FPU_DEFAULT 0x00000000
  28. /* Default + exceptions enabled. */
  29. #define _FPU_IEEE (_FPU_DEFAULT | 0x00001f00)
  30. /* Type of the control word. */
  31. typedef unsigned int fpu_control_t;
  32. /* Macros for accessing the hardware control word. */
  33. /* This is fmrx %0, fpscr. */
  34. #define _FPU_GETCW(cw) \
  35. __asm__ __volatile__ ("mrc p10, 7, %0, cr1, cr0, 0" : "=r" (cw))
  36. /* This is fmxr fpscr, %0. */
  37. #define _FPU_SETCW(cw) \
  38. __asm__ __volatile__ ("mcr p10, 7, %0, cr1, cr0, 0" : : "r" (cw))
  39. #elif defined __MAVERICK__
  40. /* DSPSC register: (from EP9312 User's Guide)
  41. *
  42. * bits 31..29 - DAID
  43. * bits 28..26 - HVID
  44. * bits 25..24 - RSVD
  45. * bit 23 - ISAT
  46. * bit 22 - UI
  47. * bit 21 - INT
  48. * bit 20 - AEXC
  49. * bits 19..18 - SAT
  50. * bits 17..16 - FCC
  51. * bit 15 - V
  52. * bit 14 - FWDEN
  53. * bit 13 - Invalid
  54. * bit 12 - Denorm
  55. * bits 11..10 - RM
  56. * bits 9..5 - IXE, UFE, OFE, RSVD, IOE
  57. * bits 4..0 - IX, UF, OF, RSVD, IO
  58. */
  59. /* masking of interrupts */
  60. #define _FPU_MASK_IM (1 << 5) /* invalid operation */
  61. #define _FPU_MASK_ZM 0 /* divide by zero */
  62. #define _FPU_MASK_OM (1 << 7) /* overflow */
  63. #define _FPU_MASK_UM (1 << 8) /* underflow */
  64. #define _FPU_MASK_PM (1 << 9) /* inexact */
  65. #define _FPU_MASK_DM 0 /* denormalized operation */
  66. #define _FPU_RESERVED 0xfffff000 /* These bits are reserved. */
  67. #define _FPU_DEFAULT 0x00b00000 /* Default value. */
  68. #define _FPU_IEEE 0x00b003a0 /* Default + exceptions enabled. */
  69. /* Type of the control word. */
  70. typedef unsigned int fpu_control_t;
  71. /* Macros for accessing the hardware control word. */
  72. #define _FPU_GETCW(cw) ({ \
  73. register int __t1, __t2; \
  74. \
  75. __asm__ __volatile__ ( \
  76. "cfmvr64l %1, mvdx0\n\t" \
  77. "cfmvr64h %2, mvdx0\n\t" \
  78. "cfmv32sc mvdx0, dspsc\n\t" \
  79. "cfmvr64l %0, mvdx0\n\t" \
  80. "cfmv64lr mvdx0, %1\n\t" \
  81. "cfmv64hr mvdx0, %2" \
  82. : "=r" (cw), "=r" (__t1), "=r" (__t2) \
  83. ); \
  84. })
  85. #define _FPU_SETCW(cw) ({ \
  86. register int __t0, __t1, __t2; \
  87. \
  88. __asm__ __volatile__ ( \
  89. "cfmvr64l %1, mvdx0\n\t" \
  90. "cfmvr64h %2, mvdx0\n\t" \
  91. "cfmv64lr mvdx0, %0\n\t" \
  92. "cfmvsc32 dspsc, mvdx0\n\t" \
  93. "cfmv64lr mvdx0, %1\n\t" \
  94. "cfmv64hr mvdx0, %2" \
  95. : "=r" (__t0), "=r" (__t1), "=r" (__t2) \
  96. : "0" (cw) \
  97. ); \
  98. })
  99. #else /* !__MAVERICK__ */
  100. /* We have a slight terminology confusion here. On the ARM, the register
  101. * we're interested in is actually the FPU status word - the FPU control
  102. * word is something different (which is implementation-defined and only
  103. * accessible from supervisor mode.)
  104. *
  105. * The FPSR looks like this:
  106. *
  107. * 31-24 23-16 15-8 7-0
  108. * | system ID | trap enable | system control | exception flags |
  109. *
  110. * We ignore the system ID bits; for interest's sake they are:
  111. *
  112. * 0000 "old" FPE
  113. * 1000 FPPC hardware
  114. * 0001 FPE 400
  115. * 1001 FPA hardware
  116. *
  117. * The trap enable and exception flags are both structured like this:
  118. *
  119. * 7 - 5 4 3 2 1 0
  120. * | reserved | INX | UFL | OFL | DVZ | IVO |
  121. *
  122. * where a `1' bit in the enable byte means that the trap can occur, and
  123. * a `1' bit in the flags byte means the exception has occurred.
  124. *
  125. * The exceptions are:
  126. *
  127. * IVO - invalid operation
  128. * DVZ - divide by zero
  129. * OFL - overflow
  130. * UFL - underflow
  131. * INX - inexact (do not use; implementations differ)
  132. *
  133. * The system control byte looks like this:
  134. *
  135. * 7-5 4 3 2 1 0
  136. * | reserved | AC | EP | SO | NE | ND |
  137. *
  138. * where the bits mean
  139. *
  140. * ND - no denormalised numbers (force them all to zero)
  141. * NE - enable NaN exceptions
  142. * SO - synchronous operation
  143. * EP - use expanded packed-decimal format
  144. * AC - use alternate definition for C flag on compare operations
  145. */
  146. /* masking of interrupts */
  147. #define _FPU_MASK_IM 0x00010000 /* invalid operation */
  148. #define _FPU_MASK_ZM 0x00020000 /* divide by zero */
  149. #define _FPU_MASK_OM 0x00040000 /* overflow */
  150. #define _FPU_MASK_UM 0x00080000 /* underflow */
  151. #define _FPU_MASK_PM 0x00100000 /* inexact */
  152. #define _FPU_MASK_DM 0x00000000 /* denormalized operation */
  153. /* The system id bytes cannot be changed.
  154. Only the bottom 5 bits in the trap enable byte can be changed.
  155. Only the bottom 5 bits in the system control byte can be changed.
  156. Only the bottom 5 bits in the exception flags are used.
  157. The exception flags are set by the fpu, but can be zeroed by the user. */
  158. #define _FPU_RESERVED 0xffe0e0e0 /* These bits are reserved. */
  159. /* The fdlibm code requires strict IEEE double precision arithmetic,
  160. no interrupts for exceptions, rounding to nearest. Changing the
  161. rounding mode will break long double I/O. Turn on the AC bit,
  162. the compiler generates code that assumes it is on. */
  163. #define _FPU_DEFAULT 0x00001000 /* Default value. */
  164. #define _FPU_IEEE 0x001f1000 /* Default + exceptions enabled. */
  165. /* Type of the control word. */
  166. typedef unsigned int fpu_control_t;
  167. /* Macros for accessing the hardware control word. */
  168. #define _FPU_GETCW(cw) __asm__ ("rfs %0" : "=r" (cw))
  169. #define _FPU_SETCW(cw) __asm__ ("wfs %0" : : "r" (cw))
  170. #endif /* __MAVERICK__ */
  171. #if 0
  172. /* Default control word set at startup. */
  173. extern fpu_control_t __fpu_control;
  174. #endif
  175. #endif /* _FPU_CONTROL_H */