fpu.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*-
  2. * Copyright (c) 1990 The Regents of the University of California.
  3. * All rights reserved.
  4. *
  5. * This code is derived from software contributed to Berkeley by
  6. * William Jolitz.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 4. Neither the name of the University nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  21. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * from: @(#)npx.h 5.3 (Berkeley) 1/18/91
  33. * $FreeBSD$
  34. */
  35. /*
  36. * Floating Point Data Structures and Constants
  37. * W. Jolitz 1/90
  38. */
  39. #ifndef _X86_FPU_H_
  40. #define _X86_FPU_H_
  41. #define __aligned(x) __attribute__((aligned(x)))
  42. /* Environment information of floating point unit. */
  43. struct env87 {
  44. int32_t en_cw; /* control word (16bits) */
  45. int32_t en_sw; /* status word (16bits) */
  46. int32_t en_tw; /* tag word (16bits) */
  47. int32_t en_fip; /* fp instruction pointer */
  48. uint16_t en_fcs; /* fp code segment selector */
  49. uint16_t en_opcode; /* opcode last executed (11 bits) */
  50. int32_t en_foo; /* fp operand offset */
  51. int32_t en_fos; /* fp operand segment selector */
  52. };
  53. /* Contents of each x87 floating point accumulator. */
  54. struct fpacc87 {
  55. uint8_t fp_bytes[10];
  56. };
  57. /* Floating point context. (i386 fnsave/frstor) */
  58. struct save87 {
  59. struct env87 sv_env; /* floating point control/status */
  60. struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */
  61. uint8_t sv_pad0[4]; /* saved status word (now unused) */
  62. uint8_t sv_pad[64];
  63. };
  64. /* Contents of each SSE extended accumulator. */
  65. struct xmmacc {
  66. uint8_t xmm_bytes[16];
  67. };
  68. /* Contents of the upper 16 bytes of each AVX extended accumulator. */
  69. struct ymmacc {
  70. uint8_t ymm_bytes[16];
  71. };
  72. /* Rename structs below depending on machine architecture. */
  73. #ifdef __i386__
  74. #define __envxmm32 envxmm
  75. #else
  76. #define __envxmm32 envxmm32
  77. #define __envxmm64 envxmm
  78. #endif
  79. struct __envxmm32 {
  80. uint16_t en_cw; /* control word (16bits) */
  81. uint16_t en_sw; /* status word (16bits) */
  82. uint16_t en_tw; /* tag word (16bits) */
  83. uint16_t en_opcode; /* opcode last executed (11 bits) */
  84. uint32_t en_fip; /* fp instruction pointer */
  85. uint16_t en_fcs; /* fp code segment selector */
  86. uint16_t en_pad0; /* padding */
  87. uint32_t en_foo; /* fp operand offset */
  88. uint16_t en_fos; /* fp operand segment selector */
  89. uint16_t en_pad1; /* padding */
  90. uint32_t en_mxcsr; /* SSE control/status register */
  91. uint32_t en_mxcsr_mask; /* valid bits in mxcsr */
  92. };
  93. struct __envxmm64 {
  94. uint16_t en_cw; /* control word (16bits) */
  95. uint16_t en_sw; /* status word (16bits) */
  96. uint8_t en_tw; /* tag word (8bits) */
  97. uint8_t en_zero;
  98. uint16_t en_opcode; /* opcode last executed (11 bits ) */
  99. uint64_t en_rip; /* fp instruction pointer */
  100. uint64_t en_rdp; /* fp operand pointer */
  101. uint32_t en_mxcsr; /* SSE control/status register */
  102. uint32_t en_mxcsr_mask; /* valid bits in mxcsr */
  103. };
  104. /* Floating point context. (i386 fxsave/fxrstor) */
  105. struct savexmm {
  106. struct __envxmm32 sv_env;
  107. struct {
  108. struct fpacc87 fp_acc;
  109. uint8_t fp_pad[6]; /* padding */
  110. } sv_fp[8];
  111. struct xmmacc sv_xmm[8];
  112. uint8_t sv_pad[224];
  113. } __aligned(16);
  114. #ifdef __i386__
  115. union savefpu {
  116. struct save87 sv_87;
  117. struct savexmm sv_xmm;
  118. };
  119. #else
  120. /* Floating point context. (amd64 fxsave/fxrstor) */
  121. struct savefpu {
  122. struct __envxmm64 sv_env;
  123. struct {
  124. struct fpacc87 fp_acc;
  125. uint8_t fp_pad[6]; /* padding */
  126. } sv_fp[8];
  127. struct xmmacc sv_xmm[16];
  128. uint8_t sv_pad[96];
  129. } __aligned(16);
  130. #endif
  131. struct xstate_hdr {
  132. uint64_t xstate_bv;
  133. uint64_t xstate_xcomp_bv;
  134. uint8_t xstate_rsrv0[8];
  135. uint8_t xstate_rsrv[40];
  136. };
  137. #define XSTATE_XCOMP_BV_COMPACT (1ULL << 63)
  138. struct savexmm_xstate {
  139. struct xstate_hdr sx_hd;
  140. struct ymmacc sx_ymm[16];
  141. };
  142. struct savexmm_ymm {
  143. struct __envxmm32 sv_env;
  144. struct {
  145. struct fpacc87 fp_acc;
  146. int8_t fp_pad[6]; /* padding */
  147. } sv_fp[8];
  148. struct xmmacc sv_xmm[16];
  149. uint8_t sv_pad[96];
  150. struct savexmm_xstate sv_xstate;
  151. } __aligned(64);
  152. struct savefpu_xstate {
  153. struct xstate_hdr sx_hd;
  154. struct ymmacc sx_ymm[16];
  155. };
  156. struct savefpu_ymm {
  157. struct __envxmm64 sv_env;
  158. struct {
  159. struct fpacc87 fp_acc;
  160. int8_t fp_pad[6]; /* padding */
  161. } sv_fp[8];
  162. struct xmmacc sv_xmm[16];
  163. uint8_t sv_pad[96];
  164. struct savefpu_xstate sv_xstate;
  165. } __aligned(64);
  166. #undef __envxmm32
  167. #undef __envxmm64
  168. /*
  169. * The hardware default control word for i387's and later coprocessors is
  170. * 0x37F, giving:
  171. *
  172. * round to nearest
  173. * 64-bit precision
  174. * all exceptions masked.
  175. *
  176. * FreeBSD/i386 uses 53 bit precision for things like fadd/fsub/fsqrt etc
  177. * because of the difference between memory and fpu register stack arguments.
  178. * If its using an intermediate fpu register, it has 80/64 bits to work
  179. * with. If it uses memory, it has 64/53 bits to work with. However,
  180. * gcc is aware of this and goes to a fair bit of trouble to make the
  181. * best use of it.
  182. *
  183. * This is mostly academic for AMD64, because the ABI prefers the use
  184. * SSE2 based math. For FreeBSD/amd64, we go with the default settings.
  185. */
  186. #define __INITIAL_FPUCW__ 0x037F
  187. #define __INITIAL_FPUCW_I386__ 0x127F
  188. #define __INITIAL_NPXCW__ __INITIAL_FPUCW_I386__
  189. #define __INITIAL_MXCSR__ 0x1F80
  190. #define __INITIAL_MXCSR_MASK__ 0xFFBF
  191. /*
  192. * The current value of %xcr0 is saved in the sv_pad[] field of the FPU
  193. * state in the NT_X86_XSTATE note in core dumps. This offset is chosen
  194. * to match the offset used by NT_X86_XSTATE in other systems.
  195. */
  196. #define X86_XSTATE_XCR0_OFFSET 464
  197. #endif /* !_X86_FPU_H_ */