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> 1837566090SMike Frysinger #elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__) 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 51*9d16e93dSJeroen Hofstee #include <time.h> 5237566090SMike Frysinger 5337566090SMike Frysinger typedef uint8_t __u8; 5437566090SMike Frysinger typedef uint16_t __u16; 5537566090SMike Frysinger typedef uint32_t __u32; 56b050c72dSMike Frysinger typedef unsigned int uint; 5737566090SMike Frysinger 5837566090SMike Frysinger #define uswap_16(x) \ 5937566090SMike Frysinger ((((x) & 0xff00) >> 8) | \ 6037566090SMike Frysinger (((x) & 0x00ff) << 8)) 6137566090SMike Frysinger #define uswap_32(x) \ 6237566090SMike Frysinger ((((x) & 0xff000000) >> 24) | \ 6337566090SMike Frysinger (((x) & 0x00ff0000) >> 8) | \ 6437566090SMike Frysinger (((x) & 0x0000ff00) << 8) | \ 6537566090SMike Frysinger (((x) & 0x000000ff) << 24)) 6637566090SMike Frysinger #define _uswap_64(x, sfx) \ 6737566090SMike Frysinger ((((x) & 0xff00000000000000##sfx) >> 56) | \ 6837566090SMike Frysinger (((x) & 0x00ff000000000000##sfx) >> 40) | \ 6937566090SMike Frysinger (((x) & 0x0000ff0000000000##sfx) >> 24) | \ 7037566090SMike Frysinger (((x) & 0x000000ff00000000##sfx) >> 8) | \ 7137566090SMike Frysinger (((x) & 0x00000000ff000000##sfx) << 8) | \ 7237566090SMike Frysinger (((x) & 0x0000000000ff0000##sfx) << 24) | \ 7337566090SMike Frysinger (((x) & 0x000000000000ff00##sfx) << 40) | \ 7437566090SMike Frysinger (((x) & 0x00000000000000ff##sfx) << 56)) 7537566090SMike Frysinger #if defined(__GNUC__) 7637566090SMike Frysinger # define uswap_64(x) _uswap_64(x, ull) 7737566090SMike Frysinger #else 7837566090SMike Frysinger # define uswap_64(x) _uswap_64(x, ) 7937566090SMike Frysinger #endif 8037566090SMike Frysinger 8137566090SMike Frysinger #if __BYTE_ORDER == __LITTLE_ENDIAN 8237566090SMike Frysinger # define cpu_to_le16(x) (x) 8337566090SMike Frysinger # define cpu_to_le32(x) (x) 8437566090SMike Frysinger # define cpu_to_le64(x) (x) 8537566090SMike Frysinger # define le16_to_cpu(x) (x) 8637566090SMike Frysinger # define le32_to_cpu(x) (x) 8737566090SMike Frysinger # define le64_to_cpu(x) (x) 8837566090SMike Frysinger # define cpu_to_be16(x) uswap_16(x) 8937566090SMike Frysinger # define cpu_to_be32(x) uswap_32(x) 9037566090SMike Frysinger # define cpu_to_be64(x) uswap_64(x) 9137566090SMike Frysinger # define be16_to_cpu(x) uswap_16(x) 9237566090SMike Frysinger # define be32_to_cpu(x) uswap_32(x) 9337566090SMike Frysinger # define be64_to_cpu(x) uswap_64(x) 9437566090SMike Frysinger #else 9537566090SMike Frysinger # define cpu_to_le16(x) uswap_16(x) 9637566090SMike Frysinger # define cpu_to_le32(x) uswap_32(x) 9737566090SMike Frysinger # define cpu_to_le64(x) uswap_64(x) 9837566090SMike Frysinger # define le16_to_cpu(x) uswap_16(x) 9937566090SMike Frysinger # define le32_to_cpu(x) uswap_32(x) 10037566090SMike Frysinger # define le64_to_cpu(x) uswap_64(x) 10137566090SMike Frysinger # define cpu_to_be16(x) (x) 10237566090SMike Frysinger # define cpu_to_be32(x) (x) 10337566090SMike Frysinger # define cpu_to_be64(x) (x) 10437566090SMike Frysinger # define be16_to_cpu(x) (x) 10537566090SMike Frysinger # define be32_to_cpu(x) (x) 10637566090SMike Frysinger # define be64_to_cpu(x) (x) 10737566090SMike Frysinger #endif 10837566090SMike Frysinger 10937566090SMike Frysinger #else /* !USE_HOSTCC */ 11037566090SMike Frysinger 11137566090SMike Frysinger #include <linux/string.h> 11237566090SMike Frysinger #include <linux/types.h> 11337566090SMike Frysinger #include <asm/byteorder.h> 11437566090SMike Frysinger 115a7551a3fSSimon Glass #if __SIZEOF_LONG__ == 8 116a7551a3fSSimon Glass # define __WORDSIZE 64 117a7551a3fSSimon Glass #elif __SIZEOF_LONG__ == 4 118a7551a3fSSimon Glass # define __WORDSIZE 32 119a7551a3fSSimon Glass #else 120a7551a3fSSimon Glass /* 121a7551a3fSSimon Glass * Assume 32-bit for now - only newer toolchains support this feature and 122a7551a3fSSimon Glass * this is only required for sandbox support at present. 123a7551a3fSSimon Glass */ 124a7551a3fSSimon Glass #define __WORDSIZE 32 125a7551a3fSSimon Glass #endif 126a7551a3fSSimon Glass 127c9502f49SSimon Glass /* Type for `void *' pointers. */ 12837566090SMike Frysinger typedef unsigned long int uintptr_t; 12937566090SMike Frysinger 130c9502f49SSimon Glass #endif /* USE_HOSTCC */ 13137566090SMike Frysinger 132d8bc55a6SAnton Vorontsov /* compiler options */ 133d8bc55a6SAnton Vorontsov #define uninitialized_var(x) x = x 134d8bc55a6SAnton Vorontsov 135b63815e3SMatthias Kaehlcke #define likely(x) __builtin_expect(!!(x), 1) 136b63815e3SMatthias Kaehlcke #define unlikely(x) __builtin_expect(!!(x), 0) 137b63815e3SMatthias Kaehlcke 13837566090SMike Frysinger #endif 139