2 * Keep all the ugly #ifdef for system stuff here
13 #if defined(__BEOS__) || \
14 defined(__NetBSD__) || \
15 defined(__FreeBSD__) || \
18 # include <inttypes.h>
19 #elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__) || defined(__OpenBSD__)
29 #if !defined(__WIN32__) && !defined(__MINGW32__)
30 # include <sys/mman.h>
33 /* Not all systems (like Windows) has this define, and yes
34 * we do replace/emulate mmap() on those systems ...
37 # define MAP_FAILED ((void *)-1)
41 #ifndef O_BINARY /* should be define'd on __WIN32__ */
47 # include <byteswap.h>
48 #elif defined(__MACH__) || defined(__FreeBSD__)
49 # include <machine/endian.h>
52 # include <sys/endian.h> /* htole32 and friends */
53 # define __BYTE_ORDER BYTE_ORDER
54 # define __LITTLE_ENDIAN LITTLE_ENDIAN
55 # define __BIG_ENDIAN BIG_ENDIAN
56 #elif defined(__OpenBSD__)
58 # define __BYTE_ORDER BYTE_ORDER
59 # define __LITTLE_ENDIAN LITTLE_ENDIAN
60 # define __BIG_ENDIAN BIG_ENDIAN
66 typedef uint16_t __u16;
67 typedef uint32_t __u32;
68 typedef unsigned int uint;
69 typedef unsigned long ulong;
71 /* Define these on the host so we can build some target code */
75 ((((x) & 0xff00) >> 8) | \
76 (((x) & 0x00ff) << 8))
78 ((((x) & 0xff000000) >> 24) | \
79 (((x) & 0x00ff0000) >> 8) | \
80 (((x) & 0x0000ff00) << 8) | \
81 (((x) & 0x000000ff) << 24))
82 #define _uswap_64(x, sfx) \
83 ((((x) & 0xff00000000000000##sfx) >> 56) | \
84 (((x) & 0x00ff000000000000##sfx) >> 40) | \
85 (((x) & 0x0000ff0000000000##sfx) >> 24) | \
86 (((x) & 0x000000ff00000000##sfx) >> 8) | \
87 (((x) & 0x00000000ff000000##sfx) << 8) | \
88 (((x) & 0x0000000000ff0000##sfx) << 24) | \
89 (((x) & 0x000000000000ff00##sfx) << 40) | \
90 (((x) & 0x00000000000000ff##sfx) << 56))
92 # define uswap_64(x) _uswap_64(x, ull)
94 # define uswap_64(x) _uswap_64(x, )
97 #if __BYTE_ORDER == __LITTLE_ENDIAN
98 # define cpu_to_le16(x) (x)
99 # define cpu_to_le32(x) (x)
100 # define cpu_to_le64(x) (x)
101 # define le16_to_cpu(x) (x)
102 # define le32_to_cpu(x) (x)
103 # define le64_to_cpu(x) (x)
104 # define cpu_to_be16(x) uswap_16(x)
105 # define cpu_to_be32(x) uswap_32(x)
106 # define cpu_to_be64(x) uswap_64(x)
107 # define be16_to_cpu(x) uswap_16(x)
108 # define be32_to_cpu(x) uswap_32(x)
109 # define be64_to_cpu(x) uswap_64(x)
111 # define cpu_to_le16(x) uswap_16(x)
112 # define cpu_to_le32(x) uswap_32(x)
113 # define cpu_to_le64(x) uswap_64(x)
114 # define le16_to_cpu(x) uswap_16(x)
115 # define le32_to_cpu(x) uswap_32(x)
116 # define le64_to_cpu(x) uswap_64(x)
117 # define cpu_to_be16(x) (x)
118 # define cpu_to_be32(x) (x)
119 # define cpu_to_be64(x) (x)
120 # define be16_to_cpu(x) (x)
121 # define be32_to_cpu(x) (x)
122 # define be64_to_cpu(x) (x)
125 #else /* !USE_HOSTCC */
127 /* Type for `void *' pointers. */
128 typedef unsigned long int uintptr_t;
130 #include <linux/string.h>
131 #include <linux/types.h>
132 #include <asm/byteorder.h>
134 #if __SIZEOF_LONG__ == 8
135 # define __WORDSIZE 64
136 #elif __SIZEOF_LONG__ == 4
137 # define __WORDSIZE 32
140 * Assume 32-bit for now - only newer toolchains support this feature and
141 * this is only required for sandbox support at present.
143 #define __WORDSIZE 32
146 #endif /* USE_HOSTCC */
148 #define likely(x) __builtin_expect(!!(x), 1)
149 #define unlikely(x) __builtin_expect(!!(x), 0)
152 #define MEM_SUPPORT_64BIT_DATA 1
154 #define MEM_SUPPORT_64BIT_DATA 0
158 * tools_build() - check if we are building host tools
160 * Return: true if building for the host, false if for a target
162 static inline bool tools_build(void)