]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/compiler.h
Revert "include/linux: move typdef for uintptr_t"
[people/ms/u-boot.git] / include / compiler.h
CommitLineData
37566090
MF
1/*
2 * Keep all the ugly #ifdef for system stuff here
3 */
4
5#ifndef __COMPILER_H__
6#define __COMPILER_H__
7
8#include <stddef.h>
9
10#ifdef USE_HOSTCC
11
12#if defined(__BEOS__) || \
13 defined(__NetBSD__) || \
14 defined(__FreeBSD__) || \
15 defined(__sun__) || \
16 defined(__APPLE__)
17# include <inttypes.h>
18#elif defined(__linux__) || defined(__WIN32__) || defined(__MINGW32__)
19# include <stdint.h>
20#endif
21
22#include <errno.h>
23#include <stdlib.h>
24#include <stdint.h>
25#include <stdio.h>
26#include <string.h>
27
37566090
MF
28#if !defined(__WIN32__) && !defined(__MINGW32__)
29# include <sys/mman.h>
30#endif
31
32/* Not all systems (like Windows) has this define, and yes
33 * we do replace/emulate mmap() on those systems ...
34 */
35#ifndef MAP_FAILED
36# define MAP_FAILED ((void *)-1)
37#endif
38
39#include <fcntl.h>
40#ifndef O_BINARY /* should be define'd on __WIN32__ */
41#define O_BINARY 0
42#endif
43
44#ifdef __linux__
45# include <endian.h>
46# include <byteswap.h>
5bce5dc3 47#elif defined(__MACH__) || defined(__FreeBSD__)
37566090
MF
48# include <machine/endian.h>
49typedef unsigned long ulong;
37566090 50#endif
ed8271d1
JH
51#ifdef __FreeBSD__
52# include <sys/endian.h> /* htole32 and friends */
53#endif
54
9d16e93d 55#include <time.h>
37566090
MF
56
57typedef uint8_t __u8;
58typedef uint16_t __u16;
59typedef uint32_t __u32;
b050c72d 60typedef unsigned int uint;
37566090
MF
61
62#define uswap_16(x) \
63 ((((x) & 0xff00) >> 8) | \
64 (((x) & 0x00ff) << 8))
65#define uswap_32(x) \
66 ((((x) & 0xff000000) >> 24) | \
67 (((x) & 0x00ff0000) >> 8) | \
68 (((x) & 0x0000ff00) << 8) | \
69 (((x) & 0x000000ff) << 24))
70#define _uswap_64(x, sfx) \
71 ((((x) & 0xff00000000000000##sfx) >> 56) | \
72 (((x) & 0x00ff000000000000##sfx) >> 40) | \
73 (((x) & 0x0000ff0000000000##sfx) >> 24) | \
74 (((x) & 0x000000ff00000000##sfx) >> 8) | \
75 (((x) & 0x00000000ff000000##sfx) << 8) | \
76 (((x) & 0x0000000000ff0000##sfx) << 24) | \
77 (((x) & 0x000000000000ff00##sfx) << 40) | \
78 (((x) & 0x00000000000000ff##sfx) << 56))
79#if defined(__GNUC__)
80# define uswap_64(x) _uswap_64(x, ull)
81#else
82# define uswap_64(x) _uswap_64(x, )
83#endif
84
85#if __BYTE_ORDER == __LITTLE_ENDIAN
86# define cpu_to_le16(x) (x)
87# define cpu_to_le32(x) (x)
88# define cpu_to_le64(x) (x)
89# define le16_to_cpu(x) (x)
90# define le32_to_cpu(x) (x)
91# define le64_to_cpu(x) (x)
92# define cpu_to_be16(x) uswap_16(x)
93# define cpu_to_be32(x) uswap_32(x)
94# define cpu_to_be64(x) uswap_64(x)
95# define be16_to_cpu(x) uswap_16(x)
96# define be32_to_cpu(x) uswap_32(x)
97# define be64_to_cpu(x) uswap_64(x)
98#else
99# define cpu_to_le16(x) uswap_16(x)
100# define cpu_to_le32(x) uswap_32(x)
101# define cpu_to_le64(x) uswap_64(x)
102# define le16_to_cpu(x) uswap_16(x)
103# define le32_to_cpu(x) uswap_32(x)
104# define le64_to_cpu(x) uswap_64(x)
105# define cpu_to_be16(x) (x)
106# define cpu_to_be32(x) (x)
107# define cpu_to_be64(x) (x)
108# define be16_to_cpu(x) (x)
109# define be32_to_cpu(x) (x)
110# define be64_to_cpu(x) (x)
111#endif
112
113#else /* !USE_HOSTCC */
114
0d296cc2
GB
115#ifdef CONFIG_USE_STDINT
116/* Provided by gcc. */
117#include <stdint.h>
2e680f92
YS
118#else
119/* Type for `void *' pointers. */
120typedef unsigned long int uintptr_t;
0d296cc2
GB
121#endif
122
37566090
MF
123#include <linux/string.h>
124#include <linux/types.h>
125#include <asm/byteorder.h>
126
a7551a3f
SG
127#if __SIZEOF_LONG__ == 8
128# define __WORDSIZE 64
129#elif __SIZEOF_LONG__ == 4
130# define __WORDSIZE 32
131#else
132/*
133 * Assume 32-bit for now - only newer toolchains support this feature and
134 * this is only required for sandbox support at present.
135 */
136#define __WORDSIZE 32
137#endif
138
c9502f49 139#endif /* USE_HOSTCC */
37566090 140
b63815e3
MK
141#define likely(x) __builtin_expect(!!(x), 1)
142#define unlikely(x) __builtin_expect(!!(x), 0)
143
37566090 144#endif