1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 2 * vim: set ts=8 sts=4 et sw=4 tw=99: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef jscpucfg_h 8 #define jscpucfg_h 9 10 #define JS_HAVE_LONG_LONG 11 12 #if defined(_WIN64) 13 14 # if defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_) 15 # define IS_LITTLE_ENDIAN 1 16 # undef IS_BIG_ENDIAN 17 # else /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ 18 # error "CPU type is unknown" 19 # endif /* !(defined(_M_X64) || defined(_M_AMD64) || defined(_AMD64_)) */ 20 21 #elif defined(_WIN32) 22 23 # ifdef __WATCOMC__ 24 # define HAVE_VA_LIST_AS_ARRAY 1 25 # endif 26 27 # define IS_LITTLE_ENDIAN 1 28 # undef IS_BIG_ENDIAN 29 30 #elif defined(__APPLE__) || defined(__powerpc__) || defined(__ppc__) 31 # if __LITTLE_ENDIAN__ 32 # define IS_LITTLE_ENDIAN 1 33 # undef IS_BIG_ENDIAN 34 # elif __BIG_ENDIAN__ 35 # undef IS_LITTLE_ENDIAN 36 # define IS_BIG_ENDIAN 1 37 # endif 38 39 #elif defined(JS_HAVE_ENDIAN_H) 40 # include <endian.h> 41 42 /* 43 * Historically, OSes providing <endian.h> only defined 44 * __BYTE_ORDER to either __LITTLE_ENDIAN or __BIG_ENDIAN. 45 * The Austin group decided to standardise <endian.h> in 46 * POSIX around 2011, expecting it to provide a BYTE_ORDER 47 * #define set to either LITTLE_ENDIAN or BIG_ENDIAN. We 48 * should try to cope with both possibilities here. 49 */ 50 51 # if defined(__BYTE_ORDER) || defined(BYTE_ORDER) 52 # if defined(__BYTE_ORDER) 53 # if __BYTE_ORDER == __LITTLE_ENDIAN 54 # define IS_LITTLE_ENDIAN 1 55 # undef IS_BIG_ENDIAN 56 # elif __BYTE_ORDER == __BIG_ENDIAN 57 # undef IS_LITTLE_ENDIAN 58 # define IS_BIG_ENDIAN 1 59 # endif 60 # endif 61 # if defined(BYTE_ORDER) 62 # if BYTE_ORDER == LITTLE_ENDIAN 63 # define IS_LITTLE_ENDIAN 1 64 # undef IS_BIG_ENDIAN 65 # elif BYTE_ORDER == BIG_ENDIAN 66 # undef IS_LITTLE_ENDIAN 67 # define IS_BIG_ENDIAN 1 68 # endif 69 # endif 70 # else /* !defined(__BYTE_ORDER) */ 71 # error "endian.h does not define __BYTE_ORDER nor BYTE_ORDER. Cannot determine endianness." 72 # endif 73 74 /* BSDs */ 75 #elif defined(JS_HAVE_MACHINE_ENDIAN_H) 76 # include <sys/types.h> 77 # include <machine/endian.h> 78 79 # if defined(_BYTE_ORDER) 80 # if _BYTE_ORDER == _LITTLE_ENDIAN 81 # define IS_LITTLE_ENDIAN 1 82 # undef IS_BIG_ENDIAN 83 # elif _BYTE_ORDER == _BIG_ENDIAN 84 # undef IS_LITTLE_ENDIAN 85 # define IS_BIG_ENDIAN 1 86 # endif 87 # else /* !defined(_BYTE_ORDER) */ 88 # error "machine/endian.h does not define _BYTE_ORDER. Cannot determine endianness." 89 # endif 90 91 #elif defined(JS_HAVE_SYS_ISA_DEFS_H) 92 # include <sys/isa_defs.h> 93 94 # if defined(_BIG_ENDIAN) 95 # undef IS_LITTLE_ENDIAN 96 # define IS_BIG_ENDIAN 1 97 # elif defined(_LITTLE_ENDIAN) 98 # define IS_LITTLE_ENDIAN 1 99 # undef IS_BIG_ENDIAN 100 # else /* !defined(_LITTLE_ENDIAN) */ 101 # error "sys/isa_defs.h does not define _BIG_ENDIAN or _LITTLE_ENDIAN. Cannot determine endianness." 102 # endif 103 # if !defined(JS_STACK_GROWTH_DIRECTION) 104 # if defined(_STACK_GROWS_UPWARD) 105 # define JS_STACK_GROWTH_DIRECTION (1) 106 # elif defined(_STACK_GROWS_DOWNWARD) 107 # define JS_STACK_GROWTH_DIRECTION (-1) 108 # endif 109 # endif 110 111 #elif defined(__sparc) || defined(__sparc__) || \ 112 defined(_POWER) || defined(__hppa) || \ 113 defined(_MIPSEB) || defined(_BIG_ENDIAN) 114 /* IA64 running HP-UX will have _BIG_ENDIAN defined. 115 * IA64 running Linux will have endian.h and be handled above. 116 */ 117 # undef IS_LITTLE_ENDIAN 118 # define IS_BIG_ENDIAN 1 119 120 #else /* !defined(__sparc) && !defined(__sparc__) && ... */ 121 # error "Cannot determine endianness of your platform. Please add support to jscpucfg.h." 122 #endif 123 124 #ifndef JS_STACK_GROWTH_DIRECTION 125 # ifdef __hppa 126 # define JS_STACK_GROWTH_DIRECTION (1) 127 # else 128 # define JS_STACK_GROWTH_DIRECTION (-1) 129 # endif 130 #endif 131 132 #endif /* jscpucfg_h */ 133