byteorder.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  3. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef _M68K_BYTEORDER_H
  24. #define _M68K_BYTEORDER_H
  25. #include <asm/types.h>
  26. #ifdef __GNUC__
  27. #define __sw16(x) \
  28. ((__u16)( \
  29. (((__u16)(x) & (__u16)0x00ffU) << 8) | \
  30. (((__u16)(x) & (__u16)0xff00U) >> 8) ))
  31. #define __sw32(x) \
  32. ((__u32)( \
  33. (((__u32)(x)) << 24) | \
  34. (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
  35. (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
  36. (((__u32)(x)) >> 24) ))
  37. extern __inline__ unsigned ld_le16(const volatile unsigned short *addr)
  38. {
  39. unsigned result = *addr;
  40. return __sw16(result);
  41. }
  42. extern __inline__ void st_le16(volatile unsigned short *addr,
  43. const unsigned val)
  44. {
  45. *addr = __sw16(val);
  46. }
  47. extern __inline__ unsigned ld_le32(const volatile unsigned *addr)
  48. {
  49. unsigned result = *addr;
  50. return __sw32(result);
  51. }
  52. extern __inline__ void st_le32(volatile unsigned *addr, const unsigned val)
  53. {
  54. *addr = __sw32(val);
  55. }
  56. #if 0
  57. /* alas, egcs sounds like it has a bug in this code that doesn't use the
  58. inline asm correctly, and can cause file corruption. Until I hear that
  59. it's fixed, I can live without the extra speed. I hope. */
  60. #if !(__GNUC__ >= 2 && __GNUC_MINOR__ >= 90)
  61. #if 0
  62. # define __arch_swab16(x) ld_le16(&x)
  63. # define __arch_swab32(x) ld_le32(&x)
  64. #else
  65. static __inline__ __attribute__ ((const))
  66. __u16 ___arch__swab16(__u16 value)
  67. {
  68. return __sw16(value);
  69. }
  70. static __inline__ __attribute__ ((const))
  71. __u32 ___arch__swab32(__u32 value)
  72. {
  73. return __sw32(value);
  74. }
  75. #define __arch__swab32(x) ___arch__swab32(x)
  76. #define __arch__swab16(x) ___arch__swab16(x)
  77. #endif /* 0 */
  78. #endif
  79. /* The same, but returns converted value from the location pointer by addr. */
  80. #define __arch__swab16p(addr) ld_le16(addr)
  81. #define __arch__swab32p(addr) ld_le32(addr)
  82. /* The same, but do the conversion in situ, ie. put the value back to addr. */
  83. #define __arch__swab16s(addr) st_le16(addr,*addr)
  84. #define __arch__swab32s(addr) st_le32(addr,*addr)
  85. #endif
  86. #endif /* __GNUC__ */
  87. #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
  88. #define __BYTEORDER_HAS_U64__
  89. #endif
  90. #include <linux/byteorder/big_endian.h>
  91. #endif /* _M68K_BYTEORDER_H */