Merge from vendor branch BINUTILS:
[dragonfly.git] / sys / i386 / gnu / fpemul / fpu_emu.h
1 /*
2  *  fpu_emu.h
3  *
4  *
5  * Copyright (C) 1992,1993,1994
6  *                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
7  *                       Australia.  E-mail   billm@vaxc.cc.monash.edu.au
8  * All rights reserved.
9  *
10  * This copyright notice covers the redistribution and use of the
11  * FPU emulator developed by W. Metzenthen. It covers only its use
12  * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
13  * use is not permitted under this copyright.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must include information specifying
21  *    that source code for the emulator is freely available and include
22  *    either:
23  *      a) an offer to provide the source code for a nominal distribution
24  *         fee, or
25  *      b) list at least two alternative methods whereby the source
26  *         can be obtained, e.g. a publically accessible bulletin board
27  *         and an anonymous ftp site from which the software can be
28  *         downloaded.
29  * 3. All advertising materials specifically mentioning features or use of
30  *    this emulator must acknowledge that it was developed by W. Metzenthen.
31  * 4. The name of W. Metzenthen may not be used to endorse or promote
32  *    products derived from this software without specific prior written
33  *    permission.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
36  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
37  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
38  * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
39  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
41  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
42  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  *
47  * The purpose of this copyright, based upon the Berkeley copyright, is to
48  * ensure that the covered software remains freely available to everyone.
49  *
50  * The software (with necessary differences) is also available, but under
51  * the terms of the GNU copyleft, for the Linux operating system and for
52  * the djgpp ms-dos extender.
53  *
54  * W. Metzenthen   June 1994.
55  *
56  *
57  * $FreeBSD: src/sys/gnu/i386/fpemul/fpu_emu.h,v 1.7 1999/08/28 00:42:50 peter Exp $
58  * $DragonFly: src/sys/i386/gnu/fpemul/Attic/fpu_emu.h,v 1.3 2003/08/07 21:17:20 dillon Exp $
59  *
60  */
61
62
63 #ifndef _FPU_EMU_H_
64 #define _FPU_EMU_H_
65
66 /*
67  * Define DENORM_OPERAND to make the emulator detect denormals
68  * and use the denormal flag of the status word. Note: this only
69  * affects the flag and corresponding interrupt, the emulator
70  * will always generate denormals and operate upon them as required.
71  */
72 #define DENORM_OPERAND
73
74 /*
75  * Define PECULIAR_486 to get a closer approximation to 80486 behaviour,
76  * rather than behaviour which appears to be cleaner.
77  * This is a matter of opinion: for all I know, the 80486 may simply
78  * be complying with the IEEE spec. Maybe one day I'll get to see the
79  * spec...
80  */
81 #define PECULIAR_486
82
83 #ifdef LOCORE
84 #include "fpu_asm.h"
85 #define Const(x)        $/**/x
86 #else
87 #define Const(x)        x
88 #endif
89
90 #define EXP_BIAS        Const(0)
91 #define EXP_OVER        Const(0x4000)   /* smallest invalid large exponent */
92 #define EXP_UNDER       Const(-0x3fff)  /* largest invalid small exponent */
93
94 #define SIGN_POS        Const(0)
95 #define SIGN_NEG        Const(1)
96
97 /* Keep the order TW_Valid, TW_Zero, TW_Denormal */
98 #define TW_Valid        Const(0)/* valid */
99 #define TW_Zero         Const(1)/* zero */
100 /* The following fold to 2 (Special) in the Tag Word */
101 #define TW_Denormal     Const(4)/* De-normal */
102 #define TW_Infinity     Const(5)/* + or - infinity */
103 #define TW_NaN          Const(6)/* Not a Number */
104
105 #define TW_Empty        Const(7)/* empty */
106
107  /* #define TW_FPU_Interrupt Const(0x80) *//* Signals an interrupt */
108
109
110 #ifndef LOCORE
111
112 #include <sys/types.h>
113 #include "math_emu.h"
114
115 #ifdef PARANOID
116 extern char emulating;
117 #define REENTRANT_CHECK(state) emulating = (state)
118 #define ON 1
119 #define OFF 0
120 #else
121 #define REENTRANT_CHECK(state)
122 #endif                          /* PARANOID */
123
124 typedef void (*FUNC) (void);
125 typedef struct fpu_reg FPU_REG;
126
127 #define st(x)   ( regs[((top+x) &7 )] )
128
129 #define STACK_OVERFLOW  (st_new_ptr = &st(-1), st_new_ptr->tag != TW_Empty)
130 #define NOT_EMPTY(i)    (st(i).tag != TW_Empty)
131 #define NOT_EMPTY_0     (FPU_st0_tag ^ TW_Empty)
132
133 extern unsigned char FPU_rm;
134
135 extern char FPU_st0_tag;
136 extern FPU_REG *FPU_st0_ptr;
137
138 extern void *FPU_data_address;
139
140 extern FPU_REG FPU_loaded_data;
141
142 #define pop()   { FPU_st0_ptr->tag = TW_Empty; top++; }
143
144 /* push() does not affect the tags */
145 #define push()  { top--; FPU_st0_ptr = st_new_ptr; }
146
147
148 #define reg_move(x, y) { \
149                  *(short *)&((y)->sign) = *(short *)&((x)->sign); \
150                  *(long *)&((y)->exp) = *(long *)&((x)->exp); \
151                  *(long long *)&((y)->sigl) = *(long long *)&((x)->sigl); }
152
153
154 /*----- Prototypes for functions written in assembler -----*/
155 /* extern void reg_move(FPU_REG *a, FPU_REG *b); */
156
157 extern void mul64(long long *a, long long *b, long long *result);
158 extern void poly_div2(long long *x);
159 extern void poly_div4(long long *x);
160 extern void poly_div16(long long *x);
161 extern void
162 polynomial(unsigned accum[], unsigned x[],
163     unsigned short terms[][4], int n);
164         extern void normalize(FPU_REG * x);
165         extern void normalize_nuo(FPU_REG * x);
166         extern void reg_div(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
167             unsigned int control_w);
168         extern void reg_u_sub(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
169             unsigned int control_w);
170         extern void reg_u_mul(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
171             unsigned int control_w);
172         extern void reg_u_div(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
173             unsigned int control_w);
174         extern void reg_u_add(FPU_REG * arg1, FPU_REG * arg2, FPU_REG * answ,
175             unsigned int control_w);
176         extern void wm_sqrt(FPU_REG * n, unsigned int control_w);
177         extern unsigned shrx(void *l, unsigned x);
178         extern unsigned shrxs(void *v, unsigned x);
179         extern unsigned long div_small(unsigned long long *x, unsigned long y);
180         extern void round_reg(FPU_REG * arg, unsigned int extent,
181             unsigned int control_w);
182
183 #ifndef MAKING_PROTO
184 #include "fpu_proto.h"
185 #endif
186
187 #endif                          /* LOCORE */
188
189 #endif                          /* _FPU_EMU_H_ */