2 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
3 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
24 #ifndef _M68K_BYTEORDER_H
25 #define _M68K_BYTEORDER_H
27 #include <asm/types.h>
32 (((__u16)(x) & (__u16)0x00ffU) << 8) | \
33 (((__u16)(x) & (__u16)0xff00U) >> 8) ))
36 (((__u32)(x)) << 24) | \
37 (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
38 (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
39 (((__u32)(x)) >> 24) ))
41 extern __inline__ unsigned ld_le16(const volatile unsigned short *addr)
43 unsigned result = *addr;
44 return __sw16(result);
47 extern __inline__ void st_le16(volatile unsigned short *addr,
53 extern __inline__ unsigned ld_le32(const volatile unsigned *addr)
55 unsigned result = *addr;
56 return __sw32(result);
59 extern __inline__ void st_le32(volatile unsigned *addr, const unsigned val)
65 /* alas, egcs sounds like it has a bug in this code that doesn't use the
66 inline asm correctly, and can cause file corruption. Until I hear that
67 it's fixed, I can live without the extra speed. I hope. */
68 #if !(__GNUC__ >= 2 && __GNUC_MINOR__ >= 90)
70 # define __arch_swab16(x) ld_le16(&x)
71 # define __arch_swab32(x) ld_le32(&x)
73 static __inline__ __attribute__ ((const))
74 __u16 ___arch__swab16(__u16 value)
79 static __inline__ __attribute__ ((const))
80 __u32 ___arch__swab32(__u32 value)
85 #define __arch__swab32(x) ___arch__swab32(x)
86 #define __arch__swab16(x) ___arch__swab16(x)
91 /* The same, but returns converted value from the location pointer by addr. */
92 #define __arch__swab16p(addr) ld_le16(addr)
93 #define __arch__swab32p(addr) ld_le32(addr)
95 /* The same, but do the conversion in situ, ie. put the value back to addr. */
96 #define __arch__swab16s(addr) st_le16(addr,*addr)
97 #define __arch__swab32s(addr) st_le32(addr,*addr)
100 #endif /* __GNUC__ */
102 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
103 #define __BYTEORDER_HAS_U64__
105 #include <linux/byteorder/big_endian.h>
107 #endif /* _M68K_BYTEORDER_H */