xref: /openbmc/u-boot/arch/m68k/include/asm/byteorder.h (revision 819833af)
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 
24 #ifndef _M68K_BYTEORDER_H
25 #define _M68K_BYTEORDER_H
26 
27 #include <asm/types.h>
28 
29 #ifdef __GNUC__
30 #define __sw16(x) \
31 	((__u16)( \
32 		(((__u16)(x) & (__u16)0x00ffU) << 8) | \
33 		(((__u16)(x) & (__u16)0xff00U) >> 8) ))
34 #define __sw32(x) \
35 	((__u32)( \
36 		(((__u32)(x)) << 24) | \
37 		(((__u32)(x) & (__u32)0x0000ff00UL) <<  8) | \
38 		(((__u32)(x) & (__u32)0x00ff0000UL) >>  8) | \
39 		(((__u32)(x)) >> 24) ))
40 
41 extern __inline__ unsigned ld_le16(const volatile unsigned short *addr)
42 {
43 	unsigned result = *addr;
44 	return __sw16(result);
45 }
46 
47 extern __inline__ void st_le16(volatile unsigned short *addr,
48 			       const unsigned val)
49 {
50 	*addr = __sw16(val);
51 }
52 
53 extern __inline__ unsigned ld_le32(const volatile unsigned *addr)
54 {
55 	unsigned result = *addr;
56 	return __sw32(result);
57 }
58 
59 extern __inline__ void st_le32(volatile unsigned *addr, const unsigned val)
60 {
61 	*addr = __sw32(val);
62 }
63 
64 #if 0
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)
69 #if 0
70 #  define __arch_swab16(x) ld_le16(&x)
71 #  define __arch_swab32(x) ld_le32(&x)
72 #else
73 static __inline__ __attribute__ ((const))
74 __u16 ___arch__swab16(__u16 value)
75 {
76 	return __sw16(value);
77 }
78 
79 static __inline__ __attribute__ ((const))
80 __u32 ___arch__swab32(__u32 value)
81 {
82 	return __sw32(value);
83 }
84 
85 #define __arch__swab32(x) ___arch__swab32(x)
86 #define __arch__swab16(x) ___arch__swab16(x)
87 #endif				/* 0 */
88 
89 #endif
90 
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)
94 
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)
98 #endif
99 
100 #endif				/* __GNUC__ */
101 
102 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
103 #define __BYTEORDER_HAS_U64__
104 #endif
105 #include <linux/byteorder/big_endian.h>
106 
107 #endif				/* _M68K_BYTEORDER_H */
108