1 /****************************************************************
2 Copyright (C) 1999-2001 Lucent Technologies
3 All Rights Reserved
4 
5 Permission to use, copy, modify, and distribute this software and
6 its documentation for any purpose and without fee is hereby
7 granted, provided that the above copyright notice appear in all
8 copies and that both that the copyright notice and this
9 permission notice and warranty disclaimer appear in supporting
10 documentation, and that the name of Lucent or any of its entities
11 not be used in advertising or publicity pertaining to
12 distribution of the software without specific, written prior
13 permission.
14 
15 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
17 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
18 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
20 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
22 THIS SOFTWARE.
23 ****************************************************************/
24 
25 #undef ASL_USE_FPINITMT
26 #ifdef __powerpc__
27 #undef  ASL_NO_FPINITMT
28 #define ASL_NO_FPINITMT
29 #endif
30 
31 #ifndef ASL_NO_FPINITMT
32 #ifdef _WIN32
33 #define ASL_USE_FPINITMT
34 #endif /*_WIN32*/
35 #endif /*ASL_NO_FPINITMT*/
36 
37 #ifdef ASL_USE_FPINITMT
38 #include "fpinitmt.c"
39 #else
40 
41 int isatty_ASL; /* for use with "sw" under NT */
42 
43 #ifndef MSpc
44 #ifdef MSDOS
45 #define MSpc
46 #else
47 
48 #ifdef _WIN32
49 #undef WIN32
50 #define WIN32
51 #endif
52 
53 #ifdef WIN32
54 #define MSpc
55 #endif
56 #endif /*MSDOS*/
57 #endif /*MSpc*/
58 
59 #ifdef KR_headers
60 #define Void /*void*/
61 #else
62 #define Void void
63 #endif
64 
65 #ifdef __cplusplus
66 extern "C" {
67  void fpinit_ASL(Void);
68  }
69 #endif
70 #undef FP_INIT_DONE
71 
72 #ifdef __APPLE__
73 #if (defined (__i386__) || defined( __x86_64__ ))
74 #define _FPU_EXTENDED	0x300
75 #define _FPU_DOUBLE	0x200
76 #define _FPU_IEEE	0x37f
77 #define _FPU_GETCW(cw) __asm__ __volatile__ ("fnstcw %0" : "=m" (*&cw))
78 #define _FPU_SETCW(cw) __asm__ __volatile__ ("fldcw %0" : : "m" (*&cw))
79 
80  void
fpinit_ASL(Void)81 fpinit_ASL(Void)
82 {
83 	unsigned int __fpu_control;
84 #ifdef ASL_FPINIT_KEEP_TRAPBITS
85 	_FPU_GETCW(__fpu_control);
86 	__fpu_control &= ~_FPU_EXTENDED;	/* clear rounding precision bits */
87 	__fpu_control |= _FPU_DOUBLE;		/* set the ones we want set */
88 #else
89 	__fpu_control = _FPU_IEEE - _FPU_EXTENDED + _FPU_DOUBLE;
90 #endif
91 	_FPU_SETCW(__fpu_control);
92 	}
93 #define ASL_NO_FP_INIT
94 #define FP_INIT_DONE
95 #endif /* __i386 */
96 #endif /*APPLE*/
97 
98 #ifndef ASL_NO_FP_INIT
99 
100 #ifdef __linux__
101 #ifndef NO_fpu_control
102 #define FP_INIT_DONE
103 #include "fpu_control.h"
104 
105 #ifdef __alpha__
106 #ifndef USE_setfpucw
107 #define __setfpucw(x) __fpu_control = (x)
108 #endif
109 #endif
110 
111 
112 #ifndef _FPU_SETCW
113 #undef  Can_use__setfpucw
114 #define Can_use__setfpucw
115 #endif
116 
117  void
fpinit_ASL(Void)118 fpinit_ASL(Void)
119 {
120 #ifdef Can_use__setfpucw /* Has __setfpucw gone missing from S.u.S.E. 6.3? */
121 #ifdef _FPU_EXTENDED /* not defined on Itanium systems running ALTIX */
122 	__setfpucw(_FPU_IEEE - _FPU_EXTENDED + _FPU_DOUBLE);
123 #endif
124 #else
125 #ifdef ASL_FPINIT_KEEP_TRAPBITS
126 	_FPU_GETCW(__fpu_control);
127 	__fpu_control &= ~_FPU_EXTENDED;	/* clear rounding precision bits */
128 	__fpu_control |= _FPU_DOUBLE;		/* set the ones we want set */
129 #else
130 #ifdef _FPU_IEEE
131 	__fpu_control = _FPU_IEEE - _FPU_EXTENDED + _FPU_DOUBLE;
132 #else
133 	__fpu_control = 0x27f;
134 #endif
135 #endif /* ASL_FPINIT_KEEP_TRAPBITS */
136 	_FPU_SETCW(__fpu_control);
137 #endif
138 	}
139 #endif /* NO_fpu_control */
140 #endif /* __linux__ */
141 
142 #ifdef sgi
143 #ifndef _ABIO32
144 #define FP_INIT_DONE
145 #include <sys/fpu.h>
146 
147  void
fpinit_ASL(Void)148 fpinit_ASL(Void)
149 {
150 	union fpc_csr f;
151 	f.fc_word = get_fpc_csr();
152 	f.fc_struct.flush = 0;
153 	set_fpc_csr(f.fc_word);
154 	}
155 #endif
156 #endif
157 
158 #ifdef MSpc
159 #ifndef No_Control87
160 #include "float.h"
161 #ifdef SYMANTEC
162 extern int _8087;
163 #endif
164 #ifndef MCW_EM
165 #ifndef _MCW_EM	/* for cygwin with -mno-cygwin */
166 #define _MCW_EM 0x0008001F
167 #endif
168 #define MCW_EM _MCW_EM
169 #endif
170 #ifndef PC_53
171 #ifndef _PC_53
172 #define _PC_53 0x00010000
173 #endif
174 #define PC_53 _PC_53
175 #endif
176 #ifndef MCW_PC
177 #ifndef _MCW_PC
178 #define _MCW_PC 0x00030000
179 #endif
180 #define MCW_PC _MCW_PC
181 #endif
182 
183 #define FP_INIT_DONE
184  void
fpinit_ASL(Void)185 fpinit_ASL(Void)
186 {
187 #ifdef SYMANTEC
188 	if (_8087)
189 #endif
190 	_control87(MCW_EM | PC_53, MCW_EM | MCW_PC);
191 	}
192 #endif
193 #endif
194 
195 #ifdef __sun
196 #ifdef __i386
197 extern
198 #ifdef __cplusplus
199 	"C"
200 #endif
201 	int fpsetprec(int);
202 
203 #define PC_24	0
204 #define PC_53	0x200
205 #define PC_64	0x300
206 
207 #define FP_INIT_DONE
208  void
fpinit_ASL(Void)209 fpinit_ASL(Void)
210 {	fpsetprec(PC_53);
211 	}
212 #endif
213 #endif /* __i386 __sun */
214 
215 /* Currently, FP_PD is the default on FreeBSD, but enabled traps */
216 /* can cause surprises, so we restore the default IEEE mask. */
217 #ifdef __FreeBSD__
218 #include "floatingpoint.h"
219 #define FP_INIT_DONE
220  void
fpinit_ASL(Void)221 fpinit_ASL(Void)
222 {
223 	fpsetprec(FP_PD);
224 	fpsetmask(0);
225 	}
226 #endif /* __FreeBSD__ */
227 
228 #endif /* ASL_NO_FP_INIT */
229 
230 #ifndef FP_INIT_DONE
fpinit_ASL(Void)231 void fpinit_ASL(Void) {}
232 #endif
233 
234 #endif /*ASL_USE_FPINITMT*/
235