From 62a1d5c0f5bc52227ba43ccb7924694d661449a2 Mon Sep 17 00:00:00 2001 From: Xiaotian Wu Date: Mon, 6 Feb 2023 12:48:50 +0000 Subject: [loong64] Add initial support for LoongArch64 Add support for building a LoongArch64 Linux userspace binary. Signed-off-by: Xiaotian Wu Modified-by: Michael Brown Signed-off-by: Michael Brown --- src/arch/loong64/include/bits/byteswap.h | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/arch/loong64/include/bits/byteswap.h (limited to 'src/arch/loong64/include/bits/byteswap.h') diff --git a/src/arch/loong64/include/bits/byteswap.h b/src/arch/loong64/include/bits/byteswap.h new file mode 100644 index 000000000..1e22d0941 --- /dev/null +++ b/src/arch/loong64/include/bits/byteswap.h @@ -0,0 +1,47 @@ +#ifndef _BITS_BYTESWAP_H +#define _BITS_BYTESWAP_H + +/** @file + * + * Byte-order swapping functions + * + */ + +#include + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +static inline __attribute__ (( always_inline, const )) uint16_t +__bswap_variable_16 ( uint16_t x ) { + __asm__ ( "revb.2h %0, %1" : "=r" ( x ) : "r" ( x ) ); + return x; +} + +static inline __attribute__ (( always_inline )) void +__bswap_16s ( uint16_t *x ) { + *x = __bswap_variable_16 ( *x ); +} + +static inline __attribute__ (( always_inline, const )) uint32_t +__bswap_variable_32 ( uint32_t x ) { + __asm__ ( "revb.2w %0, %1" : "=r" ( x ) : "r" ( x ) ); + return x; +} + +static inline __attribute__ (( always_inline )) void +__bswap_32s ( uint32_t *x ) { + *x = __bswap_variable_32 ( *x ); +} + +static inline __attribute__ (( always_inline, const )) uint64_t +__bswap_variable_64 ( uint64_t x ) { + __asm__ ( "revb.d %0, %1" : "=r" ( x ) : "r" ( x ) ); + return x; +} + +static inline __attribute__ (( always_inline )) void +__bswap_64s ( uint64_t *x ) { + *x = __bswap_variable_64 ( *x ); +} + +#endif -- cgit v1.2.3-55-g7522