1 /* Id */ 2 /* $NetBSD: target.c,v 1.1.1.1 2016/02/09 20:29:13 plunky Exp $ */ 3 4 /*- 5 * Copyright (c) 2014 Iain Hibbert. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy 8 * of this software and associated documentation files (the "Software"), to deal 9 * in the Software without restriction, including without limitation the rights 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 * copies of the Software, and to permit persons to whom the Software is 12 * furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in 15 * all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 * THE SOFTWARE. 24 */ 25 26 /* 27 * compile this file for the machine target, with 28 * -I .. 29 * -I ../os/$(TARGOS) -D os_$(TARGOS) 30 * -I ../arch/$(TARGMACH) -D mach_$(TARGMACH) 31 * -c target.c 32 * 33 * which will provide an array of the target-specific definitions 34 */ 35 36 #include "config.h" 37 38 /* 39 * Bring in the machine definitions, from 40 * "arch/$(TARGMACH)/macdefs.h" 41 */ 42 #include "macdefs.h" 43 44 /* 45 * Bring in the OS definitions, from 46 * "os/$(TARGOS)/osdefs.h" 47 */ 48 #include "osdefs.h" 49 50 /* basic type names */ 51 #define TYPE_CHAR char 52 #define TYPE_UCHAR unsigned char 53 #define TYPE_SHORT short int 54 #define TYPE_USHORT unsigned short int 55 #define TYPE_INT int 56 #define TYPE_UNSIGNED unsigned int 57 #define TYPE_LONG long int 58 #define TYPE_ULONG unsigned long int 59 #define TYPE_LONGLONG long long int 60 #define TYPE_ULONGLONG unsigned long long int 61 #define TYPE_FLOAT float 62 #define TYPE_DOUBLE double 63 #define TYPE_LDOUBLE long double 64 65 /* 66 * C99 basic type sizes (machine-dependent) 67 * - preprocessor cannot stringify the result of a division 68 */ 69 70 #if (SZSHORT/SZCHAR) == 2 71 #define SIZE_SHORT 2 72 #else 73 #error Do not understand SZSHORT 74 #endif 75 76 #if (SZINT/SZCHAR) == 2 77 #define SIZE_INT 2 78 #elif (SZINT/SZCHAR) == 4 79 #define SIZE_INT 4 80 #else 81 #error Do not understand SZINT 82 #endif 83 84 #if (SZLONG/SZCHAR) == 2 85 #define SIZE_LONG 2 86 #elif (SZLONG/SZCHAR) == 4 87 #define SIZE_LONG 4 88 #elif (SZLONG/SZCHAR) == 8 89 #define SIZE_LONG 8 90 #else 91 #error Do not understand SZLONG 92 #endif 93 94 /* 95 * C99 extended type definitions (OS-dependent) 96 */ 97 98 #if WCHAR_TYPE == USHORT 99 #define PCC_WCHAR_MIN 0 100 #define PCC_WCHAR_MAX MAX_USHORT 101 #define PCC_WCHAR_TYPE TYPE_USHORT 102 #define PCC_WCHAR_SIZE SIZE_SHORT 103 #elif WCHAR_TYPE == INT 104 #define PCC_WCHAR_MIN MIN_INT 105 #define PCC_WCHAR_MAX MAX_INT 106 #define PCC_WCHAR_TYPE TYPE_INT 107 #define PCC_WCHAR_SIZE SIZE_INT 108 #else 109 #error Do not understand WCHAR_TYPE 110 #endif 111 112 #if WCHAR_SIZE != PCC_WCHAR_SIZE 113 #error WCHAR_SIZE does not match WCHAR_TYPE 114 #endif 115 116 #if WINT_TYPE == INT 117 #define PCC_WINT_MIN MIN_INT 118 #define PCC_WINT_MAX MAX_INT 119 #define PCC_WINT_TYPE TYPE_INT 120 #define PCC_WINT_SIZE SIZE_INT 121 #elif WINT_TYPE == UNSIGNED 122 #define PCC_WINT_MIN 0 123 #define PCC_WINT_MAX MAX_UNSIGNED 124 #define PCC_WINT_TYPE TYPE_UNSIGNED 125 #define PCC_WINT_SIZE SIZE_INT 126 #else 127 #error Do not understand WINT_TYPE 128 #endif 129 130 #if SIZE_TYPE == UNSIGNED 131 #define PCC_SIZE_MIN 0 132 #define PCC_SIZE_MAX MAX_UNSIGNED 133 #define PCC_SIZE_TYPE TYPE_UNSIGNED 134 #define PCC_SIZE_SIZE SIZE_INT 135 #elif SIZE_TYPE == ULONG 136 #define PCC_SIZE_MIN 0 137 #define PCC_SIZE_MAX MAX_ULONG 138 #define PCC_SIZE_TYPE TYPE_ULONG 139 #define PCC_SIZE_SIZE SIZE_LONG 140 #else 141 #error Do not understand SIZE_TYPE 142 #endif 143 144 #if PTRDIFF_TYPE == INT 145 #define PCC_PTRDIFF_MIN MIN_INT 146 #define PCC_PTRDIFF_MAX MAX_INT 147 #define PCC_PTRDIFF_TYPE TYPE_INT 148 #define PCC_PTRDIFF_SIZE SIZE_INT 149 #elif PTRDIFF_TYPE == LONG 150 #define PCC_PTRDIFF_MIN MIN_LONG 151 #define PCC_PTRDIFF_MAX MAX_LONG 152 #define PCC_PTRDIFF_TYPE TYPE_LONG 153 #define PCC_PTRDIFF_SIZE SIZE_LONG 154 #else 155 #error Do not understand PTRDIFF_TYPE 156 #endif 157 158 /* IEEE single precision (32-bit) constants */ 159 #define SP_DIG "6" 160 #define SP_EPSILON "0x1.0p-23" 161 #define SP_MANT_DIG "24" 162 #define SP_MAX_10_EXP "38" 163 #define SP_MAX_EXP "128" 164 #define SP_MAX "0x1.fffffep+127" 165 #define SP_MIN_10_EXP "(-37)" 166 #define SP_MIN_EXP "(-125)" 167 #define SP_MIN "0x1.0p-126" 168 169 /* IEEE double precision (64-bit) constants */ 170 #define DP_DIG "15" 171 #define DP_EPSILON "0x1.0p-52" 172 #define DP_MANT_DIG "53" 173 #define DP_MAX_10_EXP "308" 174 #define DP_MAX_EXP "1024" 175 #define DP_MAX "0x1.fffffffffffffp+1023" 176 #define DP_MIN_10_EXP "(-307)" 177 #define DP_MIN_EXP "(-1021)" 178 #define DP_MIN "0x1.0p-1022" 179 180 /* Intel "double extended" precision (80-bit) constants */ 181 #define X80_DIG "18" 182 #define X80_EPSILON "0x1.0p-63" 183 #define X80_MANT_DIG "64" 184 #define X80_MAX_10_EXP "4932" 185 #define X80_MAX_EXP "16384" 186 #define X80_MAX "0x1.fffffffffffffffep+16383" 187 #define X80_MIN_10_EXP "(-4931)" 188 #define X80_MIN_EXP "(-16381)" 189 #define X80_MIN "0x1.0p-16382" 190 191 /* IEEE quad precision (128-bit) constants */ 192 #define QP_DIG "33" 193 #define QP_EPSILON "0x1.0p-112" 194 #define QP_MANT_DIG "113" 195 #define QP_MAX_10_EXP "4932" 196 #define QP_MAX_EXP "16384" 197 #define QP_MAX "0x1.ffffffffffffffffffffffffffffp+16383" 198 #define QP_MIN_10_EXP "(-4931)" 199 #define QP_MIN_EXP "(-16381)" 200 #define QP_MIN "0x1.0p-16382"" 201 202 #if SZFLOAT == 32 203 #define PCC_FLT_DIG SP_DIG 204 #define PCC_FLT_EPSILON SP_EPSILON 205 #define PCC_FLT_MANT_DIG SP_MANT_DIG 206 #define PCC_FLT_MAX_10_EXP SP_MAX_10_EXP 207 #define PCC_FLT_MAX_EXP SP_MAX_EXP 208 #define PCC_FLT_MAX SP_MAX 209 #define PCC_FLT_MIN_10_EXP SP_MIN_10_EXP 210 #define PCC_FLT_MIN_EXP SP_MIN_EXP 211 #define PCC_FLT_MIN SP_MIN 212 #else 213 #error Do not understand SZFLOAT 214 #endif 215 216 #if SZDOUBLE == 64 217 #define PCC_DBL_DIG DP_DIG 218 #define PCC_DBL_EPSILON DP_EPSILON 219 #define PCC_DBL_MANT_DIG DP_MANT_DIG 220 #define PCC_DBL_MAX_10_EXP DP_MAX_10_EXP 221 #define PCC_DBL_MAX_EXP DP_MAX_EXP 222 #define PCC_DBL_MAX DP_MAX 223 #define PCC_DBL_MIN_10_EXP DP_MIN_10_EXP 224 #define PCC_DBL_MIN_EXP DP_MIN_EXP 225 #define PCC_DBL_MIN DP_MIN 226 #else 227 #error Do not understand SZDOUBLE 228 #endif 229 230 #if SZLDOUBLE == 64 231 #define PCC_LDBL_DIG DP_DIG 232 #define PCC_LDBL_EPSILON DP_EPSILON 233 #define PCC_LDBL_MANT_DIG DP_MANT_DIG 234 #define PCC_LDBL_MAX_10_EXP DP_MAX_10_EXP 235 #define PCC_LDBL_MAX_EXP DP_MAX_EXP 236 #define PCC_LDBL_MAX DP_MAX 237 #define PCC_LDBL_MIN_10_EXP DP_MIN_10_EXP 238 #define PCC_LDBL_MIN_EXP DP_MIN_EXP 239 #define PCC_LDBL_MIN DP_MIN 240 #elif SZLDOUBLE == 96 241 #define PCC_LDBL_DIG X80_DIG 242 #define PCC_LDBL_EPSILON X80_EPSILON 243 #define PCC_LDBL_MANT_DIG X80_MANT_DIG 244 #define PCC_LDBL_MAX_10_EXP X80_MAX_10_EXP 245 #define PCC_LDBL_MAX_EXP X80_MAX_EXP 246 #define PCC_LDBL_MAX X80_MAX 247 #define PCC_LDBL_MIN_10_EXP X80_MIN_10_EXP 248 #define PCC_LDBL_MIN_EXP X80_MIN_EXP 249 #define PCC_LDBL_MIN X80_MIN 250 #elif SZLDOUBLE == 128 251 #define PCC_LDBL_DIG QP_DIG 252 #define PCC_LDBL_EPSILON QP_EPSILON 253 #define PCC_LDBL_MANT_DIG QP_MANT_DIG 254 #define PCC_LDBL_MAX_10_EXP QP_MAX_10_EXP 255 #define PCC_LDBL_MAX_EXP QP_MAX_EXP 256 #define PCC_LDBL_MAX QP_MAX 257 #define PCC_LDBL_MIN_10_EXP QP_MIN_10_EXP 258 #define PCC_LDBL_MIN_EXP QP_MIN_EXP 259 #define PCC_LDBL_MIN QP_MIN 260 #else 261 #error Do not understand SZLDOUBLE 262 #endif 263 264 #define MKS(x) _MKS(x) 265 #define _MKS(x) #x 266 267 /* 268 * target-specific definitions 269 */ 270 271 const char *target_cppdefs[] = { 272 #if defined(CPPDEFS_os) 273 CPPDEFS_os, 274 #endif 275 #if defined(CPPDEFS_mach) 276 CPPDEFS_mach, 277 #endif 278 #if (SZINT == 16) && (SZLONG == 32) && (SZPOINT(CHAR) == 32) 279 "-D__LP32__", 280 "-D_LP32", 281 #endif 282 #if (SZINT == 32) && (SZLONG == 32) && (SZPOINT(CHAR) == 32) 283 "-D__ILP32__", 284 "-D_ILP32", 285 #endif 286 #if (SZINT == 32) && (SZLONG == 64) && (SZPOINT(CHAR) == 64) 287 "-D__LP64__", 288 "-D_LP64", 289 #endif 290 #if (SZINT == 64) && (SZLONG == 64) && (SZPOINT(CHAR) == 64) 291 "-D__ILP64__", 292 "-D_ILP64", 293 #endif 294 #if defined(ELFABI) 295 "-D__ELF__", 296 #endif 297 298 "-D__CHAR_MAX__=" MKS(MAX_CHAR), 299 "-D__SHORT_MAX__=" MKS(MAX_SHORT), 300 "-D__INT_MAX__=" MKS(MAX_INT), 301 "-D__LONG_MAX__=" MKS(MAX_LONG), 302 "-D__LONG_LONG_MAX__=" MKS(MAX_LONGLONG), 303 304 "-D__WCHAR_MIN__=" MKS(PCC_WCHAR_MIN), 305 "-D__WCHAR_MAX__=" MKS(PCC_WCHAR_MAX), 306 "-D__WCHAR_TYPE__=" MKS(PCC_WCHAR_TYPE), 307 "-D__SIZEOF_WCHAR__=" MKS(PCC_WCHAR_SIZE), 308 309 "-D__WINT_MIN__=" MKS(PCC_WINT_MIN), 310 "-D__WINT_MAX__=" MKS(PCC_WINT_MAX), 311 "-D__WINT_TYPE__=" MKS(PCC_WINT_TYPE), 312 "-D__SIZEOF_WINT__=" MKS(PCC_WINT_SIZE), 313 314 "-D__SIZE_MAX__=" MKS(PCC_SIZE_MAX), 315 "-D__SIZE_TYPE__=" MKS(PCC_SIZE_TYPE), 316 "-D__SIZEOF_SIZE__=" MKS(PCC_SIZE_SIZE), 317 318 "-D__PTRDIFF_MIN__=" MKS(PCC_PTRDIFF_MIN), 319 "-D__PTRDIFF_MAX__=" MKS(PCC_PTRDIFF_MAX), 320 "-D__PTRDIFF_TYPE__=" MKS(PCC_PTRDIFF_TYPE), 321 "-D__SIZEOF_PTRDIFF__=" MKS(PCC_PTRDIFF_SIZE), 322 323 "-D__FLT_DIG__=" PCC_FLT_DIG, 324 "-D__FLT_EPSILON__=" PCC_FLT_EPSILON "F", 325 "-D__FLT_MANT_DIG__=" PCC_FLT_MANT_DIG, 326 "-D__FLT_MAX_10_EXP__=" PCC_FLT_MAX_10_EXP, 327 "-D__FLT_MAX_EXP__=" PCC_FLT_MAX_EXP, 328 "-D__FLT_MAX__=" PCC_FLT_MAX "F", 329 "-D__FLT_MIN_10_EXP__=" PCC_FLT_MIN_10_EXP, 330 "-D__FLT_MIN_EXP__=" PCC_FLT_MIN_EXP, 331 "-D__FLT_MIN__=" PCC_FLT_MIN "F", 332 333 "-D__DBL_DIG__=" PCC_DBL_DIG, 334 "-D__DBL_EPSILON__=" PCC_DBL_EPSILON, 335 "-D__DBL_MANT_DIG__=" PCC_DBL_MANT_DIG, 336 "-D__DBL_MAX_10_EXP__=" PCC_DBL_MAX_10_EXP, 337 "-D__DBL_MAX_EXP__=" PCC_DBL_MAX_EXP, 338 "-D__DBL_MAX__=" PCC_DBL_MAX, 339 "-D__DBL_MIN_10_EXP__=" PCC_DBL_MIN_10_EXP, 340 "-D__DBL_MIN_EXP__=" PCC_DBL_MIN_EXP, 341 "-D__DBL_MIN__=" PCC_DBL_MIN, 342 343 "-D__LDBL_DIG__=" PCC_LDBL_DIG, 344 "-D__LDBL_EPSILON__=" PCC_LDBL_EPSILON "L", 345 "-D__LDBL_MANT_DIG__=" PCC_LDBL_MANT_DIG, 346 "-D__LDBL_MAX_10_EXP__=" PCC_LDBL_MAX_10_EXP, 347 "-D__LDBL_MAX_EXP__=" PCC_LDBL_MAX_EXP, 348 "-D__LDBL_MAX__=" PCC_LDBL_MAX "L", 349 "-D__LDBL_MIN_10_EXP__=" PCC_LDBL_MIN_10_EXP, 350 "-D__LDBL_MIN_EXP__=" PCC_LDBL_MIN_EXP, 351 "-D__LDBL_MIN__=" PCC_LDBL_MIN "L", 352 353 NULL 354 }; 355 356 /* put these in macdefs.h ?? 357 358 #if defined(mach_amd64) 359 "-D__x86_64__", 360 "-D__x86_64", 361 "-D__amd64__", 362 "-D__amd64", 363 #endif 364 #if defined(mach_arm) 365 "-D__arm__", 366 "-D__arm", 367 #endif 368 #if defined(mach_i386) 369 "-D__x86__", 370 "-D__x86", 371 "-D__i386__", 372 "-D__i386", 373 #endif 374 #if defined(mach_nova) 375 "-D__nova__", 376 "-D__nova", 377 #endif 378 #if defined(mach_m16c) 379 "-D__m16c__", 380 "-D__m16c", 381 #endif 382 #if defined(mach_mips) 383 "-D__mips__", 384 "-D__mips", 385 #endif 386 #if defined(mach_pdp10) 387 "-D__pdp10__", 388 "-D__pdp10", 389 #endif 390 #if defined(mach_pdp11) 391 "-D__pdp11__", 392 "-D__pdp11", 393 #endif 394 #if defined(mach_powerpc) 395 "-D__powerpc__", 396 "-D__powerpc", 397 #endif 398 #if defined(mach_sparc64) 399 "-D__sparc_v9__", 400 "-D__sparc64__", 401 "-D__sparc64", 402 "-D__sparc__", 403 "-D__sparc", 404 #endif 405 #if defined(mach_vax) 406 "-D__vax__", 407 "-D__vax", 408 #endif 409 410 */ 411