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