fpu_emu.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*---------------------------------------------------------------------------+
  2. | fpu_emu.h |
  3. | |
  4. | Copyright (C) 1992,1993,1994,1997 |
  5. | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, |
  6. | Australia. E-mail billm@suburbia.net |
  7. | |
  8. +---------------------------------------------------------------------------*/
  9. #ifndef _FPU_EMU_H_
  10. #define _FPU_EMU_H_
  11. /*
  12. * Define PECULIAR_486 to get a closer approximation to 80486 behaviour,
  13. * rather than behaviour which appears to be cleaner.
  14. * This is a matter of opinion: for all I know, the 80486 may simply
  15. * be complying with the IEEE spec. Maybe one day I'll get to see the
  16. * spec...
  17. */
  18. #define PECULIAR_486
  19. #ifdef __ASSEMBLY__
  20. #include "fpu_asm.h"
  21. #define Const(x) $##x
  22. #else
  23. #define Const(x) x
  24. #endif
  25. #define EXP_BIAS Const(0)
  26. #define EXP_OVER Const(0x4000) /* smallest invalid large exponent */
  27. #define EXP_UNDER Const(-0x3fff) /* largest invalid small exponent */
  28. #define EXP_WAY_UNDER Const(-0x6000) /* Below the smallest denormal, but
  29. still a 16 bit nr. */
  30. #define EXP_Infinity EXP_OVER
  31. #define EXP_NaN EXP_OVER
  32. #define EXTENDED_Ebias Const(0x3fff)
  33. #define EXTENDED_Emin (-0x3ffe) /* smallest valid exponent */
  34. #define SIGN_POS Const(0)
  35. #define SIGN_NEG Const(0x80)
  36. #define SIGN_Positive Const(0)
  37. #define SIGN_Negative Const(0x8000)
  38. /* Keep the order TAG_Valid, TAG_Zero, TW_Denormal */
  39. /* The following fold to 2 (Special) in the Tag Word */
  40. #define TW_Denormal Const(4) /* De-normal */
  41. #define TW_Infinity Const(5) /* + or - infinity */
  42. #define TW_NaN Const(6) /* Not a Number */
  43. #define TW_Unsupported Const(7) /* Not supported by an 80486 */
  44. #define TAG_Valid Const(0) /* valid */
  45. #define TAG_Zero Const(1) /* zero */
  46. #define TAG_Special Const(2) /* De-normal, + or - infinity,
  47. or Not a Number */
  48. #define TAG_Empty Const(3) /* empty */
  49. #define TAG_Error Const(0x80) /* probably need to abort */
  50. #define LOADED_DATA Const(10101) /* Special st() number to identify
  51. loaded data (not on stack). */
  52. /* A few flags (must be >= 0x10). */
  53. #define REV 0x10
  54. #define DEST_RM 0x20
  55. #define LOADED 0x40
  56. #define FPU_Exception Const(0x80000000) /* Added to tag returns. */
  57. #ifndef __ASSEMBLY__
  58. #include "fpu_system.h"
  59. #include <uapi/asm/sigcontext.h> /* for struct _fpstate */
  60. #include <asm/math_emu.h>
  61. #include <linux/linkage.h>
  62. /*
  63. #define RE_ENTRANT_CHECKING
  64. */
  65. #ifdef RE_ENTRANT_CHECKING
  66. extern u_char emulating;
  67. # define RE_ENTRANT_CHECK_OFF emulating = 0
  68. # define RE_ENTRANT_CHECK_ON emulating = 1
  69. #else
  70. # define RE_ENTRANT_CHECK_OFF
  71. # define RE_ENTRANT_CHECK_ON
  72. #endif /* RE_ENTRANT_CHECKING */
  73. #define FWAIT_OPCODE 0x9b
  74. #define OP_SIZE_PREFIX 0x66
  75. #define ADDR_SIZE_PREFIX 0x67
  76. #define PREFIX_CS 0x2e
  77. #define PREFIX_DS 0x3e
  78. #define PREFIX_ES 0x26
  79. #define PREFIX_SS 0x36
  80. #define PREFIX_FS 0x64
  81. #define PREFIX_GS 0x65
  82. #define PREFIX_REPE 0xf3
  83. #define PREFIX_REPNE 0xf2
  84. #define PREFIX_LOCK 0xf0
  85. #define PREFIX_CS_ 1
  86. #define PREFIX_DS_ 2
  87. #define PREFIX_ES_ 3
  88. #define PREFIX_FS_ 4
  89. #define PREFIX_GS_ 5
  90. #define PREFIX_SS_ 6
  91. #define PREFIX_DEFAULT 7
  92. struct address {
  93. unsigned int offset;
  94. unsigned int selector:16;
  95. unsigned int opcode:11;
  96. unsigned int empty:5;
  97. };
  98. struct fpu__reg {
  99. unsigned sigl;
  100. unsigned sigh;
  101. short exp;
  102. };
  103. typedef void (*FUNC) (void);
  104. typedef struct fpu__reg FPU_REG;
  105. typedef void (*FUNC_ST0) (FPU_REG *st0_ptr, u_char st0_tag);
  106. typedef struct {
  107. u_char address_size, operand_size, segment;
  108. } overrides;
  109. /* This structure is 32 bits: */
  110. typedef struct {
  111. overrides override;
  112. u_char default_mode;
  113. } fpu_addr_modes;
  114. /* PROTECTED has a restricted meaning in the emulator; it is used
  115. to signal that the emulator needs to do special things to ensure
  116. that protection is respected in a segmented model. */
  117. #define PROTECTED 4
  118. #define SIXTEEN 1 /* We rely upon this being 1 (true) */
  119. #define VM86 SIXTEEN
  120. #define PM16 (SIXTEEN | PROTECTED)
  121. #define SEG32 PROTECTED
  122. extern u_char const data_sizes_16[32];
  123. #define register_base ((u_char *) registers )
  124. #define fpu_register(x) ( * ((FPU_REG *)( register_base + 10 * (x & 7) )) )
  125. #define st(x) ( * ((FPU_REG *)( register_base + 10 * ((top+x) & 7) )) )
  126. #define STACK_OVERFLOW (FPU_stackoverflow(&st_new_ptr))
  127. #define NOT_EMPTY(i) (!FPU_empty_i(i))
  128. #define NOT_EMPTY_ST0 (st0_tag ^ TAG_Empty)
  129. #define poppop() { FPU_pop(); FPU_pop(); }
  130. /* push() does not affect the tags */
  131. #define push() { top--; }
  132. #define signbyte(a) (((u_char *)(a))[9])
  133. #define getsign(a) (signbyte(a) & 0x80)
  134. #define setsign(a,b) { if (b) signbyte(a) |= 0x80; else signbyte(a) &= 0x7f; }
  135. #define copysign(a,b) { if (getsign(a)) signbyte(b) |= 0x80; \
  136. else signbyte(b) &= 0x7f; }
  137. #define changesign(a) { signbyte(a) ^= 0x80; }
  138. #define setpositive(a) { signbyte(a) &= 0x7f; }
  139. #define setnegative(a) { signbyte(a) |= 0x80; }
  140. #define signpositive(a) ( (signbyte(a) & 0x80) == 0 )
  141. #define signnegative(a) (signbyte(a) & 0x80)
  142. static inline void reg_copy(FPU_REG const *x, FPU_REG *y)
  143. {
  144. *(short *)&(y->exp) = *(const short *)&(x->exp);
  145. *(long long *)&(y->sigl) = *(const long long *)&(x->sigl);
  146. }
  147. #define exponent(x) (((*(short *)&((x)->exp)) & 0x7fff) - EXTENDED_Ebias)
  148. #define setexponentpos(x,y) { (*(short *)&((x)->exp)) = \
  149. ((y) + EXTENDED_Ebias) & 0x7fff; }
  150. #define exponent16(x) (*(short *)&((x)->exp))
  151. #define setexponent16(x,y) { (*(short *)&((x)->exp)) = (y); }
  152. #define addexponent(x,y) { (*(short *)&((x)->exp)) += (y); }
  153. #define stdexp(x) { (*(short *)&((x)->exp)) += EXTENDED_Ebias; }
  154. #define isdenormal(ptr) (exponent(ptr) == EXP_BIAS+EXP_UNDER)
  155. #define significand(x) ( ((unsigned long long *)&((x)->sigl))[0] )
  156. /*----- Prototypes for functions written in assembler -----*/
  157. /* extern void reg_move(FPU_REG *a, FPU_REG *b); */
  158. asmlinkage int FPU_normalize(FPU_REG *x);
  159. asmlinkage int FPU_normalize_nuo(FPU_REG *x);
  160. asmlinkage int FPU_u_sub(FPU_REG const *arg1, FPU_REG const *arg2,
  161. FPU_REG * answ, unsigned int control_w, u_char sign,
  162. int expa, int expb);
  163. asmlinkage int FPU_u_mul(FPU_REG const *arg1, FPU_REG const *arg2,
  164. FPU_REG * answ, unsigned int control_w, u_char sign,
  165. int expon);
  166. asmlinkage int FPU_u_div(FPU_REG const *arg1, FPU_REG const *arg2,
  167. FPU_REG * answ, unsigned int control_w, u_char sign);
  168. asmlinkage int FPU_u_add(FPU_REG const *arg1, FPU_REG const *arg2,
  169. FPU_REG * answ, unsigned int control_w, u_char sign,
  170. int expa, int expb);
  171. asmlinkage int wm_sqrt(FPU_REG *n, int dummy1, int dummy2,
  172. unsigned int control_w, u_char sign);
  173. asmlinkage unsigned FPU_shrx(void *l, unsigned x);
  174. asmlinkage unsigned FPU_shrxs(void *v, unsigned x);
  175. asmlinkage unsigned long FPU_div_small(unsigned long long *x, unsigned long y);
  176. asmlinkage int FPU_round(FPU_REG *arg, unsigned int extent, int dummy,
  177. unsigned int control_w, u_char sign);
  178. #ifndef MAKING_PROTO
  179. #include "fpu_proto.h"
  180. #endif
  181. #endif /* __ASSEMBLY__ */
  182. #endif /* _FPU_EMU_H_ */