aboutsummaryrefslogtreecommitdiffstats
path: root/src/arch/arm32/include/bits/byteswap.h
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2016-05-08 00:18:35 +0100
committerMichael Brown <mcb30@ipxe.org>2016-05-08 00:18:35 +0100
commitedea3a434ccae8dc980c715949287c9ba63babf5 (patch)
treed821d987dcf1ac0bc4f22e1363fa32c95f6bd0b2 /src/arch/arm32/include/bits/byteswap.h
parent2a187f480ecc9d7943a53658e748bb5e60104788 (diff)
downloadipxe-edea3a434ccae8dc980c715949287c9ba63babf5.tar.gz
[arm] Split out 32-bit-specific code to arch/arm32
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch/arm32/include/bits/byteswap.h')
-rw-r--r--src/arch/arm32/include/bits/byteswap.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/arch/arm32/include/bits/byteswap.h b/src/arch/arm32/include/bits/byteswap.h
new file mode 100644
index 000000000..1fc884bd8
--- /dev/null
+++ b/src/arch/arm32/include/bits/byteswap.h
@@ -0,0 +1,52 @@
+#ifndef _BITS_BYTESWAP_H
+#define _BITS_BYTESWAP_H
+
+/** @file
+ *
+ * Byte-order swapping functions
+ *
+ */
+
+#include <stdint.h>
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+static inline __attribute__ (( always_inline, const )) uint16_t
+__bswap_variable_16 ( uint16_t x ) {
+ __asm__ ( "rev16 %0, %1" : "=l" ( x ) : "l" ( 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__ ( "rev %0, %1" : "=l" ( x ) : "l" ( 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 ) {
+ uint32_t in_high = ( x >> 32 );
+ uint32_t in_low = ( x & 0xffffffffUL );
+ uint32_t out_high = __bswap_variable_32 ( in_low );
+ uint32_t out_low = __bswap_variable_32 ( in_high );
+
+ return ( ( ( ( uint64_t ) out_high ) << 32 ) |
+ ( ( uint64_t ) out_low ) );
+}
+
+static inline __attribute__ (( always_inline )) void
+__bswap_64s ( uint64_t *x ) {
+ *x = __bswap_variable_64 ( *x );
+}
+
+#endif