1 /*
2 Copyright (c) 1982, 1986, 1993
3 The Regents of the University of California.  All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. Neither the name of the University nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 SUCH DAMAGE.
28  */
29 #ifndef __SYS_CONFIG_H__
30 #define __SYS_CONFIG_H__
31 
32 #include <machine/ieeefp.h>  /* floating point macros */
33 #include <sys/features.h>	/* POSIX defs */
34 #include <float.h>
35 #include <newlib.h>
36 
37 #ifdef __aarch64__
38 #define MALLOC_ALIGNMENT 16
39 #endif
40 
41 #ifdef __AMDGCN__
42 #define __DYNAMIC_REENT__
43 #endif
44 
45 /* exceptions first */
46 #if defined(__H8500__) || defined(__W65__)
47 #define __SMALL_BITFIELDS
48 /* ???  This conditional is true for the h8500 and the w65, defining H8300
49    in those cases probably isn't the right thing to do.  */
50 #define H8300 1
51 #endif
52 
53 /* 16 bit integer machines */
54 #if defined(__Z8001__) || defined(__Z8002__) || defined(__H8500__) || defined(__W65__) || defined (__mn10200__) || defined (__AVR__) || defined (__MSP430__)
55 
56 #undef INT_MAX
57 #undef UINT_MAX
58 #define INT_MAX 32767
59 #define UINT_MAX 65535
60 #endif
61 
62 #if defined (__H8300__) || defined (__H8300H__) || defined(__H8300S__) || defined (__H8300SX__)
63 #define __SMALL_BITFIELDS
64 #define H8300 1
65 #undef INT_MAX
66 #undef UINT_MAX
67 #define INT_MAX __INT_MAX__
68 #define UINT_MAX (__INT_MAX__ * 2U + 1)
69 #endif
70 
71 #if (defined(__CR16__) || defined(__CR16C__) ||defined(__CR16CP__))
72 #ifndef __INT32__
73 #define __SMALL_BITFIELDS
74 #undef INT_MAX
75 #undef UINT_MAX
76 #define INT_MAX 32767
77 #define UINT_MAX (__INT_MAX__ * 2U + 1)
78 #else /* INT32 */
79 #undef INT_MAX
80 #undef UINT_MAX
81 #define INT_MAX 2147483647
82 #define UINT_MAX (__INT_MAX__ * 2U + 1)
83 #endif /* INT32 */
84 
85 #endif /* CR16C */
86 
87 #if defined (__xc16x__) || defined (__xc16xL__) || defined (__xc16xS__)
88 #define __SMALL_BITFIELDS
89 #endif
90 
91 #ifdef __W65__
92 #define __SMALL_BITFIELDS
93 #endif
94 
95 #if defined(__D10V__)
96 #define __SMALL_BITFIELDS
97 #undef INT_MAX
98 #undef UINT_MAX
99 #define INT_MAX __INT_MAX__
100 #define UINT_MAX (__INT_MAX__ * 2U + 1)
101 #define _POINTER_INT short
102 #endif
103 
104 #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__)
105 #undef INT_MAX
106 #undef UINT_MAX
107 #define INT_MAX __INT_MAX__
108 #define UINT_MAX (__INT_MAX__ * 2U + 1)
109 #define _POINTER_INT short
110 #endif
111 
112 #ifdef ___AM29K__
113 #define _FLOAT_RET double
114 #endif
115 
116 #ifdef __i386__
117 #ifndef __unix__
118 /* in other words, go32 */
119 #define _FLOAT_RET double
120 #endif
121 #if defined(__linux__) || defined(__RDOS__)
122 /* we want the reentrancy structure to be returned by a function */
123 #define __DYNAMIC_REENT__
124 #define HAVE_GETDATE
125 #ifndef __LARGE64_FILES
126 #define __LARGE64_FILES 1
127 #endif
128 /* we use some glibc header files so turn on glibc large file feature */
129 #define _LARGEFILE64_SOURCE 1
130 #endif
131 #endif
132 
133 #ifdef __mn10200__
134 #define __SMALL_BITFIELDS
135 #endif
136 
137 #ifdef __AVR__
138 #define __SMALL_BITFIELDS
139 #define _POINTER_INT short
140 #endif
141 
142 #if defined(__v850) && !defined(__rtems__)
143 #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__sda__))
144 #endif
145 
146 /* For the PowerPC eabi, force the _impure_ptr to be in .sdata */
147 #if defined(__PPC__)
148 #if defined(_CALL_SYSV)
149 #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__section__(".sdata")))
150 #endif
151 #ifdef __SPE__
152 #define _LONG_DOUBLE double
153 #endif
154 #endif
155 
156 /* Configure small REENT structure for Xilinx MicroBlaze platforms */
157 #if defined (__MICROBLAZE__) && !defined(__rtems__)
158 #ifndef _REENT_SMALL
159 #define _REENT_SMALL
160 #endif
161 /* Xilinx XMK uses Unix98 mutex */
162 #ifdef __XMK__
163 #define _UNIX98_THREAD_MUTEX_ATTRIBUTES
164 #endif
165 #endif
166 
167 #if defined(__mips__) && !defined(__rtems__)
168 #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__section__(".sdata")))
169 #endif
170 
171 #ifdef __xstormy16__
172 #define __SMALL_BITFIELDS
173 #undef INT_MAX
174 #undef UINT_MAX
175 #define INT_MAX __INT_MAX__
176 #define UINT_MAX (__INT_MAX__ * 2U + 1)
177 #define MALLOC_ALIGNMENT 8
178 #define _POINTER_INT short
179 #define __BUFSIZ__ 16
180 #define _REENT_SMALL
181 #endif
182 
183 #if defined __MSP430__
184 #ifndef _REENT_SMALL
185 #define _REENT_SMALL
186 #endif
187 
188 #define __BUFSIZ__ 256
189 #define __SMALL_BITFIELDS
190 
191 #ifdef __MSP430X_LARGE__
192 #define _POINTER_INT __int20
193 #else
194 #define _POINTER_INT int
195 #endif
196 #endif
197 
198 #ifdef __m32c__
199 #define __SMALL_BITFIELDS
200 #undef INT_MAX
201 #undef UINT_MAX
202 #define INT_MAX __INT_MAX__
203 #define UINT_MAX (__INT_MAX__ * 2U + 1)
204 #define MALLOC_ALIGNMENT 8
205 #if defined(__r8c_cpu__) || defined(__m16c_cpu__)
206 #define _POINTER_INT short
207 #else
208 #define _POINTER_INT long
209 #endif
210 #define __BUFSIZ__ 16
211 #define _REENT_SMALL
212 #endif /* __m32c__ */
213 
214 #ifdef __SPU__
215 #define MALLOC_ALIGNMENT 16
216 #define __CUSTOM_FILE_IO__
217 #endif
218 
219 #if defined(__or1k__) || defined(__or1knd__)
220 #define __DYNAMIC_REENT__
221 #endif
222 
223 /* This block should be kept in sync with GCC's limits.h.  The point
224    of having these definitions here is to not include limits.h, which
225    would pollute the user namespace, while still using types of the
226    the correct widths when deciding how to define __int32_t and
227    __int64_t.  */
228 #ifndef __INT_MAX__
229 # ifdef INT_MAX
230 #  define __INT_MAX__ INT_MAX
231 # else
232 #  define __INT_MAX__ 2147483647
233 # endif
234 #endif
235 
236 #ifndef __LONG_MAX__
237 # ifdef LONG_MAX
238 #  define __LONG_MAX__ LONG_MAX
239 # else
240 #  if defined (__alpha__) || (defined (__sparc__) && defined(__arch64__)) \
241       || defined (__sparcv9)
242 #   define __LONG_MAX__ 9223372036854775807L
243 #  else
244 #   define __LONG_MAX__ 2147483647L
245 #  endif /* __alpha__ || sparc64 */
246 # endif
247 #endif
248 /* End of block that should be kept in sync with GCC's limits.h.  */
249 
250 #ifndef _POINTER_INT
251 #define _POINTER_INT long
252 #endif
253 
254 #ifdef __frv__
255 #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__section__(".sdata")))
256 #endif
257 #undef __RAND_MAX
258 #if __INT_MAX__ == 32767
259 #define __RAND_MAX 32767
260 #else
261 #define __RAND_MAX 0x7fffffff
262 #endif
263 
264 #if defined(__CYGWIN__)
265 #include <cygwin/config.h>
266 #endif
267 
268 #if defined(__rtems__)
269 #define __FILENAME_MAX__ 255
270 #define __DYNAMIC_REENT__
271 #endif
272 
273 #ifndef __EXPORT
274 #define __EXPORT
275 #endif
276 
277 #ifndef __IMPORT
278 #define __IMPORT
279 #endif
280 
281 #ifndef __WCHAR_MAX__
282 #if __INT_MAX__ == 32767 || defined (_WIN32)
283 #define __WCHAR_MAX__ 0xffffu
284 #endif
285 #endif
286 
287 #ifdef PICOLIBC_TLS
288 #define NEWLIB_THREAD_LOCAL __thread
289 #else
290 #define NEWLIB_THREAD_LOCAL
291 #endif
292 
293 /* See if small reent asked for at configuration time and
294    is not chosen by the platform by default.  */
295 #ifdef _WANT_REENT_SMALL
296 #ifndef _REENT_SMALL
297 #define _REENT_SMALL
298 #endif
299 #endif
300 
301 #ifdef _WANT_USE_LONG_TIME_T
302 #ifndef _USE_LONG_TIME_T
303 #define _USE_LONG_TIME_T
304 #endif
305 #endif
306 
307 #ifdef _WANT_USE_GDTOA
308 #ifndef _USE_GDTOA
309 #define _USE_GDTOA
310 #endif
311 #endif
312 
313 #ifdef _WANT_REENT_BACKWARD_BINARY_COMPAT
314 #ifndef _REENT_BACKWARD_BINARY_COMPAT
315 #define _REENT_BACKWARD_BINARY_COMPAT
316 #endif
317 #endif
318 
319 #define _REENT_THREAD_LOCAL
320 
321 /* If _MB_EXTENDED_CHARSETS_ALL is set, we want all of the extended
322    charsets.  The extended charsets add a few functions and a couple
323    of tables of a few K each. */
324 #ifdef _MB_EXTENDED_CHARSETS_ALL
325 #define _MB_EXTENDED_CHARSETS_ISO 1
326 #define _MB_EXTENDED_CHARSETS_WINDOWS 1
327 #endif
328 
329 /* Figure out if long double is the same size as double. If the system
330  * doesn't provide long double, then those values will be undefined
331  * and cpp will substitute 0 for them in the test
332  */
333 #if LDBL_MANT_DIG == DBL_MANT_DIG && LDBL_MIN_EXP == DBL_MIN_EXP && \
334     LDBL_MAX_EXP == DBL_MAX_EXP
335 #define _LDBL_EQ_DBL
336 #endif
337 
338 /* Newlib doesn't fully support long double math functions so far.
339    On platforms where long double equals double the long double functions
340    simply call the double functions.  On Cygwin the long double functions
341    are implemented independently from newlib to be able to use optimized
342    assembler functions despite using the Microsoft x86_64 ABI. */
343 #if defined (_LDBL_EQ_DBL) || defined (__CYGWIN__) || (defined(__SIZEOF_LONG_DOUBLE__) && __SIZEOF_LONG_DOUBLE__ <= 8) || (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113)
344 #define _HAVE_LONG_DOUBLE_MATH
345 #endif
346 
347 #endif /* __SYS_CONFIG_H__ */
348