137566090SMike Frysinger /* 237566090SMike Frysinger * Keep all the ugly #ifdef for system stuff here 337566090SMike Frysinger */ 437566090SMike Frysinger 537566090SMike Frysinger #ifndef __COMPILER_H__ 637566090SMike Frysinger #define __COMPILER_H__ 737566090SMike Frysinger 837566090SMike Frysinger #include <stddef.h> 937566090SMike Frysinger 1037566090SMike Frysinger #ifdef USE_HOSTCC 1137566090SMike Frysinger 1237566090SMike Frysinger #if defined(__BEOS__) || \ 1337566090SMike Frysinger defined(__NetBSD__) || \ 1437566090SMike Frysinger defined(__FreeBSD__) || \ 1537566090SMike Frysinger defined(__sun__) || \ 1637566090SMike Frysinger defined(__APPLE__) 1737566090SMike Frysinger # include <inttypes.h> 183715a540SJonathan Gray #elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__) || defined(__OpenBSD__) 1937566090SMike Frysinger # include <stdint.h> 2037566090SMike Frysinger #endif 2137566090SMike Frysinger 2237566090SMike Frysinger #include <errno.h> 2337566090SMike Frysinger #include <stdlib.h> 2437566090SMike Frysinger #include <stdint.h> 2537566090SMike Frysinger #include <stdio.h> 2637566090SMike Frysinger #include <string.h> 2737566090SMike Frysinger 2837566090SMike Frysinger #if !defined(__WIN32__) && !defined(__MINGW32__) 2937566090SMike Frysinger # include <sys/mman.h> 3037566090SMike Frysinger #endif 3137566090SMike Frysinger 3237566090SMike Frysinger /* Not all systems (like Windows) has this define, and yes 3337566090SMike Frysinger * we do replace/emulate mmap() on those systems ... 3437566090SMike Frysinger */ 3537566090SMike Frysinger #ifndef MAP_FAILED 3637566090SMike Frysinger # define MAP_FAILED ((void *)-1) 3737566090SMike Frysinger #endif 3837566090SMike Frysinger 3937566090SMike Frysinger #include <fcntl.h> 4037566090SMike Frysinger #ifndef O_BINARY /* should be define'd on __WIN32__ */ 4137566090SMike Frysinger #define O_BINARY 0 4237566090SMike Frysinger #endif 4337566090SMike Frysinger 4437566090SMike Frysinger #ifdef __linux__ 4537566090SMike Frysinger # include <endian.h> 4637566090SMike Frysinger # include <byteswap.h> 475bce5dc3SJeroen Hofstee #elif defined(__MACH__) || defined(__FreeBSD__) 4837566090SMike Frysinger # include <machine/endian.h> 4937566090SMike Frysinger typedef unsigned long ulong; 5037566090SMike Frysinger #endif 51ed8271d1SJeroen Hofstee #ifdef __FreeBSD__ 52ed8271d1SJeroen Hofstee # include <sys/endian.h> /* htole32 and friends */ 53*f29aa23bSJustin Hibbits # define __BYTE_ORDER BYTE_ORDER 54*f29aa23bSJustin Hibbits # define __LITTLE_ENDIAN LITTLE_ENDIAN 55*f29aa23bSJustin Hibbits # define __BIG_ENDIAN BIG_ENDIAN 563715a540SJonathan Gray #elif defined(__OpenBSD__) 573715a540SJonathan Gray # include <endian.h> 58fd184b9cSJonathan Gray # define __BYTE_ORDER BYTE_ORDER 59fd184b9cSJonathan Gray # define __LITTLE_ENDIAN LITTLE_ENDIAN 60fd184b9cSJonathan Gray # define __BIG_ENDIAN BIG_ENDIAN 61ed8271d1SJeroen Hofstee #endif 62ed8271d1SJeroen Hofstee 639d16e93dSJeroen Hofstee #include <time.h> 6437566090SMike Frysinger 6537566090SMike Frysinger typedef uint8_t __u8; 6637566090SMike Frysinger typedef uint16_t __u16; 6737566090SMike Frysinger typedef uint32_t __u32; 68b050c72dSMike Frysinger typedef unsigned int uint; 6937566090SMike Frysinger 7037566090SMike Frysinger #define uswap_16(x) \ 7137566090SMike Frysinger ((((x) & 0xff00) >> 8) | \ 7237566090SMike Frysinger (((x) & 0x00ff) << 8)) 7337566090SMike Frysinger #define uswap_32(x) \ 7437566090SMike Frysinger ((((x) & 0xff000000) >> 24) | \ 7537566090SMike Frysinger (((x) & 0x00ff0000) >> 8) | \ 7637566090SMike Frysinger (((x) & 0x0000ff00) << 8) | \ 7737566090SMike Frysinger (((x) & 0x000000ff) << 24)) 7837566090SMike Frysinger #define _uswap_64(x, sfx) \ 7937566090SMike Frysinger ((((x) & 0xff00000000000000##sfx) >> 56) | \ 8037566090SMike Frysinger (((x) & 0x00ff000000000000##sfx) >> 40) | \ 8137566090SMike Frysinger (((x) & 0x0000ff0000000000##sfx) >> 24) | \ 8237566090SMike Frysinger (((x) & 0x000000ff00000000##sfx) >> 8) | \ 8337566090SMike Frysinger (((x) & 0x00000000ff000000##sfx) << 8) | \ 8437566090SMike Frysinger (((x) & 0x0000000000ff0000##sfx) << 24) | \ 8537566090SMike Frysinger (((x) & 0x000000000000ff00##sfx) << 40) | \ 8637566090SMike Frysinger (((x) & 0x00000000000000ff##sfx) << 56)) 8737566090SMike Frysinger #if defined(__GNUC__) 8837566090SMike Frysinger # define uswap_64(x) _uswap_64(x, ull) 8937566090SMike Frysinger #else 9037566090SMike Frysinger # define uswap_64(x) _uswap_64(x, ) 9137566090SMike Frysinger #endif 9237566090SMike Frysinger 93fd184b9cSJonathan Gray #if __BYTE_ORDER == __LITTLE_ENDIAN 9437566090SMike Frysinger # define cpu_to_le16(x) (x) 9537566090SMike Frysinger # define cpu_to_le32(x) (x) 9637566090SMike Frysinger # define cpu_to_le64(x) (x) 9737566090SMike Frysinger # define le16_to_cpu(x) (x) 9837566090SMike Frysinger # define le32_to_cpu(x) (x) 9937566090SMike Frysinger # define le64_to_cpu(x) (x) 10037566090SMike Frysinger # define cpu_to_be16(x) uswap_16(x) 10137566090SMike Frysinger # define cpu_to_be32(x) uswap_32(x) 10237566090SMike Frysinger # define cpu_to_be64(x) uswap_64(x) 10337566090SMike Frysinger # define be16_to_cpu(x) uswap_16(x) 10437566090SMike Frysinger # define be32_to_cpu(x) uswap_32(x) 10537566090SMike Frysinger # define be64_to_cpu(x) uswap_64(x) 10637566090SMike Frysinger #else 10737566090SMike Frysinger # define cpu_to_le16(x) uswap_16(x) 10837566090SMike Frysinger # define cpu_to_le32(x) uswap_32(x) 10937566090SMike Frysinger # define cpu_to_le64(x) uswap_64(x) 11037566090SMike Frysinger # define le16_to_cpu(x) uswap_16(x) 11137566090SMike Frysinger # define le32_to_cpu(x) uswap_32(x) 11237566090SMike Frysinger # define le64_to_cpu(x) uswap_64(x) 11337566090SMike Frysinger # define cpu_to_be16(x) (x) 11437566090SMike Frysinger # define cpu_to_be32(x) (x) 11537566090SMike Frysinger # define cpu_to_be64(x) (x) 11637566090SMike Frysinger # define be16_to_cpu(x) (x) 11737566090SMike Frysinger # define be32_to_cpu(x) (x) 11837566090SMike Frysinger # define be64_to_cpu(x) (x) 11937566090SMike Frysinger #endif 12037566090SMike Frysinger 12137566090SMike Frysinger #else /* !USE_HOSTCC */ 12237566090SMike Frysinger 1232e680f92SYork Sun /* Type for `void *' pointers. */ 1242e680f92SYork Sun typedef unsigned long int uintptr_t; 1250d296cc2SGabe Black 12637566090SMike Frysinger #include <linux/string.h> 12737566090SMike Frysinger #include <linux/types.h> 12837566090SMike Frysinger #include <asm/byteorder.h> 12937566090SMike Frysinger 130a7551a3fSSimon Glass #if __SIZEOF_LONG__ == 8 131a7551a3fSSimon Glass # define __WORDSIZE 64 132a7551a3fSSimon Glass #elif __SIZEOF_LONG__ == 4 133a7551a3fSSimon Glass # define __WORDSIZE 32 134a7551a3fSSimon Glass #else 135a7551a3fSSimon Glass /* 136a7551a3fSSimon Glass * Assume 32-bit for now - only newer toolchains support this feature and 137a7551a3fSSimon Glass * this is only required for sandbox support at present. 138a7551a3fSSimon Glass */ 139a7551a3fSSimon Glass #define __WORDSIZE 32 140a7551a3fSSimon Glass #endif 141a7551a3fSSimon Glass 142c9502f49SSimon Glass #endif /* USE_HOSTCC */ 14337566090SMike Frysinger 144b63815e3SMatthias Kaehlcke #define likely(x) __builtin_expect(!!(x), 1) 145b63815e3SMatthias Kaehlcke #define unlikely(x) __builtin_expect(!!(x), 0) 146b63815e3SMatthias Kaehlcke 14737566090SMike Frysinger #endif 148