diff options
Diffstat (limited to 'usr/src/lib')
| -rw-r--r-- | usr/src/lib/libc/amd64/Makefile | 1 | ||||
| -rw-r--r-- | usr/src/lib/libc/amd64/gen/byteorder.s | 87 | ||||
| -rw-r--r-- | usr/src/lib/libc/amd64/gen/endian.c | 74 | ||||
| -rw-r--r-- | usr/src/lib/libc/i386/Makefile.com | 1 | ||||
| -rw-r--r-- | usr/src/lib/libc/i386/gen/byteorder.s | 63 | ||||
| -rw-r--r-- | usr/src/lib/libc/i386/gen/byteorder64.c | 37 | ||||
| -rw-r--r-- | usr/src/lib/libc/i386/gen/endian.c | 57 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/mapfile-vers | 22 | ||||
| -rw-r--r-- | usr/src/lib/libc/sparc/Makefile.com | 2 | ||||
| -rw-r--r-- | usr/src/lib/libc/sparc/gen/endian.c | 158 | ||||
| -rw-r--r-- | usr/src/lib/libc/sparcv9/Makefile.com | 2 | ||||
| -rw-r--r-- | usr/src/lib/libc/sparcv9/gen/endian.c | 158 |
12 files changed, 661 insertions, 1 deletions
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile index 0a55bf964f..4580972482 100644 --- a/usr/src/lib/libc/amd64/Makefile +++ b/usr/src/lib/libc/amd64/Makefile @@ -115,6 +115,7 @@ GENOBJS= \ byteorder.o \ cuexit.o \ ecvt.o \ + endian.o \ errlst.o \ amd64_data.o \ ldivide.o \ diff --git a/usr/src/lib/libc/amd64/gen/byteorder.s b/usr/src/lib/libc/amd64/gen/byteorder.s index 5a192f0a68..12ea90f649 100644 --- a/usr/src/lib/libc/amd64/gen/byteorder.s +++ b/usr/src/lib/libc/amd64/gen/byteorder.s @@ -21,6 +21,7 @@ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2015, Joyent, Inc. */ .file "byteorder.s" @@ -90,3 +91,89 @@ shrl $16, %eax /* moves high 16-bit to low 16-bit */ ret /* return (%eax) */ SET_SIZE(ntohs) + +/* + * uint16_t htobe16(uint16_t in); + * uint32_t htobe32(uint32_t in); + * uint64_t htobe64(uint64_t in); + * + * Byte swap 16, 32, and 64 bits respectively. + * eg. htons(), htonl(), and htonll(). + */ + ENTRY(htobe16) + movl %edi, %eax /* %eax = hs */ + bswap %eax /* reverses the byte order of %eax */ + shrl $16, %eax /* moves high 16-bit to low 16-bit */ + ret /* return (%eax) */ + SET_SIZE(htobe16) + + ENTRY(htobe32) + movl %edi, %eax /* %eax = hl */ + bswap %eax /* reverses the byte order of %eax */ + ret /* return (%eax) */ + SET_SIZE(htobe32) + + ENTRY(htobe64) + movq %rdi, %rax /* %rax = hll */ + bswapq %rax /* reverses the byte order of %rax */ + ret /* return (%rax) */ + SET_SIZE(htobe64) + + +/* + * uint16_t betoh16(uint16_t in) + * uint16_t be16toh(uint16_t in) + * + * Convert in to little endian, eg. ntohs() + */ + ENTRY(betoh16) + movl %edi, %eax /* %eax = hs */ + bswap %eax /* reverses the byte order of %eax */ + shrl $16, %eax /* moves high 16-bit to low 16-bit */ + ret /* return (%eax) */ + SET_SIZE(betoh16) + + ENTRY(be16toh) + movl %edi, %eax /* %eax = hs */ + bswap %eax /* reverses the byte order of %eax */ + shrl $16, %eax /* moves high 16-bit to low 16-bit */ + ret /* return (%eax) */ + SET_SIZE(be16toh) + + +/* + * uint32_t betoh32(uint32_t in) + * uint32_t be32toh(uint32_t in) + * + * Convert in to little endian, eg. ntohl() + */ + ENTRY(betoh32) + movl %edi, %eax /* %eax = hl */ + bswap %eax /* reverses the byte order of %eax */ + ret /* return (%eax) */ + SET_SIZE(betoh32) + + ENTRY(be32toh) + movl %edi, %eax /* %eax = hl */ + bswap %eax /* reverses the byte order of %eax */ + ret /* return (%eax) */ + SET_SIZE(be32toh) + + +/* + * uint64_t betoh64(uint64_t in) + * uint64_t be64toh(uint64_t in) + * + * Convert in to little endian, eg. ntohll() + */ + ENTRY(betoh64) + movq %rdi, %rax /* %rax = hll */ + bswapq %rax /* reverses the byte order of %rax */ + ret /* return (%rax) */ + SET_SIZE(betoh64) + + ENTRY(be64toh) + movq %rdi, %rax /* %rax = hll */ + bswapq %rax /* reverses the byte order of %rax */ + ret /* return (%rax) */ + SET_SIZE(be64toh) diff --git a/usr/src/lib/libc/amd64/gen/endian.c b/usr/src/lib/libc/amd64/gen/endian.c new file mode 100644 index 0000000000..b04a2d0b5b --- /dev/null +++ b/usr/src/lib/libc/amd64/gen/endian.c @@ -0,0 +1,74 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2015, Joyent, Inc. + */ + +/* + * General, no-op functions for endian(3C). The rest are in byteorder.s. + */ + +#include <endian.h> + +uint16_t +htole16(uint16_t in) +{ + return (in); +} + +uint32_t +htole32(uint32_t in) +{ + return (in); +} + +uint64_t +htole64(uint64_t in) +{ + return (in); +} + +uint16_t +letoh16(uint16_t in) +{ + return (in); +} + +uint16_t +le16toh(uint16_t in) +{ + return (in); +} + +uint32_t +letoh32(uint32_t in) +{ + return (in); +} + +uint32_t +le32toh(uint32_t in) +{ + return (in); +} + +uint64_t +letoh64(uint64_t in) +{ + return (in); +} + +uint64_t +le64toh(uint64_t in) +{ + return (in); +} diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com index 21adf0d5a1..c73b03879f 100644 --- a/usr/src/lib/libc/i386/Makefile.com +++ b/usr/src/lib/libc/i386/Makefile.com @@ -122,6 +122,7 @@ GENOBJS= \ byteorder64.o \ cuexit.o \ ecvt.o \ + endian.o \ errlst.o \ i386_data.o \ ladd.o \ diff --git a/usr/src/lib/libc/i386/gen/byteorder.s b/usr/src/lib/libc/i386/gen/byteorder.s index 9689b2b6bf..2b1204d1ba 100644 --- a/usr/src/lib/libc/i386/gen/byteorder.s +++ b/usr/src/lib/libc/i386/gen/byteorder.s @@ -21,6 +21,7 @@ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2015, Joyent, Inc. */ .file "byteorder.s" @@ -32,7 +33,9 @@ * As such, they could be implemented as a single routine, using * multiple ALTENTRY/SET_SIZE definitions. We don't do this so * that they will have unique addresses, allowing DTrace and - * other debuggers to tell them apart. + * other debuggers to tell them apart. With the endian + * functions we do the same, even though it's similarly + * repetitive. */ / unsigned long htonl( hl ) @@ -70,3 +73,61 @@ shrl $16, %eax / moves high 16-bit to low 16-bit ret / return (%eax) SET_SIZE(ntohs) + +/ uint16_t htobe16(uint16_t in) +/ +/ Convert in to big endian, eg. htons() +/ + ENTRY(htobe16) + movl 4(%esp), %eax / %eax = hs + bswap %eax / reverses the byte order of %eax + shrl $16, %eax / moves high 16-bit to low 16-bit + ret / return (%eax) + SET_SIZE(htobe16) + +/ uint32_t htobe32(uint32_t in) +/ +/ Convert in to big endian, eg. htonl() +/ + ENTRY(htobe32) + movl 4(%esp), %eax / %eax = hl + bswap %eax / reverses the byte order of %eax + ret / return (%eax) + SET_SIZE(htobe32) + +/ uint16_t betoh16(uint16_t in) +/ uint16_t be16toh(uint16_t in) +/ +/ Convert in to little endian, eg. ntohs() +/ + ENTRY(betoh16) + movl 4(%esp), %eax / %eax = hs + bswap %eax / reverses the byte order of %eax + shrl $16, %eax / moves high 16-bit to low 16-bit + ret / return (%eax) + SET_SIZE(betoh16) + + ENTRY(be16toh) + movl 4(%esp), %eax / %eax = hs + bswap %eax / reverses the byte order of %eax + shrl $16, %eax / moves high 16-bit to low 16-bit + ret / return (%eax) + SET_SIZE(be16toh) + + +/ uint32_t be32toh(uint32_t in) +/ uint32_t betoh32(uint32_t in) +/ +/ Convert in to little endian, eg. ntohl() +/ + ENTRY(be32toh) + movl 4(%esp), %eax / %eax = hl + bswap %eax / reverses the byte order of %eax + ret / return (%eax) + SET_SIZE(be32toh) + + ENTRY(betoh32) + movl 4(%esp), %eax / %eax = hl + bswap %eax / reverses the byte order of %eax + ret / return (%eax) + SET_SIZE(betoh32) diff --git a/usr/src/lib/libc/i386/gen/byteorder64.c b/usr/src/lib/libc/i386/gen/byteorder64.c index 3806a62f34..00c37d2a1b 100644 --- a/usr/src/lib/libc/i386/gen/byteorder64.c +++ b/usr/src/lib/libc/i386/gen/byteorder64.c @@ -22,6 +22,7 @@ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright (c) 2015, Joyent, Inc. */ #include <sys/isa_defs.h> @@ -47,4 +48,40 @@ ntohll(uint64_t in) return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32); } +uint64_t +htobe64(uint64_t in) +{ + return (htonl(in >> 32) | ((uint64_t)htonl(in) << 32)); +} + +uint64_t +htole64(uint64_t in) +{ + return (in); +} + +uint64_t +betoh64(uint64_t in) +{ + return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32); +} + +uint64_t +letoh64(uint64_t in) +{ + return (in); +} + +uint64_t +be64toh(uint64_t in) +{ + return (ntohl(in >> 32) | (uint64_t)ntohl(in) << 32); +} + +uint64_t +le64toh(uint64_t in) +{ + return (in); +} + #endif /* (_BIG_ENDIAN) || _LP64) && !__lint */ diff --git a/usr/src/lib/libc/i386/gen/endian.c b/usr/src/lib/libc/i386/gen/endian.c new file mode 100644 index 0000000000..580c965406 --- /dev/null +++ b/usr/src/lib/libc/i386/gen/endian.c @@ -0,0 +1,57 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2015, Joyent, Inc. + */ + +#include <sys/isa_defs.h> +#include <endian.h> + +/* + * General endian(3C) functions that are basically no-ops. + */ + +uint16_t +letoh16(uint16_t in) +{ + return (in); +} + +uint16_t +le16toh(uint16_t in) +{ + return (in); +} + +uint32_t +letoh32(uint32_t in) +{ + return (in); +} + +uint32_t +le32toh(uint32_t in) +{ + return (in); +} + +uint16_t +htole16(uint16_t in) +{ + return (in); +} + +uint32_t +htole32(uint32_t in) +{ + return (in); +} diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers index 78e2707b49..afb07a4bb9 100644 --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -93,6 +93,28 @@ $if _x86 && _ELF64 $add amd64 $endif +SYMBOL_VERSION ILLUMOS_0.22 { # endian(3C) + protected: + htobe16; + htobe32; + htobe64; + htole16; + htole32; + htole64; + betoh16; + letoh16; + be16toh; + le16toh; + betoh32; + letoh32; + be32toh; + le32toh; + betoh64; + letoh64; + be64toh; + le64toh; +} ILLUMOS_0.21; + SYMBOL_VERSION ILLUMOS_0.21 { protected: pthread_attr_get_np; diff --git a/usr/src/lib/libc/sparc/Makefile.com b/usr/src/lib/libc/sparc/Makefile.com index 5302bb8ebd..062949b3f9 100644 --- a/usr/src/lib/libc/sparc/Makefile.com +++ b/usr/src/lib/libc/sparc/Makefile.com @@ -147,6 +147,7 @@ GENOBJS= \ byteorder.o \ cuexit.o \ ecvt.o \ + endian.o \ errlst.o \ getctxt.o \ ladd.o \ @@ -1189,6 +1190,7 @@ SRCS= \ $(LIBCBASE)/gen/_xregs_clrptr.c \ $(LIBCBASE)/gen/byteorder.c \ $(LIBCBASE)/gen/ecvt.c \ + $(LIBCBASE)/gen/endian.c \ $(LIBCBASE)/gen/getctxt.c \ $(LIBCBASE)/gen/lmul.c \ $(LIBCBASE)/gen/makectxt.c \ diff --git a/usr/src/lib/libc/sparc/gen/endian.c b/usr/src/lib/libc/sparc/gen/endian.c new file mode 100644 index 0000000000..b19974b86a --- /dev/null +++ b/usr/src/lib/libc/sparc/gen/endian.c @@ -0,0 +1,158 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2015, Joyent, Inc. + */ + +/* + * endian(3C) routines + */ + +uint16_t +htole16(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint32_t +htole32(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint64_t +htole64(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +uint16_t +letoh16(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint16_t +le16toh(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint32_t +letoh32(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint32_t +le32toh(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint64_t +letoh64(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +uint64_t +le64toh(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +/* Anything to or from big-endian is a no-op */ + +uint16_t +htobe16(uint16_t in) +{ + return (in); +} + +uint32_t +htobe32(uint32_t in) +{ + return (in); +} + +uint64_t +htobe64(uint64_t in) +{ + return (in); +} + +uint16_t +betoh16(uint16_t in) +{ + return (in); +} + +uint16_t +be16toh(uint16_t in) +{ + return (in); +} + +uint32_t +betoh32(uint32_t in) +{ + return (in); +} + +uint32_t +be32toh(uint32_t in) +{ + return (in); +} + +uint64_t +betoh64(uint64_t in) +{ + return (in); +} + +uint64_t +be64toh(uint64_t in) +{ + return (in); +} diff --git a/usr/src/lib/libc/sparcv9/Makefile.com b/usr/src/lib/libc/sparcv9/Makefile.com index d323044aff..596d349dfb 100644 --- a/usr/src/lib/libc/sparcv9/Makefile.com +++ b/usr/src/lib/libc/sparcv9/Makefile.com @@ -147,6 +147,7 @@ GENOBJS= \ byteorder.o \ cuexit.o \ ecvt.o \ + endian.o \ getctxt.o \ lock.o \ makectxt.o \ @@ -1118,6 +1119,7 @@ SRCS= \ $(LIBCBASE)/crt/_ftou.c \ $(LIBCBASE)/gen/_xregs_clrptr.c \ $(LIBCBASE)/gen/byteorder.c \ + $(LIBCBASE)/gen/endian.c \ $(LIBCBASE)/gen/ecvt.c \ $(LIBCBASE)/gen/getctxt.c \ $(LIBCBASE)/gen/makectxt.c \ diff --git a/usr/src/lib/libc/sparcv9/gen/endian.c b/usr/src/lib/libc/sparcv9/gen/endian.c new file mode 100644 index 0000000000..b19974b86a --- /dev/null +++ b/usr/src/lib/libc/sparcv9/gen/endian.c @@ -0,0 +1,158 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright (c) 2015, Joyent, Inc. + */ + +/* + * endian(3C) routines + */ + +uint16_t +htole16(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint32_t +htole32(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint64_t +htole64(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +uint16_t +letoh16(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint16_t +le16toh(uint16_t in) +{ + return (((in & 0xff) << 8) | ((in & 0xff00) >> 8)); +} + +uint32_t +letoh32(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint32_t +le32toh(uint32_t in) +{ + return (((in & 0xffUL) << 24) | + (in & 0xff00UL) << 8 | + (in & 0xff0000UL) >> 8 | + ((in & 0xff000000UL) >> 24)); +} + +uint64_t +letoh64(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +uint64_t +le64toh(uint64_t in) +{ + return (((in & 0xffULL) << 56) | + ((in & 0xff00ULL) << 40) | + ((in & 0xff0000ULL) << 24) | + ((in & 0xff000000ULL) << 8) | + ((in & 0xff00000000ULL) >> 8) | + ((in & 0xff0000000000ULL) >> 24) | + ((in & 0xff000000000000ULL) >> 40) | + ((in & 0xff00000000000000ULL) >> 56)); +} + +/* Anything to or from big-endian is a no-op */ + +uint16_t +htobe16(uint16_t in) +{ + return (in); +} + +uint32_t +htobe32(uint32_t in) +{ + return (in); +} + +uint64_t +htobe64(uint64_t in) +{ + return (in); +} + +uint16_t +betoh16(uint16_t in) +{ + return (in); +} + +uint16_t +be16toh(uint16_t in) +{ + return (in); +} + +uint32_t +betoh32(uint32_t in) +{ + return (in); +} + +uint32_t +be32toh(uint32_t in) +{ + return (in); +} + +uint64_t +betoh64(uint64_t in) +{ + return (in); +} + +uint64_t +be64toh(uint64_t in) +{ + return (in); +} |
