bsd_npx.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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/i386/include/npx.h,v 1.29.2.1 2006/07/01 00:57:55 davidxu Exp $
  34. */
  35. /*
  36. * 287/387 NPX Coprocessor Data Structures and Constants
  37. * W. Jolitz 1/90
  38. */
  39. #ifndef _MACHINE_NPX_H_
  40. #define _MACHINE_NPX_H_
  41. /* Environment information of floating point unit */
  42. struct env87 {
  43. long en_cw; /* control word (16bits) */
  44. long en_sw; /* status word (16bits) */
  45. long en_tw; /* tag word (16bits) */
  46. long en_fip; /* floating point instruction pointer */
  47. unsigned short en_fcs; /* floating code segment selector */
  48. unsigned short en_opcode; /* opcode last executed (11 bits ) */
  49. long en_foo; /* floating operand offset */
  50. long en_fos; /* floating operand segment selector */
  51. };
  52. /* Contents of each floating point accumulator */
  53. struct fpacc87 {
  54. #ifdef dontdef /* too unportable */
  55. unsigned long fp_mantlo; /* mantissa low (31:0) */
  56. unsigned long fp_manthi; /* mantissa high (63:32) */
  57. int fp_exp:15; /* exponent */
  58. int fp_sgn:1; /* mantissa sign */
  59. #else
  60. unsigned char fp_bytes[10];
  61. #endif
  62. };
  63. /* Floating point context */
  64. struct save87 {
  65. struct env87 sv_env; /* floating point control/status */
  66. struct fpacc87 sv_ac[8]; /* accumulator contents, 0-7 */
  67. unsigned char sv_pad0[4]; /* padding for (now unused) saved status word */
  68. /*
  69. * Bogus padding for emulators. Emulators should use their own
  70. * struct and arrange to store into this struct (ending here)
  71. * before it is inspected for ptracing or for core dumps. Some
  72. * emulators overwrite the whole struct. We have no good way of
  73. * knowing how much padding to leave. Leave just enough for the
  74. * GPL emulator's i387_union (176 bytes total).
  75. */
  76. unsigned char sv_pad[64]; /* padding; used by emulators */
  77. };
  78. struct envxmm {
  79. uint16_t en_cw; /* control word (16bits) */
  80. uint16_t en_sw; /* status word (16bits) */
  81. uint16_t en_tw; /* tag word (16bits) */
  82. uint16_t en_opcode; /* opcode last executed (11 bits ) */
  83. uint32_t en_fip; /* floating point instruction pointer */
  84. uint16_t en_fcs; /* floating code segment selector */
  85. uint16_t en_pad0; /* padding */
  86. uint32_t en_foo; /* floating operand offset */
  87. uint16_t en_fos; /* floating operand segment selector */
  88. uint16_t en_pad1; /* padding */
  89. uint32_t en_mxcsr; /* SSE sontorol/status register */
  90. uint32_t en_mxcsr_mask; /* valid bits in mxcsr */
  91. };
  92. /* Contents of each SSE extended accumulator */
  93. struct xmmacc {
  94. unsigned char xmm_bytes[16];
  95. };
  96. struct savexmm {
  97. struct envxmm sv_env;
  98. struct {
  99. struct fpacc87 fp_acc;
  100. unsigned char fp_pad[6]; /* padding */
  101. } sv_fp[8];
  102. struct xmmacc sv_xmm[8];
  103. unsigned char sv_pad[224];
  104. } __attribute__((__aligned__(16)));
  105. union savefpu {
  106. struct save87 sv_87;
  107. struct savexmm sv_xmm;
  108. };
  109. /*
  110. * The hardware default control word for i387's and later coprocessors is
  111. * 0x37F, giving:
  112. *
  113. * round to nearest
  114. * 64-bit precision
  115. * all exceptions masked.
  116. *
  117. * We modify the affine mode bit and precision bits in this to give:
  118. *
  119. * affine mode for 287's (if they work at all) (1 in bitfield 1<<12)
  120. * 53-bit precision (2 in bitfield 3<<8)
  121. *
  122. * 64-bit precision often gives bad results with high level languages
  123. * because it makes the results of calculations depend on whether
  124. * intermediate values are stored in memory or in FPU registers.
  125. */
  126. #define __INITIAL_NPXCW__ 0x127F
  127. #define __INITIAL_MXCSR__ 0x1F80
  128. #ifdef _KERNEL
  129. #define IO_NPX 0x0F0 /* Numeric Coprocessor */
  130. #define IO_NPXSIZE 16 /* 80387/80487 NPX registers */
  131. #define IRQ_NPX 13
  132. /* full reset on some systems, NOP on others */
  133. #define npx_full_reset() outb(IO_NPX + 1, 0)
  134. int npxdna(void);
  135. void npxdrop(void);
  136. void npxexit(struct thread *td);
  137. int npxformat(void);
  138. int npxgetregs(struct thread *td, union savefpu *addr);
  139. void npxinit(unsigned short control);
  140. void npxsave(union savefpu *addr);
  141. void npxsetregs(struct thread *td, union savefpu *addr);
  142. int npxtrap(void);
  143. #endif
  144. #endif /* !_MACHINE_NPX_H_ */