Alex James has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/60219 )
Change subject: commonlib: Add endian definitions for macOS ......................................................................
commonlib: Add endian definitions for macOS
Change-Id: I44d59869a4420030f3ce26118175304c680d57a1 Signed-off-by: Alex James theracermaster@gmail.com --- M src/commonlib/bsd/include/commonlib/bsd/sysincludes.h 1 file changed, 62 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/19/60219/1
diff --git a/src/commonlib/bsd/include/commonlib/bsd/sysincludes.h b/src/commonlib/bsd/include/commonlib/bsd/sysincludes.h index 3a87cda..7d77223 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/sysincludes.h +++ b/src/commonlib/bsd/include/commonlib/bsd/sysincludes.h @@ -1,6 +1,68 @@ /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */ #if defined(__FreeBSD__) #include <sys/endian.h> +#elif defined(__APPLE__) +#include <libkern/OSByteOrder.h> + +static inline uint16_t htobe16(uint16_t host_16bits) +{ + return OSSwapHostToBigInt16(host_16bits); +} + +static inline uint16_t htole16(uint16_t host_16bits) +{ + return OSSwapHostToLittleInt16(host_16bits); +} + +static inline uint16_t be16toh(uint16_t big_endian_16bits) +{ + return OSSwapBigToHostInt16(big_endian_16bits); +} + +static inline uint16_t le16toh(uint16_t little_endian_16bits) +{ + return OSSwapLittleToHostInt16(little_endian_16bits); +} + +static inline uint32_t htobe32(uint32_t host_32bits) +{ + return OSSwapHostToBigInt32(host_32bits); +} + +static inline uint32_t htole32(uint32_t host_32bits) +{ + return OSSwapHostToLittleInt32(host_32bits); +} + +static inline uint32_t be32toh(uint32_t big_endian_32bits) +{ + return OSSwapBigToHostInt32(big_endian_32bits); +} + +static inline uint32_t le32toh(uint32_t little_endian_32bits) +{ + return OSSwapLittleToHostInt32(little_endian_32bits); +} + +static inline uint64_t htobe64(uint64_t host_64bits) +{ + return OSSwapHostToBigInt64(host_64bits); +} + +static inline uint64_t htole64(uint64_t host_64bits) +{ + return OSSwapHostToLittleInt64(host_64bits); +} + +static inline uint64_t be64toh(uint64_t big_endian_64bits) +{ + return OSSwapBigToHostInt64(big_endian_64bits); +} + +static inline uint64_t le64toh(uint64_t little_endian_64bits) +{ + return OSSwapLittleToHostInt64(little_endian_64bits); +} #else #include <endian.h> #endif