byteorder.h 2.2 KB

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