summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libstand/Makefile10
-rw-r--r--sys/alpha/include/bus.h64
-rw-r--r--sys/alpha/include/endian.h8
-rw-r--r--sys/amd64/include/bus.h64
-rw-r--r--sys/conf/files.alpha6
-rw-r--r--sys/conf/files.ia646
-rw-r--r--sys/dev/iir/iir.h6
-rw-r--r--sys/dev/usb/ohci.c14
-rw-r--r--sys/dev/usb/uhci.c2
-rw-r--r--sys/dev/usb/usb_port.h1
-rw-r--r--sys/dev/wi/if_wi.c6
-rw-r--r--sys/i386/include/bus.h64
-rw-r--r--sys/i386/include/endian.h25
-rw-r--r--sys/ia64/include/bus.h64
-rw-r--r--sys/ia64/include/endian.h40
-rw-r--r--sys/libkern/alpha/bswap16.S (renamed from sys/libkern/alpha/htons.S)11
-rw-r--r--sys/libkern/alpha/bswap32.S (renamed from sys/libkern/alpha/htonl.S)13
-rw-r--r--sys/libkern/alpha/byte_swap_2.S5
-rw-r--r--sys/libkern/alpha/byte_swap_4.S5
-rw-r--r--sys/libkern/alpha/ntohl.S34
-rw-r--r--sys/libkern/alpha/ntohs.S34
-rw-r--r--sys/libkern/ia64/bswap16.S (renamed from sys/libkern/ia64/htons.S)11
-rw-r--r--sys/libkern/ia64/bswap32.S (renamed from sys/libkern/ia64/htonl.S)11
-rw-r--r--sys/libkern/ia64/byte_swap_2.S5
-rw-r--r--sys/libkern/ia64/byte_swap_4.S5
-rw-r--r--sys/libkern/ia64/ntohl.S34
-rw-r--r--sys/libkern/ia64/ntohs.S34
-rw-r--r--sys/powerpc/include/endian.h12
-rw-r--r--sys/sparc64/include/endian.h5
-rw-r--r--sys/sys/imgact_aout.h8
-rw-r--r--sys/sys/mchain.h23
-rw-r--r--sys/sys/param.h92
32 files changed, 438 insertions, 284 deletions
diff --git a/lib/libstand/Makefile b/lib/libstand/Makefile
index 184f690..3349522 100644
--- a/lib/libstand/Makefile
+++ b/lib/libstand/Makefile
@@ -33,6 +33,10 @@ SRCS+= __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \
# private (pruned) versions of libc string functions
SRCS+= strcasecmp.c
+# byte order functions from libc
+.PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/net
+SRCS+= htons.S ntohs.S htonl.S ntohl.S
+
# string functions from libc
.PATH: ${.CURDIR}/../libc/string
.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "powerpc" || \
@@ -50,9 +54,6 @@ SRCS+= bcmp.c bcopy.S bzero.S ffs.S index.c memccpy.c memchr.c memcmp.c \
strncat.c strncmp.c strncpy.c strpbrk.c strrchr.c strsep.c \
strspn.c strstr.c strtok.c swab.c
-.PATH: ${.CURDIR}/../libc/alpha/net
-SRCS+= htons.S ntohs.S htonl.S ntohl.S
-
SRCS+= __divqu.S __divq.S __divlu.S __divl.S
SRCS+= __remqu.S __remq.S __remlu.S __reml.S
@@ -100,9 +101,6 @@ SRCS+= bcmp.c bcopy.S bzero.S ffs.S index.c memccpy.c memchr.c memcmp.c \
strncat.c strncmp.c strncpy.c strpbrk.c strrchr.c strsep.c \
strspn.c strstr.c strtok.c swab.c
-.PATH: ${.CURDIR}/../libc/ia64/net
-SRCS+= htons.S ntohs.S htonl.S ntohl.S
-
.PATH: ${.CURDIR}/../libc/ia64/gen
SRCS+= __divdi3.S __divsi3.S __moddi3.S __modsi3.S
SRCS+= __udivdi3.S __udivsi3.S __umoddi3.S __umodsi3.S
diff --git a/sys/alpha/include/bus.h b/sys/alpha/include/bus.h
index d1f0206..1a805b1 100644
--- a/sys/alpha/include/bus.h
+++ b/sys/alpha/include/bus.h
@@ -366,6 +366,70 @@ void busspace_generic_barrier(struct alpha_busspace *space,
(t)->ab_ops->abo_barrier(t, (h)+(o), l, f)
/*
+ * Stream accesses are the same as normal accesses on alpha; there are no
+ * supported bus systems with an endianess different from the host one.
+ */
+#define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o))
+#define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o))
+#define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o))
+
+#define bus_space_read_multi_stream_1(t, h, o, a, c) \
+ bus_space_read_multi_1((t), (h), (o), (a), (c))
+#define bus_space_read_multi_stream_2(t, h, o, a, c) \
+ bus_space_read_multi_2((t), (h), (o), (a), (c))
+#define bus_space_read_multi_stream_4(t, h, o, a, c) \
+ bus_space_read_multi_4((t), (h), (o), (a), (c))
+
+#define bus_space_write_stream_1(t, h, o, v) \
+ bus_space_write_1((t), (h), (o), (v))
+#define bus_space_write_stream_2(t, h, o, v) \
+ bus_space_write_2((t), (h), (o), (v))
+#define bus_space_write_stream_4(t, h, o, v) \
+ bus_space_write_4((t), (h), (o), (v))
+
+#define bus_space_write_multi_stream_1(t, h, o, a, c) \
+ bus_space_write_multi_1((t), (h), (o), (a), (c))
+#define bus_space_write_multi_stream_2(t, h, o, a, c) \
+ bus_space_write_multi_2((t), (h), (o), (a), (c))
+#define bus_space_write_multi_stream_4(t, h, o, a, c) \
+ bus_space_write_multi_4((t), (h), (o), (a), (c))
+
+#define bus_space_set_multi_stream_1(t, h, o, v, c) \
+ bus_space_set_multi_1((t), (h), (o), (v), (c))
+#define bus_space_set_multi_stream_2(t, h, o, v, c) \
+ bus_space_set_multi_2((t), (h), (o), (v), (c))
+#define bus_space_set_multi_stream_4(t, h, o, v, c) \
+ bus_space_set_multi_4((t), (h), (o), (v), (c))
+
+#define bus_space_read_region_stream_1(t, h, o, a, c) \
+ bus_space_read_region_1((t), (h), (o), (a), (c))
+#define bus_space_read_region_stream_2(t, h, o, a, c) \
+ bus_space_read_region_2((t), (h), (o), (a), (c))
+#define bus_space_read_region_stream_4(t, h, o, a, c) \
+ bus_space_read_region_4((t), (h), (o), (a), (c))
+
+#define bus_space_write_region_stream_1(t, h, o, a, c) \
+ bus_space_write_region_1((t), (h), (o), (a), (c))
+#define bus_space_write_region_stream_2(t, h, o, a, c) \
+ bus_space_write_region_2((t), (h), (o), (a), (c))
+#define bus_space_write_region_stream_4(t, h, o, a, c) \
+ bus_space_write_region_4((t), (h), (o), (a), (c))
+
+#define bus_space_set_region_stream_1(t, h, o, v, c) \
+ bus_space_set_region_1((t), (h), (o), (v), (c))
+#define bus_space_set_region_stream_2(t, h, o, v, c) \
+ bus_space_set_region_2((t), (h), (o), (v), (c))
+#define bus_space_set_region_stream_4(t, h, o, v, c) \
+ bus_space_set_region_4((t), (h), (o), (v), (c))
+
+#define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
+#define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
+#define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
+
+/*
* Flags used in various bus DMA methods.
*/
#define BUS_DMA_WAITOK 0x00 /* safe to sleep (pseudo-flag) */
diff --git a/sys/alpha/include/endian.h b/sys/alpha/include/endian.h
index d9e64c8..5f8c050 100644
--- a/sys/alpha/include/endian.h
+++ b/sys/alpha/include/endian.h
@@ -56,6 +56,14 @@
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */
#define BYTE_ORDER LITTLE_ENDIAN
+
+#ifdef _KERNEL
+#define _BSWAP16_DEFINED
+__uint16_t __bswap16(__uint16_t);
+#define _BSWAP32_DEFINED
+__uint32_t __bswap32(__uint32_t);
+#endif /* _KERNEL */
+
#endif /* !_POSIX_SOURCE */
#endif /* !_MACHINE_ENDIAN_H_ */
diff --git a/sys/amd64/include/bus.h b/sys/amd64/include/bus.h
index 33d4162..a33569f 100644
--- a/sys/amd64/include/bus.h
+++ b/sys/amd64/include/bus.h
@@ -43,4 +43,68 @@
#endif
#include <machine/bus_dma.h>
+/*
+ * Stream accesses are the same as normal accesses on i386/pc98; there are no
+ * supported bus systems with an endianess different from the host one.
+ */
+#define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o))
+#define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o))
+#define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o))
+
+#define bus_space_read_multi_stream_1(t, h, o, a, c) \
+ bus_space_read_multi_1((t), (h), (o), (a), (c))
+#define bus_space_read_multi_stream_2(t, h, o, a, c) \
+ bus_space_read_multi_2((t), (h), (o), (a), (c))
+#define bus_space_read_multi_stream_4(t, h, o, a, c) \
+ bus_space_read_multi_4((t), (h), (o), (a), (c))
+
+#define bus_space_write_stream_1(t, h, o, v) \
+ bus_space_write_1((t), (h), (o), (v))
+#define bus_space_write_stream_2(t, h, o, v) \
+ bus_space_write_2((t), (h), (o), (v))
+#define bus_space_write_stream_4(t, h, o, v) \
+ bus_space_write_4((t), (h), (o), (v))
+
+#define bus_space_write_multi_stream_1(t, h, o, a, c) \
+ bus_space_write_multi_1((t), (h), (o), (a), (c))
+#define bus_space_write_multi_stream_2(t, h, o, a, c) \
+ bus_space_write_multi_2((t), (h), (o), (a), (c))
+#define bus_space_write_multi_stream_4(t, h, o, a, c) \
+ bus_space_write_multi_4((t), (h), (o), (a), (c))
+
+#define bus_space_set_multi_stream_1(t, h, o, v, c) \
+ bus_space_set_multi_1((t), (h), (o), (v), (c))
+#define bus_space_set_multi_stream_2(t, h, o, v, c) \
+ bus_space_set_multi_2((t), (h), (o), (v), (c))
+#define bus_space_set_multi_stream_4(t, h, o, v, c) \
+ bus_space_set_multi_4((t), (h), (o), (v), (c))
+
+#define bus_space_read_region_stream_1(t, h, o, a, c) \
+ bus_space_read_region_1((t), (h), (o), (a), (c))
+#define bus_space_read_region_stream_2(t, h, o, a, c) \
+ bus_space_read_region_2((t), (h), (o), (a), (c))
+#define bus_space_read_region_stream_4(t, h, o, a, c) \
+ bus_space_read_region_4((t), (h), (o), (a), (c))
+
+#define bus_space_write_region_stream_1(t, h, o, a, c) \
+ bus_space_write_region_1((t), (h), (o), (a), (c))
+#define bus_space_write_region_stream_2(t, h, o, a, c) \
+ bus_space_write_region_2((t), (h), (o), (a), (c))
+#define bus_space_write_region_stream_4(t, h, o, a, c) \
+ bus_space_write_region_4((t), (h), (o), (a), (c))
+
+#define bus_space_set_region_stream_1(t, h, o, v, c) \
+ bus_space_set_region_1((t), (h), (o), (v), (c))
+#define bus_space_set_region_stream_2(t, h, o, v, c) \
+ bus_space_set_region_2((t), (h), (o), (v), (c))
+#define bus_space_set_region_stream_4(t, h, o, v, c) \
+ bus_space_set_region_4((t), (h), (o), (v), (c))
+
+#define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
+#define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
+#define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
+
#endif /* _I386_BUS_H_ */
diff --git a/sys/conf/files.alpha b/sys/conf/files.alpha
index 8d3e222..4e3377c 100644
--- a/sys/conf/files.alpha
+++ b/sys/conf/files.alpha
@@ -215,9 +215,7 @@ isa/psm.c optional psm
isa/syscons_isa.c optional sc
isa/vga_isa.c optional vga
kern/subr_diskmbr.c standard
-libkern/alpha/htonl.S standard
-libkern/alpha/htons.S standard
-libkern/alpha/ntohl.S standard
-libkern/alpha/ntohs.S standard
+libkern/alpha/bswap16.S standard
+libkern/alpha/bswap32.S standard
libkern/bcmp.c standard
libkern/ffs.c standard
diff --git a/sys/conf/files.ia64 b/sys/conf/files.ia64
index 56f5bae..b301f9c 100644
--- a/sys/conf/files.ia64
+++ b/sys/conf/files.ia64
@@ -99,10 +99,8 @@ isa/psm.c optional psm
isa/syscons_isa.c optional sc
isa/vga_isa.c optional vga
kern/subr_diskmbr.c standard
-libkern/ia64/htonl.S standard
-libkern/ia64/htons.S standard
-libkern/ia64/ntohl.S standard
-libkern/ia64/ntohs.S standard
+libkern/ia64/bswap16.S standard
+libkern/ia64/bswap32.S standard
libkern/ia64/__divsi3.S standard
libkern/ia64/__modsi3.S standard
libkern/ia64/__udivsi3.S standard
diff --git a/sys/dev/iir/iir.h b/sys/dev/iir/iir.h
index b165c84..3b325cb 100644
--- a/sys/dev/iir/iir.h
+++ b/sys/dev/iir/iir.h
@@ -372,10 +372,8 @@ extern int ser_printf(const char *fmt, ...);
#define GDT_SCRATCH_SZ 3072 /* 3KB scratch buffer */
/* macros */
-#define htole32(v) (v)
-#define htole16(v) (v)
-#define letoh32(v) (v)
-#define letoh16(v) (v)
+#define letoh32(v) le32toh(v)
+#define letoh16(v) le16toh(v)
/* Map minor numbers to device identity */
#define LUN_MASK 0x0007
diff --git a/sys/dev/usb/ohci.c b/sys/dev/usb/ohci.c
index 369f246..70675c0 100644
--- a/sys/dev/usb/ohci.c
+++ b/sys/dev/usb/ohci.c
@@ -96,20 +96,6 @@ int ohcidebug = 1;
#define DPRINTFN(n,x)
#endif
-/*
- * The OHCI controller is little endian, so on big endian machines
- * the data strored in memory needs to be swapped.
- */
-#if defined(__FreeBSD__)
-#if BYTE_ORDER == BIG_ENDIAN
-#define htole32(x) (bswap32(x))
-#define le32toh(x) (bswap32(x))
-#else
-#define htole32(x) (x)
-#define le32toh(x) (x)
-#endif
-#endif
-
struct ohci_pipe;
Static ohci_soft_ed_t *ohci_alloc_sed(ohci_softc_t *);
diff --git a/sys/dev/usb/uhci.c b/sys/dev/usb/uhci.c
index de4e64f..d01c131 100644
--- a/sys/dev/usb/uhci.c
+++ b/sys/dev/usb/uhci.c
@@ -112,7 +112,7 @@ int uhcinoloop = 0;
* The UHCI controller is little endian, so on big endian machines
* the data strored in memory needs to be swapped.
*/
-#if defined(__FreeBSD__) || defined(__OpenBSD__)
+#if defined(__OpenBSD__)
#if BYTE_ORDER == BIG_ENDIAN
#define htole32(x) (bswap32(x))
#define le32toh(x) (bswap32(x))
diff --git a/sys/dev/usb/usb_port.h b/sys/dev/usb/usb_port.h
index 642b439..1f4b191 100644
--- a/sys/dev/usb/usb_port.h
+++ b/sys/dev/usb/usb_port.h
@@ -314,7 +314,6 @@ typedef struct thread *usb_proc_ptr;
/* XXX Change this when FreeBSD has memset */
#define memcpy(d, s, l) bcopy((s),(d),(l))
#define memset(d, v, l) bzero((d),(l))
-#define bswap32(x) swap32(x)
#define kthread_create1(f, s, p, a0, a1) \
kthread_create((f), (s), (p), RFHIGHPID, (a0), (a1))
diff --git a/sys/dev/wi/if_wi.c b/sys/dev/wi/if_wi.c
index 1620593..317a4bc 100644
--- a/sys/dev/wi/if_wi.c
+++ b/sys/dev/wi/if_wi.c
@@ -125,11 +125,9 @@ static u_int8_t wi_mcast_addr[6] = { 0x01, 0x60, 0x1D, 0x00, 0x01, 0x00 };
#endif
/*
- * The following is for compatibility with NetBSD, but should really be
- * brought in from NetBSD en toto.
+ * The following is for compatibility with NetBSD.
*/
-#define le16toh(a) (a)
-#define LE16TOH(a)
+#define LE16TOH(a) ((a) = le16toh((a)))
static void wi_intr __P((void *));
static void wi_reset __P((struct wi_softc *));
diff --git a/sys/i386/include/bus.h b/sys/i386/include/bus.h
index 33d4162..a33569f 100644
--- a/sys/i386/include/bus.h
+++ b/sys/i386/include/bus.h
@@ -43,4 +43,68 @@
#endif
#include <machine/bus_dma.h>
+/*
+ * Stream accesses are the same as normal accesses on i386/pc98; there are no
+ * supported bus systems with an endianess different from the host one.
+ */
+#define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o))
+#define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o))
+#define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o))
+
+#define bus_space_read_multi_stream_1(t, h, o, a, c) \
+ bus_space_read_multi_1((t), (h), (o), (a), (c))
+#define bus_space_read_multi_stream_2(t, h, o, a, c) \
+ bus_space_read_multi_2((t), (h), (o), (a), (c))
+#define bus_space_read_multi_stream_4(t, h, o, a, c) \
+ bus_space_read_multi_4((t), (h), (o), (a), (c))
+
+#define bus_space_write_stream_1(t, h, o, v) \
+ bus_space_write_1((t), (h), (o), (v))
+#define bus_space_write_stream_2(t, h, o, v) \
+ bus_space_write_2((t), (h), (o), (v))
+#define bus_space_write_stream_4(t, h, o, v) \
+ bus_space_write_4((t), (h), (o), (v))
+
+#define bus_space_write_multi_stream_1(t, h, o, a, c) \
+ bus_space_write_multi_1((t), (h), (o), (a), (c))
+#define bus_space_write_multi_stream_2(t, h, o, a, c) \
+ bus_space_write_multi_2((t), (h), (o), (a), (c))
+#define bus_space_write_multi_stream_4(t, h, o, a, c) \
+ bus_space_write_multi_4((t), (h), (o), (a), (c))
+
+#define bus_space_set_multi_stream_1(t, h, o, v, c) \
+ bus_space_set_multi_1((t), (h), (o), (v), (c))
+#define bus_space_set_multi_stream_2(t, h, o, v, c) \
+ bus_space_set_multi_2((t), (h), (o), (v), (c))
+#define bus_space_set_multi_stream_4(t, h, o, v, c) \
+ bus_space_set_multi_4((t), (h), (o), (v), (c))
+
+#define bus_space_read_region_stream_1(t, h, o, a, c) \
+ bus_space_read_region_1((t), (h), (o), (a), (c))
+#define bus_space_read_region_stream_2(t, h, o, a, c) \
+ bus_space_read_region_2((t), (h), (o), (a), (c))
+#define bus_space_read_region_stream_4(t, h, o, a, c) \
+ bus_space_read_region_4((t), (h), (o), (a), (c))
+
+#define bus_space_write_region_stream_1(t, h, o, a, c) \
+ bus_space_write_region_1((t), (h), (o), (a), (c))
+#define bus_space_write_region_stream_2(t, h, o, a, c) \
+ bus_space_write_region_2((t), (h), (o), (a), (c))
+#define bus_space_write_region_stream_4(t, h, o, a, c) \
+ bus_space_write_region_4((t), (h), (o), (a), (c))
+
+#define bus_space_set_region_stream_1(t, h, o, v, c) \
+ bus_space_set_region_1((t), (h), (o), (v), (c))
+#define bus_space_set_region_stream_2(t, h, o, v, c) \
+ bus_space_set_region_2((t), (h), (o), (v), (c))
+#define bus_space_set_region_stream_4(t, h, o, v, c) \
+ bus_space_set_region_4((t), (h), (o), (v), (c))
+
+#define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
+#define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
+#define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
+
#endif /* _I386_BUS_H_ */
diff --git a/sys/i386/include/endian.h b/sys/i386/include/endian.h
index 7428ee3..4076422 100644
--- a/sys/i386/include/endian.h
+++ b/sys/i386/include/endian.h
@@ -58,12 +58,12 @@
#define BYTE_ORDER LITTLE_ENDIAN
#endif /* ! _POSIX_SOURCE */
+#ifdef _KERNEL
#ifdef __GNUC__
-__BEGIN_DECLS
-
+#define _BSWAP32_DEFINED
static __inline __uint32_t
-__htonl(__uint32_t __x)
+__bswap32(__uint32_t __x)
{
#if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU)
__asm ("bswap %0" : "+r" (__x));
@@ -76,29 +76,16 @@ __htonl(__uint32_t __x)
return __x;
}
+#define _BSWAP16_DEFINED
static __inline __uint16_t
-__htons(__uint16_t __x)
+__bswap16(__uint16_t __x)
{
__asm ("xchgb %h0, %b0" : "+q" (__x));
return __x;
}
-static __inline __uint32_t
-__ntohl(__uint32_t __x)
-{
-
- return (__htonl(__x));
-}
-
-static __inline __uint16_t
-__ntohs(__uint16_t __x)
-{
-
- return (__htons(__x));
-}
-
-__END_DECLS
+#endif /* _KERNEL */
#endif /* __GNUC__ */
diff --git a/sys/ia64/include/bus.h b/sys/ia64/include/bus.h
index 724d1d5..d7231c4 100644
--- a/sys/ia64/include/bus.h
+++ b/sys/ia64/include/bus.h
@@ -1000,6 +1000,70 @@ bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
#endif
}
+/*
+ * Stream accesses are the same as normal accesses on ia64; there are no
+ * supported bus systems with an endianess different from the host one.
+ */
+#define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o))
+#define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o))
+#define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o))
+
+#define bus_space_read_multi_stream_1(t, h, o, a, c) \
+ bus_space_read_multi_1((t), (h), (o), (a), (c))
+#define bus_space_read_multi_stream_2(t, h, o, a, c) \
+ bus_space_read_multi_2((t), (h), (o), (a), (c))
+#define bus_space_read_multi_stream_4(t, h, o, a, c) \
+ bus_space_read_multi_4((t), (h), (o), (a), (c))
+
+#define bus_space_write_stream_1(t, h, o, v) \
+ bus_space_write_1((t), (h), (o), (v))
+#define bus_space_write_stream_2(t, h, o, v) \
+ bus_space_write_2((t), (h), (o), (v))
+#define bus_space_write_stream_4(t, h, o, v) \
+ bus_space_write_4((t), (h), (o), (v))
+
+#define bus_space_write_multi_stream_1(t, h, o, a, c) \
+ bus_space_write_multi_1((t), (h), (o), (a), (c))
+#define bus_space_write_multi_stream_2(t, h, o, a, c) \
+ bus_space_write_multi_2((t), (h), (o), (a), (c))
+#define bus_space_write_multi_stream_4(t, h, o, a, c) \
+ bus_space_write_multi_4((t), (h), (o), (a), (c))
+
+#define bus_space_set_multi_stream_1(t, h, o, v, c) \
+ bus_space_set_multi_1((t), (h), (o), (v), (c))
+#define bus_space_set_multi_stream_2(t, h, o, v, c) \
+ bus_space_set_multi_2((t), (h), (o), (v), (c))
+#define bus_space_set_multi_stream_4(t, h, o, v, c) \
+ bus_space_set_multi_4((t), (h), (o), (v), (c))
+
+#define bus_space_read_region_stream_1(t, h, o, a, c) \
+ bus_space_read_region_1((t), (h), (o), (a), (c))
+#define bus_space_read_region_stream_2(t, h, o, a, c) \
+ bus_space_read_region_2((t), (h), (o), (a), (c))
+#define bus_space_read_region_stream_4(t, h, o, a, c) \
+ bus_space_read_region_4((t), (h), (o), (a), (c))
+
+#define bus_space_write_region_stream_1(t, h, o, a, c) \
+ bus_space_write_region_1((t), (h), (o), (a), (c))
+#define bus_space_write_region_stream_2(t, h, o, a, c) \
+ bus_space_write_region_2((t), (h), (o), (a), (c))
+#define bus_space_write_region_stream_4(t, h, o, a, c) \
+ bus_space_write_region_4((t), (h), (o), (a), (c))
+
+#define bus_space_set_region_stream_1(t, h, o, v, c) \
+ bus_space_set_region_1((t), (h), (o), (v), (c))
+#define bus_space_set_region_stream_2(t, h, o, v, c) \
+ bus_space_set_region_2((t), (h), (o), (v), (c))
+#define bus_space_set_region_stream_4(t, h, o, v, c) \
+ bus_space_set_region_4((t), (h), (o), (v), (c))
+
+#define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
+#define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
+#define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
+ bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
+
#endif /* defined(_MACHINE_BUS_PIO_H_) || defined(_MACHINE_BUS_MEMIO_H_) */
#if 0 /* Cause a link error for bus_space_copy_8 */
diff --git a/sys/ia64/include/endian.h b/sys/ia64/include/endian.h
index c1efac9..fe927a2 100644
--- a/sys/ia64/include/endian.h
+++ b/sys/ia64/include/endian.h
@@ -59,12 +59,12 @@
#define BYTE_ORDER LITTLE_ENDIAN
#endif /* !_POSIX_SOURCE */
+#ifdef _KERNEL
#ifdef __GNUC__
-__BEGIN_DECLS
-
+#define _BSWAP64_DEFINED
static __inline __uint64_t
-__uint8_swap_uint64(__uint64_t __x)
+__bswap64(__uint64_t __x)
{
__uint64_t __r;
__asm __volatile("mux1 %0=%1,@rev"
@@ -72,36 +72,30 @@ __uint8_swap_uint64(__uint64_t __x)
return __r;
}
+#define _BSWAP32_DEFINED
static __inline __uint32_t
-__htonl(__uint32_t __x)
+__bswap32(__uint32_t __x)
{
- return (__uint8_swap_uint64(__x) >> 32);
+ return (__bswap64(__x) >> 32);
}
+#define _BSWAP16_DEFINED
static __inline __uint16_t
-__htons(__uint16_t __x)
+__bswap16(__uint16_t __x)
{
- return (__uint8_swap_uint64(__x) >> 48);
+ return (__bswap64(__x) >> 48);
}
-static __inline __uint32_t
-__ntohl(__uint32_t __x)
-{
-
- return (__uint8_swap_uint64(__x) >> 32);
-}
-
-static __inline __uint16_t
-__ntohs(__uint16_t __x)
-{
-
- return (__uint8_swap_uint64(__x) >> 48);
-}
-
-__END_DECLS
-
+#else /* !__GNUC__ */
+/* XXX: use the libkern versions for now; these might go away soon. */
+#define _BSWAP16_DEFINED
+__uint16_t __bswap16(__uint16_t);
+#define _BSWAP32_DEFINED
+__uint32_t __bswap32(__uint32_t);
#endif /* __GNUC__ */
+#endif /* _KERNEL */
+
#endif /* !_MACHINE_ENDIAN_H_ */
diff --git a/sys/libkern/alpha/htons.S b/sys/libkern/alpha/bswap16.S
index 6b8ea16..98cf054 100644
--- a/sys/libkern/alpha/htons.S
+++ b/sys/libkern/alpha/bswap16.S
@@ -1,6 +1,3 @@
-/* $FreeBSD$ */
-/* $NetBSD: htons.S,v 1.1 1996/04/17 22:36:54 cgd Exp $ */
-
/*
* Copyright (c) 1996 Carnegie-Mellon University.
* All rights reserved.
@@ -26,9 +23,13 @@
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
+ *
+ * from: NetBSD: htons.S,v 1.1 1996/04/17 22:36:54 cgd
+ * from: src/sys/libkern/alpha/htons.S,v 1.3 2002/02/18 20:35:21
+ *
+ * $FreeBSD$
*/
-#define ALIAS htons
-#define NAME __htons
+#define NAME __bswap16
#include <libkern/alpha/byte_swap_2.S>
diff --git a/sys/libkern/alpha/htonl.S b/sys/libkern/alpha/bswap32.S
index 2604034..bc1b127 100644
--- a/sys/libkern/alpha/htonl.S
+++ b/sys/libkern/alpha/bswap32.S
@@ -1,6 +1,3 @@
-/* $FreeBSD$ */
-/* $NetBSD: htonl.S,v 1.1 1996/04/17 22:36:52 cgd Exp $ */
-
/*
* Copyright (c) 1996 Carnegie-Mellon University.
* All rights reserved.
@@ -25,10 +22,14 @@
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
+ * rights to redistribute these changes.
+ *
+ * from: NetBSD: htonl.S,v 1.1 1996/04/17 22:36:52 cgd
+ * from: src/sys/libkern/alpha/htonl.S,v 1.3 2002/02/18 20:35:21
+ *
+ * $FreeBSD$
*/
-#define ALIAS htonl
-#define NAME __htonl
+#define NAME __bswap32
#include <libkern/alpha/byte_swap_4.S>
diff --git a/sys/libkern/alpha/byte_swap_2.S b/sys/libkern/alpha/byte_swap_2.S
index 8111918..613eef6 100644
--- a/sys/libkern/alpha/byte_swap_2.S
+++ b/sys/libkern/alpha/byte_swap_2.S
@@ -30,8 +30,8 @@
#include <machine/asm.h>
-#if !defined(ALIAS) || !defined(NAME)
-#error ALIAS or NAME not defined
+#ifndef NAME
+#error NAME not defined
#endif
/*
@@ -39,7 +39,6 @@
*
* Argument is an unsigned 2-byte integer (u_int16_t).
*/
-XLEAF(ALIAS, 1)
LEAF(NAME, 1) /* a0 contains 0x0123 */
extbl a0, 0, t0 /* t0 = 0x 23 */
extbl a0, 1, t1 /* t1 = 0x 01 */
diff --git a/sys/libkern/alpha/byte_swap_4.S b/sys/libkern/alpha/byte_swap_4.S
index d31bbe8..2a66f17 100644
--- a/sys/libkern/alpha/byte_swap_4.S
+++ b/sys/libkern/alpha/byte_swap_4.S
@@ -30,8 +30,8 @@
#include <machine/asm.h>
-#if !defined(ALIAS) || !defined(NAME)
-#error ALIAS or NAME not defined
+#ifndef NAME
+#error NAME not defined
#endif
/*
@@ -39,7 +39,6 @@
*
* Argument is an unsigned 4-byte integer (u_int32_t).
*/
-XLEAF(ALIAS, 1)
LEAF(NAME, 1) /* a0 contains 0x01234567 */
extbl a0, 0, t0 /* t0 = 0x 67 */
extbl a0, 1, t1 /* t1 = 0x 45 */
diff --git a/sys/libkern/alpha/ntohl.S b/sys/libkern/alpha/ntohl.S
deleted file mode 100644
index 590203a..0000000
--- a/sys/libkern/alpha/ntohl.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: ntohl.S,v 1.1 1996/04/17 22:36:57 cgd Exp $ */
-
-/*
- * Copyright (c) 1996 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-#define ALIAS ntohl
-#define NAME __ntohl
-
-#include <libkern/alpha/byte_swap_4.S>
diff --git a/sys/libkern/alpha/ntohs.S b/sys/libkern/alpha/ntohs.S
deleted file mode 100644
index 9306881..0000000
--- a/sys/libkern/alpha/ntohs.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: ntohs.S,v 1.1 1996/04/17 22:37:02 cgd Exp $ */
-
-/*
- * Copyright (c) 1996 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-#define ALIAS ntohs
-#define NAME __ntohs
-
-#include <libkern/alpha/byte_swap_2.S>
diff --git a/sys/libkern/ia64/htons.S b/sys/libkern/ia64/bswap16.S
index 16a83d6..746e906 100644
--- a/sys/libkern/ia64/htons.S
+++ b/sys/libkern/ia64/bswap16.S
@@ -1,6 +1,3 @@
-/* $FreeBSD$ */
-/* $NetBSD: htons.S,v 1.1 1996/04/17 22:36:54 cgd Exp $ */
-
/*
* Copyright (c) 1996 Carnegie-Mellon University.
* All rights reserved.
@@ -26,9 +23,13 @@
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
+ *
+ * from: NetBSD: htons.S,v 1.1 1996/04/17 22:36:54 cgd
+ * from: src/sys/libkern/ia64/htons.S,v 1.2 2002/02/18 20:35:21
+ *
+ * $FreeBSD$
*/
-#define ALIAS htons
-#define NAME __htons
+#define NAME __bswap16
#include <libkern/ia64/byte_swap_2.S>
diff --git a/sys/libkern/ia64/htonl.S b/sys/libkern/ia64/bswap32.S
index f0c89f4..d2a22b2 100644
--- a/sys/libkern/ia64/htonl.S
+++ b/sys/libkern/ia64/bswap32.S
@@ -1,6 +1,3 @@
-/* $FreeBSD$ */
-/* $NetBSD: htonl.S,v 1.1 1996/04/17 22:36:52 cgd Exp $ */
-
/*
* Copyright (c) 1996 Carnegie-Mellon University.
* All rights reserved.
@@ -26,9 +23,13 @@
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
+ *
+ * from: NetBSD: htonl.S,v 1.1 1996/04/17 22:36:52 cgd
+ * from: src/sys/libkern/ia64/htonl.S,v 1.2 2002/02/18 20:35:21
+ *
+ * $FreeBSD$
*/
-#define ALIAS htonl
-#define NAME __htonl
+#define NAME __bswap32
#include <libkern/ia64/byte_swap_4.S>
diff --git a/sys/libkern/ia64/byte_swap_2.S b/sys/libkern/ia64/byte_swap_2.S
index 19d0eef..b9ea7d2 100644
--- a/sys/libkern/ia64/byte_swap_2.S
+++ b/sys/libkern/ia64/byte_swap_2.S
@@ -30,8 +30,8 @@
#include <machine/asm.h>
-#if !defined(ALIAS) || !defined(NAME)
-#error ALIAS or NAME not defined
+#ifndef NAME
+#error NAME not defined
#endif
/*
@@ -39,7 +39,6 @@
*
* Argument is an unsigned 2-byte integer (u_int16_t).
*/
-WEAK_ALIAS(ALIAS, NAME)
ENTRY(NAME, 1)
mux1 r16=in0,@rev
;;
diff --git a/sys/libkern/ia64/byte_swap_4.S b/sys/libkern/ia64/byte_swap_4.S
index 71019ba..facce77 100644
--- a/sys/libkern/ia64/byte_swap_4.S
+++ b/sys/libkern/ia64/byte_swap_4.S
@@ -30,8 +30,8 @@
#include <machine/asm.h>
-#if !defined(ALIAS) || !defined(NAME)
-#error ALIAS or NAME not defined
+#ifndef NAME
+#error NAME not defined
#endif
/*
@@ -39,7 +39,6 @@
*
* Argument is an unsigned 4-byte integer (u_int32_t).
*/
-WEAK_ALIAS(ALIAS, NAME)
ENTRY(NAME, 1)
mux1 r16=in0,@rev
;;
diff --git a/sys/libkern/ia64/ntohl.S b/sys/libkern/ia64/ntohl.S
deleted file mode 100644
index 2f2e7ba..0000000
--- a/sys/libkern/ia64/ntohl.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: ntohl.S,v 1.1 1996/04/17 22:36:57 cgd Exp $ */
-
-/*
- * Copyright (c) 1996 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-#define ALIAS ntohl
-#define NAME __ntohl
-
-#include <libkern/ia64/byte_swap_4.S>
diff --git a/sys/libkern/ia64/ntohs.S b/sys/libkern/ia64/ntohs.S
deleted file mode 100644
index 051f103..0000000
--- a/sys/libkern/ia64/ntohs.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/* $FreeBSD$ */
-/* $NetBSD: ntohs.S,v 1.1 1996/04/17 22:37:02 cgd Exp $ */
-
-/*
- * Copyright (c) 1996 Carnegie-Mellon University.
- * All rights reserved.
- *
- * Author: Chris G. Demetriou
- *
- * Permission to use, copy, modify and distribute this software and
- * its documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
- * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
- * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * Carnegie Mellon requests users of this software to return to
- *
- * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
- * School of Computer Science
- * Carnegie Mellon University
- * Pittsburgh PA 15213-3890
- *
- * any improvements or extensions that they make and grant Carnegie the
- * rights to redistribute these changes.
- */
-
-#define ALIAS ntohs
-#define NAME __ntohs
-
-#include <libkern/ia64/byte_swap_2.S>
diff --git a/sys/powerpc/include/endian.h b/sys/powerpc/include/endian.h
index 3b45b73..4acd586 100644
--- a/sys/powerpc/include/endian.h
+++ b/sys/powerpc/include/endian.h
@@ -60,18 +60,6 @@
#ifndef _KERNEL
#include <sys/cdefs.h>
-
-__BEGIN_DECLS
-__uint32_t __htonl __P((__uint32_t));
-__uint16_t __htons __P((__uint16_t));
-__uint32_t __ntohl __P((__uint32_t));
-__uint16_t __ntohs __P((__uint16_t));
-__END_DECLS
#endif /* _KERNEL */
-#define __htonl(x) (x)
-#define __htons(x) (x)
-#define __ntohl(x) (x)
-#define __ntohs(x) (x)
-
#endif /* !_MACHINE_ENDIAN_H_ */
diff --git a/sys/sparc64/include/endian.h b/sys/sparc64/include/endian.h
index 532daab..fc51c7e 100644
--- a/sys/sparc64/include/endian.h
+++ b/sys/sparc64/include/endian.h
@@ -57,9 +57,4 @@
#define BYTE_ORDER BIG_ENDIAN
#endif /* !_POSIX_SOURCE */
-#define __htonl(x) (x)
-#define __htons(x) (x)
-#define __ntohl(x) (x)
-#define __ntohs(x) (x)
-
#endif /* !_MACHINE_ENDIAN_H_ */
diff --git a/sys/sys/imgact_aout.h b/sys/sys/imgact_aout.h
index 4b20b87..07d03d0 100644
--- a/sys/sys/imgact_aout.h
+++ b/sys/sys/imgact_aout.h
@@ -50,13 +50,13 @@
((mag) & 0xffff) )
#define N_GETMAGIC_NET(ex) \
- (__ntohl((ex).a_midmag) & 0xffff)
+ (ntohl((ex).a_midmag) & 0xffff)
#define N_GETMID_NET(ex) \
- ((__ntohl((ex).a_midmag) >> 16) & 0x03ff)
+ ((ntohl((ex).a_midmag) >> 16) & 0x03ff)
#define N_GETFLAG_NET(ex) \
- ((__ntohl((ex).a_midmag) >> 26) & 0x3f)
+ ((ntohl((ex).a_midmag) >> 26) & 0x3f)
#define N_SETMAGIC_NET(ex,mag,mid,flag) \
- ( (ex).a_midmag = __htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) \
+ ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) \
| (((mag)&0xffff)) ) )
#define N_ALIGN(ex,x) \
diff --git a/sys/sys/mchain.h b/sys/sys/mchain.h
index 57278f4..7b4f7ec 100644
--- a/sys/sys/mchain.h
+++ b/sys/sys/mchain.h
@@ -36,6 +36,28 @@
#include <machine/endian.h>
+#ifdef _KERNEL
+
+/*
+ * XXX: remove these defines and change the function calls in the code. Use
+ * it unconditionally if (when) the extended byte order functions become
+ * available in user space.
+ */
+#define htoles(x) htole16((x))
+#define letohs(x) le16toh((x))
+#define htolel(x) htole32((x))
+#define letohl(x) le32toh((x))
+#define htoleq(x) htole64((int64_t)(x))
+#define letohq(x) le64toh((int64_t)(x))
+
+#define htobes(x) htobe16((x))
+#define betohs(x) be16toh((x))
+#define htobel(x) htobe32((x))
+#define betohl(x) be32toh((x))
+#define htobeq(x) htobe64((int64_t)(x))
+#define betohq(x) be64toh((int64_t)(x))
+
+#else
/*
* This macros probably belongs to the endian.h
*/
@@ -78,6 +100,7 @@ betohq(int64_t x)
#define letohl(x) ((u_int32_t)(x))
*/
#endif /* (BYTE_ORDER == LITTLE_ENDIAN) */
+#endif /* _KERNEL */
#ifdef _KERNEL
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 3a2fa5f..6f13c4b 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -188,28 +188,92 @@
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
+#ifdef _KERNEL
/*
- * Kernel exposed versions of byteorder(3) functions.
- *
- * XXX this section should only be defined in the kernel, but some userland
- * software utilizes it.
+ * Extended byte order support functions, for kernel use only currently.
+ * First, generic implementation of the byte swapping functions for those
+ * architectures that do not have optimized variants of each.
*/
-#ifndef _BYTEORDER_FUNC_DEFINED
-#define _BYTEORDER_FUNC_DEFINED
-#define htonl(x) __htonl(x)
-#define htons(x) __htons(x)
-#define ntohl(x) __ntohl(x)
-#define ntohs(x) __ntohs(x)
+#ifndef _BSWAP16_DEFINED
+#define _BSWAP16_DEFINED
+static __inline __uint16_t
+__bswap16(__uint16_t x)
+{
+ return ((x >> 8) | ((x << 8) & 0xff00U));
+}
+#endif
+
+#ifndef _BSWAP32_DEFINED
+#define _BSWAP32_DEFINED
+static __inline __uint32_t
+__bswap32(__uint32_t x)
+{
+ return ((x >> 24) | ((x >> 8) & 0xff00U) | ((x << 8) & 0xff0000U) |
+ ((x << 24) & 0xff000000U));
+}
+#endif
+
+#ifndef _BSWAP64_DEFINED
+#define _BSWAP64_DEFINED
+static __inline __uint64_t
+__bswap64(__uint64_t x)
+{
+ return ((x >> 56) | ((x >> 40) & 0xff00UL) | ((x >> 24) & 0xff0000UL) |
+ ((x >> 8) & 0xff000000UL) | ((x << 8) & 0xff00000000UL) |
+ ((x << 24) & 0xff0000000000UL) | ((x << 40) & 0xff000000000000UL) |
+ ((x << 56)));
+}
#endif
+#define bswap16(x) __bswap16(x)
+#define bswap32(x) __bswap32(x)
+#define bswap64(x) __bswap64(x)
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define htobe16(x) bswap16((x))
+#define htobe32(x) bswap32((x))
+#define htobe64(x) bswap64((x))
+#define htole16(x) ((__uint16_t)(x))
+#define htole32(x) ((__uint32_t)(x))
+#define htole64(x) ((__uint64_t)(x))
+
+#define be16toh(x) bswap16((x))
+#define be32toh(x) bswap32((x))
+#define be64toh(x) bswap64((x))
+#define le16toh(x) ((__uint16_t)(x))
+#define le32toh(x) ((__uint32_t)(x))
+#define le64toh(x) ((__uint64_t)(x))
+#else /* BYTE_ORDER != LITTLE_ENDIAN */
+#define htobe16(x) ((__uint16_t)(x))
+#define htobe32(x) ((__uint32_t)(x))
+#define htobe64(x) ((__uint64_t)(x))
+#define htole16(x) bswap16((x))
+#define htole32(x) bswap32((x))
+#define htole64(x) bswap64((x))
+
+#define be16toh(x) ((__uint16_t)(x))
+#define be32toh(x) ((__uint32_t)(x))
+#define be64toh(x) ((__uint64_t)(x))
+#define le16toh(x) bswap16((x))
+#define le32toh(x) bswap32((x))
+#define le64toh(x) bswap64((x))
+#endif /* BYTE_ORDER */
+
+#define htonl(x) htobe32((x))
+#define htons(x) htobe16((x))
+#define ntohl(x) be32toh((x))
+#define ntohs(x) be16toh((x))
+
+#endif /* _KERNEL */
+
/*
* XXX deprecated uppercase variants for byteorder(3) functions.
*/
#ifndef _POSIX_SOURCE
-#define NTOHL(x) ((x) = __ntohl(x))
-#define NTOHS(x) ((x) = __ntohs(x))
-#define HTONL(x) ((x) = __htonl(x))
-#define HTONS(x) ((x) = __htons(x))
+#define NTOHL(x) ((x) = ntohl(x))
+#define NTOHS(x) ((x) = ntohs(x))
+#define HTONL(x) ((x) = htonl(x))
+#define HTONS(x) ((x) = htons(x))
#endif /* _POSIX_SOURCE */
/*
OpenPOWER on IntegriCloud