Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*---------------------------------------------------------------------------+
0003  |  fpu_emu.h                                                                |
0004  |                                                                           |
0005  | Copyright (C) 1992,1993,1994,1997                                         |
0006  |                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,      |
0007  |                       Australia.  E-mail   billm@suburbia.net             |
0008  |                                                                           |
0009  +---------------------------------------------------------------------------*/
0010 
0011 #ifndef _FPU_EMU_H_
0012 #define _FPU_EMU_H_
0013 
0014 /*
0015  * Define PECULIAR_486 to get a closer approximation to 80486 behaviour,
0016  * rather than behaviour which appears to be cleaner.
0017  * This is a matter of opinion: for all I know, the 80486 may simply
0018  * be complying with the IEEE spec. Maybe one day I'll get to see the
0019  * spec...
0020  */
0021 #define PECULIAR_486
0022 
0023 #ifdef __ASSEMBLY__
0024 #include "fpu_asm.h"
0025 #define Const(x)    $##x
0026 #else
0027 #define Const(x)    x
0028 #endif
0029 
0030 #define EXP_BIAS    Const(0)
0031 #define EXP_OVER    Const(0x4000)   /* smallest invalid large exponent */
0032 #define EXP_UNDER   Const(-0x3fff)  /* largest invalid small exponent */
0033 #define EXP_WAY_UNDER   Const(-0x6000)  /* Below the smallest denormal, but
0034                        still a 16 bit nr. */
0035 #define EXP_Infinity    EXP_OVER
0036 #define EXP_NaN         EXP_OVER
0037 
0038 #define EXTENDED_Ebias Const(0x3fff)
0039 #define EXTENDED_Emin (-0x3ffe) /* smallest valid exponent */
0040 
0041 #define SIGN_POS    Const(0)
0042 #define SIGN_NEG    Const(0x80)
0043 
0044 #define SIGN_Positive   Const(0)
0045 #define SIGN_Negative   Const(0x8000)
0046 
0047 /* Keep the order TAG_Valid, TAG_Zero, TW_Denormal */
0048 /* The following fold to 2 (Special) in the Tag Word */
0049 #define TW_Denormal     Const(4)    /* De-normal */
0050 #define TW_Infinity Const(5)    /* + or - infinity */
0051 #define TW_NaN      Const(6)    /* Not a Number */
0052 #define TW_Unsupported  Const(7)    /* Not supported by an 80486 */
0053 
0054 #define TAG_Valid   Const(0)    /* valid */
0055 #define TAG_Zero    Const(1)    /* zero */
0056 #define TAG_Special Const(2)    /* De-normal, + or - infinity,
0057                        or Not a Number */
0058 #define TAG_Empty   Const(3)    /* empty */
0059 #define TAG_Error   Const(0x80) /* probably need to abort */
0060 
0061 #define LOADED_DATA Const(10101)    /* Special st() number to identify
0062                        loaded data (not on stack). */
0063 
0064 /* A few flags (must be >= 0x10). */
0065 #define REV             0x10
0066 #define DEST_RM         0x20
0067 #define LOADED          0x40
0068 
0069 #define FPU_Exception   Const(0x80000000)   /* Added to tag returns. */
0070 
0071 #ifndef __ASSEMBLY__
0072 
0073 #include "fpu_system.h"
0074 
0075 #include <uapi/asm/sigcontext.h>    /* for struct _fpstate */
0076 #include <asm/math_emu.h>
0077 #include <linux/linkage.h>
0078 
0079 /*
0080 #define RE_ENTRANT_CHECKING
0081  */
0082 
0083 #ifdef RE_ENTRANT_CHECKING
0084 extern u_char emulating;
0085 #  define RE_ENTRANT_CHECK_OFF emulating = 0
0086 #  define RE_ENTRANT_CHECK_ON emulating = 1
0087 #else
0088 #  define RE_ENTRANT_CHECK_OFF
0089 #  define RE_ENTRANT_CHECK_ON
0090 #endif /* RE_ENTRANT_CHECKING */
0091 
0092 #define FWAIT_OPCODE 0x9b
0093 #define OP_SIZE_PREFIX 0x66
0094 #define ADDR_SIZE_PREFIX 0x67
0095 #define PREFIX_CS 0x2e
0096 #define PREFIX_DS 0x3e
0097 #define PREFIX_ES 0x26
0098 #define PREFIX_SS 0x36
0099 #define PREFIX_FS 0x64
0100 #define PREFIX_GS 0x65
0101 #define PREFIX_REPE 0xf3
0102 #define PREFIX_REPNE 0xf2
0103 #define PREFIX_LOCK 0xf0
0104 #define PREFIX_CS_ 1
0105 #define PREFIX_DS_ 2
0106 #define PREFIX_ES_ 3
0107 #define PREFIX_FS_ 4
0108 #define PREFIX_GS_ 5
0109 #define PREFIX_SS_ 6
0110 #define PREFIX_DEFAULT 7
0111 
0112 struct address {
0113     unsigned int offset;
0114     unsigned int selector:16;
0115     unsigned int opcode:11;
0116     unsigned int empty:5;
0117 };
0118 struct fpu__reg {
0119     unsigned sigl;
0120     unsigned sigh;
0121     short exp;
0122 };
0123 
0124 typedef void (*FUNC) (void);
0125 typedef struct fpu__reg FPU_REG;
0126 typedef void (*FUNC_ST0) (FPU_REG *st0_ptr, u_char st0_tag);
0127 typedef struct {
0128     u_char address_size, operand_size, segment;
0129 } overrides;
0130 /* This structure is 32 bits: */
0131 typedef struct {
0132     overrides override;
0133     u_char default_mode;
0134 } fpu_addr_modes;
0135 /* PROTECTED has a restricted meaning in the emulator; it is used
0136    to signal that the emulator needs to do special things to ensure
0137    that protection is respected in a segmented model. */
0138 #define PROTECTED 4
0139 #define SIXTEEN   1     /* We rely upon this being 1 (true) */
0140 #define VM86      SIXTEEN
0141 #define PM16      (SIXTEEN | PROTECTED)
0142 #define SEG32     PROTECTED
0143 extern u_char const data_sizes_16[32];
0144 
0145 #define register_base ((u_char *) registers )
0146 #define fpu_register(x)  ( * ((FPU_REG *)( register_base + 10 * (x & 7) )) )
0147 #define st(x)      ( * ((FPU_REG *)( register_base + 10 * ((top+x) & 7) )) )
0148 
0149 #define STACK_OVERFLOW  (FPU_stackoverflow(&st_new_ptr))
0150 #define NOT_EMPTY(i)    (!FPU_empty_i(i))
0151 
0152 #define NOT_EMPTY_ST0   (st0_tag ^ TAG_Empty)
0153 
0154 #define poppop() { FPU_pop(); FPU_pop(); }
0155 
0156 /* push() does not affect the tags */
0157 #define push()  { top--; }
0158 
0159 #define signbyte(a) (((u_char *)(a))[9])
0160 #define getsign(a) (signbyte(a) & 0x80)
0161 #define setsign(a,b) { if ((b) != 0) signbyte(a) |= 0x80; else signbyte(a) &= 0x7f; }
0162 #define copysign(a,b) { if (getsign(a)) signbyte(b) |= 0x80; \
0163                         else signbyte(b) &= 0x7f; }
0164 #define changesign(a) { signbyte(a) ^= 0x80; }
0165 #define setpositive(a) { signbyte(a) &= 0x7f; }
0166 #define setnegative(a) { signbyte(a) |= 0x80; }
0167 #define signpositive(a) ( (signbyte(a) & 0x80) == 0 )
0168 #define signnegative(a) (signbyte(a) & 0x80)
0169 
0170 static inline void reg_copy(FPU_REG const *x, FPU_REG *y)
0171 {
0172     *(short *)&(y->exp) = *(const short *)&(x->exp);
0173     *(long long *)&(y->sigl) = *(const long long *)&(x->sigl);
0174 }
0175 
0176 #define exponent(x)  (((*(short *)&((x)->exp)) & 0x7fff) - EXTENDED_Ebias)
0177 #define setexponentpos(x,y) { (*(short *)&((x)->exp)) = \
0178   ((y) + EXTENDED_Ebias) & 0x7fff; }
0179 #define exponent16(x)         (*(short *)&((x)->exp))
0180 #define setexponent16(x,y)  { (*(short *)&((x)->exp)) = (u16)(y); }
0181 #define addexponent(x,y)    { (*(short *)&((x)->exp)) += (y); }
0182 #define stdexp(x)           { (*(short *)&((x)->exp)) += EXTENDED_Ebias; }
0183 
0184 #define isdenormal(ptr)   (exponent(ptr) == EXP_BIAS+EXP_UNDER)
0185 
0186 #define significand(x) ( ((unsigned long long *)&((x)->sigl))[0] )
0187 
0188 /*----- Prototypes for functions written in assembler -----*/
0189 /* extern void reg_move(FPU_REG *a, FPU_REG *b); */
0190 
0191 asmlinkage int FPU_normalize(FPU_REG *x);
0192 asmlinkage int FPU_normalize_nuo(FPU_REG *x);
0193 asmlinkage int FPU_u_sub(FPU_REG const *arg1, FPU_REG const *arg2,
0194              FPU_REG * answ, unsigned int control_w, u_char sign,
0195              int expa, int expb);
0196 asmlinkage int FPU_u_mul(FPU_REG const *arg1, FPU_REG const *arg2,
0197              FPU_REG * answ, unsigned int control_w, u_char sign,
0198              int expon);
0199 asmlinkage int FPU_u_div(FPU_REG const *arg1, FPU_REG const *arg2,
0200              FPU_REG * answ, unsigned int control_w, u_char sign);
0201 asmlinkage int FPU_u_add(FPU_REG const *arg1, FPU_REG const *arg2,
0202              FPU_REG * answ, unsigned int control_w, u_char sign,
0203              int expa, int expb);
0204 asmlinkage int wm_sqrt(FPU_REG *n, int dummy1, int dummy2,
0205                unsigned int control_w, u_char sign);
0206 asmlinkage unsigned FPU_shrx(void *l, unsigned x);
0207 asmlinkage unsigned FPU_shrxs(void *v, unsigned x);
0208 asmlinkage unsigned long FPU_div_small(unsigned long long *x, unsigned long y);
0209 asmlinkage int FPU_round(FPU_REG *arg, unsigned int extent, int dummy,
0210              unsigned int control_w, u_char sign);
0211 
0212 #ifndef MAKING_PROTO
0213 #include "fpu_proto.h"
0214 #endif
0215 
0216 #endif /* __ASSEMBLY__ */
0217 
0218 #endif /* _FPU_EMU_H_ */