summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-04-11 11:38:43 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-04-11 14:29:59 +0200
commit7134c18c8071b119e7166c4f65235705fda08c23 (patch)
tree54a6fdaec32eb2517ef79ba0835d1c298dc871b5
parent6db5b2854e081da07c71ea07a07381e191d7e7eb (diff)
downloadbarebox-7134c18c8071b119e7166c4f65235705fda08c23.tar.gz
scripts: compiler.h: add Windows support
We lack endianness conversion functions for Windows. Import them from the public-domain portable_endian.h[1]. We skip the 64-bit XBox support though as it's unlikely we'll need to run imx-usb-loader on that particular game console. While at it, only define min when it's undefined. This works around one of the winapi headers indirectly included defining it. [1]: https://gist.github.com/panzi/6856583 Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230411093844.1297004-3-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--scripts/compiler.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/compiler.h b/scripts/compiler.h
index c932f715c5..925cad21b6 100644
--- a/scripts/compiler.h
+++ b/scripts/compiler.h
@@ -61,6 +61,37 @@ typedef unsigned int uint;
#elif defined(__OpenBSD__) || defined(__FreeBSD__) || \
defined(__NetBSD__) || defined(__DragonFly__)
# include <sys/endian.h>
+#elif defined _WIN32
+# if defined(_MSC_VER)
+# include <stdlib.h>
+# define htobe16(x) _byteswap_ushort(x)
+# define htole16(x) (x)
+# define be16toh(x) _byteswap_ushort(x)
+# define le16toh(x) (x)
+# define htobe32(x) _byteswap_ulong(x)
+# define htole32(x) (x)
+# define be32toh(x) _byteswap_ulong(x)
+# define le32toh(x) (x)
+# define htobe64(x) _byteswap_uint64(x)
+# define htole64(x) (x)
+# define be64toh(x) _byteswap_uint64(x)
+# define le64toh(x) (x)
+# elif defined(__GNUC__) || defined(__clang__)
+# define htobe16(x) __builtin_bswap16(x)
+# define htole16(x) (x)
+# define be16toh(x) __builtin_bswap16(x)
+# define le16toh(x) (x)
+# define htobe32(x) __builtin_bswap32(x)
+# define htole32(x) (x)
+# define be32toh(x) __builtin_bswap32(x)
+# define le32toh(x) (x)
+# define htobe64(x) __builtin_bswap64(x)
+# define htole64(x) (x)
+# define be64toh(x) __builtin_bswap64(x)
+# define le64toh(x) (x)
+#else
+# error platform not supported
+#endif
#else /* assume Linux */
# include <sys/types.h>
# include <endian.h>
@@ -128,11 +159,13 @@ typedef uint32_t __u32;
# define be64_to_cpu(x) (x)
#endif
+#ifndef min
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
+#endif
static inline void *xmalloc(size_t size)
{