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 36 #ifdef __aarch64__ 37 #define MALLOC_ALIGNMENT 16 38 #endif 39 40 #ifdef __AMDGCN__ 41 #define __DYNAMIC_REENT__ 42 #endif 43 44 /* exceptions first */ 45 #if defined(__H8500__) || defined(__W65__) 46 #define __SMALL_BITFIELDS 47 /* ??? This conditional is true for the h8500 and the w65, defining H8300 48 in those cases probably isn't the right thing to do. */ 49 #define H8300 1 50 #endif 51 52 /* 16 bit integer machines */ 53 #if defined(__Z8001__) || defined(__Z8002__) || defined(__H8500__) || defined(__W65__) || defined (__mn10200__) || defined (__AVR__) || defined (__MSP430__) 54 55 #undef INT_MAX 56 #undef UINT_MAX 57 #define INT_MAX 32767 58 #define UINT_MAX 65535 59 #endif 60 61 #if defined (__H8300__) || defined (__H8300H__) || defined(__H8300S__) || defined (__H8300SX__) 62 #define __SMALL_BITFIELDS 63 #define H8300 1 64 #undef INT_MAX 65 #undef UINT_MAX 66 #define INT_MAX __INT_MAX__ 67 #define UINT_MAX (__INT_MAX__ * 2U + 1) 68 #endif 69 70 #if (defined(__CR16__) || defined(__CR16C__) ||defined(__CR16CP__)) 71 #ifndef __INT32__ 72 #define __SMALL_BITFIELDS 73 #undef INT_MAX 74 #undef UINT_MAX 75 #define INT_MAX 32767 76 #define UINT_MAX (__INT_MAX__ * 2U + 1) 77 #else /* INT32 */ 78 #undef INT_MAX 79 #undef UINT_MAX 80 #define INT_MAX 2147483647 81 #define UINT_MAX (__INT_MAX__ * 2U + 1) 82 #endif /* INT32 */ 83 84 #endif /* CR16C */ 85 86 #if defined (__xc16x__) || defined (__xc16xL__) || defined (__xc16xS__) 87 #define __SMALL_BITFIELDS 88 #endif 89 90 #ifdef __W65__ 91 #define __SMALL_BITFIELDS 92 #endif 93 94 #if defined(__D10V__) 95 #define __SMALL_BITFIELDS 96 #undef INT_MAX 97 #undef UINT_MAX 98 #define INT_MAX __INT_MAX__ 99 #define UINT_MAX (__INT_MAX__ * 2U + 1) 100 #define _POINTER_INT short 101 #endif 102 103 #if defined(__mc68hc11__) || defined(__mc68hc12__) || defined(__mc68hc1x__) 104 #undef INT_MAX 105 #undef UINT_MAX 106 #define INT_MAX __INT_MAX__ 107 #define UINT_MAX (__INT_MAX__ * 2U + 1) 108 #define _POINTER_INT short 109 #endif 110 111 #ifdef ___AM29K__ 112 #define _FLOAT_RET double 113 #endif 114 115 #ifdef __i386__ 116 #ifndef __unix__ 117 /* in other words, go32 */ 118 #define _FLOAT_RET double 119 #endif 120 #if defined(__linux__) || defined(__RDOS__) 121 /* we want the reentrancy structure to be returned by a function */ 122 #define __DYNAMIC_REENT__ 123 #define HAVE_GETDATE 124 #ifndef __LARGE64_FILES 125 #define __LARGE64_FILES 1 126 #endif 127 /* we use some glibc header files so turn on glibc large file feature */ 128 #define _LARGEFILE64_SOURCE 1 129 #endif 130 #endif 131 132 #ifdef __mn10200__ 133 #define __SMALL_BITFIELDS 134 #endif 135 136 #ifdef __AVR__ 137 #define __SMALL_BITFIELDS 138 #define _POINTER_INT short 139 #endif 140 141 #if defined(__v850) && !defined(__rtems__) 142 #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__sda__)) 143 #endif 144 145 /* For the PowerPC eabi, force the _impure_ptr to be in .sdata */ 146 #if defined(__PPC__) 147 #if defined(_CALL_SYSV) 148 #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__section__(".sdata"))) 149 #endif 150 #ifdef __SPE__ 151 #define _LONG_DOUBLE double 152 #endif 153 #endif 154 155 /* Configure small REENT structure for Xilinx MicroBlaze platforms */ 156 #if defined (__MICROBLAZE__) && !defined(__rtems__) 157 #ifndef _REENT_SMALL 158 #define _REENT_SMALL 159 #endif 160 /* Xilinx XMK uses Unix98 mutex */ 161 #ifdef __XMK__ 162 #define _UNIX98_THREAD_MUTEX_ATTRIBUTES 163 #endif 164 #endif 165 166 #if defined(__mips__) && !defined(__rtems__) 167 #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__section__(".sdata"))) 168 #endif 169 170 #ifdef __xstormy16__ 171 #define __SMALL_BITFIELDS 172 #undef INT_MAX 173 #undef UINT_MAX 174 #define INT_MAX __INT_MAX__ 175 #define UINT_MAX (__INT_MAX__ * 2U + 1) 176 #define MALLOC_ALIGNMENT 8 177 #define _POINTER_INT short 178 #define __BUFSIZ__ 16 179 #define _REENT_SMALL 180 #endif 181 182 #if defined __MSP430__ 183 #ifndef _REENT_SMALL 184 #define _REENT_SMALL 185 #endif 186 187 #define __BUFSIZ__ 256 188 #define __SMALL_BITFIELDS 189 190 #ifdef __MSP430X_LARGE__ 191 #define _POINTER_INT __int20 192 #else 193 #define _POINTER_INT int 194 #endif 195 #endif 196 197 #ifdef __m32c__ 198 #define __SMALL_BITFIELDS 199 #undef INT_MAX 200 #undef UINT_MAX 201 #define INT_MAX __INT_MAX__ 202 #define UINT_MAX (__INT_MAX__ * 2U + 1) 203 #define MALLOC_ALIGNMENT 8 204 #if defined(__r8c_cpu__) || defined(__m16c_cpu__) 205 #define _POINTER_INT short 206 #else 207 #define _POINTER_INT long 208 #endif 209 #define __BUFSIZ__ 16 210 #define _REENT_SMALL 211 #endif /* __m32c__ */ 212 213 #ifdef __SPU__ 214 #define MALLOC_ALIGNMENT 16 215 #define __CUSTOM_FILE_IO__ 216 #endif 217 218 #if defined(__or1k__) || defined(__or1knd__) 219 #define __DYNAMIC_REENT__ 220 #endif 221 222 /* This block should be kept in sync with GCC's limits.h. The point 223 of having these definitions here is to not include limits.h, which 224 would pollute the user namespace, while still using types of the 225 the correct widths when deciding how to define __int32_t and 226 __int64_t. */ 227 #ifndef __INT_MAX__ 228 # ifdef INT_MAX 229 # define __INT_MAX__ INT_MAX 230 # else 231 # define __INT_MAX__ 2147483647 232 # endif 233 #endif 234 235 #ifndef __LONG_MAX__ 236 # ifdef LONG_MAX 237 # define __LONG_MAX__ LONG_MAX 238 # else 239 # if defined (__alpha__) || (defined (__sparc__) && defined(__arch64__)) \ 240 || defined (__sparcv9) 241 # define __LONG_MAX__ 9223372036854775807L 242 # else 243 # define __LONG_MAX__ 2147483647L 244 # endif /* __alpha__ || sparc64 */ 245 # endif 246 #endif 247 /* End of block that should be kept in sync with GCC's limits.h. */ 248 249 #ifndef _POINTER_INT 250 #define _POINTER_INT long 251 #endif 252 253 #ifdef __frv__ 254 #define __ATTRIBUTE_IMPURE_PTR__ __attribute__((__section__(".sdata"))) 255 #endif 256 #undef __RAND_MAX 257 #if __INT_MAX__ == 32767 258 #define __RAND_MAX 32767 259 #else 260 #define __RAND_MAX 0x7fffffff 261 #endif 262 263 264 #if defined(__rtems__) 265 #define __FILENAME_MAX__ 255 266 #define __DYNAMIC_REENT__ 267 #endif 268 269 #ifndef __WCHAR_MAX__ 270 #if __INT_MAX__ == 32767 || defined (_WIN32) 271 #define __WCHAR_MAX__ 0xffffu 272 #endif 273 #endif 274 275 #ifdef PICOLIBC_TLS 276 #if (defined(__cplusplus) && (__cplusplus) >= 201103L) || \ 277 (defined(__STDC_VERSION__) && (__STDC_VERSION__) >= 202311L) 278 #define NEWLIB_THREAD_LOCAL thread_local 279 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__) >= 201112L 280 #define NEWLIB_THREAD_LOCAL _Thread_local 281 #else 282 #define NEWLIB_THREAD_LOCAL __thread 283 #endif 284 #else 285 #define NEWLIB_THREAD_LOCAL 286 #endif 287 288 /* See if small reent asked for at configuration time and 289 is not chosen by the platform by default. */ 290 #ifdef _WANT_REENT_SMALL 291 #ifndef _REENT_SMALL 292 #define _REENT_SMALL 293 #endif 294 #endif 295 296 #ifdef _WANT_USE_LONG_TIME_T 297 #ifndef _USE_LONG_TIME_T 298 #define _USE_LONG_TIME_T 299 #endif 300 #endif 301 302 #ifdef _WANT_USE_GDTOA 303 #ifndef _USE_GDTOA 304 #define _USE_GDTOA 305 #endif 306 #endif 307 308 #ifdef _WANT_REENT_BACKWARD_BINARY_COMPAT 309 #ifndef _REENT_BACKWARD_BINARY_COMPAT 310 #define _REENT_BACKWARD_BINARY_COMPAT 311 #endif 312 #endif 313 314 #define _REENT_THREAD_LOCAL 315 316 /* If _MB_EXTENDED_CHARSETS_ALL is set, we want all of the extended 317 charsets. The extended charsets add a few functions and a couple 318 of tables of a few K each. */ 319 #ifdef _MB_EXTENDED_CHARSETS_ALL 320 #define _MB_EXTENDED_CHARSETS_ISO 1 321 #define _MB_EXTENDED_CHARSETS_WINDOWS 1 322 #endif 323 324 /* Figure out if long double is the same size as double. If the system 325 * doesn't provide long double, then those values will be undefined 326 * and cpp will substitute 0 for them in the test 327 */ 328 #if LDBL_MANT_DIG == DBL_MANT_DIG && LDBL_MIN_EXP == DBL_MIN_EXP && \ 329 LDBL_MAX_EXP == DBL_MAX_EXP 330 #define _LDBL_EQ_DBL 331 #endif 332 333 /* Newlib doesn't fully support long double math functions so far. 334 On platforms where long double equals double the long double functions 335 simply call the double functions. On Cygwin the long double functions 336 are implemented independently from newlib to be able to use optimized 337 assembler functions despite using the Microsoft x86_64 ABI. */ 338 #if defined (_LDBL_EQ_DBL) || defined (__CYGWIN__) || (defined(__SIZEOF_LONG_DOUBLE__) && __SIZEOF_LONG_DOUBLE__ <= 8) || (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) 339 #define _HAVE_LONG_DOUBLE_MATH 340 #endif 341 342 /* 343 * When the address sanitizer is enabled, we must prevent the library 344 * from even reading beyond the end of input data. This happens in 345 * many optimized string functions. 346 */ 347 #ifdef __has_feature 348 #if __has_feature(address_sanitizer) 349 #define PICOLIBC_NO_OUT_OF_BOUNDS_READS 350 #endif 351 #elif defined(__SANITIZE_ADDRESS__) 352 #define PICOLIBC_NO_OUT_OF_BOUNDS_READS 353 #endif 354 355 #endif /* __SYS_CONFIG_H__ */ 356