xref: /openbmc/u-boot/include/compiler.h (revision d8bc55a6fb28876abcbf4a3fc3b6c3ce429c1bb3)
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 extern int errno;
2937566090SMike Frysinger 
3037566090SMike Frysinger #if !defined(__WIN32__) && !defined(__MINGW32__)
3137566090SMike Frysinger # include <sys/mman.h>
3237566090SMike Frysinger #endif
3337566090SMike Frysinger 
3437566090SMike Frysinger /* Not all systems (like Windows) has this define, and yes
3537566090SMike Frysinger  * we do replace/emulate mmap() on those systems ...
3637566090SMike Frysinger  */
3737566090SMike Frysinger #ifndef MAP_FAILED
3837566090SMike Frysinger # define MAP_FAILED ((void *)-1)
3937566090SMike Frysinger #endif
4037566090SMike Frysinger 
4137566090SMike Frysinger #include <fcntl.h>
4237566090SMike Frysinger #ifndef O_BINARY		/* should be define'd on __WIN32__ */
4337566090SMike Frysinger #define O_BINARY	0
4437566090SMike Frysinger #endif
4537566090SMike Frysinger 
4637566090SMike Frysinger #ifdef __linux__
4737566090SMike Frysinger # include <endian.h>
4837566090SMike Frysinger # include <byteswap.h>
4937566090SMike Frysinger #elif defined(__MACH__)
5037566090SMike Frysinger # include <machine/endian.h>
5137566090SMike Frysinger typedef unsigned long ulong;
5237566090SMike Frysinger typedef unsigned int  uint;
5337566090SMike Frysinger #endif
5437566090SMike Frysinger 
5537566090SMike Frysinger typedef uint8_t __u8;
5637566090SMike Frysinger typedef uint16_t __u16;
5737566090SMike Frysinger typedef uint32_t __u32;
5837566090SMike Frysinger 
5937566090SMike Frysinger #define uswap_16(x) \
6037566090SMike Frysinger 	((((x) & 0xff00) >> 8) | \
6137566090SMike Frysinger 	 (((x) & 0x00ff) << 8))
6237566090SMike Frysinger #define uswap_32(x) \
6337566090SMike Frysinger 	((((x) & 0xff000000) >> 24) | \
6437566090SMike Frysinger 	 (((x) & 0x00ff0000) >>  8) | \
6537566090SMike Frysinger 	 (((x) & 0x0000ff00) <<  8) | \
6637566090SMike Frysinger 	 (((x) & 0x000000ff) << 24))
6737566090SMike Frysinger #define _uswap_64(x, sfx) \
6837566090SMike Frysinger 	((((x) & 0xff00000000000000##sfx) >> 56) | \
6937566090SMike Frysinger 	 (((x) & 0x00ff000000000000##sfx) >> 40) | \
7037566090SMike Frysinger 	 (((x) & 0x0000ff0000000000##sfx) >> 24) | \
7137566090SMike Frysinger 	 (((x) & 0x000000ff00000000##sfx) >>  8) | \
7237566090SMike Frysinger 	 (((x) & 0x00000000ff000000##sfx) <<  8) | \
7337566090SMike Frysinger 	 (((x) & 0x0000000000ff0000##sfx) << 24) | \
7437566090SMike Frysinger 	 (((x) & 0x000000000000ff00##sfx) << 40) | \
7537566090SMike Frysinger 	 (((x) & 0x00000000000000ff##sfx) << 56))
7637566090SMike Frysinger #if defined(__GNUC__)
7737566090SMike Frysinger # define uswap_64(x) _uswap_64(x, ull)
7837566090SMike Frysinger #else
7937566090SMike Frysinger # define uswap_64(x) _uswap_64(x, )
8037566090SMike Frysinger #endif
8137566090SMike Frysinger 
8237566090SMike Frysinger #if __BYTE_ORDER == __LITTLE_ENDIAN
8337566090SMike Frysinger # define cpu_to_le16(x)		(x)
8437566090SMike Frysinger # define cpu_to_le32(x)		(x)
8537566090SMike Frysinger # define cpu_to_le64(x)		(x)
8637566090SMike Frysinger # define le16_to_cpu(x)		(x)
8737566090SMike Frysinger # define le32_to_cpu(x)		(x)
8837566090SMike Frysinger # define le64_to_cpu(x)		(x)
8937566090SMike Frysinger # define cpu_to_be16(x)		uswap_16(x)
9037566090SMike Frysinger # define cpu_to_be32(x)		uswap_32(x)
9137566090SMike Frysinger # define cpu_to_be64(x)		uswap_64(x)
9237566090SMike Frysinger # define be16_to_cpu(x)		uswap_16(x)
9337566090SMike Frysinger # define be32_to_cpu(x)		uswap_32(x)
9437566090SMike Frysinger # define be64_to_cpu(x)		uswap_64(x)
9537566090SMike Frysinger #else
9637566090SMike Frysinger # define cpu_to_le16(x)		uswap_16(x)
9737566090SMike Frysinger # define cpu_to_le32(x)		uswap_32(x)
9837566090SMike Frysinger # define cpu_to_le64(x)		uswap_64(x)
9937566090SMike Frysinger # define le16_to_cpu(x)		uswap_16(x)
10037566090SMike Frysinger # define le32_to_cpu(x)		uswap_32(x)
10137566090SMike Frysinger # define le64_to_cpu(x)		uswap_64(x)
10237566090SMike Frysinger # define cpu_to_be16(x)		(x)
10337566090SMike Frysinger # define cpu_to_be32(x)		(x)
10437566090SMike Frysinger # define cpu_to_be64(x)		(x)
10537566090SMike Frysinger # define be16_to_cpu(x)		(x)
10637566090SMike Frysinger # define be32_to_cpu(x)		(x)
10737566090SMike Frysinger # define be64_to_cpu(x)		(x)
10837566090SMike Frysinger #endif
10937566090SMike Frysinger 
11037566090SMike Frysinger #else /* !USE_HOSTCC */
11137566090SMike Frysinger 
11237566090SMike Frysinger #include <linux/string.h>
11337566090SMike Frysinger #include <linux/types.h>
11437566090SMike Frysinger #include <asm/byteorder.h>
11537566090SMike Frysinger 
11637566090SMike Frysinger /* Types for `void *' pointers. */
11737566090SMike Frysinger #if __WORDSIZE == 64
11837566090SMike Frysinger typedef unsigned long int       uintptr_t;
11937566090SMike Frysinger #else
12037566090SMike Frysinger typedef unsigned int            uintptr_t;
12137566090SMike Frysinger #endif
12237566090SMike Frysinger 
12337566090SMike Frysinger #endif
12437566090SMike Frysinger 
125*d8bc55a6SAnton Vorontsov /* compiler options */
126*d8bc55a6SAnton Vorontsov #define uninitialized_var(x)		x = x
127*d8bc55a6SAnton Vorontsov 
12837566090SMike Frysinger #endif
129