From 153412f53edea4bd12dc5910ef95a63a74997476 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Sun, 14 May 2023 05:13:09 +0200 Subject: [PATCH] host: Perform compile-time endian check if supported --- host/limine.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/host/limine.c b/host/limine.c index bc2007af..039f83c4 100644 --- a/host/limine.c +++ b/host/limine.c @@ -151,8 +151,6 @@ static uint32_t crc32(void *_stream, size_t len) { return ret; } -static bool bigendian = false; - static uint16_t endswap16(uint16_t value) { uint16_t ret = 0; ret |= (value >> 8) & 0x00ff; @@ -182,6 +180,20 @@ static uint64_t endswap64(uint64_t value) { return ret; } +#ifdef __BYTE_ORDER__ + +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define bigendian true +#else +#define bigendian false +#endif + +#else /* !__BYTE_ORDER__ */ + +static bool bigendian = false; + +#endif /* !__BYTE_ORDER__ */ + #define ENDSWAP(VALUE) (bigendian ? ( \ sizeof(VALUE) == 1 ? (VALUE) : \ sizeof(VALUE) == 2 ? endswap16(VALUE) : \ @@ -535,9 +547,11 @@ static int bios_install(int argc, char *argv[]) { uint8_t orig_mbr[70], timestamp[6]; const char *part_ndx = NULL; +#ifndef __BYTE_ORDER__ uint32_t endcheck = 0x12345678; uint8_t endbyte = *((uint8_t *)&endcheck); bigendian = endbyte == 0x12; +#endif if (argc < 2) { bios_install_usage(argv[-1]);