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