byteorder.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  4. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  5. */
  6. #ifndef _M68K_BYTEORDER_H
  7. #define _M68K_BYTEORDER_H
  8. #include <asm/types.h>
  9. #ifdef __GNUC__
  10. #define __sw16(x) \
  11. ((__u16)( \
  12. (((__u16)(x) & (__u16)0x00ffU) << 8) | \
  13. (((__u16)(x) & (__u16)0xff00U) >> 8) ))
  14. #define __sw32(x) \
  15. ((__u32)( \
  16. (((__u32)(x)) << 24) | \
  17. (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
  18. (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
  19. (((__u32)(x)) >> 24) ))
  20. static __inline__ unsigned ld_le16(const volatile unsigned short *addr)
  21. {
  22. unsigned result = *addr;
  23. return __sw16(result);
  24. }
  25. static __inline__ void st_le16(volatile unsigned short *addr,
  26. const unsigned val)
  27. {
  28. *addr = __sw16(val);
  29. }
  30. static __inline__ unsigned ld_le32(const volatile unsigned *addr)
  31. {
  32. unsigned result = *addr;
  33. return __sw32(result);
  34. }
  35. static __inline__ void st_le32(volatile unsigned *addr, const unsigned val)
  36. {
  37. *addr = __sw32(val);
  38. }
  39. #if 0
  40. /* alas, egcs sounds like it has a bug in this code that doesn't use the
  41. inline asm correctly, and can cause file corruption. Until I hear that
  42. it's fixed, I can live without the extra speed. I hope. */
  43. #if !(__GNUC__ >= 2 && __GNUC_MINOR__ >= 90)
  44. #if 0
  45. # define __arch_swab16(x) ld_le16(&x)
  46. # define __arch_swab32(x) ld_le32(&x)
  47. #else
  48. static __inline__ __attribute__ ((const))
  49. __u16 ___arch__swab16(__u16 value)
  50. {
  51. return __sw16(value);
  52. }
  53. static __inline__ __attribute__ ((const))
  54. __u32 ___arch__swab32(__u32 value)
  55. {
  56. return __sw32(value);
  57. }
  58. #define __arch__swab32(x) ___arch__swab32(x)
  59. #define __arch__swab16(x) ___arch__swab16(x)
  60. #endif /* 0 */
  61. #endif
  62. /* The same, but returns converted value from the location pointer by addr. */
  63. #define __arch__swab16p(addr) ld_le16(addr)
  64. #define __arch__swab32p(addr) ld_le32(addr)
  65. /* The same, but do the conversion in situ, ie. put the value back to addr. */
  66. #define __arch__swab16s(addr) st_le16(addr,*addr)
  67. #define __arch__swab32s(addr) st_le32(addr,*addr)
  68. #endif
  69. #endif /* __GNUC__ */
  70. #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  71. #define __BYTEORDER_HAS_U64__
  72. #endif
  73. #include <linux/byteorder/big_endian.h>
  74. #endif /* _M68K_BYTEORDER_H */