bsd_fpu.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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: src/sys/x86/include/fpu.h,v 1.1 2012/03/16 20:24:30 tijl Exp $
  34. */
  35. /*
  36. * Floating Point Data Structures and Constants
  37. * W. Jolitz 1/90
  38. */
  39. #ifndef _BSD_FPU_H_
  40. #define _BSD_FPU_H_
  41. #include "types-compat.h"
  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. /*
  63. * Bogus padding for emulators. Emulators should use their own
  64. * struct and arrange to store into this struct (ending here)
  65. * before it is inspected for ptracing or for core dumps. Some
  66. * emulators overwrite the whole struct. We have no good way of
  67. * knowing how much padding to leave. Leave just enough for the
  68. * GPL emulator's i387_union (176 bytes total).
  69. */
  70. uint8_t sv_pad[64]; /* padding; used by emulators */
  71. };
  72. /* Contents of each SSE extended accumulator. */
  73. struct xmmacc {
  74. uint8_t xmm_bytes[16];
  75. };
  76. /* Contents of the upper 16 bytes of each AVX extended accumulator. */
  77. struct ymmacc {
  78. uint8_t ymm_bytes[16];
  79. };
  80. /* Rename structs below depending on machine architecture. */
  81. #ifdef __i386__
  82. #define __envxmm32 envxmm
  83. #else
  84. #define __envxmm32 envxmm32
  85. #define __envxmm64 envxmm
  86. #endif
  87. struct __envxmm32 {
  88. uint16_t en_cw; /* control word (16bits) */
  89. uint16_t en_sw; /* status word (16bits) */
  90. uint16_t en_tw; /* tag word (16bits) */
  91. uint16_t en_opcode; /* opcode last executed (11 bits) */
  92. uint32_t en_fip; /* fp instruction pointer */
  93. uint16_t en_fcs; /* fp code segment selector */
  94. uint16_t en_pad0; /* padding */
  95. uint32_t en_foo; /* fp operand offset */
  96. uint16_t en_fos; /* fp operand segment selector */
  97. uint16_t en_pad1; /* padding */
  98. uint32_t en_mxcsr; /* SSE control/status register */
  99. uint32_t en_mxcsr_mask; /* valid bits in mxcsr */
  100. };
  101. struct __envxmm64 {
  102. uint16_t en_cw; /* control word (16bits) */
  103. uint16_t en_sw; /* status word (16bits) */
  104. uint8_t en_tw; /* tag word (8bits) */
  105. uint8_t en_zero;
  106. uint16_t en_opcode; /* opcode last executed (11 bits ) */
  107. uint64_t en_rip; /* fp instruction pointer */
  108. uint64_t en_rdp; /* fp operand pointer */
  109. uint32_t en_mxcsr; /* SSE control/status register */
  110. uint32_t en_mxcsr_mask; /* valid bits in mxcsr */
  111. };
  112. /* Floating point context. (i386 fxsave/fxrstor) */
  113. struct savexmm {
  114. struct __envxmm32 sv_env;
  115. struct {
  116. struct fpacc87 fp_acc;
  117. uint8_t fp_pad[6]; /* padding */
  118. } sv_fp[8];
  119. struct xmmacc sv_xmm[8];
  120. uint8_t sv_pad[224];
  121. } __attribute__ ((aligned(16)));
  122. #ifdef __i386__
  123. union savefpu {
  124. struct save87 sv_87;
  125. struct savexmm sv_xmm;
  126. };
  127. #else
  128. /* Floating point context. (amd64 fxsave/fxrstor) */
  129. struct savefpu {
  130. struct __envxmm64 sv_env;
  131. struct {
  132. struct fpacc87 fp_acc;
  133. uint8_t fp_pad[6]; /* padding */
  134. } sv_fp[8];
  135. struct xmmacc sv_xmm[16];
  136. uint8_t sv_pad[96];
  137. } __attribute__ ((aligned(16)));
  138. #endif
  139. struct xstate_hdr {
  140. uint64_t xstate_bv;
  141. uint8_t xstate_rsrv0[16];
  142. uint8_t xstate_rsrv[40];
  143. };
  144. struct savexmm_xstate {
  145. struct xstate_hdr sx_hd;
  146. struct ymmacc sx_ymm[16];
  147. };
  148. struct savexmm_ymm {
  149. struct __envxmm32 sv_env;
  150. struct {
  151. struct fpacc87 fp_acc;
  152. int8_t fp_pad[6]; /* padding */
  153. } sv_fp[8];
  154. struct xmmacc sv_xmm[16];
  155. uint8_t sv_pad[96];
  156. struct savexmm_xstate sv_xstate;
  157. } __attribute__ ((aligned(16)));
  158. struct savefpu_xstate {
  159. struct xstate_hdr sx_hd;
  160. struct ymmacc sx_ymm[16];
  161. };
  162. struct savefpu_ymm {
  163. struct __envxmm64 sv_env;
  164. struct {
  165. struct fpacc87 fp_acc;
  166. int8_t fp_pad[6]; /* padding */
  167. } sv_fp[8];
  168. struct xmmacc sv_xmm[16];
  169. uint8_t sv_pad[96];
  170. struct savefpu_xstate sv_xstate;
  171. } __attribute__ ((aligned(64)));
  172. #undef __envxmm32
  173. #undef __envxmm64
  174. /*
  175. * The hardware default control word for i387's and later coprocessors is
  176. * 0x37F, giving:
  177. *
  178. * round to nearest
  179. * 64-bit precision
  180. * all exceptions masked.
  181. *
  182. * FreeBSD/i386 uses 53 bit precision for things like fadd/fsub/fsqrt etc
  183. * because of the difference between memory and fpu register stack arguments.
  184. * If its using an intermediate fpu register, it has 80/64 bits to work
  185. * with. If it uses memory, it has 64/53 bits to work with. However,
  186. * gcc is aware of this and goes to a fair bit of trouble to make the
  187. * best use of it.
  188. *
  189. * This is mostly academic for AMD64, because the ABI prefers the use
  190. * SSE2 based math. For FreeBSD/amd64, we go with the default settings.
  191. */
  192. #define __INITIAL_FPUCW__ 0x037F
  193. #define __INITIAL_FPUCW_I386__ 0x127F
  194. #define __INITIAL_NPXCW__ __INITIAL_FPUCW_I386__
  195. #define __INITIAL_MXCSR__ 0x1F80
  196. #define __INITIAL_MXCSR_MASK__ 0xFFBF
  197. #endif /* !_BSD_FPU_H_ */