blob: eb03b6a053db4b9fa83c034b2b29fd6667ae4a06 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
TsiChung Liewf6afe722007-06-18 13:50:13 -05002/*
3 * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
4 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChung Liewf6afe722007-06-18 13:50:13 -05005 */
6
wdenke65527f2004-02-12 00:47:09 +00007#ifndef _M68K_BYTEORDER_H
8#define _M68K_BYTEORDER_H
9
10#include <asm/types.h>
TsiChung Liewf6afe722007-06-18 13:50:13 -050011
12#ifdef __GNUC__
13#define __sw16(x) \
14 ((__u16)( \
15 (((__u16)(x) & (__u16)0x00ffU) << 8) | \
16 (((__u16)(x) & (__u16)0xff00U) >> 8) ))
17#define __sw32(x) \
18 ((__u32)( \
19 (((__u32)(x)) << 24) | \
20 (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
21 (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
22 (((__u32)(x)) >> 24) ))
23
Måns Rullgård4dc39702015-11-06 12:44:01 +000024static __inline__ unsigned ld_le16(const volatile unsigned short *addr)
TsiChung Liewf6afe722007-06-18 13:50:13 -050025{
26 unsigned result = *addr;
27 return __sw16(result);
28}
29
Måns Rullgård4dc39702015-11-06 12:44:01 +000030static __inline__ void st_le16(volatile unsigned short *addr,
TsiChung Liewf6afe722007-06-18 13:50:13 -050031 const unsigned val)
32{
33 *addr = __sw16(val);
34}
35
Måns Rullgård4dc39702015-11-06 12:44:01 +000036static __inline__ unsigned ld_le32(const volatile unsigned *addr)
TsiChung Liewf6afe722007-06-18 13:50:13 -050037{
38 unsigned result = *addr;
39 return __sw32(result);
40}
41
Måns Rullgård4dc39702015-11-06 12:44:01 +000042static __inline__ void st_le32(volatile unsigned *addr, const unsigned val)
TsiChung Liewf6afe722007-06-18 13:50:13 -050043{
44 *addr = __sw32(val);
45}
46
47#if 0
48/* alas, egcs sounds like it has a bug in this code that doesn't use the
49 inline asm correctly, and can cause file corruption. Until I hear that
50 it's fixed, I can live without the extra speed. I hope. */
51#if !(__GNUC__ >= 2 && __GNUC_MINOR__ >= 90)
52#if 0
53# define __arch_swab16(x) ld_le16(&x)
54# define __arch_swab32(x) ld_le32(&x)
55#else
56static __inline__ __attribute__ ((const))
57__u16 ___arch__swab16(__u16 value)
58{
59 return __sw16(value);
60}
61
62static __inline__ __attribute__ ((const))
63__u32 ___arch__swab32(__u32 value)
64{
65 return __sw32(value);
66}
67
68#define __arch__swab32(x) ___arch__swab32(x)
69#define __arch__swab16(x) ___arch__swab16(x)
70#endif /* 0 */
71
72#endif
73
74/* The same, but returns converted value from the location pointer by addr. */
75#define __arch__swab16p(addr) ld_le16(addr)
76#define __arch__swab32p(addr) ld_le32(addr)
77
78/* The same, but do the conversion in situ, ie. put the value back to addr. */
79#define __arch__swab16s(addr) st_le16(addr,*addr)
80#define __arch__swab32s(addr) st_le32(addr,*addr)
81#endif
82
83#endif /* __GNUC__ */
84
85#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
86#define __BYTEORDER_HAS_U64__
87#endif
wdenke65527f2004-02-12 00:47:09 +000088#include <linux/byteorder/big_endian.h>
89
TsiChung Liewf6afe722007-06-18 13:50:13 -050090#endif /* _M68K_BYTEORDER_H */