00001
00041 #ifndef BYTEORDER_H_INCLUDED
00042 #define BYTEORDER_H_INCLUDED
00043
00044 #include <compiler.h>
00045 #include <types.h>
00046
00047 #include <arch/byteorder.h>
00048
00049 #ifndef swab32
00050
00051 # define swab32(x) \
00052 ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) \
00053 | (((x) >> 8) & 0xff00) | (((x) >> 24) & 0xff))
00054 #endif
00055 #ifndef swab16
00056 # define swab16(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
00057 #endif
00058
00059 #ifdef CPU_IS_BIG_ENDIAN
00060
00061 #define LE16(x) ((le16_t __force)((((x) & 0xff) << 8) \
00062 | (((x) >> 8) & 0xff)))
00063 #define LE32(x) ((le32_t __force)((((x) & 0xff) << 24) \
00064 | (((x) & 0xff00) << 8) \
00065 | (((x) >> 8) & 0xff00) \
00066 | (((x) >> 24) & 0xff)))
00067 #define BE16(x) ((be16_t __force)(x))
00068 #define BE32(x) ((be32_t __force)(x))
00069
00070 static inline uint16_t le16_to_cpu(le16_t x)
00071 {
00072 return swab16((uint16_t __force)x);
00073 }
00074 static inline uint32_t le32_to_cpu(le32_t x)
00075 {
00076 return swab32((uint32_t __force)x);
00077 }
00078 static inline le16_t cpu_to_le16(uint16_t x)
00079 {
00080 return (le16_t __force)swab16(x);
00081 }
00082 static inline le32_t cpu_to_le32(uint32_t x)
00083 {
00084 return (le32_t __force)swab32(x);
00085 }
00086
00087 static inline uint16_t be16_to_cpu(be16_t x)
00088 {
00089 return (uint16_t __force)x;
00090 }
00091 static inline uint32_t be32_to_cpu(be32_t x)
00092 {
00093 return (uint32_t __force)x;
00094 }
00095 static inline be16_t cpu_to_be16(uint16_t x)
00096 {
00097 return (be16_t __force)x;
00098 }
00099 static inline be32_t cpu_to_be32(uint32_t x)
00100 {
00101 return (be32_t __force)x;
00102 }
00103
00104 #else
00105
00106 #define LE16(x) ((le16_t __force)(x))
00107 #define LE32(x) ((le32_t __force)(x))
00108 #define BE16(x) ((be16_t __force)((((x) & 0xff) << 8) \
00109 | (((x) >> 8) & 0xff)))
00110 #define BE32(x) ((be32_t __force)((((x) & 0xff) << 24) \
00111 | (((x) & 0xff00) << 8) \
00112 | (((x) >> 8) & 0xff00) \
00113 | (((x) >> 24) & 0xff)))
00114
00115 static inline uint16_t le16_to_cpu(le16_t x)
00116 {
00117 return (uint16_t __force)x;
00118 }
00119 static inline uint32_t le32_to_cpu(le32_t x)
00120 {
00121 return (uint32_t __force)x;
00122 }
00123 static inline le16_t cpu_to_le16(uint16_t x)
00124 {
00125 return (le16_t __force)x;
00126 }
00127 static inline le32_t cpu_to_le32(uint32_t x)
00128 {
00129 return (le32_t __force)x;
00130 }
00131
00132 static inline uint16_t be16_to_cpu(be16_t x)
00133 {
00134 return swab16((uint16_t __force)x);
00135 }
00136 static inline uint32_t be32_to_cpu(be32_t x)
00137 {
00138 return swab32((uint32_t __force)x);
00139 }
00140 static inline be16_t cpu_to_be16(uint16_t x)
00141 {
00142 return (be16_t __force)swab16(x);
00143 }
00144 static inline be32_t cpu_to_be32(uint32_t x)
00145 {
00146 return (be32_t __force)swab32(x);
00147 }
00148
00149 #endif
00150
00151 #endif